-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.lua
More file actions
227 lines (184 loc) · 7.81 KB
/
server.lua
File metadata and controls
227 lines (184 loc) · 7.81 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
local RSGCore = exports['rsg-core']:GetCoreObject()
exports('SendCustomAlert', function(message, distance, alertJobs, options)
local src = source
local player = RSGCore.Functions.GetPlayer(src)
if not player then
if Config.Debug then
print(('Player with source %s not found in RSG Core.'):format(src))
end
return
end
local playerCoords = GetEntityCoords(GetPlayerPed(src))
if Config.Debug then
print(('Custom alert triggered by %s at %s with distance: %s'):format(player.PlayerData.name, playerCoords, distance))
end
-- Geçerli mesafe değeri kontrolü
if distance == nil or type(distance) ~= "number" then
distance = Config.AlertDistance -- Varsayılan değer kullan
if Config.Debug then
print('Invalid distance value, using default: ' .. distance)
end
end
local jobsToAlert = {}
if alertJobs and type(alertJobs) == "table" then
if #alertJobs > 0 then
jobsToAlert = alertJobs
else
for job, active in pairs(alertJobs) do
if active then
table.insert(jobsToAlert, job)
end
end
end
elseif Config.Debug then
print('No alert jobs specified or invalid format. Using default jobs.')
for job, _ in pairs(Config.AlertJobs) do
table.insert(jobsToAlert, job)
end
end
local players = RSGCore.Functions.GetPlayers()
for _, playerId in ipairs(players) do
local targetPlayer = RSGCore.Functions.GetPlayer(playerId)
if targetPlayer then
local targetJob = targetPlayer.PlayerData.job.name
local targetCoords = GetEntityCoords(GetPlayerPed(playerId))
local isJobMatch = false
for _, job in ipairs(jobsToAlert) do
if targetJob == job then
isJobMatch = true
break
end
end
if isJobMatch then
local distanceBetween = #(playerCoords - targetCoords)
if distanceBetween <= distance then
TriggerClientEvent('af-alert:client:customAlert', playerId, playerCoords, message, options)
if Config.Debug then
print(('Custom alert sent to %s (Job: %s, Distance: %.2f)'):format(
GetPlayerName(playerId), targetJob, distanceBetween))
end
elseif Config.Debug then
print(('Player %s is too far (%.2f > %s), no alert sent'):format(
GetPlayerName(playerId), distanceBetween, distance))
end
end
end
end
end)
RegisterNetEvent('af-alert:server:fireAlert')
AddEventHandler('af-alert:server:fireAlert', function(coords)
if not Config.ShootAlert then
if Config.Debug then
print('Shoot alerts are disabled in the config.')
end
return
end
local src = source
local player = RSGCore.Functions.GetPlayer(src)
if not player then
if Config.Debug then
print(('Player with source %s not found in RSG Core.'):format(src))
end
return
end
local playerJob = player.PlayerData.job.name
if Config.AlertJobs[playerJob] and Config.AlertJobs[playerJob] == true then
if Config.Debug then
print(('Player %s is in an ignored alert job (%s), no notification sent.'):format(player.PlayerData.name, playerJob))
end
return
end
local playerCoords = GetEntityCoords(GetPlayerPed(src))
if Config.Debug then
print(('Player %s shot at %s'):format(player.PlayerData.name, coords))
end
-- Sunucu üzerindeki tüm oyuncuları kontrol et
local players = RSGCore.Functions.GetPlayers()
for _, playerId in ipairs(players) do
local targetPlayer = RSGCore.Functions.GetPlayer(playerId)
if targetPlayer then
local targetJob = targetPlayer.PlayerData.job.name
local targetCoords = GetEntityCoords(GetPlayerPed(playerId))
local distanceBetween = #(playerCoords - targetCoords)
if distanceBetween <= Config.AlertDistance then
TriggerClientEvent('af-alert:client:fireAlert', playerId, coords)
if Config.Debug then
print(('Shotfire alert sent to %s (Job: %s, Distance: %.2f)'):format(
GetPlayerName(playerId), targetJob, distanceBetween))
end
elseif Config.Debug then
print(('Player %s is too far (%.2f > %s), no shotfire alert sent'):format(
GetPlayerName(playerId), distanceBetween, Config.AlertDistance))
end
end
end
end)
RegisterNetEvent('af-alert:server:customAlertTrigger')
AddEventHandler('af-alert:server:customAlertTrigger', function(message, distance, alertJobs, alertData)
local src = source
local player = RSGCore.Functions.GetPlayer(src)
if not player then
if Config.Debug then
print(('Player with source %s not found in RSG Core.'):format(src))
end
return
end
local playerCoords = GetEntityCoords(GetPlayerPed(src))
if Config.Debug then
print(('Custom alert triggered by %s at %s with distance: %s'):format(
player.PlayerData.name, playerCoords, distance))
end
if distance == nil or type(distance) ~= "number" then
distance = Config.AlertDistance
if Config.Debug then
print('Invalid distance value, using default: ' .. distance)
end
end
local jobsToAlert = {}
if alertJobs and type(alertJobs) == "table" then
-- Eğer array ise (örn: {"police", "sheriff"}) direkt kullan
if #alertJobs > 0 then
jobsToAlert = alertJobs
else
-- Eğer hash map ise (örn: {police=true, sheriff=true}) key'leri al
for job, active in pairs(alertJobs) do
if active then
table.insert(jobsToAlert, job)
end
end
end
elseif Config.Debug then
print('No alert jobs specified or invalid format. Using default jobs.')
for job, _ in pairs(Config.AlertJobs) do
table.insert(jobsToAlert, job)
end
end
local players = RSGCore.Functions.GetPlayers()
for _, playerId in ipairs(players) do
local targetPlayer = RSGCore.Functions.GetPlayer(playerId)
if targetPlayer then
local targetJob = targetPlayer.PlayerData.job.name
local targetCoords = GetEntityCoords(GetPlayerPed(playerId))
local isJobMatch = false
for _, job in ipairs(jobsToAlert) do
if targetJob == job then
isJobMatch = true
break
end
end
if isJobMatch then
local distanceBetween = #(playerCoords - targetCoords)
if distanceBetween <= distance then
TriggerClientEvent('af-alert:client:customAlert', playerId, playerCoords, message, alertData)
if Config.Debug then
print(('Custom alert sent to %s (Job: %s, Distance: %.2f)'):format(
GetPlayerName(playerId), targetJob, distanceBetween))
end
elseif Config.Debug then
print(('Player %s is too far (%.2f > %s), no alert sent'):format(
GetPlayerName(playerId), distanceBetween, distance))
end
end
end
end
end)