Turfwar/server/player_police.lua

75 lines
2.0 KiB
Lua

-- server/player_police.lua
print("^2[turfwar]^7 server/player_police.lua loaded (police tracking)")
local PP = Config.PlayerPolice or {}
local POLICE = tonumber(PP.POLICE_GANG_ID) or 3
local PREFIX = PP.CHAT_PREFIX or "^4[POLICE]^7 "
local ONLY_UP = (PP.ONLY_ANNOUNCE_ON_STAR_INCREASE ~= false)
local lastStars = {} -- [src] = stars
local function isPolice(src)
local g = (PlayerGang and PlayerGang[src]) or 0
return tonumber(g) == POLICE
end
local function sendToPolice(eventName, ...)
for _, sid in ipairs(GetPlayers()) do
local p = tonumber(sid)
if p and isPolice(p) then
TriggerClientEvent(eventName, p, ...)
end
end
end
local function chatToPolice(msg)
sendToPolice('turfwar:pp:chat', msg)
end
RegisterNetEvent('turfwar:pp:starsChanged', function(stars, interior)
local src = source
stars = tonumber(stars) or 0
interior = (interior == true)
local prev = lastStars[src] or 0
lastStars[src] = stars
if stars > 0 then
local announce = true
if ONLY_UP then announce = (stars > prev) end
if announce then
chatToPolice(("%sA %d star crime has been detected"):format(PREFIX, stars))
end
end
-- tell police the mode changed
sendToPolice('turfwar:pp:update', src, {
type = "mode",
stars = stars,
interior = interior
})
end)
RegisterNetEvent('turfwar:pp:posUpdate', function(stars, interior, x, y, z, heading)
local src = source
stars = tonumber(stars) or 0
interior = (interior == true)
x = tonumber(x); y = tonumber(y); z = tonumber(z)
heading = tonumber(heading) or 0.0
if not x or not y or not z then return end
sendToPolice('turfwar:pp:update', src, {
type = "pos",
stars = stars,
interior = interior,
x = x, y = y, z = z,
heading = heading
})
end)
AddEventHandler('playerDropped', function()
local src = source
lastStars[src] = nil
sendToPolice('turfwar:pp:clear', src)
end)