Introduction
I’d like to introduce you to a new command processor that’ll make writing commands extremely simple.
Why?
Main reason is how simple it is to implement commands with this processor and the fact that commands won’t be centralized any longer (all in a single file). It’s also way cleaner in the way that it allows you to have more control over commands and restrict some of them if that’s something you might want to do (Think of it as an admin system, no need to write checks inside the command, instead you can just disable such command for anyone less than a specific rank).
Setup Guide:
Setting up the command processor is pretty simple. All you do once you download or clone the repository is extract the contents of (FiveReborn_CMD_Processor-master\resources\your-custom-resource
) into the resource folder where you want to utilize the command processor. FiveRebornServerFolder\resources\your-custom-resource-folder-name\
.
For example mine could be FiveRebornServerFolder\resources\fivem-map-skater\
.
You will see something like the following once you open the zip file and go into your-custom-resource
directory:
The command processor will replace your chat resource in resources\[system]\chat so make sure you back up anything you may fear losing before replacing. This command processor no longer replaces the chat resource.
resource file:
In your main resource file (named __resource.lua) inside your custom server resource folder add server/server_commands.lua
and client/client_commands.lua
to the list so the lua scripts get loaded upon server startup. Also make sure the server folder path matches the one on the list, otherwise the script won’t load. Refer to setup guide before doing this step.
#__resource.lua file example:
client_scripts {
"client/yourscripts.lua",
"client/client_commands.lua"
}
server_scripts {
"server/yourscripts.lua",
"server/server_commands.lua"
}
Ready to go!
That’s pretty much it, you should be able to write commands now, check the wiki (Implementing Commands) for information on how to do that.
Brief Guide:
http://i.imgur.com/qVIpbwp.png
Brief explanation on what some functions do
- chatCommandEntered: Gets executed when a command is entered to later start processing the command.
- ProcessedCMD: Is the function that is responsible for executing the command and returning one of the success codes which are:
CMD_EXIT_CODE_PREPROC_NOT_ALLOWED
,CMD_EXIT_CODE_SUCCESS
. - parseInput: This function can be used to validate the parameters that were sent to the command, it basically acts as a sscanf except that it doesn’t output anything at the moment, it’s just used for validation. Returns greater than 0 if everything matches, false if not.
local arguments = argsToLocals(args)
if parseInput("fffsd", arguments) then --simply makes sure all the entered arguments are valid
local x, y, z, name, money = table.unpack(arguments)
TriggerClientEvent('chatMessage', source, '', { 0, 255, 0 }, 'Successful: ' .. x .. ' ' .. y .. ' ' .. z .. ' ' .. name .. ' ' .. money)
else
TriggerClientEvent('chatMessage', source, '', { 255, 0, 0 }, 'Error.')
end
- unloadExcludedCMDSForPlayer: Unloads commands that may have been excluded for a player before.
- excludeCMDForPlayer: Excludes a command for a player.
- isCMDExcludedForPlayer: Checks if a command is excluded and returns true if it is.
- Command_GetNext_Wrapper: Will return the name of the command from a table by index for any given player.
- getRegisteredCommandCount: Will return the amount of commands currently registered on the server.
- getMaxCommands: Gets the maximum command limit in the server defined by
MAX_COMMANDS
.
function CMD_commands(source, args, help)
if help then
TriggerClientEvent('chatMessage', source, '', {0,0,0}, 'Shows commands')
end
for i = 1, getRegisteredCommandCount(source) do
TriggerClientEvent('chatMessage', source, '', {0,0,0}, "/" .. Command_GetNext_Wrapper(source, i))
end
end
A simple command:
function CMD_testcmd(source, args, help)
if help then
TriggerClientEvent('chatMessage', source, '', { 0, 0, 0 }, 'Test command.')
end
local arguments = argsToLocals(args)
if parseInput("fffsd", arguments) then --simply makes sure all the entered arguments are valid
local x, y, z, name, money = table.unpack(arguments)
TriggerClientEvent('chatMessage', source, '', { 0, 255, 0 }, 'Successful: ' .. x .. ' ' .. y .. ' ' .. z .. ' ' .. name .. ' ' .. money)
else
TriggerClientEvent('chatMessage', source, '', { 255, 0, 0 }, 'Error.')
end
end
Download - Github - Wiki
Enjoy and feel free to report any bugs you may find.