glitchdetector icon

atc/server.lua

glitchdetector | PRO | 08/05/18 04:27:42 PM UTC | 0 ⭐ | 460 👁️ | Never ⏰ | []
Lua |

1.18 KB

|

None

|

0 👍

/

0 👎

activeBlips = {}
 
function hashPos(pos)
    x = math.floor(pos.x) * 2^12
    y = math.floor(pos.y) * 2^6
    z = math.floor(pos.z)
    
    return x+y+z
end
 
RegisterServerEvent("atc:flashingBlip")
AddEventHandler("atc:flashingBlip", function(posv, blipid, time, col)
    TriggerClientEvent("atc:startFlashingBlip", -1, posv, blipid, time, col)
 
    local pos = hashPos(posv)
 
    if activeBlips[pos] == nil then
        activeBlips[pos] = 0
    elseif activeBlips[pos] > 0 then
        TriggerClientEvent("atc:warning", source)
        print("[ATC] warning player "..source.." for calling out at "..pos)
 
        print("[ATC] current state:")
        for k,v in next, activeBlips do
            print(k.." = "..v)
        end
    end
 
    activeBlips[pos] = activeBlips[pos] + 1
    --print("[atc] added blip   "..pos.." = "..activeBlips[pos])
    SetTimeout(time * 1000, function()
        activeBlips[pos] = activeBlips[pos] - 1
        --print("[atc] removed blip "..pos.." = "..activeBlips[pos])
 
        if activeBlips[pos] < 0 then
            print("[ATC] Bug or race condition detected... Resetting.")
            activeBlips[pos] = 0
        end
    end)
end)

Comments