Files
esx_core/client/main.lua
T
renaiku ac3975105a added isEating callback
fixed animation issues
you can now use a personnalized prop by calling onEat or onDrink.
2017-09-17 19:58:14 +02:00

160 lines
3.7 KiB
Lua

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)
end)
AddEventHandler('playerSpawned', function()
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 true
end,
function(status)
status.remove(200)
end
)
TriggerEvent('esx_status:registerStatus', 'thirst', 1000000, '#0C98F1',
function(status)
return true
end,
function(status)
status.remove(250)
end
)
Citizen.CreateThread(function()
while true do
Wait(1000)
local playerPed = GetPlayerPed(-1)
local prevHealth = GetEntityHealth(playerPed)
local health = prevHealth
TriggerEvent('esx_status:getStatus', 'hunger', function(status)
if status.val == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end)
TriggerEvent('esx_status:getStatus', 'thirst', function(status)
if status.val == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end)
if health ~= prevHealth then
SetEntityHealth(playerPed, health)
end
end
end)
Citizen.CreateThread(function()
while true do
Wait(0)
local playerPed = GetPlayerPed(-1)
if IsEntityDead(playerPed) and not IsDead then
IsDead = true
end
end
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
local prop_name = prop_name or 'prop_cs_burger_01'
IsAnimated = true
local playerPed = GetPlayerPed(-1)
Citizen.CreateThread(function()
local x,y,z = table.unpack(GetEntityCoords(playerPed))
prop = CreateObject(GetHashKey(prop_name), x, y, z+0.2, true, true, true)
AttachEntityToEntity(prop, playerPed, GetPedBoneIndex(playerPed, 18905), 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
RequestAnimDict('mp_player_inteat@burger')
while not HasAnimDictLoaded('mp_player_inteat@burger') do
Wait(0)
end
TaskPlayAnim(playerPed, 'mp_player_inteat@burger', 'mp_player_int_eat_burger_fp', 8.0, -8, -1, 49, 0, 0, 0, 0)
Wait(3000)
IsAnimated = false
ClearPedSecondaryTask(playerPed)
DeleteObject(prop)
end)
end
end)
RegisterNetEvent('esx_basicneeds:onDrink')
AddEventHandler('esx_basicneeds:onDrink', function(prop_name)
if not IsAnimated then
local prop_name = prop_name or 'prop_ld_flow_bottle'
IsAnimated = true
local playerPed = GetPlayerPed(-1)
Citizen.CreateThread(function()
local x,y,z = table.unpack(GetEntityCoords(playerPed))
prop = CreateObject(GetHashKey(prop_name), x, y, z+0.2, true, true, true)
AttachEntityToEntity(prop, playerPed, GetPedBoneIndex(playerPed, 18905), 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
RequestAnimDict('mp_player_intdrink')
while not HasAnimDictLoaded('mp_player_intdrink') do
Wait(0)
end
TaskPlayAnim(playerPed, 'mp_player_intdrink', 'loop_bottle', 1.0, -1.0, 2000, 0, 1, true, true, true)
Wait(3000)
IsAnimated = false
ClearPedSecondaryTask(playerPed)
DeleteObject(prop)
end)
end
end)