Hey I’m trying to make a Panic Button script but I have multiple bugs I dont know how to fix.
-
When using the Script multiple times and reconnecting it then shows every Panic Button that was ever used
-
It wont delete the enabled blips after 5 minutes. I dont know how to fix it…
-
I think every player sees the blips but I want it so only people with the police job see it.
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
local blips = {}
local function sendPanicMessage()
local message = "Panic Button got pressed!"
for _, player in ipairs(ESX.GetPlayers()) do
local xPlayer = ESX.GetPlayerFromId(player)
if xPlayer.job.name == "police" then
TriggerClientEvent('okokNotify:Alert', player, 'Panic Button', message, 5000, 'panic', true)
local playerPed = GetPlayerPed(player)
local playerCoords = GetEntityCoords(playerPed)
local blip = AddBlipForCoord(playerCoords)
SetBlipSprite(blip, 41)
table.insert(blips, blip)
SetTimeout(60000, function()
print("Removing blip")
for i, existingBlip in ipairs(blips) do
if existingBlip == blip then
table.remove(blips, i)
RemoveBlip(blip)
break
end
end
end)
end
end
end
RegisterCommand("panic", function(source, args)
local xPlayer = ESX.GetPlayerFromId(source)
local jobName = xPlayer.job.name
if jobName == 'police' then
sendPanicMessage()
else
TriggerClientEvent('esx:showNotification', source, "You cannot use this command.")
end
end, false)