Turfwar/server/police_wanted_escalate.lua

97 lines
3.2 KiB
Lua

print("^2[turfwar]^7 police_wanted_escalate.lua loaded (server)")
local HEAT_WINDOW_SEC = 600
local POLICE_GANG_ID = 3
local MIN_STARS_FOR_COP_DAMAGE = 1
local function StarsForCount(n)
if n <= 0 then return 0 end
if n == 1 then return 2 end
if n == 2 then return 3 end
if n == 3 then return 4 end
return 5
end
-- heat[killerSrc] = { timestamps = { t1, t2, ... } }
local heat = {}
local function nowSec() return os.time() end
local function pruneOld(killerSrc)
local h = heat[killerSrc]
if not h then return 0 end
local cutoff = nowSec() - HEAT_WINDOW_SEC
local keep = {}
for _, t in ipairs(h.timestamps) do
if t >= cutoff then keep[#keep+1] = t end
end
h.timestamps = keep
return #keep
end
local function addCopKill(killerSrc)
heat[killerSrc] = heat[killerSrc] or { timestamps = {} }
heat[killerSrc].timestamps[#heat[killerSrc].timestamps + 1] = nowSec()
return pruneOld(killerSrc)
end
-- IMPORTANT: This is the #1 failure point.
-- Your PlayerGang table might not be global in THIS file.
local function IsPolicePlayer(src)
-- If PlayerGang is global, great:
if PlayerGang ~= nil then
return PlayerGang[src] == POLICE_GANG_ID
end
-- Fallback option: ACE permission check (enable if you use it)
-- return IsPlayerAceAllowed(src, "police")
return false
end
-- Debug helper
local function dbg(msg)
print(("^3[turfwar wanted]^7 %s"):format(msg))
end
-- --------------- TEST PIPELINE (temporary) ---------------
-- Set to true to bypass police checks while testing wiring
local BYPASS_POLICE_CHECK = true
-- --------------- /TEST PIPELINE --------------------------
RegisterNetEvent('turfwar:wanted:policeDamagedBy', function(killerSrc)
local victimSrc = source
killerSrc = tonumber(killerSrc) or 0
dbg(("policeDamagedBy victim=%d killer=%d"):format(victimSrc, killerSrc))
if killerSrc <= 0 or killerSrc == victimSrc then return end
if not BYPASS_POLICE_CHECK then
local isPolice = IsPolicePlayer(victimSrc)
dbg((" IsPolicePlayer(%d)=%s"):format(victimSrc, tostring(isPolice)))
if not isPolice then return end
end
TriggerClientEvent('turfwar:wanted:setMinimum', killerSrc, MIN_STARS_FOR_COP_DAMAGE)
dbg((" -> setMinimum %d stars to %d"):format(MIN_STARS_FOR_COP_DAMAGE, killerSrc))
end)
RegisterNetEvent('turfwar:wanted:policeKilledBy', function(killerSrc)
local victimSrc = source
killerSrc = tonumber(killerSrc) or 0
dbg(("policeKilledBy victim=%d killer=%d"):format(victimSrc, killerSrc))
if killerSrc <= 0 or killerSrc == victimSrc then return end
if not BYPASS_POLICE_CHECK then
local isPolice = IsPolicePlayer(victimSrc)
dbg((" IsPolicePlayer(%d)=%s"):format(victimSrc, tostring(isPolice)))
if not isPolice then return end
end
local count = addCopKill(killerSrc)
local stars = StarsForCount(count)
TriggerClientEvent('turfwar:wanted:setEscalated', killerSrc, stars, count, HEAT_WINDOW_SEC)
dbg((" -> setEscalated killer=%d heat=%d stars=%d"):format(killerSrc, count, stars))
end)