Functions Information regarding boii_base server command functions
Locals
Local functions are assigned to the boii object you can access this object by adding the export below into your server side files.
Copy local boii = exports[ 'boii_base' ]: get_object ()
Copy boii.register_command = register_command
has_permission(unique_id, required_rank)
Function to check if a user has the required permissions to use the command.
Copy local function has_permission ( unique_id , required_rank )
local function get_user_data ( unique_id )
local query = 'SELECT * FROM users WHERE unique_id = ?'
local params = {unique_id}
local result = MySQL.query. await (query, params)
if # result > 0 then return result[ 1 ] end
end
local user_data = get_user_data (unique_id)
if not user_data then print ( 'user data not found' ) return false end
local user_rank = user_data.rank
required_rank = type (required_rank) == "table" and required_rank or {required_rank}
for _, rank in ipairs (required_rank) do
if rank == user_rank or rank == 'all' then return true end
end return false
end
register_chat_suggestion(command, help, params)
Function to register chat suggestions for the commands
Copy local function register_chat_suggestion ( command , help , params )
chat_suggestions[ # chat_suggestions + 1 ] = {command = command, help = help, params = params}
end
register_command(command, required_rank, help, params, handler)
Function to register a new command on the server
Copy boii.register_command('server_example', {'civ'}, 'Example command', {{name = 'param1', help = 'First parameter'}}, function(source, args, raw)
TriggerClientEvent ( 'chat:addMessage' , source, {args = { '^2Success' , 'Example server command executed.' }})
end )
Copy local function register_command ( command , required_rank , help , params , handler )
if help and params then
register_chat_suggestion (command, help, params)
end
RegisterCommand (command, function ( source , args , raw )
local user = boii. get_user (source)
local unique_id = user.unique_id
if not required_rank or required_rank == 'all' or has_permission (unique_id, required_rank) then
handler (source, args, raw)
else
TriggerClientEvent('chat:addMessage', source, {args = {'^1SYSTEM', 'You do not have permission to execute this command.'}})
end
end , false )
end