Files
cfx-server-data/resources/[gameplay]/[examples]/ped-money-drops/server.lua
T
MattiandGitHub c6afa3909c fix(runcode): timeout sweep and ped-money-drops cleanup (#231)
* fix(runcode): use pairs for codes timeout sweep

Signed-off-by: matti.bat <[email protected]>

* fix(ped-money-drops): match entityRemoved cleanup key

Signed-off-by: matti.bat <[email protected]>

---------

Signed-off-by: matti.bat <[email protected]>
2026-09-23 21:52:35 +02:00

38 lines
870 B
Lua

local safePositions = {}
RegisterNetEvent('money:allowPickupNear', function(pedId)
local entity = NetworkGetEntityFromNetworkId(pedId)
Wait(250)
if not DoesEntityExist(entity) then
return
end
if GetEntityHealth(entity) > 100 then
return
end
local coords = GetEntityCoords(entity)
safePositions[pedId] = coords
end)
RegisterNetEvent('money:tryPickup', function(entity)
if not safePositions[entity] then
return
end
local source = source
local playerPed = GetPlayerPed(source)
local coords = GetEntityCoords(playerPed)
if #(safePositions[entity] - coords) < 2.5 then
exports['money']:addMoney(source, 'cash', 40)
end
safePositions[entity] = nil
end)
AddEventHandler('entityRemoved', function(entity)
safePositions[NetworkGetNetworkIdFromEntity(entity)] = nil
end)