-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathclient.lua
120 lines (105 loc) · 3.76 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
--------------------------------
--- RP Revive, Made by FAXES ---
--------------------------------
--- Config ---
local reviveTimer = 10 -- Change the amount of time to wait before allowing revive (in seconds)
local respawnTimer = 5 -- Change the amount of time to wait before allowing revive (in seconds)
local reviveColor = "~y~" -- Color used for revive button
local respawnColor = "~r~" -- Color used for respawn button
local chatColor = "~b~" -- The chat color overall
-- Add/remove spawn points at line 77
--- Code ---
timerCount1 = reviveTimer
timerCount2 = respawnTimer
isDead = false
cHavePerms = false
AddEventHandler('playerSpawned', function()
local src = source
TriggerServerEvent("RPRevive:CheckPermission", src)
end)
RegisterNetEvent("RPRevive:CheckPermission:Return")
AddEventHandler("RPRevive:CheckPermission:Return", function(havePerms)
cHavePerms = havePerms
end)
-- Turn off automatic respawn here instead of updating FiveM file.
AddEventHandler('onClientMapStart', function()
Citizen.Trace("RPRevive: Disabling the autospawn.")
exports.spawnmanager:spawnPlayer() -- Ensure player spawns into server.
Citizen.Wait(2500)
exports.spawnmanager:setAutoSpawn(false)
Citizen.Trace("RPRevive: Autospawn is disabled.")
end)
function respawnPed(ped, coords)
isDead = false
timerCount1 = reviveTimer
timerCount2 = respawnTimer
SetEntityCoordsNoOffset(ped, coords.x, coords.y, coords.z, false, false, false, true)
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, coords.heading, true, false)
SetPlayerInvincible(ped, false)
TriggerEvent('playerSpawned', coords.x, coords.y, coords.z, coords.heading)
ClearPedBloodDamage(ped)
end
function revivePed(ped)
isDead = false
timerCount1 = reviveTimer
timerCount2 = respawnTimer
local playerPos = GetEntityCoords(ped, true)
NetworkResurrectLocalPlayer(playerPos, true, true, false)
SetPlayerInvincible(ped, false)
ClearPedBloodDamage(ped)
end
function ShowInfoRevive(text)
SetNotificationTextEntry("STRING")
AddTextComponentSubstringPlayerName(text)
DrawNotification(true, true)
end
Citizen.CreateThread(function()
local spawnPoints = {}
function createSpawnPoint(x, y, z, heading)
local newObject = {
x = x,
y = y,
z = z,
heading = heading
}
table.insert(spawnPoints, newObject)
end
createSpawnPoint(1828.44, 3692.32, 34.22, 37.12) -- Back of Sandy Shores Hospital
while true do
Citizen.Wait(0)
ped = GetPlayerPed(-1)
if IsEntityDead(ped) then
isDead = true
SetPlayerInvincible(ped, true)
SetEntityHealth(ped, 1)
ShowInfoRevive(chatColor .. 'You are dead. Use ' .. reviveColor .. 'E ' .. chatColor ..'to revive or ' .. respawnColor .. 'R ' .. chatColor .. 'to respawn.')
if IsControlJustReleased(0, 38) and GetLastInputMethod(0) then
if timerCount1 == 0 or cHavePerms then
revivePed(ped)
else
TriggerEvent('chat:addMessage', {args = {'^1^*Wait ' .. timerCount1 .. ' more seconds before reviving'}})
end
elseif IsControlJustReleased(0, 45) and GetLastInputMethod(0) then
if timerCount2 == 0 or cHavePerms then
local coords = spawnPoints[math.random(1,#spawnPoints)]
respawnPed(ped, coords)
else
TriggerEvent('chat:addMessage', {args = {'^1^*Wait ' .. timerCount2 .. ' more seconds before respawning'}})
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
if isDead then
if timerCount1 ~= 0 then
timerCount1 = timerCount1 - 1
end
if timerCount2 ~= 0 then
timerCount2 = timerCount2 - 1
end
end
Citizen.Wait(1000)
end
end)