-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
104 lines (93 loc) · 2.45 KB
/
client.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
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
local isSpectating = false
local lastCoords = nil
RegisterNUICallback('close', function(data, cb)
SetNuiFocus(false, false)
cb('ok')
end)
RegisterNUICallback('GetPlayersData', function(data, cb)
ESX.TriggerServerCallback("RAGE_SpectateMenu:GetPlayers", function(players)
return cb({
message = 'playersList',
playersObject = players
})
end)
end)
RegisterNUICallback('SpectatePlayer', function(data, cb)
if GetPlayerServerId(PlayerId()) == data.playerId then
return cb({
method = 'self',
message = Config.SelfSpectateMessage
})
else
startSpectate(data.playerId)
return cb('ok')
end
end)
RegisterNUICallback('KickPlayer', function(data, cb)
if GetPlayerServerId(PlayerId()) == data.playerId then
return cb({
method = "self",
message = Config.KickSelfMessage
})
else
kickPlayer(data.playerId)
Wait(1000)
return cb({
method = "ok",
message = Config.KickPlayerMessage
})
end
end)
function startSpectate(targetPlayerId)
if not isSpectating then
local localPed = PlayerPedId()
lastCoords = GetEntityCoords(localPed)
ESX.TriggerServerCallback("RAGE_SpectateMenu:GetPlayerCoords", function(coords)
RequestCollisionAtCoord(coords)
SetEntityVisible(localPed, false)
SetEntityCoords(localPed, coords + vector3(0, 0, 10))
FreezeEntityPosition(localPed, true)
Wait(1500)
SetEntityCoords(localPed, coords - vector3(0, 0, 10))
local targetPed = GetPlayerPed(GetPlayerFromServerId(targetPlayerId))
NetworkSetInSpectatorMode(true, targetPed)
isSpectating = true
spectateThred(localPed)
end, targetPlayerId)
end
end
function stopSpectate(localPed)
if isSpectating then
RequestCollisionAtCoord(lastCoords)
NetworkSetInSpectatorMode(false, localPed)
FreezeEntityPosition(localPed, false)
SetEntityCoords(localPed, lastCoords)
SetEntityVisible(localPed, true)
SendNUIMessage({
action = "StopSpec"
})
currentPlayer = nil
isSpectating = false
lastCoords = nil
end
end
function kickPlayer(targetPlayerId)
TriggerServerEvent("RAGE_SpectateMenu:KickPlayer", targetPlayerId)
end
RegisterNetEvent('RAGE_SpectateMenu:OpenMenu')
AddEventHandler('RAGE_SpectateMenu:OpenMenu', function()
SendNUIMessage({
action = "ShowMenu"
})
SetNuiFocus(true, true)
end)
function spectateThred(localPed)
Citizen.CreateThread(function()
while isSpectating do
Citizen.Wait(0)
if IsControlJustReleased(0, Config.StopSpecKey) then
stopSpectate(localPed)
end
end
end)
end