From b0481a87f9c0f3196fdfc4f028eea05e41ba906e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20N=27gadi?= Date: Sat, 12 Aug 2017 11:46:03 +0200 Subject: [PATCH] Add files --- __resource.lua | 13 ++++++ client/main.lua | 113 +++++++++++++++++++++++++++++++++++++++++++++ config.lua | 4 ++ esx_basicneeds.sql | 6 +++ server/main.lua | 74 +++++++++++++++++++++++++++++ 5 files changed, 210 insertions(+) create mode 100644 __resource.lua create mode 100644 client/main.lua create mode 100644 config.lua create mode 100644 esx_basicneeds.sql create mode 100644 server/main.lua diff --git a/__resource.lua b/__resource.lua new file mode 100644 index 00000000..70b8e086 --- /dev/null +++ b/__resource.lua @@ -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' +} diff --git a/client/main.lua b/client/main.lua new file mode 100644 index 00000000..1ea6d25e --- /dev/null +++ b/client/main.lua @@ -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) diff --git a/config.lua b/config.lua new file mode 100644 index 00000000..db3c2fca --- /dev/null +++ b/config.lua @@ -0,0 +1,4 @@ +Config = {} + +Config.TickTime = 100 +Config.UpdateClientTime = 5000 \ No newline at end of file diff --git a/esx_basicneeds.sql b/esx_basicneeds.sql new file mode 100644 index 00000000..fa844f57 --- /dev/null +++ b/esx_basicneeds.sql @@ -0,0 +1,6 @@ +USE `essentialmode`; + +INSERT INTO `items` (name, label) VALUES + ('bread', 'Pain') + ('water', 'Eau') +; \ No newline at end of file diff --git a/server/main.lua b/server/main.lua new file mode 100644 index 00000000..ec61b623 --- /dev/null +++ b/server/main.lua @@ -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) \ No newline at end of file