forked from StockholmCityRP/esx_basicneeds
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
206 lines (172 loc) · 5.7 KB
/
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
ESX = nil
local IsDead = false
local IsAnimated = false
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
end)
AddEventHandler('esx_basicneeds:resetStatus', function()
TriggerEvent('esx_status:set', 'hunger', 500000)
TriggerEvent('esx_status:set', 'thirst', 500000)
TriggerEvent('esx_status:set', 'stress', 100000)
end)
RegisterNetEvent('esx_basicneeds:healPlayer')
AddEventHandler('esx_basicneeds:healPlayer', function()
-- restore hunger & thirst
TriggerEvent('esx_status:set', 'hunger', 1000000)
TriggerEvent('esx_status:set', 'thirst', 1000000)
TriggerEvent('esx_status:set', 'stress', 0)
-- restore hp
local playerPed = PlayerPedId()
SetEntityHealth(playerPed, GetEntityMaxHealth(playerPed))
end)
AddEventHandler('esx:onPlayerDeath', function()
IsDead = true
end)
AddEventHandler('esx:onPlayerSpawn', function(spawn)
if IsDead then
TriggerEvent('esx_basicneeds:resetStatus')
end
IsDead = false
end)
AddEventHandler('esx_status:loaded', function(status)
TriggerEvent('esx_status:registerStatus', 'hunger', 1000000, '#CFAD0F', function(status)
return Config.Visible
end, function(status)
status.remove(100)
end)
TriggerEvent('esx_status:registerStatus', 'thirst', 1000000, '#0C98F1', function(status)
return Config.Visible
end, function(status)
status.remove(75)
end)
TriggerEvent('esx_status:registerStatus', 'stress', 0, '#CF380F', function(status)
return Config.Visible
end, function(status)
end)
end)
local stressWait, aiming, holding, melee, still, stealth, jacking = 0, 0, 0, 0, 0, 0, 0
AddEventHandler('esx_status:onTick', function(data)
local playerPed = PlayerPedId()
local prevHealth = GetEntityHealth(playerPed)
local health = prevHealth
for k, v in pairs(data) do
if v.name == 'hunger' and v.percent == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
elseif v.name == 'thirst' and v.percent == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
elseif v.name == 'stress' then stress = v.percent
local stress = 0
local calm = true
if aiming <= 0 and GetPedConfigFlag(playerPed, 78, 1) then
local suppressed = IsPedCurrentWeaponSilenced(playerPed)
if not suppressed then
stress = stress + 500
aiming = 5
calm = false
else
stress = stress + 1000
aiming = 5
calm = false
end
else aiming = aiming - 1 end
if holding <= 0 and IsPedArmed(playerPed, 4) then
stress = stress + 10000
holding = 15
calm = false
else holding = holding - 1 end
if melee <= 0 and IsPedInMeleeCombat(playerPed) then
stress = stress + 5000
melee = 5
calm = false
else melee = melee - 1 end
if stealth <= 0 and GetPedStealthMovement(playerPed) then
stress = stress + 10000
stealth = 8
calm = false
else stealth = stealth - 1 end
if jacking <= 0 and IsPedJacking(playerPed) then
stress = stress + 500
jacking = 7
calm = false
else jacking = jacking - 1 end
if calm and still <= 0 and IsPedStill(playerPed) then
stress = stress - 30000
still = 15
else still = still - 1 end
if stressWait > 0 then stressWait = stressWait - 1
elseif v.percent >= 80 then
stressWait = 3
ShakeGameplayCam('VIBRATE_SHAKE', 0.50)
elseif v.percent >= 65 then
stressWait = 4
ShakeGameplayCam('VIBRATE_SHAKE', 0.30)
elseif v.percent >= 50 then
stressWait = 5
ShakeGameplayCam('VIBRATE_SHAKE', 0.12)
elseif v.percent >= 35 then
stressWait = 6
ShakeGameplayCam('VIBRATE_SHAKE', 0.07)
end
if stress ~= 0 then
if stress > 0 then TriggerEvent('esx_status:add', 'stress', stress) else TriggerEvent('esx_status:remove', 'stress', -stress) end
end
end
end
if health ~= prevHealth then SetEntityHealth(playerPed, health) end
end)
AddEventHandler('esx_basicneeds:isEating', function(cb)
cb(IsAnimated)
end)
RegisterNetEvent('esx_basicneeds:onEat')
AddEventHandler('esx_basicneeds:onEat', function(prop_name)
if not IsAnimated then
prop_name = prop_name or 'prop_cs_burger_01'
IsAnimated = true
Citizen.CreateThread(function()
local playerPed = PlayerPedId()
local x,y,z = table.unpack(GetEntityCoords(playerPed))
local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
ESX.Streaming.RequestAnimDict('mp_player_inteat@burger', function()
TaskPlayAnim(playerPed, 'mp_player_inteat@burger', 'mp_player_int_eat_burger_fp', 8.0, -8, -1, 49, 0, 0, 0, 0)
Citizen.Wait(3000)
IsAnimated = false
ClearPedSecondaryTask(playerPed)
DeleteObject(prop)
end)
end)
end
end)
RegisterNetEvent('esx_basicneeds:onDrink')
AddEventHandler('esx_basicneeds:onDrink', function(prop_name)
if not IsAnimated then
prop_name = prop_name or 'prop_ld_flow_bottle'
IsAnimated = true
Citizen.CreateThread(function()
local playerPed = PlayerPedId()
local x,y,z = table.unpack(GetEntityCoords(playerPed))
local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
ESX.Streaming.RequestAnimDict('mp_player_intdrink', function()
TaskPlayAnim(playerPed, 'mp_player_intdrink', 'loop_bottle', 1.0, -1.0, 2000, 0, 1, true, true, true)
Citizen.Wait(3000)
IsAnimated = false
ClearPedSecondaryTask(playerPed)
DeleteObject(prop)
end)
end)
end
end)