Gets a players server id (source). Returns 0 if no player is found.
Copy
---@param identifier string---@return numberfunction RSGCore.Functions.GetSource(identifier) for src, _ in pairs(RSGCore.Players) do local idens = GetPlayerIdentifiers(src) for _, id in pairs(idens) do if identifier == id then return src end end end return 0end-- Examplelocal identifier = RSGCore.Functions.GetIdentifier(source, 'license')local playerSource = RSGCore.Functions.GetSource(identifier)print(playerSource)
---@param source any---@return tablefunction RSGCore.Functions.GetPlayer(source) if type(source) == 'number' then return RSGCore.Players[source] else return RSGCore.Players[RSGCore.Functions.GetSource(source)] endend-- Examplelocal Player = RSGCore.Functions.GetPlayer(source)print(RSGCore.Debug(Player))OR -- access some player datalocal Player = RSGCore.Functions.GetPlayer(source)print(Player.PlayerData.citizenid)
---@param citizenid string---@return table?function RSGCore.Functions.GetPlayerByCitizenId(citizenid) for src in pairs(RSGCore.Players) do if RSGCore.Players[src].PlayerData.citizenid == citizenid then return RSGCore.Players[src] end end return nilend-- Examplelocal Player = RSGCore.Functions.GetPlayerByCitizenId('ONZ55343')print(RSGCore.Debug(Player))OR -- access some player datalocal Player = RSGCore.Functions.GetPlayerByCitizenId('ONZ55343')print(Player.PlayerData.license)
Get all players. Returns the server ids of all players.
Copy
---@return tablefunction RSGCore.Functions.GetPlayers() local sources = {} for k in pairs(RSGCore.Players) do sources[#sources + 1] = k end return sourcesend-- Examplelocal Players = RSGCore.Functions.GetPlayers()print(RSGCore.Debug(Players))
---@param item string---@param data functionfunction RSGCore.Functions.CreateUseableItem(item, data) RSGCore.UsableItems[item] = dataend-- ExampleRSGCore.Functions.CreateUseableItem('my_cool_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 doend)
---@param source any---@param item stringfunction RSGCore.Functions.UseItem(source, item) if GetResourceState('rsg-inventory') == 'missing' then return end exports['rsg-inventory']:UseItem(source, item)end-- Examplelocal Player = RSGCore.Functions.GetPlayer(source)if not Player.Functions.GetItemByName('my_cool_item') then return endRSGCore.Functions.UseItem(source, 'my_cool_item')