forked from CsokiHUN/fl_spectate
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.lua
64 lines (50 loc) · 1.59 KB
/
server.lua
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
function getPlayerList()
local players = {}
for _, serverId in pairs(GetPlayers()) do
local xPlayer = ESX.GetPlayerFromId(serverId)
if xPlayer then
local job = xPlayer.getJob()
local jobText = job.label .. " - " .. job.grade_label
table.insert(players, {
serverId = serverId,
name = xPlayer.getName() .. " (" .. GetPlayerName(serverId) .. ")",
group = xPlayer.getGroup(),
jobText = jobText,
})
end
end
return players
end
ESX.RegisterServerCallback("requestServerPlayers", function(source, cb)
local xSource = ESX.GetPlayerFromId(source)
if not xSource or not ALLOWED_GROUPS[xSource.getGroup()] then
return cb(false)
end
cb(getPlayerList())
end)
ESX.RegisterServerCallback("requestPlayerCoords", function(source, cb, serverId)
local xSource = ESX.GetPlayerFromId(source)
if not xSource then
return cb(false)
end
local targetPed = GetPlayerPed(serverId)
if targetPed <= 0 or not ALLOWED_GROUPS[xSource.getGroup()] then
return cb(false)
end
cb(GetEntityCoords(targetPed))
end)
ESX.RegisterServerCallback("kickPlayerSpectate", function(source, cb, target, reason)
local xSource = ESX.GetPlayerFromId(source)
if not xSource or not ALLOWED_GROUPS[xSource.getGroup()] then
return
end
DropPlayer(target, ("Kicked from the server.\nReason: %s\nAdmin: %s"):format(GetPlayerName(source), reason))
cb(getPlayerList())
end)
RegisterCommand("spectate", function(player)
local xPlayer = ESX.GetPlayerFromId(player)
if not xPlayer or not ALLOWED_GROUPS[xPlayer.getGroup()] then
return
end
TriggerClientEvent("openSpectateMenu", player, getPlayerList())
end)