-
Notifications
You must be signed in to change notification settings - Fork 0
/
cl_main.lua
122 lines (101 loc) · 3.33 KB
/
cl_main.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
local VORPcore = {}
TriggerEvent("getCore", function(core)
VORPcore = core
end)
local headMask = false
RegisterNetEvent('RemoveHeadBag', function(player)
DeleteEntity(Object)
SetEntityAsNoLongerNeeded(Object)
SendNUIMessage({
["action"] = "remove"
})
headMask = false
end)
RegisterNetEvent("StartThread", function(player)
ped = PlayerPedId()
Object = CreateObject(GetHashKey("p_bucket03x"), 0, 0, 0, true, true, true)
AttachEntityToEntity(Object, ped, GetPedBoneIndex(ped, 21030), 0.2, 0-0.02, 0, 0, 270.0, 60.0, true, true, false, true, 1, true)
SetEntityCompletelyDisableCollision(Object, false, true)
SendNUIMessage({
["action"] = "open"
})
headMask = true
while headMask do
Wait(10)
if IsEntityDead(ped) then
if not Config.RemoveonDeath then
OnRespawn()
else
DeleteEntity(Object)
SendNUIMessage({
["action"] = "remove"
})
break
end
end
end
end)
AddEventHandler("playerSpawned", function()
DeleteEntity(Object)
SetEntityAsNoLongerNeeded(Object)
headMask = false
end)
RegisterNetEvent("CheckThread")
AddEventHandler("CheckThread", function()
local closestPlayer, closestDistance = GetClosestPlayer()
local player = GetPlayerPed(-1)
if closestPlayer == -1 or closestDistance > 2.0 then
VORPcore.NotifyRightTip("No players nearby!",4000)
else
if not headMask then
TriggerServerEvent("nc-headbag:getClosestPlayer", GetPlayerServerId(closestPlayer))
headMask = true
else
TriggerServerEvent("nc-headbag:getClosestPlayer2", GetPlayerServerId(closestPlayer))
headMask = false
end
end
end)
function GetClosestPlayer()
local players, closestDistance, closestPlayer = GetActivePlayers(), -1, -1
local playerPed, playerId = PlayerPedId(), PlayerId()
local coords, usePlayerPed = coords, false
if coords then
coords = vector3(coords.x, coords.y, coords.z)
else
usePlayerPed = true
coords = GetEntityCoords(playerPed)
end
for i=1, #players, 1 do
local tgt = GetPlayerPed(players[i])
if not usePlayerPed or (usePlayerPed and players[i] ~= playerId) then
local targetCoords = GetEntityCoords(tgt)
local distance = #(coords - targetCoords)
if closestDistance == -1 or closestDistance > distance then
closestPlayer = players[i]
closestDistance = distance
playerid = GetPlayerServerId(players[i])
tgt1 = GetPlayerPed(players[i])
end
end
end
return closestPlayer, closestDistance, playerid, tgt1
end
function OnRespawn()
RegisterNetEvent("vorp:PlayerForceRespawn", function()
print("THIS IS HAPPENING")
DeleteEntity(Object)
SetEntityAsNoLongerNeeded(Object)
SendNUIMessage({
["action"] = "remove"
})
headMask = false
end)
end
RegisterCommand(Config.bucketcommand, function() -- on duty command
local _source = source
if headMask then
TriggerServerEvent("nc-headbag:givebagback", _source)
TriggerEvent("CheckThread")
end
end)