Creating your own custom commands
Epic! You will require a basic understanding of Lua to create a custom command.
I've created the system to be relatively easy to create your own commands. Although, you will require some Lua experience to get this prepared. If you're an xPanel Pro buyer, you can get full setup support!
Make sure to check out our reference guide first if you need a sense of our ranks and stuff of the sorts.
Creating your first custom command!
All custom commands are added through the configuration side of xPanel.
Your configuration folder should be set up like this:
--> Folder
--> Commands
--> CustomCommands
--> Modifications
--> Main
We're interested in the "CustomCommands" module. Once you open the module it may seem intimidating. Once you learn how it works, this is an extremely easy to use system.
Here's a sample command:
testCommand = {
aliases = { --> Aliases, the command can also be run under these names:
"test",
"debug"
};
level = 6; --> The command's level!
category = "Misc";
name = "eval"; --> The command's main name, this is the display name as well.
args = {
{
name = "Target"; --> Argument name, this will be displayed ;test <Target> <Text>
class = "player"; --> The argument class
allowAll = true; --> Allow stuff like "others","all", or "me"
teamsAllowed = true; --> Can you do stuff like "%neutral"?
wrapPlayer = true; --> Run a custom wrapping function, this will add custom properties to the player!
default = "speaker" --> If a player parameter is not provided, and it's the only argument it will be overriden by the speaker. Ex: ;fly will be equivalent to ;fly me
},
{
name = "Text";
class = "string";
untilEnd = true;
}
};
description = "A cool command."; --> The command's description!
onSyntaxError = function(syntaxError, message)
print(syntaxError, message) --> This function will be called when a syntax error occurs.
end,
onPermissionError = function(user, message, info)
print(message) --> This function will be called when a permission error occurs.
end,
callback = function(speaker, message, args)
print(args[1],args[2]) --> Sample output: table: 0xecb5049f0tFf894c example string
end
};
You will require the values:
aliases <table> (can be left blank)
level <int>
category <string>
name <string>
args <table>
description <string>
callback <function>
Optional values:
onSyntaxError <function>
onPermissionError <function>
Let's set up a basic speed command!
First, add it to the custom commands table like this:
walkspeed = {
};
This will define it, but if you start the game you'll notice it errors. This is because we haven't defined anything inside of it.
Let's give it a name, alias, description, category, and assign a level.
walkspeed = {
name = "speed"; --> The command's name.
aliases = {"ws","walkspeed"}; -- Add an "alias" separated by a ","
level = 2; --> Moderators are the only role that can run this.
category = "Fun"; --> The category it's assigned to.
description = "Let's run!"; --> The command's description.
}
The name is what you'll by default run it by. Ex: ;speed me 50
The alias is a secondary name if you want it to be run by multiple names.
The level can be found in our reference guide and is the permission required to run the command.
The category is where the command is located with our help command.
The description will be shown in the help menu.
This will normally error, but check out how to remove commands and remove the default speed command if you're going to be testing this alongside the tutorial.
Let's give the command some arguments!
walkspeed = {
name = "speed"; --> The command's name.
aliases = {"ws","walkspeed"}; -- Add an "alias" separated by a ","
level = 2; --> Moderators are the only role that can run this.
category = "Fun"; --> The category it's assigned to.
description = "Let's run!"; --> The command's description.
args = {
{
name = "Target"; --> The argument name, this will display it as this for an example: ;ws <Target> <Speed>
class = "player"; --> The type of argument, see our reference guide for help on this.
allowAll = true; --> This will allow methods such as "all","others", and "me".
teamsAllowed = true; --> Allow methods like ;ws %neutral 50 to work.
wrapPlayer = true; --> For more advanced developers, this will create a custom player object.
default = "speaker"; --> If this is a single-argument command this will set the default to the player who ran the command. Ex: ";fly" will be the same as ";fly me"
}
}
}
This will create the target argument! This allows you to define your target when running the command. Check out the reference guide for help on types of arguments and what they do.
Let's add the speed argument!
walkspeed = {
name = "speed"; --> The command's name.
aliases = {"ws","walkspeed"}; -- Add an "alias" separated by a ","
level = 2; --> Moderators are the only role that can run this.
category = "Fun"; --> The category it's assigned to.
description = "Let's run!"; --> The command's description.
args = {
{
name = "Target"; --> The argument name, this will display it as this for an example: ;ws <Target> <Speed>
class = "player"; --> The type of argument, see our reference guide for help on this.
allowAll = true; --> This will allow methods such as "all","others", and "me".
teamsAllowed = true; --> Allow methods like ;ws %neutral 50 to work.
wrapPlayer = true; --> For more advanced developers, this will create a custom player object.
default = "speaker"; --> If this is a single-argument command this will set the default to the player who ran the command. Ex: ";fly" will be the same as ";fly me"
},
{
name = "Speed"; --> The argument name, this will display it as this for an example: ;ws <Target> <Speed>
class = "int"; --> The type of argument, see our reference guide for help on this.
floor = true; --> This will remove decimals that the user may send in.
}
}
}
This will create the number argument, so you can set their speed to what you want it to be.
Let's give the command it's callbacks!
walkspeed = {
name = "speed"; --> The command's name.
aliases = {"ws","walkspeed"}; -- Add an "alias" separated by a ","
level = 2; --> Moderators are the only role that can run this.
category = "Fun"; --> The category it's assigned to.
description = "Let's run!"; --> The command's description.
args = {
{
name = "Target"; --> The argument name, this will display it as this for an example: ;ws <Target> <Speed>
class = "player"; --> The type of argument, see our reference guide for help on this.
allowAll = true; --> This will allow methods such as "all","others", and "me".
teamsAllowed = true; --> Allow methods like ;ws %neutral 50 to work.
wrapPlayer = true; --> For more advanced developers, this will create a custom player object.
default = "speaker"; --> If this is a single-argument command this will set the default to the player who ran the command. Ex: ";fly" will be the same as ";fly me"
},
{
name = "Speed"; --> The argument name, this will display it as this for an example: ;ws <Target> <Speed>
class = "int"; --> The type of argument, see our reference guide for help on this.
floor = true; --> This will remove decimals that the user may send in.
}
};
onSyntaxError = function(syntaxError,message) --> This will be called when someone wrongly calls the command.
print(syntaxError,'on command:',message);
end;
callback = function(speaker,message,arguments) --> This will be called when the command is successfully parsed and arguments are created.
for _,v in pairs(arguments[1]) do --> Loop through the players sent
if(v.Character ~= nil) then --> Check if their character exists
v.Character.Humanoid.WalkSpeed = arguments[2]; --> Set their walkspeed!
end
end
end
}
List of available callbacks:
onPermissionError
onSyntaxError
callback
The callback is called with 3 arguments listed above: speaker,message, and argument. The code above will loop through the targets selected, check if their character exists and if it does then it'll set their speed.
Last updated
Was this helpful?