RSGCore Server Function Reference
This documentation covers all available server-side functions in the RSGCore framework, including detailed usage examples and implementation details.
Table of Contents
- RSGCore.Functions.GetCoords
- RSGCore.Functions.GetIdentifier
- RSGCore.Functions.GetSource
- RSGCore.Functions.GetPlayer
- RSGCore.Functions.GetPlayerByCitizenId
- RSGCore.Functions.GetPlayers
- RSGCore.Functions.GetRSGPlayers
- RSGCore.Functions.CreateCallback
- RSGCore.Functions.CreateUseableItem
- RSGCore.Functions.CanUseItem
- RSGCore.Functions.UseItem
- RSGCore.Functions.Kick
- RSGCore.Functions.AddPermission
- RSGCore.Functions.RemovePermission
- RSGCore.Functions.HasPermission
- RSGCore.Functions.GetPermission
- RSGCore.Functions.IsPlayerBanned
- RSGCore.Functions.IsLicenseInUse
RSGCore.Functions.GetCoords > Description
Get the coordinates of a passed entity, returning both position and heading in a vector4 format.
RSGCore.Functions.GetCoords > Function Definition
function RSGCore.Functions.GetCoords(entity)
local coords = GetEntityCoords(entity, false)
local heading = GetEntityHeading(entity)
return vector4(coords.x, coords.y, coords.z, heading)
end
RSGCore.Functions.GetCoords > Parameters
entity(number) - Entity handle to get coordinates from
RSGCore.Functions.GetCoords > Return Value
vector4- Contains x, y, z coordinates and heading (w component)
RSGCore.Functions.GetCoords > Usage Example
local ped = GetPlayerPed(source)
local coords = RSGCore.Functions.GetCoords(ped)
print(coords)
RSGCore.Functions.GetCoords > Use Cases
- Getting player positions for teleportation
- Storing vehicle locations
- Calculating distances between entities
- Setting spawn positions with proper rotation
RSGCore.Functions.GetIdentifier > Description
Get a specific identifier of a player. Defaults to the identifier type specified in RSGCore configuration.
RSGCore.Functions.GetIdentifier > Function Definition
function RSGCore.Functions.GetIdentifier(source, idtype)
local idtype = idtype or RSGConfig.IdentifierType
for key, value in pairs(GetPlayerIdentifiers(source)) do
if string.find(value, idtype) then
return identifier
end
end
return nil
end
RSGCore.Functions.GetIdentifier > Parameters
source(number) - Player source IDidtype(string, optional) - Identifier type to retrieve (defaults to config value)
RSGCore.Functions.GetIdentifier > Return Value
stringornil- The requested identifier or nil if not found
RSGCore.Functions.GetIdentifier > Usage Examples > Get Specific Identifier
local identifier = RSGCore.Functions.GetIdentifier(source, 'license')
print(identifier)
RSGCore.Functions.GetIdentifier > Usage Examples > Get Default Identifier
-- Uses the identifier type from rsg-core config
local identifier = RSGCore.Functions.GetIdentifier(source)
print(identifier)
RSGCore.Functions.GetIdentifier > Common Identifier Types
license- Rockstar Social Club licensesteam- Steam identifierdiscord- Discord identifierfivem- FiveM identifier
RSGCore.Functions.GetIdentifier > Use Cases
- Player identification and tracking
- Database lookups
- Ban system implementation
- Player data management
RSGCore.Functions.GetSource > Description
Get a player's source ID by their identifier.
RSGCore.Functions.GetSource > Function Definition
function RSGCore.Functions.GetSource(identifier)
for key, value in pairs(RSGCore.Players) do
local identifiers = GetPlayerIdentifiers(key)
for _, id in pairs(identifiers) do
if identifier == id then
return key
end
end
end
return 0
end
RSGCore.Functions.GetSource > Parameters
identifier(string) - Player identifier to search for
RSGCore.Functions.GetSource > Return Value
number- Player source ID or 0 if not found
RSGCore.Functions.GetSource > Usage Example
local identifier = RSGCore.Functions.GetIdentifier(source, 'license')
local playerSource = RSGCore.Functions.GetSource(identifier)
print(playerSource)
RSGCore.Functions.GetSource > Use Cases
- Converting stored identifiers back to active sources
- Cross-referencing player data
- Admin tools and commands
- Player management systems
RSGCore.Functions.GetPlayer > Description
Get a player object by their source ID and access their complete data. This is one of the most important functions for player data management.
RSGCore.Functions.GetPlayer > Function Definition
function RSGCore.Functions.GetPlayer(source)
local src = source
if type(src) == 'number' then
return RSGCore.Players[src]
else
return RSGCore.Players[RSGCore.Functions.GetSource(src)]
end
end
RSGCore.Functions.GetPlayer > Parameters
source(number or string) - Player source ID or identifier
RSGCore.Functions.GetPlayer > Return Value
tableornil- Player object with complete PlayerData or nil if not found
RSGCore.Functions.GetPlayer > Usage Examples > Basic Player Access
local Player = RSGCore.Functions.GetPlayer(source)
print(RSGCore.Debug(Player))
RSGCore.Functions.GetPlayer > Usage Examples > Accessing Player Data
local Player = RSGCore.Functions.GetPlayer(source)
print(Player.PlayerData.citizenid)
RSGCore.Functions.GetPlayer > Usage Examples > Comprehensive Player Data Access
local Player = RSGCore.Functions.GetPlayer(source)
if Player then
local citizenId = Player.PlayerData.citizenid
local firstName = Player.PlayerData.charinfo.firstname
local lastName = Player.PlayerData.charinfo.lastname
local job = Player.PlayerData.job.name
local money = Player.PlayerData.money.cash
print(string.format("Player: %s %s (%s) - Job: %s - Cash: $%d",
firstName, lastName, citizenId, job, money))
end
RSGCore.Functions.GetPlayer > Use Cases
- Accessing player inventory
- Checking player job and permissions
- Managing player money and assets
- Player data validation
- Character information retrieval
RSGCore.Functions.GetPlayerByCitizenId > Description
Get a player by their citizen ID and access their data. The player must be online for this function to work.
RSGCore.Functions.GetPlayerByCitizenId > Function Definition
function RSGCore.Functions.GetPlayerByCitizenId(citizenid)
for key, value in pairs(RSGCore.Players) do
if RSGCore.Players[key].PlayerData.citizenid == citizenid then
return RSGCore.Players[key]
end
end
return nil
end
RSGCore.Functions.GetPlayerByCitizenId > Parameters
citizenid(string) - Citizen ID to search for
RSGCore.Functions.GetPlayerByCitizenId > Return Value
tableornil- Player object or nil if not found/offline
RSGCore.Functions.GetPlayerByCitizenId > Usage Examples > Basic Citizen ID Search
local Player = RSGCore.Functions.GetPlayerByCitizenId('ONZ55343')
print(RSGCore.Debug(Player))
RSGCore.Functions.GetPlayerByCitizenId > Usage Examples > Accessing Player Data by Citizen ID
local Player = RSGCore.Functions.GetPlayerByCitizenId('ONZ55343')
if Player then
print(Player.PlayerData.license)
else
print('Player not found or offline')
end
RSGCore.Functions.GetPlayerByCitizenId > Use Cases
- Admin commands targeting specific characters
- Player-to-player transactions
- Quest and mission systems
- Character-specific data retrieval
RSGCore.Functions.GetPlayers > Description
Get all player IDs currently on the server. This is a deprecated method; prefer GetRSGPlayers().
RSGCore.Functions.GetPlayers > Function Definition
function RSGCore.Functions.GetPlayers()
local sources = {}
for key, value in pairs(RSGCore.Players) do
sources[#sources + 1] = key
end
return sources
end
RSGCore.Functions.GetPlayers > Return Value
table- Array of player source IDs
RSGCore.Functions.GetPlayers > Usage Example
local Players = RSGCore.Functions.GetPlayers()
print(RSGCore.Debug(Players))
RSGCore.Functions.GetPlayers > Note
This function is deprecated. Use RSGCore.Functions.GetRSGPlayers() instead for better performance and more complete data access.
RSGCore.Functions.GetRSGPlayers > Description
Access the table of all active players on the server. This is the preferred method over GetPlayers().
RSGCore.Functions.GetRSGPlayers > Function Definition
function RSGCore.Functions.GetRSGPlayers()
return RSGCore.Players
end
RSGCore.Functions.GetRSGPlayers > Return Value
table- Complete RSGCore.Players table with full player objects
RSGCore.Functions.GetRSGPlayers > Usage Example
local Players = RSGCore.Functions.GetRSGPlayers()
print(RSGCore.Debug(Players))
RSGCore.Functions.GetRSGPlayers > Advanced Usage
-- Iterate through all online players
local Players = RSGCore.Functions.GetRSGPlayers()
for source, Player in pairs(Players) do
print(string.format("Player %d: %s %s (Job: %s)",
source,
Player.PlayerData.charinfo.firstname,
Player.PlayerData.charinfo.lastname,
Player.PlayerData.job.name))
end
RSGCore.Functions.GetRSGPlayers > Use Cases
- Server-wide announcements
- Mass player operations
- Statistics collection
- Administrative tools
RSGCore.Functions.CreateCallback > Description
Creates a callback which is used on the client-side code with RSGCore.Functions.TriggerCallback. This enables secure client-server communication.
RSGCore.Functions.CreateCallback > Function Definition
function RSGCore.Functions.CreateCallback(name, cb)
RSGCore.ServerCallbacks[name] = cb
end
RSGCore.Functions.CreateCallback > Parameters
name(string) - Unique callback namecb(function) - Callback function to execute
RSGCore.Functions.CreateCallback > Usage Example
RSGCore.Functions.CreateCallback('callbackName', function(source, cb)
cb('Ok')
end)
RSGCore.Functions.CreateCallback > Advanced Examples > Player Data Callback
RSGCore.Functions.CreateCallback('getPlayerMoney', function(source, cb)
local Player = RSGCore.Functions.GetPlayer(source)
if Player then
cb({
cash = Player.PlayerData.money.cash,
bank = Player.PlayerData.money.bank
})
else
cb(nil)
end
end)
RSGCore.Functions.CreateCallback > Advanced Examples > Database Query Callback
RSGCore.Functions.CreateCallback('getUserVehicles', function(source, cb, citizenId)
local Player = RSGCore.Functions.GetPlayer(source)
if not Player then return cb(nil) end
MySQL.Async.fetchAll('SELECT * FROM player_vehicles WHERE citizenid = ?', {
citizenId or Player.PlayerData.citizenid
}, function(result)
cb(result)
end)
end)
RSGCore.Functions.CreateCallback > Use Cases
- Secure data retrieval from server
- Database queries from client
- Validation checks
- Complex server-side calculations
RSGCore.Functions.CreateUseableItem > Description
Register an item as usable in the core framework. This allows players to use items from their inventory.
RSGCore.Functions.CreateUseableItem > Function Definition
function RSGCore.Functions.CreateUseableItem(item, cb)
RSGCore.UseableItems[item] = cb
end
RSGCore.Functions.CreateUseableItem > Parameters
item(string) - Item name to registercb(function) - Function to execute when item is used
RSGCore.Functions.CreateUseableItem > Usage Example
RSGCore.Functions.CreateUseableItem('example_item', function(source, item)
local Player = RSGCore.Functions.GetPlayer(source)
if not Player.Functions.GetItemByName(item.name) then return end
-- Trigger code here for what item should do
end)
RSGCore.Functions.CreateUseableItem > Advanced Examples > Consumable Item
RSGCore.Functions.CreateUseableItem('sandwich', function(source, item)
local Player = RSGCore.Functions.GetPlayer(source)
if not Player.Functions.GetItemByName(item.name) then return end
-- Remove item from inventory
Player.Functions.RemoveItem('sandwich', 1)
-- Restore hunger
Player.Functions.SetMetaData('hunger', math.min(100, Player.PlayerData.metadata.hunger + 25))
-- Notify player
TriggerClientEvent('RSGCore:Notify', source, 'You ate a sandwich and feel less hungry', 'success')
end)
RSGCore.Functions.CreateUseableItem > Advanced Examples > Tool Item
RSGCore.Functions.CreateUseableItem('lockpick', function(source, item)
local Player = RSGCore.Functions.GetPlayer(source)
if not Player.Functions.GetItemByName(item.name) then return end
-- Check if player has required skill
if Player.PlayerData.metadata.lockpicking_skill < 10 then
TriggerClientEvent('RSGCore:Notify', source, 'You don\'t have enough lockpicking skill', 'error')
return
end
-- Trigger client-side lockpicking minigame
TriggerClientEvent('lockpicking:startMinigame', source)
end)
RSGCore.Functions.CreateUseableItem > Use Cases
- Consumable items (food, drinks, medicine)
- Tools and equipment
- Key items and documents
- Crafting materials
RSGCore.Functions.CanUseItem > Description
Check if an item is registered as usable before attempting to use it.
RSGCore.Functions.CanUseItem > Function Definition
function RSGCore.Functions.CanUseItem(item)
return RSGCore.UseableItems[item]
end
RSGCore.Functions.CanUseItem > Parameters
item(string) - Item name to check
RSGCore.Functions.CanUseItem > Return Value
functionornil- The useable item function or nil if not registered
RSGCore.Functions.CanUseItem > Usage Examples > Basic Check
local canUse = RSGCore.Functions.CanUseItem('example_item')
print(canUse)
RSGCore.Functions.CanUseItem > Usage Examples > Conditional Usage
local canUse = RSGCore.Functions.CanUseItem('example_item')
if not canUse then return end
-- Trigger code here
RSGCore.Functions.CanUseItem > Use Cases
- Inventory system validation
- UI element states
- Error prevention
- Dynamic item behavior
RSGCore.Functions.UseItem > Description
Trigger an item to be used on the player. This manually executes the useable item function.
RSGCore.Functions.UseItem > Function Definition
function RSGCore.Functions.UseItem(source, item)
RSGCore.UseableItems[item.name](source, item)
end
RSGCore.Functions.UseItem > Parameters
source(number) - Player source IDitem(table) - Item data table
RSGCore.Functions.UseItem > Usage Example
local Player = RSGCore.Functions.GetPlayer(source)
if not Player.Functions.GetItemByName('example_item') then return end
RSGCore.Functions.UseItem(source, 'example_item')
RSGCore.Functions.UseItem > Advanced Usage
-- Use item with full item data
local Player = RSGCore.Functions.GetPlayer(source)
local itemData = Player.Functions.GetItemByName('medkit')
if itemData then
RSGCore.Functions.UseItem(source, itemData)
end
RSGCore.Functions.UseItem > Use Cases
- Programmatic item usage
- Admin commands
- Automated systems
- Quest rewards
RSGCore.Functions.Kick > Description
Kick a player from the server with a custom reason and optional Discord information.
RSGCore.Functions.Kick > Function Definition
function RSGCore.Functions.Kick(source, reason, setKickReason, deferrals)
local src = source
reason = '\n'..reason..'\n🔸 Check our Discord for further information: '..RSGCore.Config.Server.discord
if setKickReason then
setKickReason(reason)
end
CreateThread(function()
if deferrals then
deferrals.update(reason)
Wait(2500)
end
if src then
DropPlayer(src, reason)
end
local i = 0
while (i <= 4) do
i = i + 1
while true do
if src then
if(GetPlayerPing(src) >= 0) then
break
end
Wait(100)
CreateThread(function()
DropPlayer(src, reason)
end)
end
end
Wait(5000)
end
end)
end
RSGCore.Functions.Kick > Parameters
source(number) - Player source ID to kickreason(string) - Reason for the kicksetKickReason(boolean, optional) - Whether to set kick reasondeferrals(boolean, optional) - Whether to use deferrals
RSGCore.Functions.Kick > Usage Example
RSGCore.Functions.Kick(playerId, 'You messed up', true, true)
RSGCore.Functions.Kick > Advanced Examples > Admin Command Kick
RegisterCommand('kick', function(source, args)
if not RSGCore.Functions.HasPermission(source, 'admin') then return end
local targetId = tonumber(args[1])
local reason = table.concat(args, ' ', 2) or 'No reason specified'
if targetId and RSGCore.Functions.GetPlayer(targetId) then
RSGCore.Functions.Kick(targetId, reason, true, false)
TriggerClientEvent('RSGCore:Notify', source, 'Player kicked successfully', 'success')
else
TriggerClientEvent('RSGCore:Notify', source, 'Invalid player ID', 'error')
end
end)
RSGCore.Functions.Kick > Use Cases
- Administrative punishment
- Rule violation enforcement
- Security measures
- Connection management
RSGCore.Functions.AddPermission > Description
Give a player a specific permission level for the current session only. Permissions are lost on disconnect.
RSGCore.Functions.AddPermission > Function Definition
function RSGCore.Functions.AddPermission(source, permission)
local license = RSGCore.Functions.GetIdentifier(source, 'license')
ExecuteCommand(('add_principal identifier.%s rsgcore.%s'):format(license, permission))
RSGCore.Commands.Refresh(source)
end
RSGCore.Functions.AddPermission > Parameters
source(number) - Player source IDpermission(string) - Permission level to add
RSGCore.Functions.AddPermission > Usage Example
local Player = RSGCore.Functions.GetPlayer(playerId)
local permission = 'admin'
RSGCore.Functions.AddPermission(Player.PlayerData.source, permission)
RSGCore.Functions.AddPermission > Advanced Usage
-- Temporary permission assignment
RegisterCommand('tempmod', function(source, args)
if not RSGCore.Functions.HasPermission(source, 'admin') then return end
local targetId = tonumber(args[1])
if targetId and RSGCore.Functions.GetPlayer(targetId) then
RSGCore.Functions.AddPermission(targetId, 'mod')
TriggerClientEvent('RSGCore:Notify', source, 'Temporary moderator permissions granted', 'success')
TriggerClientEvent('RSGCore:Notify', targetId, 'You have been granted temporary moderator permissions', 'info')
end
end)
RSGCore.Functions.AddPermission > Common Permission Levels
user- Standard user permissionsmod- Moderator permissionsadmin- Administrator permissionsgod- Highest level permissions
RSGCore.Functions.AddPermission > Use Cases
- Temporary staff assignments
- Event management
- Trial moderator periods
- Emergency permissions
RSGCore.Functions.RemovePermission > Description
Remove specific or all permissions from a player for the current session only.
RSGCore.Functions.RemovePermission > Function Definition
function RSGCore.Functions.RemovePermission(source, permission)
local src = source
local license = RSGCore.Functions.GetIdentifier(src, 'license')
if permission then
if IsPlayerAceAllowed(src, permission) then
ExecuteCommand(('remove_principal identifier.%s rsgcore.%s'):format(license, permission))
RSGCore.Commands.Refresh(src)
end
else
for k,v in pairs(RSGCore.Config.Server.Permissions) do
if IsPlayerAceAllowed(src, v) then
ExecuteCommand(('remove_principal identifier.%s rsgcore.%s'):format(license, v))
RSGCore.Commands.Refresh(src)
end
end
end
end
RSGCore.Functions.RemovePermission > Parameters
source(number) - Player source IDpermission(string, optional) - Specific permission to remove (if nil, removes all)
RSGCore.Functions.RemovePermission > Usage Examples > Remove Specific Permission
local Player = RSGCore.Functions.GetPlayer(playerId)
local permission = 'admin'
RSGCore.Functions.RemovePermission(Player.PlayerData.source, permission)
RSGCore.Functions.RemovePermission > Usage Examples > Remove All Permissions
local Player = RSGCore.Functions.GetPlayer(playerId)
RSGCore.Functions.RemovePermission(Player.PlayerData.source) -- No permission specified = remove all
RSGCore.Functions.RemovePermission > Use Cases
- Staff punishment/demotion
- Security revocation
- Trial period endings
- Permission auditing
RSGCore.Functions.HasPermission > Description
Check if a player has the required permission level.
RSGCore.Functions.HasPermission > Function Definition
function RSGCore.Functions.HasPermission(source, permission)
if IsPlayerAceAllowed(source, permission) then return true end
return false
end
RSGCore.Functions.HasPermission > Parameters
source(number) - Player source IDpermission(string) - Permission level to check
RSGCore.Functions.HasPermission > Return Value
boolean- True if player has permission, false otherwise
RSGCore.Functions.HasPermission > Usage Examples > Basic Permission Check
local hasPerms = RSGCore.Functions.HasPermission(source, 'admin')
print(hasPerms)
RSGCore.Functions.HasPermission > Usage Examples > Conditional Code Execution
local hasPerms = RSGCore.Functions.HasPermission(source, 'admin')
if not hasPerms then return end
-- Trigger code here
RSGCore.Functions.HasPermission > Usage Examples > Command Permission Validation
RegisterCommand('adminpanel', function(source)
if not RSGCore.Functions.HasPermission(source, 'admin') then
TriggerClientEvent('RSGCore:Notify', source, 'You don\'t have permission to use this command', 'error')
return
end
-- Open admin panel
TriggerClientEvent('admin:openPanel', source)
end)
RSGCore.Functions.HasPermission > Use Cases
- Command access control
- Feature gating
- UI element visibility
- Action authorization
RSGCore.Functions.GetPermission > Description
Get all permissions that a player currently has.
RSGCore.Functions.GetPermission > Function Definition
function RSGCore.Functions.GetPermission(source)
local src = source
local perms = {}
for key, value in pairs (RSGCore.Config.Server.Permissions) do
if IsPlayerAceAllowed(src, value) then
perms[value] = true
end
end
return perms
end
RSGCore.Functions.GetPermission > Parameters
source(number) - Player source ID
RSGCore.Functions.GetPermission > Return Value
table- Table of permissions where key is permission name and value is true
RSGCore.Functions.GetPermission > Usage Examples > Get All Permissions
local permissions = RSGCore.Functions.GetPermission(source)
print(RSGCore.Debug(permissions))
RSGCore.Functions.GetPermission > Usage Examples > Iterate Through Permissions
local permissions = RSGCore.Functions.GetPermission(source)
for key, value in pairs(permissions) do
if value == true then
print(key)
end
end
RSGCore.Functions.GetPermission > Usage Examples > Permission Level Detection
local permissions = RSGCore.Functions.GetPermission(source)
local highestPerm = 'user'
if permissions['god'] then
highestPerm = 'god'
elseif permissions['admin'] then
highestPerm = 'admin'
elseif permissions['mod'] then
highestPerm = 'mod'
end
print('Player has', highestPerm, 'permissions')
RSGCore.Functions.GetPermission > Use Cases
- Permission auditing
- Dynamic UI generation
- Role assignment verification
- Access level determination
RSGCore.Functions.IsPlayerBanned > Description
Check if a player is banned from the server. Used primarily during connection process.
RSGCore.Functions.IsPlayerBanned > Function Definition
function RSGCore.Functions.IsPlayerBanned(source)
local plicense = RSGCore.Functions.GetIdentifier(source, 'license')
local result = MySQL.Sync.fetchSingle('SELECT * FROM bans WHERE license = ?', { plicense })
if not result then return false end
if os.time() < result.expire then
local timeTable = os.date('*t', tonumber(result.expire))
return true, 'You have been banned from the server:\n' .. result.reason .. '\nYour ban expires ' .. timeTable.day .. '/' .. timeTable.month .. '/' .. timeTable.year .. ' ' .. timeTable.hour .. ':' .. timeTable.min .. '\n'
else
MySQL.Async.execute('DELETE FROM bans WHERE id = ?', { result.id })
end
return false
end
RSGCore.Functions.IsPlayerBanned > Parameters
source(number) - Player source ID
RSGCore.Functions.IsPlayerBanned > Return Values
boolean- True if player is bannedstring(optional) - Ban message with reason and expiration time
RSGCore.Functions.IsPlayerBanned > Usage Example
local isBanned = RSGCore.Functions.IsPlayerBanned(source)
print(isBanned)
RSGCore.Functions.IsPlayerBanned > Advanced Usage
-- Check ban status during connection
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local source = source
deferrals.defer()
local isBanned, banMessage = RSGCore.Functions.IsPlayerBanned(source)
if isBanned then
deferrals.done(banMessage)
return
end
deferrals.done()
end)
RSGCore.Functions.IsPlayerBanned > Database Schema
Expected bans table structure:
id- Unique ban IDlicense- Player license identifierreason- Ban reasonexpire- Unix timestamp of ban expiration
RSGCore.Functions.IsPlayerBanned > Use Cases
- Connection filtering
- Ban system implementation
- Player validation
- Security enforcement
RSGCore.Functions.IsLicenseInUse > Description
Prevent duplicate licenses on the server. Used during connection to ensure unique player identities.
RSGCore.Functions.IsLicenseInUse > Function Definition
function RSGCore.Functions.IsLicenseInUse(license)
local players = GetPlayers()
for key, value in pairs(players) do
local identifiers = GetPlayerIdentifiers(value)
for _, id in pairs(identifiers) do
if string.find(id, 'license') then
if id == license then
return true
end
end
end
end
return false
end
RSGCore.Functions.IsLicenseInUse > Parameters
license(string) - License identifier to check
RSGCore.Functions.IsLicenseInUse > Return Value
boolean- True if license is already in use, false otherwise
RSGCore.Functions.IsLicenseInUse > Usage Example
local license = RSGCore.Functions.GetIdentifier(source, 'license')
local isUsed = RSGCore.Functions.IsLicenseInUse(license)
print(isUsed)
RSGCore.Functions.IsLicenseInUse > Connection Validation Example
AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)
local source = source
deferrals.defer()
local license = RSGCore.Functions.GetIdentifier(source, 'license')
if RSGCore.Functions.IsLicenseInUse(license) then
deferrals.done('This license is already in use on the server. Please try again later.')
return
end
deferrals.done()
end)
RSGCore.Functions.IsLicenseInUse > Use Cases
- Preventing multiple connections from same account
- Connection security
- Server integrity
- Account management
Best Practices > Performance Optimization
- Caching: Cache frequently accessed player data instead of repeated
GetPlayer()calls - Validation: Always validate player existence before operations
- Batch Operations: Group multiple player operations when possible
- Database Efficiency: Use appropriate MySQL query types (Sync vs Async)
Best Practices > Security Considerations
- Permission Validation: Always check permissions before sensitive operations
- Input Sanitization: Validate all parameters before processing
- Error Handling: Handle database errors gracefully
- Rate Limiting: Implement rate limiting for user-triggered functions
Best Practices > Code Organization
- Function Naming: Use descriptive names for callback functions
- Error Messages: Provide clear, user-friendly error messages
- Documentation: Document custom callbacks and their expected parameters
- Modular Design: Keep functions focused on single responsibilities
Best Practices > Database Management
- Connection Handling: Ensure proper database connection management
- Query Optimization: Use indexed columns for frequent lookups
- Data Validation: Validate data before database operations
- Backup Considerations: Handle critical data operations safely
Common Integration Patterns > Player Management System
-- Comprehensive player utilities
local PlayerUtils = {}
function PlayerUtils.GetOnlinePlayersCount()
local players = RSGCore.Functions.GetRSGPlayers()
return #players
end
function PlayerUtils.GetPlayersByJob(jobName)
local players = RSGCore.Functions.GetRSGPlayers()
local jobPlayers = {}
for source, Player in pairs(players) do
if Player.PlayerData.job.name == jobName then
jobPlayers[#jobPlayers + 1] = Player
end
end
return jobPlayers
end
function PlayerUtils.BroadcastToPermission(permission, message, messageType)
local players = RSGCore.Functions.GetRSGPlayers()
for source, Player in pairs(players) do
if RSGCore.Functions.HasPermission(source, permission) then
TriggerClientEvent('RSGCore:Notify', source, message, messageType or 'info')
end
end
end
Common Integration Patterns > Secure Callback System
-- Advanced callback with permission checking
RSGCore.Functions.CreateCallback('admin:getPlayerData', function(source, cb, targetId)
if not RSGCore.Functions.HasPermission(source, 'admin') then
cb(nil, 'No permission')
return
end
local targetPlayer = RSGCore.Functions.GetPlayer(targetId)
if not targetPlayer then
cb(nil, 'Player not found')
return
end
cb({
citizenid = targetPlayer.PlayerData.citizenid,
name = targetPlayer.PlayerData.charinfo.firstname .. ' ' .. targetPlayer.PlayerData.charinfo.lastname,
job = targetPlayer.PlayerData.job,
money = targetPlayer.PlayerData.money,
metadata = targetPlayer.PlayerData.metadata
})
end)
Common Integration Patterns > Item Management System
-- Advanced useable item with cooldowns
local itemCooldowns = {}
RSGCore.Functions.CreateUseableItem('energy_drink', function(source, item)
local Player = RSGCore.Functions.GetPlayer(source)
if not Player then return end
-- Check cooldown
if itemCooldowns[source] and itemCooldowns[source] > GetGameTimer() then
local remainingTime = math.ceil((itemCooldowns[source] - GetGameTimer()) / 1000)
TriggerClientEvent('RSGCore:Notify', source, 'You must wait ' .. remainingTime .. ' seconds', 'error')
return
end
-- Check if player has item
if not Player.Functions.GetItemByName('energy_drink') then return end
-- Use item
Player.Functions.RemoveItem('energy_drink', 1)
Player.Functions.SetMetaData('stress', math.max(0, Player.PlayerData.metadata.stress - 10))
-- Set cooldown (60 seconds)
itemCooldowns[source] = GetGameTimer() + 60000
TriggerClientEvent('RSGCore:Notify', source, 'You feel energized!', 'success')
TriggerClientEvent('energy:boost', source) -- Trigger client effects
end)
Error Handling Examples > Robust Function Wrappers
-- Safe player operations
function SafePlayerOperation(source, operation, ...)
local Player = RSGCore.Functions.GetPlayer(source)
if not Player then
print('Error: Invalid player for operation:', operation)
return false
end
local success, result = pcall(operation, Player, ...)
if not success then
print('Error in player operation:', operation, result)
return false
end
return true, result
end
-- Usage
SafePlayerOperation(source, function(Player, amount)
Player.Functions.AddMoney('cash', amount)
end, 1000)
Error Handling Examples > Database Error Handling
-- Safe database operations with callbacks
RSGCore.Functions.CreateCallback('safeQuery:getPlayerVehicles', function(source, cb)
local Player = RSGCore.Functions.GetPlayer(source)
if not Player then
cb(nil, 'Player not found')
return
end
MySQL.Async.fetchAll('SELECT * FROM player_vehicles WHERE citizenid = ?', {
Player.PlayerData.citizenid
}, function(result)
if result then
cb(result)
else
cb(nil, 'Database error')
end
end)
end)
Additional Resources
- RSGCore Client Function Reference
- RSGCore Event Reference
- RSGCore Database Schema
- RSGCore Configuration Guide
This documentation is based on the RSGCore framework server function reference. For the most up-to-date information, please refer to the official RSGCore documentation.