[Release] Command Processor

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.

1 Like

Very nice!

Work for freeroam resource? Thx for support

@KawatarY Works on pretty much everything as long as the command resource and chat resource are enabled and the required modifications are done to the chat resource.

Hey not sure if you could give some direction. I’m trying get this command processor to work with the FreeRoam gamemode - By kanersps. I followed the setup guide but I’m having no luck.
If you can give any kind of suggests or guidance I would appreciate it immensely.
This is the log I get when connecting to the server.
Server Log
Thank you

@PsYiiX FreeRoam is broken like said in the topic.

@kanersps Okay thanks for the response, I appreciate it.

i do not understand how to install this can somebody please explain it to me in a simpler way? thanks

  1. Download
  2. Extract the contents (lua files) of the first folder in your resource scripts folder / whatever it is
  3. Add each script to the __resource.lua file, one is used for the client client_commands.lua and the other one is used for the server server_commands.lua
  4. Write a command and try it out!

If you have any more questions let me know and I’ll try to help!

one more question if i want to add a command where do i put it?
just like the other scripts in the resources folder or do i put it in the command processor folder?

In any given script. Just make sure the command starts with CMD_ and that server_commands.lua is always the last script in the __resource.lua list (always at the bottom), otherwise it won’t find the command.
Here’s an example on how to implement commands:

This part confuses me, probably more than it should. Inside the folder I downloaded, I have two folders (‘client’ and ‘server’) along with ‘License’. There’s no _resource.lua. I’m not sure what you mean by ‘main resource file named resource.lua’ and I don’t understand where to place server/servercommands.lua.

New to commands and never had luck getting it to work before.

I updated the guide. It should be more clear now.

This used to work perfectly for me.
But now I add it to my resource it now stops the map resource from running.
as soon as I add “client/client_commands.lua” , “server/servercommands.lua” to __resources.lua to be loaded to the server it just doesn’t load the resource.

I’ve tested it on a fresh server and still the same.

is anyone else having this issue?

cheers

It’s supposed to be server/server_commands.lua are you sure you got that right?

I actually just noticed the markup messed up and was showing server/servercommands.lua in the guide instead of just server/server_commands.lua which would be the correct one. Fixed, my apologies.

That’ll be why! Lol I shoulda figured that out myself.
Cheers man.

Still no luck?
I’ve made sure it’s all correct but the resource is still not loading when I add :
server/server_commands.lua
server/servercommands.lua
to the resource __resource.lua.

As soon as I delete it again it loads up fine.

Is anyone else having similar issue?

#__resource.lua file

client_scripts {
	"client/yourscripts.lua",
	"client/client_commands.lua"
}

server_scripts {
	"server/yourscripts.lua",
	"server/server_commands.lua"
}

server/server_commands.lua and client/client_commands.lua should always be last in the resource list.