Skip to content

Commit

Permalink
BETA 2
Browse files Browse the repository at this point in the history
  • Loading branch information
IlMelons authored Oct 27, 2024
1 parent 89c37cc commit b607cd6
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 18 deletions.
75 changes: 61 additions & 14 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
Alerts = {}
AlertsBlips = {Blips = {}, Radius = {}}

local AlertsDisabled = false
local SilentAlerts = false

function DeleteAlert(alertdata)
for k, data in pairs(Alerts) do
if data.id == alertdata.id then
Alerts[k] = nil
break
end
end
end

function ConvertColor(priority)
if priority == "normal" then
return "#FFFF00"
Expand All @@ -21,6 +14,60 @@ function ConvertColor(priority)
end
end

function ConvertBlipColor(priority)
if priority == "normal" then
return 5
elseif priority == "medium" then
return 47
elseif priority == "high" then
return 1
end
end

function HandleAlerts(alertdata, action)
if action == "add" then
Alerts[#Alerts + 1] = alertdata
elseif action == "remove" then
for k, data in pairs(Alerts) do
if data.id == alertdata.id then
Alerts[k] = nil
break
end
end
end
end

function HandleBlips(alertdata, action)
if action == "add" then
local id = alertdata.id
local coords = alertdata.coords
local color = ConvertBlipColor(alertdata.priority)

local alertBlip = AddBlipForCoord(coords.x, coords.y, coords.z)
local alertBlipRadius = AddBlipForRadius(coords.x, coords.y, coords.z, 30.0)
SetBlipSprite(alertBlip, alertdata.blip or 2)
SetBlipColour(alertBlip, color or 5)
SetBlipScale(alertBlip, 0.8)
SetBlipDisplay(alertBlip, 2)
SetBlipCategory(alertBlip, 1)
SetBlipColour(alertBlipRadius, color or 84)
SetBlipAlpha(alertBlipRadius, 128)

BeginTextCommandSetBlipName("STRING")
AddTextComponentSubstringPlayerName(alertdata.title or id)
EndTextCommandSetBlipName(alertBlip)

AlertsBlips.Blips[id] = alertBlip
AlertsBlips.Radius[id] = alertBlipRadius
elseif action == "remove" then
local id = alertdata.id
RemoveBlip(AlertsBlips.Blips[id])
RemoveBlip(AlertsBlips.Radius[id])
AlertsBlips.Blips[id] = nil
AlertsBlips.Radius[id] = nil
end
end

RegisterNetEvent("melons_dispatch:client:SettingsAlerts", function(action)
if action == "toggle" then
AlertsDisabled = not AlertsDisabled
Expand All @@ -36,11 +83,14 @@ end)
RegisterNetEvent("melons_dispatch:client:DispatchAlert", function(alertdata, action)
if AlertsDisabled then return end

HandleAlerts(alertdata, action)
HandleBlips(alertdata, action)

if action == "add" then
TriggerEvent("melons_dispatch:client:EditAlerts", alertdata, true)
if not SilentAlerts then
PlaySoundFrontend(-1, "CONFIRM_BEEP", "HUD_MINI_GAME_SOUNDSET", 0)
end

lib.notify({
title = alertdata.code.." | "..alertdata.title,
description = alertdata.message,
Expand All @@ -50,9 +100,6 @@ RegisterNetEvent("melons_dispatch:client:DispatchAlert", function(alertdata, act
icon = alertdata.icon,
iconColor = ConvertColor(alertdata.priority)
})
Alerts[#Alerts + 1] = alertdata
elseif action == "remove" then
DeleteAlert(alertdata)
end
end)

Expand Down Expand Up @@ -91,7 +138,7 @@ RegisterNetEvent("melons_dispatch:client:OpenDispatchMenu", function()
OpenDispatchMenu()
end)

local OpenDispatchMenu = lib.addKeybind({
OpenDispatchMenu = lib.addKeybind({
name = 'OpenDispatchMenu',
description = 'Open Dispatch Menu',
defaultKey = "F10",
Expand Down
5 changes: 4 additions & 1 deletion config/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ return {
code = "10-1",
icon = "cart-shopping",
priority = "normal", -- "normal", "medium", "high"
blip = 59,
},
["fleecarobbery"] = {
title = "Fleeca Robbery",
message = "A robbery has been reported.",
code = "10-2",
icon = "dollar-sign",
priority = "medium", -- "normal", "medium", "high"
blip = 276,
},
["pacificrobbery"] = {
title = "Pacific Robbery",
message = "A robbery has been reported.",
code = "10-2",
icon = "building-columns",
priority = "high", -- "normal", "medium", "high"
}
blip = 84,
},
}
}
3 changes: 1 addition & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ lua54 "yes"

author "IlMelons"
description "Simple Dispatch made with ox_lib"
version "1.0.0 [BETA]"
version "1.0.0 [BETA 2]"

ox_lib "locale"

Expand All @@ -13,7 +13,6 @@ shared_scripts {
}

client_scripts {
"config/client.lua",
"client/client.lua",
}

Expand Down
8 changes: 8 additions & 0 deletions locales/it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"alerts_toggle_title": "Avvisi",
"alerts_mute_title": "Avvisi Silenziati",
"alerts_toggle_message": "Stato avvisi: ",
"alerts_mute_message": "Stato avvisi silenziosi: ",
"enabled": "Attivati",
"disabled": "Disattivati"
}
9 changes: 8 additions & 1 deletion server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ end)

lib.addCommand("opendispatch", { help = "Opens Dispatch Menu", restricted = false}, function(source, args, raw)
TriggerClientEvent("melons_dispatch:client:OpenDispatchMenu", source)
end)
end)

---@description UNCOMMENT FOR TESTING
-- lib.addCommand("testalerts", { help = "Test Alerts", restricted = false}, function(source, args, raw)
-- DispatchAlert({ coords = vector3(0.0, 0.0, 0.0), jobs = "police"}, "storerobbery")
-- DispatchAlert({ coords = vector3(0.0, 50.0, 0.0), jobs = "police"}, "fleecarobbery")
-- DispatchAlert({ coords = vector3(0.0, -50.0, 0.0), jobs = "police"}, "pacificrobbery")
-- end)

0 comments on commit b607cd6

Please sign in to comment.