migrate cache.ped to PlayerPedId()

This commit is contained in:
MrNewb committed 2025-07-28 01:37:52 -04:00
1 parent eb8a7e4449
commit 88b4daa2e8
7 files changed
+30 -21

No files matched your search

+2 -1
View File
@@ -36,6 +36,7 @@ Placeable.PlaceObject = function(object, distance, snapToGround, allowedMats, of
local propObject = type(object) == 'string' and joaat(object) or object local propObject = type(object) == 'string' and joaat(object) or object
local heading = 0.0 local heading = 0.0
local checkDist = distance or 10.0 local checkDist = distance or 10.0
local ped = PlayerPedId()
Utility.LoadModel(propObject) Utility.LoadModel(propObject)
@@ -60,7 +61,7 @@ Placeable.PlaceObject = function(object, distance, snapToGround, allowedMats, of
end end
SetEntityCoords(activePlacementProp, coords.x, coords.y, coords.z, false, false, false, false) SetEntityCoords(activePlacementProp, coords.x, coords.y, coords.z, false, false, false, false)
local distCheck = #(GetEntityCoords(cache.ped) - coords) local distCheck = #(GetEntityCoords(ped) - coords)
SetEntityHeading(activePlacementProp, heading) SetEntityHeading(activePlacementProp, heading)
if snapToGround then if snapToGround then
+15 -12
View File
@@ -312,10 +312,11 @@ end
---Reload the player's skin and remove attached objects ---Reload the player's skin and remove attached objects
---@return boolean ---@return boolean
function Utility.ReloadSkin() function Utility.ReloadSkin()
local skinData = Utility.GetEntitySkinData(cache.ped) local ped = PlayerPedId()
Utility.SetEntitySkinData(cache.ped, skinData) local skinData = Utility.GetEntitySkinData(ped)
Utility.SetEntitySkinData(ped, skinData)
for _, props in pairs(GetGamePool("CObject")) do for _, props in pairs(GetGamePool("CObject")) do
if IsEntityAttachedToEntity(cache.ped, props) then if IsEntityAttachedToEntity(ped, props) then
SetEntityAsMissionEntity(props, true, true) SetEntityAsMissionEntity(props, true, true)
DeleteObject(props) DeleteObject(props)
DeleteEntity(props) DeleteEntity(props)
@@ -366,6 +367,7 @@ end
---@param conditionFunction function|nil ---@param conditionFunction function|nil
---@param afterTeleportFunction function|nil ---@param afterTeleportFunction function|nil
function Utility.TeleportPlayer(coords, conditionFunction, afterTeleportFunction) function Utility.TeleportPlayer(coords, conditionFunction, afterTeleportFunction)
local ped = PlayerPedId()
if conditionFunction ~= nil then if conditionFunction ~= nil then
if not conditionFunction() then if not conditionFunction() then
return return
@@ -373,18 +375,18 @@ function Utility.TeleportPlayer(coords, conditionFunction, afterTeleportFunction
end end
DoScreenFadeOut(2500) DoScreenFadeOut(2500)
Wait(2500) Wait(2500)
SetEntityCoords(cache.ped, coords.x, coords.y, coords.z, false, false, false, false) SetEntityCoords(ped, coords.x, coords.y, coords.z, false, false, false, false)
if coords.w then if coords.w then
SetEntityHeading(cache.ped, coords.w) SetEntityHeading(ped, coords.w)
end end
FreezeEntityPosition(cache.ped, true) FreezeEntityPosition(ped, true)
local count = 0 local count = 0
while not HasCollisionLoadedAroundEntity(cache.ped) and count <= 30000 do while not HasCollisionLoadedAroundEntity(ped) and count <= 30000 do
RequestCollisionAtCoord(coords.x, coords.y, coords.z) RequestCollisionAtCoord(coords.x, coords.y, coords.z)
Wait(0) Wait(0)
count = count + 1 count = count + 1
end end
FreezeEntityPosition(cache.ped, false) FreezeEntityPosition(ped, false)
DoScreenFadeIn(1000) DoScreenFadeIn(1000)
if afterTeleportFunction ~= nil then if afterTeleportFunction ~= nil then
afterTeleportFunction() afterTeleportFunction()
@@ -406,8 +408,8 @@ end
function Utility.GetClosestPlayer(coords, distanceScope, includeMe) function Utility.GetClosestPlayer(coords, distanceScope, includeMe)
local players = GetActivePlayers() local players = GetActivePlayers()
local closestPlayer = 0 local closestPlayer = 0
local selfPed = cache.ped local selfPed = PlayerPedId()
local selfCoords = coords or GetEntityCoords(cache.ped) local selfCoords = coords or GetEntityCoords(selfPed)
local closestDistance = distanceScope or 5 local closestDistance = distanceScope or 5
for _, player in ipairs(players) do for _, player in ipairs(players) do
@@ -434,12 +436,13 @@ function Utility.GetClosestVehicle(coords, distanceScope, includePlayerVeh)
local vehicleEntity = nil local vehicleEntity = nil
local vehicleNetID = nil local vehicleNetID = nil
local vehicleCoords = nil local vehicleCoords = nil
local selfCoords = coords or GetEntityCoords(cache.ped) local ped = PlayerPedId()
local selfCoords = coords or GetEntityCoords(ped)
local closestDistance = distanceScope or 5 local closestDistance = distanceScope or 5
local includeMyVeh = includePlayerVeh or false local includeMyVeh = includePlayerVeh or false
local gamePoolVehicles = GetGamePool("CVehicle") local gamePoolVehicles = GetGamePool("CVehicle")
local playerVehicle = IsPedInAnyVehicle(cache.ped, false) and GetVehiclePedIsIn(cache.ped, false) or 0 local playerVehicle = IsPedInAnyVehicle(ped, false) and GetVehiclePedIsIn(ped, false) or 0
for i = 1, #gamePoolVehicles do for i = 1, #gamePoolVehicles do
local thisVehicle = gamePoolVehicles[i] local thisVehicle = gamePoolVehicles[i]
+4 -3
View File
@@ -5,15 +5,16 @@ Dispatch = Dispatch or {}
---@param data table The data to send to the dispatch system. ---@param data table The data to send to the dispatch system.
---@return nil ---@return nil
Dispatch.SendAlert = function(data) Dispatch.SendAlert = function(data)
local ped = PlayerPedId()
TriggerServerEvent('community_bridge:Server:DispatchAlert', { TriggerServerEvent('community_bridge:Server:DispatchAlert', {
sprite = data.blipData.sprite or 161, sprite = data.blipData.sprite or 161,
color = data.blipData.color or 1, color = data.blipData.color or 1,
scale = data.blipData.scale or 0.8, scale = data.blipData.scale or 0.8,
vehicle = data.vehicle or nil, vehicle = data.vehicle or nil,
plate = data.vehicle and GetVehicleNumberPlateText(data.vehicle) or nil, plate = data.vehicle and GetVehicleNumberPlateText(data.vehicle) or nil,
ped = data.ped or cache.ped, ped = data.ped or ped,
pedCoords = data.pedCoords or GetEntityCoords(cache.ped), pedCoords = data.pedCoords or GetEntityCoords(ped),
coords = data.coords or GetEntityCoords(cache.ped), coords = data.coords or GetEntityCoords(ped),
message = data.message or "An Alert Has Been Made", message = data.message or "An Alert Has Been Made",
code = data.code or '10-80', code = data.code or '10-80',
icon = data.icon or 'fas fa-question', icon = data.icon or 'fas fa-question',
+3 -2
View File
@@ -3,14 +3,15 @@ if GetResourceState('bub-mdt') == 'missing' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
Dispatch.SendAlert = function(data) Dispatch.SendAlert = function(data)
local ped = PlayerPedId()
local alertData = { local alertData = {
code = data.code or '10-80', code = data.code or '10-80',
offense = data.message, offense = data.message,
coords = data.coords or GetEntityCoords(cache.ped), coords = data.coords or GetEntityCoords(ped),
info = { label = data.code or '10-80', icon = data.icon or 'fas fa-question' }, info = { label = data.code or '10-80', icon = data.icon or 'fas fa-question' },
blip = data.blipData.sprite or 1, blip = data.blipData.sprite or 1,
isEmergency = data.priority == 1 and true or false, isEmergency = data.priority == 1 and true or false,
blipCoords = data.coords or cache.ped and GetEntityCoords(cache.ped) or { x = 0, y = 0}, blipCoords = data.coords or ped and GetEntityCoords(ped) or { x = 0, y = 0},
} }
exports["bub-mdt"]:CustomAlert(alertData) exports["bub-mdt"]:CustomAlert(alertData)
end end
@@ -3,6 +3,7 @@ if GetResourceState('linden_outlawalert') == 'missing' then return end
Dispatch = Dispatch or {} Dispatch = Dispatch or {}
Dispatch.SendAlert = function(data) Dispatch.SendAlert = function(data)
local ped = PlayerPedId()
TriggerServerEvent('wf-alerts:svNotify', { TriggerServerEvent('wf-alerts:svNotify', {
dispatchData = { dispatchData = {
displayCode = data.code or '211', displayCode = data.code or '211',
@@ -14,7 +15,7 @@ Dispatch.SendAlert = function(data)
info = data.message or "Alert" info = data.message or "Alert"
}, },
caller = 'Anonymous', caller = 'Anonymous',
coords = data.coords or GetEntityCoords(cache.ped) coords = data.coords or GetEntityCoords(ped)
}) })
end end
+2 -1
View File
@@ -6,10 +6,11 @@ Doorlock = Doorlock or {}
---This will get the closest door to the ped ---This will get the closest door to the ped
---@return string | nil ---@return string | nil
Doorlock.GetClosestDoor = function() Doorlock.GetClosestDoor = function()
local ped = PlayerPedId()
local closestDoor = exports["qb-doorlock"]:GetClosestDoor() local closestDoor = exports["qb-doorlock"]:GetClosestDoor()
if Table.CheckPopulated(closestDoor) then return closestDoor end if Table.CheckPopulated(closestDoor) then return closestDoor end
local allDoors = exports["qb-doorlock"]:GetDoorList() local allDoors = exports["qb-doorlock"]:GetDoorList()
local pedCoords = GetEntityCoords(cache.ped) local pedCoords = GetEntityCoords(ped)
local door = 0 local door = 0
local doorDist = 1000.0 local doorDist = 1000.0
for doorID, data in pairs(allDoors) do for doorID, data in pairs(allDoors) do
+2 -1
View File
@@ -6,8 +6,9 @@ Doorlock = Doorlock or {}
---This will get the closest door to the ped ---This will get the closest door to the ped
---@return string | nil ---@return string | nil
Doorlock.GetClosestDoor = function() Doorlock.GetClosestDoor = function()
local ped = PlayerPedId()
local allDoors = exports.rcore_doorlock:getLoadedDoors() local allDoors = exports.rcore_doorlock:getLoadedDoors()
local pedCoords = GetEntityCoords(cache.ped) local pedCoords = GetEntityCoords(ped)
local door = 0 local door = 0
local doorDist = 1000.0 local doorDist = 1000.0
for _, data in pairs(allDoors) do for _, data in pairs(allDoors) do