RSGCore Server Event Reference
This documentation covers all available server-side events in the RSGCore framework, including detailed usage examples and implementation details.
Table of Contents
- RSGCore:Server:CloseServer
- RSGCore:Server:OpenServer
- RSGCore:UpdatePlayer
- RSGCore:Server:SetMetaData
- RSGCore:ToggleDuty
- RSGCore:CallCommand
RSGCore:Server:CloseServer > Description
Event to check if the server is closed and handle server closure with optional reason. This event kicks all non-whitelisted players when triggered by an admin.
RSGCore:Server:CloseServer > Event Handler
RegisterNetEvent('RSGCore:Server:CloseServer', function(reason)
local src = source
if RSGCore.Functions.HasPermission(src, 'admin') then
reason = reason or 'No reason specified'
RSGCore.Config.Server.Closed = true
RSGCore.Config.Server.ClosedReason = reason
for k in pairs(RSGCore.Players) do
if not RSGCore.Functions.HasPermission(k, RSGCore.Config.Server.WhitelistPermission) then
RSGCore.Functions.Kick(k, reason, nil, nil)
end
end
else
RSGCore.Functions.Kick(src, 'You don\'t have permissions for this..', nil, nil)
end
end)
RSGCore:Server:CloseServer > Parameters
reason(string, optional) - Reason for server closure (defaults to 'No reason specified')
RSGCore:Server:CloseServer > Behavior
- Permission Check: Verifies the triggering player has 'admin' permissions
- Server State: Sets
RSGCore.Config.Server.Closed = true - Reason Storage: Stores the closure reason in
RSGCore.Config.Server.ClosedReason - Player Removal: Kicks all players without whitelist permissions
- Security: Kicks unauthorized players attempting to use this event
RSGCore:Server:CloseServer > Usage Examples > Triggering from Client
-- Close server with custom reason
TriggerServerEvent('RSGCore:Server:CloseServer', 'Server maintenance in progress')
-- Close server with default reason
TriggerServerEvent('RSGCore:Server:CloseServer')
RSGCore:Server:CloseServer > Usage Examples > Server-side Trigger
-- Emergency server closure
TriggerEvent('RSGCore:Server:CloseServer', 'Emergency maintenance required')
RSGCore:Server:CloseServer > Use Cases
- Emergency server maintenance
- Scheduled maintenance periods
- Administrative server control
- Security lockdowns
RSGCore:Server:OpenServer > Description
Event to open the server and allow new connections. This reverses the effects of the CloseServer event.
RSGCore:Server:OpenServer > Event Handler
RegisterNetEvent('RSGCore:Server:OpenServer', function()
local src = source
if RSGCore.Functions.HasPermission(src, 'admin') then
RSGCore.Config.Server.Closed = false
else
RSGCore.Functions.Kick(src, 'You don\'t have permissions for this..', nil, nil)
end
end)
RSGCore:Server:OpenServer > Parameters
None
RSGCore:Server:OpenServer > Behavior
- Permission Check: Verifies the triggering player has 'admin' permissions
- Server State: Sets
RSGCore.Config.Server.Closed = false - Security: Kicks unauthorized players attempting to use this event
RSGCore:Server:OpenServer > Usage Examples > Triggering from Client
-- Open server for normal operations
TriggerServerEvent('RSGCore:Server:OpenServer')
RSGCore:Server:OpenServer > Usage Examples > Server-side Trigger
-- Programmatically open server
TriggerEvent('RSGCore:Server:OpenServer')
RSGCore:Server:OpenServer > Use Cases
- Ending maintenance periods
- Reopening after emergency closure
- Administrative server management
- Automated server scheduling
RSGCore:UpdatePlayer > Description
Event for updating and saving player data, specifically handling hunger and thirst degradation over time.
RSGCore:UpdatePlayer > Event Handler
RegisterNetEvent('RSGCore:UpdatePlayer', function()
local src = source
local Player = RSGCore.Functions.GetPlayer(src)
if not Player then return end
local newHunger = Player.PlayerData.metadata['hunger'] - RSGCore.Config.Player.HungerRate
local newThirst = Player.PlayerData.metadata['thirst'] - RSGCore.Config.Player.ThirstRate
if newHunger <= 0 then newHunger = 0 end
if newThirst <= 0 then newThirst = 0 end
Player.Functions.SetMetaData('thirst', newThirst)
Player.Functions.SetMetaData('hunger', newHunger)
TriggerClientEvent('hud:client:UpdateNeeds', src, newHunger, newThirst)
Player.Functions.Save()
end)
RSGCore:UpdatePlayer > Parameters
None
RSGCore:UpdatePlayer > Behavior
- Player Validation: Checks if player exists
- Hunger Calculation: Reduces hunger by configured rate
- Thirst Calculation: Reduces thirst by configured rate
- Bounds Checking: Ensures values don't go below 0
- Metadata Update: Updates player metadata
- Client Sync: Triggers HUD update on client
- Data Persistence: Saves player data to database
RSGCore:UpdatePlayer > Configuration
The degradation rates are controlled by:
RSGCore.Config.Player.HungerRate- Amount of hunger lost per updateRSGCore.Config.Player.ThirstRate- Amount of thirst lost per update
RSGCore:UpdatePlayer > Usage Examples > Manual Trigger
-- Trigger player update from client
TriggerServerEvent('RSGCore:UpdatePlayer')
RSGCore:UpdatePlayer > Usage Examples > Automated System
-- Server-side timer for regular updates
CreateThread(function()
while true do
Wait(60000) -- Update every minute
for playerId in pairs(RSGCore.Players) do
TriggerEvent('RSGCore:UpdatePlayer')
end
end
end)
RSGCore:UpdatePlayer > Use Cases
- Automatic hunger/thirst degradation
- Survival gameplay mechanics
- Resource management systems
- Player status synchronization
RSGCore:Server:SetMetaData > Description
Event to set a player's metadata with built-in validation for hunger and thirst values.
RSGCore:Server:SetMetaData > Event Handler
RegisterNetEvent('RSGCore:Server:SetMetaData', function(meta, data)
local src = source
local Player = RSGCore.Functions.GetPlayer(src)
if meta == 'hunger' or meta == 'thirst' then
if data > 100 then
data = 100
end
end
if Player then
Player.Functions.SetMetaData(meta, data)
end
TriggerClientEvent('hud:client:UpdateNeeds', src, Player.PlayerData.metadata['hunger'], Player.PlayerData.metadata['thirst'])
end)
RSGCore:Server:SetMetaData > Parameters
meta(string) - The metadata key to setdata(any) - The value to set for the metadata
RSGCore:Server:SetMetaData > Behavior
- Player Validation: Checks if player exists
- Value Capping: Limits hunger and thirst to maximum of 100
- Metadata Update: Sets the specified metadata
- HUD Sync: Updates client HUD with current hunger/thirst values
RSGCore:Server:SetMetaData > Usage Examples > Setting Hunger
-- Set player hunger to 50
TriggerServerEvent('RSGCore:Server:SetMetaData', 'hunger', 50)
RSGCore:Server:SetMetaData > Usage Examples > Setting Thirst
-- Set player thirst to 75
TriggerServerEvent('RSGCore:Server:SetMetaData', 'thirst', 75)
RSGCore:Server:SetMetaData > Usage Examples > Setting Custom Metadata
-- Set custom metadata
TriggerServerEvent('RSGCore:Server:SetMetaData', 'stress', 25)
TriggerServerEvent('RSGCore:Server:SetMetaData', 'reputation', 100)
RSGCore:Server:SetMetaData > Usage Examples > Server-side Usage
-- Set metadata from server
local playerId = source
TriggerEvent('RSGCore:Server:SetMetaData', 'hunger', 100) -- Full hunger
RSGCore:Server:SetMetaData > Use Cases
- Consumable item effects
- Status effect applications
- Admin commands for player management
- Quest/event rewards
- Punishment systems
RSGCore:ToggleDuty > Description
Event to toggle a player's duty status for their current job.
RSGCore:ToggleDuty > Event Handler
RegisterNetEvent('RSGCore:ToggleDuty', function()
local src = source
local Player = RSGCore.Functions.GetPlayer(src)
if not Player then return end
if Player.PlayerData.job.onduty then
Player.Functions.SetJobDuty(false)
TriggerClientEvent('RSGCore:Notify', src, Lang:t('info.off_duty'))
else
Player.Functions.SetJobDuty(true)
TriggerClientEvent('RSGCore:Notify', src, Lang:t('info.on_duty'))
end
TriggerClientEvent('RSGCore:Client:SetDuty', src, Player.PlayerData.job.onduty)
end)
RSGCore:ToggleDuty > Parameters
None
RSGCore:ToggleDuty > Behavior
- Player Validation: Checks if player exists
- Duty Toggle: Switches between on-duty and off-duty states
- Notification: Sends appropriate notification to player
- Client Sync: Updates client-side duty status
RSGCore:ToggleDuty > Notifications
- On Duty: Shows language-translated 'on_duty' message
- Off Duty: Shows language-translated 'off_duty' message
RSGCore:ToggleDuty > Usage Examples > Client Toggle
-- Toggle duty status
TriggerServerEvent('RSGCore:ToggleDuty')
RSGCore:ToggleDuty > Usage Examples > Command Implementation
-- Create a command for duty toggle
RegisterCommand('duty', function()
TriggerServerEvent('RSGCore:ToggleDuty')
end)
RSGCore:ToggleDuty > Usage Examples > UI Integration
-- Button click handler in UI
RegisterNUICallback('toggleDuty', function()
TriggerServerEvent('RSGCore:ToggleDuty')
end)
RSGCore:ToggleDuty > Use Cases
- Police/EMS duty systems
- Job-based access control
- Salary/payment systems
- Role-playing mechanics
- Administrative job management
RSGCore:CallCommand > Description
Event to trigger a command outside the chat system with full permission checking and argument validation.
RSGCore:CallCommand > Event Handler
RegisterNetEvent('RSGCore:CallCommand', function(command, args)
local src = source
if not RSGCore.Commands.List[command] then return end
local Player = RSGCore.Functions.GetPlayer(src)
if not Player then return end
local hasPerm = RSGCore.Functions.HasPermission(src, "command."..RSGCore.Commands.List[command].name)
if hasPerm then
if RSGCore.Commands.List[command].argsrequired and #RSGCore.Commands.List[command].arguments ~= 0 and not args[#RSGCore.Commands.List[command].arguments] then
TriggerClientEvent('RSGCore:Notify', src, Lang:t('error.missing_args2'), 'error')
else
RSGCore.Commands.List[command].callback(src, args)
end
else
TriggerClientEvent('RSGCore:Notify', src, Lang:t('error.no_access'), 'error')
end
end)
RSGCore:CallCommand > Parameters
command(string) - The command name to executeargs(table) - Array of arguments for the command
RSGCore:CallCommand > Behavior
- Command Validation: Checks if command exists in RSGCore.Commands.List
- Player Validation: Verifies player exists
- Permission Check: Validates player has required permissions
- Argument Validation: Ensures required arguments are provided
- Execution: Calls the command callback with source and arguments
- Error Handling: Provides appropriate error notifications
RSGCore:CallCommand > Error Messages
- Missing Arguments: 'error.missing_args2' language key
- No Access: 'error.no_access' language key
RSGCore:CallCommand > Usage Examples > Basic Command Call
-- Execute a command with arguments
TriggerServerEvent('RSGCore:CallCommand', 'teleport', {'player_name'})
RSGCore:CallCommand > Usage Examples > Admin Command
-- Execute admin command
TriggerServerEvent('RSGCore:CallCommand', 'ban', {'player_id', 'reason'})
RSGCore:CallCommand > Usage Examples > UI Command Integration
-- Execute command from UI
RegisterNUICallback('executeCommand', function(data)
TriggerServerEvent('RSGCore:CallCommand', data.command, data.args)
end)
RSGCore:CallCommand > Usage Examples > Command with Multiple Arguments
-- Complex command execution
local args = {'target_player', 'vehicle_model', 'color_primary', 'color_secondary'}
TriggerServerEvent('RSGCore:CallCommand', 'givevehicle', args)
RSGCore:CallCommand > Use Cases
- UI-based admin panels
- Automated command execution
- Script-triggered admin actions
- Custom command interfaces
- Permission-based tool access
Best Practices > Security Considerations
- Permission Validation: Always validate permissions before executing sensitive operations
- Input Sanitization: Validate and sanitize all input parameters
- Error Handling: Provide appropriate error messages without exposing system details
- Rate Limiting: Consider implementing rate limiting for frequently used events
Best Practices > Performance Optimization
- Player Validation: Always check if player exists before operations
- Early Returns: Use early returns for validation failures
- Batch Operations: Group multiple metadata updates when possible
- Efficient Queries: Minimize database operations in frequently called events
Best Practices > Code Organization
- Event Naming: Use consistent naming conventions for events
- Documentation: Document expected parameters and behavior
- Error Messages: Use language translation keys for user-facing messages
- Modular Design: Keep event handlers focused on single responsibilities
Best Practices > Data Management
- State Synchronization: Ensure client-server state consistency
- Data Validation: Validate data before applying changes
- Backup Considerations: Ensure critical operations are properly saved
- Transaction Safety: Handle database operations safely
Common Integration Patterns > Admin Panel Integration
-- Admin panel server events
RegisterNetEvent('admin:closeServer', function(reason)
local src = source
if RSGCore.Functions.HasPermission(src, 'admin') then
TriggerEvent('RSGCore:Server:CloseServer', reason)
end
end)
RegisterNetEvent('admin:openServer', function()
local src = source
if RSGCore.Functions.HasPermission(src, 'admin') then
TriggerEvent('RSGCore:Server:OpenServer')
end
end)
Common Integration Patterns > Status Management System
-- Comprehensive status management
RegisterNetEvent('status:updateAll', function(hunger, thirst, stress)
local src = source
TriggerEvent('RSGCore:Server:SetMetaData', 'hunger', hunger)
TriggerEvent('RSGCore:Server:SetMetaData', 'thirst', thirst)
TriggerEvent('RSGCore:Server:SetMetaData', 'stress', stress)
end)
Common Integration Patterns > Command Wrapper System
-- Safe command execution wrapper
function ExecuteCommand(source, command, args)
if RSGCore.Functions.GetPlayer(source) then
TriggerEvent('RSGCore:CallCommand', command, args)
else
print('Invalid player attempted command execution')
end
end
Error Handling Examples > Robust Event Handlers
RegisterNetEvent('myResource:safeEvent', function(data)
local src = source
local Player = RSGCore.Functions.GetPlayer(src)
-- Validate player
if not Player then
print('Error: Invalid player for event myResource:safeEvent')
return
end
-- Validate data
if not data or type(data) ~= 'table' then
TriggerClientEvent('RSGCore:Notify', src, 'Invalid data provided', 'error')
return
end
-- Process safely
local success, result = pcall(function()
-- Your event logic here
return processData(data)
end)
if not success then
print('Error processing event:', result)
TriggerClientEvent('RSGCore:Notify', src, 'Processing error occurred', 'error')
end
end)
Additional Resources
- RSGCore Client Event Reference
- RSGCore Function Reference
- RSGCore Configuration Guide
- RSGCore Command System
This documentation is based on the RSGCore framework server event reference. For the most up-to-date information, please refer to the official RSGCore documentation.