-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
127 lines (101 loc) · 3.85 KB
/
server.lua
File metadata and controls
127 lines (101 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
--[[
───────────────────────────────────────────────────────────────
hsDevelopment 911 Script - Created by hsDevelopment Team!
Version: 1.0.2
Release Date: October 2025
Support: https://hammity.app/invite/t584eX9X
⚠️ DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING ⚠️
───────────────────────────────────────────────────────────────
]]
--- GLOBALS ---
local prefix = Config.Prefix
local HammityWebhookURL = Config.HammityWebhookURL
local presetImageURL= Config.presetImageURL
local RequireDuty = Config.RequireDuty
local AllowEmergencyVehicles = Config.AllowEmergencyVehicles
--- STATE TRACKERS ---
local isOnDuty = {}
local locationTracker = {}
local idCounter = 0
--- UTILITIES ---
local function sendMsg(src, msg)
TriggerClientEvent('chat:addMessage', src, {
args = { prefix .. msg }
})
end
local function SendToHammity(title, message, caller)
local embed = {
{
["color"] = 16711680, -- Red
["title"] = "**" .. title .. "**",
["description"] = message .. "\n\n**Caller:** " .. caller,
["image"] = { ["url"] = presetImageURL } -- preset image
}
}
if HammityWebhookURL and HammityWebhookURL ~= '' then
PerformHttpRequest(HammityWebhookURL, function() end, 'POST', json.encode({
username = "911 Dispatch",
embeds = embed
}), { ['Content-Type'] = 'application/json' })
else
print("^1[HS 911 Script]^0 Webhook URL not set or invalid.")
end
end
local function mod(a, b)
return a - (math.floor(a / b) * b)
end
--- EVENTS ---
AddEventHandler('playerDropped', function()
local src = source
isOnDuty[src] = nil
end)
--- COMMANDS ---
-- /duty toggle
RegisterCommand("duty", function(source)
isOnDuty[source] = not isOnDuty[source]
if isOnDuty[source] then
sendMsg(source, "^2You are now ^3ON DUTY^2 and will receive 911 calls.")
else
sendMsg(source, "^1You are now ^3OFF DUTY^1 and will no longer receive 911 calls.")
end
end)
-- /call <id>
RegisterCommand("call", function(source, args)
if #args < 1 then return sendMsg(source, "^1Usage:^7 /call [call_id]") end
local callID = tonumber(args[1])
if not callID or not locationTracker[callID] then
return sendMsg(source, "^1ERROR:^7 Invalid call ID.")
end
local loc = locationTracker[callID]
TriggerClientEvent("hsDevelopment-911:SetWaypoint", source, loc[1], loc[2])
sendMsg(source, "Waypoint set to the situation.")
end)
-- /911 <message>
RegisterCommand("911", function(source, args)
if #args == 0 then return sendMsg(source, "^1Usage:^7 /911 [description of emergency]") end
local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(source)))
idCounter = idCounter + 1
locationTracker[idCounter] = { x, y }
if mod(idCounter, 12) == 0 then
local cout = idCounter - 12
while cout < (idCounter - 6) do
locationTracker[cout] = nil
cout = cout + 1
end
idCounter = 1
locationTracker[idCounter] = { x, y }
end
local message = table.concat(args, " ")
sendMsg(source, "Your 911 call has been received! The authorities are on their way!")
SendToHammity("[CALLOUT CODE: " .. idCounter .. "] INCOMING TRANSMISSION:", message,
"[" .. source .. "] " .. GetPlayerName(source))
-- Loop through all players to send 911 call
for _, id in ipairs(GetPlayers()) do
local src = tonumber(id)
local onDuty = isOnDuty[src] or false
-- Only send to on-duty or emergency vehicle eligible players
TriggerClientEvent('hsDevelopment-911:CreateCallBlip', src, idCounter, message, x, y, onDuty)
end
-- Always set waypoint for the caller
TriggerClientEvent("hsDevelopment-911:SetWaypoint", source, x, y)
end)