mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-28 23:01:26 +00:00
esx_basicneeds rework -Kuuzoo
This commit is contained in:
@@ -6,7 +6,6 @@ AddEventHandler('esx_basicneeds:resetStatus', function()
|
||||
TriggerEvent('esx_status:set', 'thirst', 500000)
|
||||
end)
|
||||
|
||||
|
||||
RegisterNetEvent('esx_basicneeds:healPlayer')
|
||||
AddEventHandler('esx_basicneeds:healPlayer', function()
|
||||
-- restore hunger & thirst
|
||||
@@ -27,11 +26,10 @@ AddEventHandler('esx:onPlayerSpawn', function(spawn)
|
||||
TriggerEvent('esx_basicneeds:resetStatus')
|
||||
end
|
||||
|
||||
IsDead = false
|
||||
IsDead = false
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_status:loaded', function(status)
|
||||
|
||||
TriggerEvent('esx_status:registerStatus', 'hunger', 1000000, '#CFAD0F', function(status)
|
||||
return Config.Visible
|
||||
end, function(status)
|
||||
@@ -43,7 +41,6 @@ AddEventHandler('esx_status:loaded', function(status)
|
||||
end, function(status)
|
||||
status.remove(75)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_status:onTick', function(data)
|
||||
@@ -74,11 +71,18 @@ AddEventHandler('esx_basicneeds:isEating', function(cb)
|
||||
cb(IsAnimated)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_basicneeds:onEat')
|
||||
AddEventHandler('esx_basicneeds:onEat', function(prop_name)
|
||||
RegisterNetEvent('esx_basicneeds:onUse')
|
||||
AddEventHandler('esx_basicneeds:onUse', function(type, prop_name)
|
||||
if not IsAnimated then
|
||||
prop_name = prop_name or 'prop_cs_burger_01'
|
||||
local anim = {dict = 'mp_player_inteat@burger', name = 'mp_player_int_eat_burger_fp', settings = {8.0, -8, -1, 49, 0, 0, 0, 0}}
|
||||
IsAnimated = true
|
||||
if type == 'food' then
|
||||
prop_name = prop_name or 'prop_cs_burger_01'
|
||||
anim = {dict = 'mp_player_inteat@burger', name = 'mp_player_int_eat_burger_fp', settings = {8.0, -8, -1, 49, 0, 0, 0, 0}}
|
||||
elseif type == 'drink' then
|
||||
prop_name = prop_name or 'prop_ld_flow_bottle'
|
||||
anim = {dict = 'mp_player_intdrink', name = 'loop_bottle', settings = {1.0, -1.0, 2000, 0, 1, true, true, true}}
|
||||
end
|
||||
|
||||
CreateThread(function()
|
||||
local playerPed = PlayerPedId()
|
||||
@@ -87,9 +91,9 @@ AddEventHandler('esx_basicneeds:onEat', function(prop_name)
|
||||
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)
|
||||
RemoveAnimDict('mp_player_inteat@burger')
|
||||
ESX.Streaming.RequestAnimDict(anim.dict, function()
|
||||
TaskPlayAnim(playerPed, anim.dict, anim.name, anim.settings[1], anim.settings[2], anim.settings[3], anim.settings[4], anim.settings[5], anim.settings[6], anim.settings[7], anim.settings[8])
|
||||
RemoveAnimDict(anim.dict)
|
||||
|
||||
Wait(3000)
|
||||
IsAnimated = false
|
||||
@@ -97,33 +101,28 @@ AddEventHandler('esx_basicneeds:onEat', function(prop_name)
|
||||
DeleteObject(prop)
|
||||
end)
|
||||
end)
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
-- Backwards compatibility
|
||||
RegisterNetEvent('esx_basicneeds:onEat')
|
||||
AddEventHandler('esx_basicneeds:onEat', function(prop_name)
|
||||
local Invoke = GetInvokingResource()
|
||||
print(('[^3WARNING^7] ^5%s^7 used ^5esx_basicneeds:onEat^7, this method is deprecated and should not be used! Refer to ^5https://docs.esx-framework.org/tutorials/basicneeds^7 for more info!'):format(Invoke))
|
||||
|
||||
if not prop_name then
|
||||
prop_name = 'prop_cs_burger_01'
|
||||
end
|
||||
TriggerEvent('esx_basicneeds:onUse', 'food', prop_name)
|
||||
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
|
||||
local Invoke = GetInvokingResource()
|
||||
print(('[^3WARNING^7] ^5%s^7 used ^5esx_basicneeds:onDrink^7, this method is deprecated and should not be used! Refer to ^5https://docs.esx-framework.org/tutorials/basicneeds^7 for more info!'):format(Invoke))
|
||||
|
||||
CreateThread(function()
|
||||
local playerPed = PlayerPedId()
|
||||
local x,y,z = table.unpack(GetEntityCoords(playerPed))
|
||||
local prop = CreateObject(joaat(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)
|
||||
RemoveAnimDict('mp_player_intdrink')
|
||||
|
||||
Wait(3000)
|
||||
IsAnimated = false
|
||||
ClearPedSecondaryTask(playerPed)
|
||||
DeleteObject(prop)
|
||||
end)
|
||||
end)
|
||||
|
||||
end
|
||||
if not prop_name then
|
||||
prop_name = 'prop_ld_flow_bottle'
|
||||
end
|
||||
TriggerEvent('esx_basicneeds:onUse', 'drink', prop_name)
|
||||
end)
|
||||
|
||||
@@ -2,15 +2,17 @@ Config = {}
|
||||
Config.Locale = GetConvar('esx:locale', 'en')
|
||||
Config.Visible = true
|
||||
|
||||
Config.Food = {
|
||||
Config.Items = {
|
||||
["bread"] = {
|
||||
type = "food",
|
||||
prop= "prop_cs_burger_01",
|
||||
status = 200000,
|
||||
remove = true
|
||||
}
|
||||
}
|
||||
|
||||
Config.Drinks = {
|
||||
},
|
||||
|
||||
["water"] = {
|
||||
type = "drink",
|
||||
prop = "prop_ld_flow_bottle",
|
||||
status = 100000,
|
||||
remove = true
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Locales['de'] = {
|
||||
['used_bread'] = 'du hast 1x Brot gegessen',
|
||||
['used_water'] = 'du hast 1x Wasser getrunken',
|
||||
}
|
||||
['used_food'] = 'Du hast 1x %s gegessen.',
|
||||
['used_drink'] = 'Du hast 1x %s getrunken.',
|
||||
['got_healed'] = 'Du wurdest geheilt.'
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
Locales['en'] = {
|
||||
['used_eat'] = 'you have used 1x %s',
|
||||
['used_drink'] = 'you have used 1x %s',
|
||||
['used_food'] = 'You have eaten 1x %s',
|
||||
['used_drink'] = 'You have drinked 1x %s',
|
||||
['got_healed'] = 'You have been healed.'
|
||||
}
|
||||
|
||||
@@ -1,34 +1,28 @@
|
||||
CreateThread(function()
|
||||
for k,v in pairs(Config.Food) do
|
||||
for k,v in pairs(Config.Items) do
|
||||
ESX.RegisterUsableItem(k, function(source)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
if v.remove then
|
||||
xPlayer.removeInventoryItem(k,1)
|
||||
end
|
||||
TriggerClientEvent("esx_status:add",source,"hunger",v.status)
|
||||
TriggerClientEvent('esx_basicneeds:onEat',source)
|
||||
xPlayer.showNotification(TranslateCap('used_eat', ESX.GetItemLabel(k)))
|
||||
end)
|
||||
end
|
||||
end)
|
||||
|
||||
CreateThread(function()
|
||||
for k,v in pairs(Config.Drinks) do
|
||||
ESX.RegisterUsableItem(k, function(source)
|
||||
local xPlayer = ESX.GetPlayerFromId(source)
|
||||
if v.remove then
|
||||
xPlayer.removeInventoryItem(k,1)
|
||||
if v.type == "food" then
|
||||
TriggerClientEvent("esx_status:add", source, "hunger", v.status)
|
||||
TriggerClientEvent('esx_basicneeds:onUse', source, v.type)
|
||||
xPlayer.showNotification(TranslateCap('used_food', ESX.GetItemLabel(k)))
|
||||
elseif v.type == "drink" then
|
||||
TriggerClientEvent("esx_status:add", source, "thirst", v.status)
|
||||
TriggerClientEvent('esx_basicneeds:onUse', source, v.type)
|
||||
xPlayer.showNotification(TranslateCap('used_drink', ESX.GetItemLabel(k)))
|
||||
else
|
||||
print(string.format('^1[ERROR]^0 %s has no correct type defined.', k))
|
||||
end
|
||||
TriggerClientEvent("esx_status:add",source,"thirst",v.status)
|
||||
TriggerClientEvent('esx_basicneeds:onDrink',source)
|
||||
xPlayer.showNotification(TranslateCap('used_drink', ESX.GetItemLabel(k)))
|
||||
end)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
ESX.RegisterCommand('heal', 'admin', function(xPlayer, args, showError)
|
||||
args.playerId.triggerEvent('esx_basicneeds:healPlayer')
|
||||
args.playerId.showNotification('You have been healed.')
|
||||
args.playerId.showNotification(TranslateCap('got_healed'))
|
||||
end, true, {help = 'Heal a player, or yourself - restores thirst, hunger and health.', validate = true, arguments = {
|
||||
{name = 'playerId', help = 'the player id', type = 'player'}
|
||||
}})
|
||||
|
||||
Reference in New Issue
Block a user