Module Creation - Partixel/v-handle GitHub Wiki

In this page we will go through all it takes to make modules, what is required and what they can do.

An example module can be found here. This contains full documentation with more up-to-date information then this page.

To start, create a new table, preferably called Module, aka local Module = {}

Now give it some information, firstly give it a name Module.Name = "Default" and a description Module.Description = "Default Module"

Now for the basic things your module can do, such as adding commands or running custom hooks.

Adding a command:

First, create the modules command list, Module.Commands = {} Now add a command, you may add as many as you want here. Module.Commands.DefaultCommand = { } In that table, add all the things your command may need as follows.

  • Aliases = {"AnotherCommand"} -- Names that can be used to run the command as well as the key
  • Prefix = "!" -- The character(s) that needs to be put before the command
  • Description = "Does default stuff" -- The desciption of the command for display
  • Usage = "<Player>" -- A description of how the command is used
  • Permission = "SetRank" -- The permission required to run the command
  • MinArgs = 2 -- The minimum amount of arguements needed for the command

Now give your command a Run function and carry out all code you need in there. function Module.Commands.DefaultCommand.Run(Player, Args, Alias, RankID, Perm) end

Now tell v-handle what variables can be entered for this command with a Vars function.

function Module.Commands.DefaultCommand.Vars(ArgNumber) end

To use it, simply return a table of strings for what can be inputted, aka: return {"1", "2", "Three", "Ok"}

You can also add console commands similarly using Module.ConCommands instead of Module.Commands

It only allows the arguments Player, Command, Args

Adding a hook:

Adding a hook is really simple, you could do it the usual way, but it is easier and more efficient to let v-handle run them.

Start by making a table filled with information. Module.Hooks = { } Add another table instead for each hook you want to add. {Type = "PlayerSay", Run = PlayerTalked} Type refers to the hook you want to be used (Default garrysmod hook names) and Run refers to the function you want to call when the hook is triggered.

Registering your module

All it takes is a simple one line of code to register your module so that it is recognized by v-handle. vh.RegisterModule(Module)

Extras

There are a few extra things you can use with your module, firstly, Module.Disabled = true will make your module disabled and not allow it to run. Also, you can add pre-cached strings with your module to increase efficiency. Module.PrecacheStrings = { } Inside that table add your pre-caches in this format: dstr = "_white_ Ran _red_ default _blue_ command" To run that simply use "dstr" in your messages and it will auto be replaced.

⚠️ **GitHub.com Fallback** ⚠️