-
Notifications
You must be signed in to change notification settings - Fork 5
/
client.lua
126 lines (110 loc) · 3.65 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
121
122
123
124
125
126
local Config = require("shared.sh_config")
local Locales = require("shared.sh_locales")
local isDead = false
local function DisableControls()
CreateThread(function()
while isDead do
DisableAllControlActions(0) -- This will disable in-game controls (e.g., movement, actions) but will not prevent menus or UIs that open via key mappings from appearing.
for _, keyCode in ipairs(Config.EnabledControls) do
EnableControlAction(0, keyCode, true)
end
Wait(0)
end
end)
end
local function ToggleUI(bool)
SendNUIMessage({ action = "toggleDeathscreen", isVisible = bool })
SetNuiFocus(bool, bool)
SetNuiFocusKeepInput(bool)
DisableControls()
if Config.BlurUIBackground then
if bool then
TriggerScreenblurFadeIn(0)
else
TriggerScreenblurFadeOut(0)
end
end
end
local function LoadAnimDict(animDict)
while not HasAnimDictLoaded(animDict) do
RequestAnimDict(animDict)
Wait(10)
end
end
-- credits to qb-ambulancejob for parts of this function
local function DoDeathAnim()
local playerPed = cache.ped
while GetEntitySpeed(playerPed) > 0.5 or IsPedRagdoll(playerPed) do
Wait(10)
end
if isDead then
local coords = GetEntityCoords(playerPed)
local heading = GetEntityHeading(playerPed)
if IsPedInAnyVehicle(playerPed, false) then
local playerVeh = GetVehiclePedIsIn(playerPed, false)
local vehSeats = GetVehicleModelNumberOfSeats(GetHashKey(GetEntityModel(playerVeh)))
for i = -1, vehSeats do
local vehSeatPed = GetPedInVehicleSeat(playerVeh, i)
if vehSeatPed == playerPed then
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z + 0.5, heading, 0, false)
SetPedIntoVehicle(playerPed, playerVeh, i)
end
end
else
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z + 0.5, heading, 0, false)
end
local maxHealth = GetPedMaxHealth(playerPed)
SetEntityInvincible(playerPed, true)
SetEntityHealth(playerPed, maxHealth)
local animDict = IsPedInAnyVehicle(playerPed, false) and "veh@low@front_ps@idle_duck" or Config.DeathAnim.animDict
local animName = IsPedInAnyVehicle(playerPed, false) and "sit" or Config.DeathAnim.animName
LoadAnimDict(animDict)
while isDead do
if not IsEntityPlayingAnim(playerPed, animDict, animName, 8) then TaskPlayAnim(playerPed, animDict, animName, 1.0, 1.0, -1, 8, 0, false, false, false) end
Wait(1000)
end
end
end
local function OnPlayerDeath()
isDead = true
if IsPauseMenuActive() then SetFrontendActive(false) end
ToggleUI(true)
HandleVoiceState(false)
if Config.DeathAnim.enabled then DoDeathAnim() end
end
RegisterNetEvent("cloud-deathscreen:client:OnPlayerDeath", OnPlayerDeath)
local function OnPlayerSpawn()
isDead = false
ToggleUI(false)
HandleVoiceState(true)
end
RegisterNetEvent("cloud-deathscreen:client:OnPlayerSpawn", OnPlayerSpawn)
local function ReviveActions()
isDead = false
ToggleUI(false)
RevivePed()
HandleVoiceState(true)
end
RegisterNUICallback("deathscreen:fetchData", function(data, cb)
local label = data.label
if label == "setData" then
cb({ locales = Locales.UI, soundVolume = Config.SoundVolume, mainTimer = Config.MainTimer, faceDeathTimer = Config.FaceDeathTimer })
elseif label == "callEmergency" then
PlaySoundFrontend(-1, "Click", "DLC_HEIST_HACKING_SNAKE_SOUNDS", true)
CallEmergency()
cb("ok")
elseif label == "faceDeath" then
local paymentSuccess = lib.callback.await("cloud-deathscreen:server:PayFine", false)
if paymentSuccess then
PlaySoundFrontend(-1, "Click", "DLC_HEIST_HACKING_SNAKE_SOUNDS", true)
ReviveActions()
cb("ok")
else
PlaySoundFrontend(-1, "CHECKPOINT_MISSED", "HUD_MINI_GAME_SOUNDSET", true)
cb("error")
end
elseif label == "timeExpired" then
ReviveActions()
cb("ok")
end
end)