mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 20:01:27 +00:00
Add files
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
|
||||
|
||||
description 'ESX Basic Needs'
|
||||
|
||||
server_scripts {
|
||||
'config.lua',
|
||||
'server/main.lua'
|
||||
}
|
||||
|
||||
client_scripts {
|
||||
'config.lua',
|
||||
'client/main.lua'
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
ESX = nil
|
||||
local IsDead = false
|
||||
|
||||
Citizen.CreateThread(function()
|
||||
while ESX == nil do
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
Citizen.Wait(0)
|
||||
end
|
||||
end)
|
||||
|
||||
AddEventHandler('playerSpawned', function()
|
||||
|
||||
if IsDead then
|
||||
TriggerServerEvent('esx_basicneeds:resetStatus')
|
||||
end
|
||||
|
||||
IsDead = false
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_status:loaded', function(status)
|
||||
|
||||
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)
|
||||
|
||||
RegisterNetEvent('esx_basicneeds:onEat')
|
||||
AddEventHandler('esx_basicneeds:onEat', function()
|
||||
|
||||
local pid = PlayerPedId()
|
||||
|
||||
RequestAnimDict("mp_player_inteat@burger")
|
||||
|
||||
while not HasAnimDictLoaded("mp_player_inteat@burger") do
|
||||
Wait(0)
|
||||
end
|
||||
|
||||
TaskPlayAnim(pid, 'mp_player_inteat@burger', 'mp_player_int_eat_burger', 1.0, -1.0, 2000, 0, 1, true, true, true)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_basicneeds:onDrink')
|
||||
AddEventHandler('esx_basicneeds:onDrink', function()
|
||||
|
||||
local pid = PlayerPedId()
|
||||
|
||||
RequestAnimDict("amb@world_human_drinking@coffee@male@idle_a")
|
||||
|
||||
while not HasAnimDictLoaded("amb@world_human_drinking@coffee@male@idle_a") do
|
||||
Wait(0)
|
||||
end
|
||||
|
||||
TaskPlayAnim(pid, 'amb@world_human_drinking@coffee@male@idle_a', 'idle_a', 1.0, -1.0, 2000, 0, 1, true, true, true)
|
||||
|
||||
end)
|
||||
@@ -0,0 +1,4 @@
|
||||
Config = {}
|
||||
|
||||
Config.TickTime = 100
|
||||
Config.UpdateClientTime = 5000
|
||||
@@ -0,0 +1,6 @@
|
||||
USE `essentialmode`;
|
||||
|
||||
INSERT INTO `items` (name, label) VALUES
|
||||
('bread', 'Pain')
|
||||
('water', 'Eau')
|
||||
;
|
||||
@@ -0,0 +1,74 @@
|
||||
TriggerEvent('esx_status:registerStatus', 'hunger', 1000000, '#CFAD0F',
|
||||
function(status)
|
||||
return true
|
||||
end,
|
||||
function(status)
|
||||
status.remove(200)
|
||||
end,
|
||||
{remove = 200}
|
||||
)
|
||||
|
||||
TriggerEvent('esx_status:registerStatus', 'thirst', 1000000, '#0C98F1',
|
||||
function(status)
|
||||
return true
|
||||
end,
|
||||
function(status)
|
||||
status.remove(250)
|
||||
end,
|
||||
{remove = 250}
|
||||
)
|
||||
|
||||
RegisterServerEvent('esx_basicneeds:resetStatus')
|
||||
AddEventHandler('esx_basicneeds:resetStatus', function()
|
||||
|
||||
local _source = source
|
||||
|
||||
TriggerEvent('esx_status:getStatus', _source, 'hunger', function(status)
|
||||
status.set(500000)
|
||||
status.updateClient()
|
||||
end)
|
||||
|
||||
TriggerEvent('esx_status:getStatus', _source, 'thirst', function(status)
|
||||
status.set(500000)
|
||||
status.updateClient()
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
TriggerEvent('esx:registerUsableItem', 'bread', function(source)
|
||||
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
|
||||
xPlayer.removeInventoryItem('bread', 1)
|
||||
|
||||
TriggerEvent('esx_status:getStatus', _source, 'hunger', function(status)
|
||||
|
||||
status.add(200000)
|
||||
status.updateClient()
|
||||
|
||||
TriggerClientEvent('esx_basicneeds:onEat', _source)
|
||||
TriggerClientEvent('esx:showNotification', _source, 'Vous avez utilisé 1x pain')
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
TriggerEvent('esx:registerUsableItem', 'water', function(source)
|
||||
|
||||
local _source = source
|
||||
local xPlayer = ESX.GetPlayerFromId(_source)
|
||||
|
||||
xPlayer.removeInventoryItem('water', 1)
|
||||
|
||||
TriggerEvent('esx_status:getStatus', _source, 'thirst', function(status)
|
||||
|
||||
status.add(200000)
|
||||
status.updateClient()
|
||||
|
||||
TriggerClientEvent('esx_basicneeds:onDrink', _source)
|
||||
TriggerClientEvent('esx:showNotification', _source, 'Vous avez utilisé 1x Eau')
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
Reference in New Issue
Block a user