Perhaps the most used function in the framework. This function returns the players data of the current source which, since its used client side, is automatically the client or player. It can be used with modifiers on the end starting with a ”.” (period)
Copy
function RSGCore.Functions.GetPlayerData(cb) if not cb then return RSGCore.PlayerData end cb(RSGCore.PlayerData)end-- Examplelocal Player = RSGCore.Functions.GetPlayerData()print(RSGCore.Debug(Player))ORlocal Player = RSGCore.Functions.GetPlayerData()local jobName = Player.job.nameprint(jobName)
exports('GetCoreObject', function() return RSGCoreend)local RSGCore = exports['rsg-core']:GetCoreObject()OR -- call the core in a single file that loads before the othersRSGCore = exports['rsg-core']:GetCoreObject()
function RSGCore.Functions.GetPeds(ignoreList) local pedPool = GetGamePool('CPed') local peds = {} local ignoreTable = {} ignoreList = ignoreList or {} for i = 1, #ignoreList do ignoreTable[ignoreList[i]] = true end for i = 1, #pedPool do if not ignoreTable[pedPool[i]] then peds[#peds + 1] = pedPool[i] end end return pedsend-- Examplelocal peds = RSGCore.Functions.GetPeds({`mp_m_freemode_01`})print(RSGCore.Debug(peds))
function RSGCore.Functions.GetClosestPed(coords, ignoreList) local ped = PlayerPedId() if coords then coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords else coords = GetEntityCoords(ped) end ignoreList = ignoreList or {} local peds = RSGCore.Functions.GetPeds(ignoreList) local closestDistance = -1 local closestPed = -1 for i = 1, #peds, 1 do local pedCoords = GetEntityCoords(peds[i]) local distance = #(pedCoords - coords) if closestDistance == -1 or closestDistance > distance then closestPed = peds[i] closestDistance = distance end end return closestPed, closestDistanceend-- Examplelocal coords = GetEntityCoords(PlayerPedId())local closestPed, distance = RSGCore.Functions.GetClosestPed(coords)print(closestPed, distance)
function RSGCore.Functions.GetClosestVehicle(coords) local ped = PlayerPedId() local vehicles = GetGamePool('CVehicle') local closestDistance = -1 local closestVehicle = -1 if coords then coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords else coords = GetEntityCoords(ped) end for i = 1, #vehicles, 1 do local vehicleCoords = GetEntityCoords(vehicles[i]) local distance = #(vehicleCoords - coords) if closestDistance == -1 or closestDistance > distance then closestVehicle = vehicles[i] closestDistance = distance end end return closestVehicle, closestDistanceend-- Examplelocal coords = GetEntityCoords(PlayerPedId())local closestVehicle, distance = RSGCore.Functions.GetClosestVehicle(coords)print(closestVehicle, distance)
function RSGCore.Functions.GetClosestObject(coords) local ped = PlayerPedId() local objects = GetGamePool('CObject') local closestDistance = -1 local closestObject = -1 if coords then coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords else coords = GetEntityCoords(ped) end for i = 1, #objects, 1 do local objectCoords = GetEntityCoords(objects[i]) local distance = #(objectCoords - coords) if closestDistance == -1 or closestDistance > distance then closestObject = objects[i] closestDistance = distance end end return closestObject, closestDistanceend-- Examplelocal coords = GetEntityCoords(PlayerPedId())local closestObject, distance = RSGCore.Functions.GetClosestObject(coords)print(closestObject, distance)
Returns a list of players within a certain radius from the given coordinates
Copy
function RSGCore.Functions.GetPlayersFromCoords(coords, distance) local players = GetActivePlayers() local ped = PlayerPedId() if coords then coords = type(coords) == 'table' and vec3(coords.x, coords.y, coords.z) or coords else coords = GetEntityCoords(ped) end distance = distance or 5 local closePlayers = {} for _, player in ipairs(players) do local targetCoords = GetEntityCoords(GetPlayerPed(player)) local targetdistance = #(targetCoords - coords) if targetdistance <= distance then closePlayers[#closePlayers + 1] = player end end return closePlayersend-- Examplelocal coords = GetEntityCoords(PlayerPedId())local radius = 5.0local closestPlayers = RSGCore.Functions.GetPlayersFromCoords(coords, radius)print(RSGCore.Debug(closestPlayers))
Spawns a vehicle at the given coordinates with the given model and color
Copy
---@param model string|number---@param cb? fun(vehicle: number)---@param coords? vector4 player position if not specified---@param isnetworked? boolean defaults to true---@param teleportInto boolean teleport player to driver seat if truefunction RSGCore.Functions.SpawnVehicle(model, cb, coords, isnetworked, teleportInto) local playerCoords = GetEntityCoords(cache.ped) local combinedCoords = vec4(playerCoords.x, playerCoords.y, playerCoords.z, GetEntityHeading(cache.ped)) coords = type(coords) == 'table' and vec4(coords.x, coords.y, coords.z, coords.w or combinedCoords.w) or coords or combinedCoords model = type(model) == 'string' and joaat(model) or model if not IsModelInCdimage(model) then return end isnetworked = isnetworked == nil or isnetworked lib.requestModel(model) local veh = CreateVehicle(model, coords.x, coords.y, coords.z, coords.w, isnetworked, false) local netid = NetworkGetNetworkIdFromEntity(veh) SetVehicleHasBeenOwnedByPlayer(veh, true) SetNetworkIdCanMigrate(netid, true) SetModelAsNoLongerNeeded(model) if teleportInto then TaskWarpPedIntoVehicle(cache.ped, veh, -1) end if cb then cb(veh) endend--- Examplelocal coords = RSGCore.Functions.GetCoords(PlayerPedId()) -- Ensure `coords` is vector4 with a heading valuecoords = vec4(coords.x, coords.y, coords.z, coords.w or GetEntityHeading(PlayerPedId()))RSGCore.Functions.SpawnVehicle('CART01', function(veh) SetEntityHeading(veh, coords.w) -- Set the heading of the vehicle TaskWarpPedIntoVehicle(PlayerPedId(), veh, -1) -- Teleport player into the vehicleend, coords, true)
function RSGCore.Functions.DeleteVehicle(vehicle) SetEntityAsMissionEntity(vehicle, true, true) DeleteVehicle(vehicle)end-- Examplelocal ped = PlayerPedId()local veh = GetVehiclePedIsUsing(ped)if veh ~= 0 then RSGCore.Functions.DeleteVehicle(veh)else local pcoords = GetEntityCoords(ped) local vehicles = GetGamePool('CVehicle') for k, v in pairs(vehicles) do if #(pcoords - GetEntityCoords(v)) <= 5.0 then RSGCore.Functions.DeleteVehicle(v) end endendOR -- preferred methodlocal ped = PlayerPedId()local veh = GetVehiclePedIsUsing(ped)if veh ~= 0 then SetEntityAsMissionEntity(veh, true, true) DeleteVehicle(veh)else local pcoords = GetEntityCoords(ped) local vehicles = GetGamePool('CVehicle') for k, v in pairs(vehicles) do if #(pcoords - GetEntityCoords(v)) <= 5.0 then SetEntityAsMissionEntity(v, true, true) DeleteVehicle(v) end endend