-
Notifications
You must be signed in to change notification settings - Fork 193
Expand file tree
/
Copy patheventhandlers.lua
More file actions
179 lines (151 loc) · 5.41 KB
/
eventhandlers.lua
File metadata and controls
179 lines (151 loc) · 5.41 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
local timer = {}
--- Safely checks a boolean export on a started resource.
---@param res string Resource name
---@param exp string Export function name
---@return boolean
function InMinigame(res, exp)
if GetResourceState(res) ~= "started" then return false end
local ok, result = pcall(function()
return exports[res] and exports[res][exp] and exports[res][exp]()
end)
return ok and result == true
end
---@param name string -- The name of the timer
---@param action function -- The function to execute when the timer is up
---@vararg any -- Arguments to pass to the action function
local function WaitTimer(name, action, ...)
if not Config.DefaultAlerts[name] then return end
if not timer[name] then
timer[name] = true
action(...)
Wait(Config.DefaultAlertsDelay * 1000)
timer[name] = false
end
end
---@param witnesses table | Array of peds that witnessed the event
---@param ped number | Ped ID to check
---@return boolean | Returns true if the ped is in the witnesses table
local function isPedAWitness(witnesses, ped)
for k, v in pairs(witnesses) do
if v == ped then
return true
end
end
return false
end
---@param ped number | Ped ID to check
---@return boolean | Returns true if the ped is holding a whitelisted gun
local function BlacklistedWeapon(ped)
for i = 1, #Config.WeaponWhitelist do
local weaponHash = joaat(Config.WeaponWhitelist[i])
if GetSelectedPedWeapon(ped) == weaponHash then
return true -- Is a whitelisted weapon
end
end
return false -- Is not a whitelisted weapon
end
AddEventHandler('CEventGunShot', function(witnesses, ped)
if InMinigame("pug-paintball", "IsInPaintball") or InMinigame("pug-battleroyale", "IsInBattleRoyale") then return end
if IsPedCurrentWeaponSilenced(cache.ped) then return end
if inNoDispatchZone then return end
if BlacklistedWeapon(cache.ped) then return end
WaitTimer('Shooting', function()
if cache.ped ~= ped then return end
if PlayerData.job.type == 'leo' then
if not Config.Debug then
return
end
end
if inHuntingZone then
exports['ps-dispatch']:Hunting()
return
end
if witnesses and not isPedAWitness(witnesses, ped) then return end
if cache.vehicle then
exports['ps-dispatch']:VehicleShooting()
else
exports['ps-dispatch']:Shooting()
end
end)
end)
AddEventHandler('CEventShockingSeenMeleeAction', function(witnesses, ped)
WaitTimer('Melee', function()
if cache.ped ~= ped then return end
if witnesses and not isPedAWitness(witnesses, ped) then return end
if not IsPedInMeleeCombat(ped) then return end
exports['ps-dispatch']:Fight()
end)
end)
AddEventHandler('CEventPedJackingMyVehicle', function(_, ped)
WaitTimer('Autotheft', function()
if cache.ped ~= ped then return end
local vehicle = GetVehiclePedIsUsing(ped, true)
exports['ps-dispatch']:CarJacking(vehicle)
end)
end)
AddEventHandler('CEventShockingCarAlarm', function(_, ped)
WaitTimer('Autotheft', function()
if cache.ped ~= ped then return end
local vehicle = GetVehiclePedIsUsing(ped, true)
exports['ps-dispatch']:VehicleTheft(vehicle)
end)
end)
AddEventHandler('CEventExplosionHeard', function(witnesses, ped)
if witnesses and not isPedAWitness(witnesses, ped) then return end
WaitTimer('Explosion', function()
exports['ps-dispatch']:Explosion()
end)
end)
AddEventHandler('gameEventTriggered', function(name, args)
if name ~= 'CEventNetworkEntityDamage' then return end
local victim = args[1]
local isDead = args[6] == 1
WaitTimer('PlayerDowned', function()
if not victim or victim ~= cache.ped then return end
if not isDead then return end
if PlayerData.job.type == 'leo' then
exports['ps-dispatch']:OfficerDown()
elseif PlayerData.job.type == 'ems' then
exports['ps-dispatch']:EmsDown()
else
exports['ps-dispatch']:InjuriedPerson()
end
end)
end)
local SpeedingEvents = {
'CEventShockingCarChase',
'CEventShockingDrivingOnPavement',
'CEventShockingBicycleOnPavement',
'CEventShockingMadDriverBicycle',
'CEventShockingMadDriverExtreme',
'CEventShockingEngineRevved',
'CEventShockingInDangerousVehicle'
}
local exemptVehicleClass = {
[15] = true, -- Helicopters
[16] = true, -- Planes
}
local SpeedTrigger = 0
for i = 1, #SpeedingEvents do
local event = SpeedingEvents[i]
AddEventHandler(event, function(_, ped)
WaitTimer('Speeding', function()
local currentTime = GetGameTimer()
if currentTime - SpeedTrigger < 10000 then
return
end
if cache.ped ~= ped then return end
if PlayerData.job.type == 'leo' then
if not Config.Debug then
return
end
end
local vehicleClass = GetVehicleClass(cache.vehicle)
if exemptVehicleClass[vehicleClass] then return end
if GetEntitySpeed(cache.vehicle) * 3.6 < (80 + math.random(0, 20)) then return end
if cache.ped ~= GetPedInVehicleSeat(cache.vehicle, -1) then return end
exports['ps-dispatch']:SpeedingVehicle()
SpeedTrigger = GetGameTimer()
end)
end)
end