API
Set Admin Duty by Player ID
If you want to add an option to set admin duty by player ID (the player must have the necessary permissions to be assigned admin duty), you can create a new file in the server/lib
folder. You can name the file, for example, customAdminDuty.lua
, or anything else you prefer.
In this file, add two server-side events that can be triggered to enable admin duty for a specified player by their ID.
AddEventHandler('rcore_report:server_setAdminDutyOn', function(playerId)
if hasAdminPermissions(playerId) then
local isSuperAdmin = hasSuperAdminPermissions(playerId)
setAdminDutyOn(playerId, isSuperAdmin)
end
end)
AddEventHandler('rcore_report:server_setAdminDutyOff', function(playerId)
setAdminDutyOff(playerId)
end)
If you also want to add commands for that, you can include them below the events. Do not forget to rename the commands.
RegisterCommand('COMMAND_TO_TOGGLE_DUTY_FOR_ADMIN_ON', function(source, args)
local playerId = tonumber(args[1])
-- Check for the permissions required to use this command here.
if not hasAdminPermissions(source) then
sendNotification(source, 'You don\'t have permissions to use this command.')
return
end
-- Checks if playerId is used
if not playerId then
sendNotification(source, 'You need to specify the player\'s ID for this command.')
return
end
-- Checks if player exist
if not GetPlayerName(playerId) then
sendNotification(source, 'The player with the specified ID is not online.')
return
end
-- Check for the permissions of the selected player.
if not hasAdminPermissions(playerId) then
sendNotification(source, 'The player with the specified ID does not have admin permissions.')
return
end
TriggerEvent('rcore_report:server_setAdminDutyOn', playerId)
end)
RegisterCommand('COMMAND_TO_TOGGLE_DUTY_FOR_ADMIN_OFF', function(source, args)
local playerId = tonumber(args[1])
-- Check for the permissions required to use this command here.
if not hasAdminPermissions(source) then
sendNotification(source, 'You don\'t have permissions to use this command.')
return
end
-- Checks if playerId is used
if not playerId then
sendNotification(source, 'You need to specify the player\'s ID for this command.')
return
end
-- Checks if player exist
if not GetPlayerName(playerId) then
sendNotification(source, 'The player with the specified ID is not online.')
return
end
-- Check for the permissions of the selected player.
if not hasAdminPermissions(playerId) then
sendNotification(source, 'The player with the specified ID does not have admin permissions.')
return
end
TriggerEvent('rcore_report:server_setAdminDutyOff', playerId)
end)
Last updated
Was this helpful?