From e4056aa7d701103698dd468574867acde5e30243 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 1 Jul 2018 11:47:57 +0200 Subject: [PATCH] Major cleanup, /heal, fixed #12, sv locale --- README.md | 49 +++++++++----- __resource.lua | 5 ++ client/main.lua | 103 ++++++++++++----------------- config.lua | 5 +- esx_basicneeds.sql | 8 +-- locales/br.lua | 8 +-- locales/de.lua | 8 +-- locales/en.lua | 8 +-- locales/fi.lua | 8 +-- locales/fr.lua | 8 +-- locales/sv.lua | 4 ++ localization/de_esx_basicneeds.sql | 8 +-- localization/fi_esx_basicneeds.sql | 8 +-- localization/sv_esx_basicneeds.sql | 6 ++ server/main.lua | 38 ++++++++--- 15 files changed, 151 insertions(+), 123 deletions(-) create mode 100644 locales/sv.lua create mode 100644 localization/sv_esx_basicneeds.sql diff --git a/README.md b/README.md index 58a49a4f..6e4a7189 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,43 @@ -# fxserver-esx_basicneeds -FXServer ESX Basic Needs +# esx_basicneeds +This script implements hunger and thirst status, they can be increased when eating bread or drinking water. -[REQUIREMENTS] +## Requirements +- [esx_status](https://github.com/ESX-Org/esx_status) -- esx_status => https://github.com/FXServer-ESX/fxserver-esx_status +## Download & Installation -[INFO] - -This plugin add hunger and thirst status, they can be increased when eating bread or drinking water - -[INSTALLATION] - -1) CD in your resources/[esx] folder -2) Clone the repository +### Using [fvm](https://github.com/qlaffont/fvm-installer) ``` -git clone https://github.com/FXServer-ESX/fxserver-esx_basicneeds esx_basicneeds +fvm install --save --folder=esx esx-org/esx_basicneeds ``` -3) Import esx_basicneeds.sql in your database -4) Add this in your server.cfg : + +### Using Git +``` +cd resources +git clone https://github.com/ESX-Org/esx_basicneeds [esx]/esx_basicneeds +``` + +### Manually +- Download https://github.com/ESX-Org/esx_basicneeds/archive/master.zip +- Put it in the `[esx]` directory + + +## Installation +- Import `esx_basicneeds.sql` in your database +- Add this in your server.cfg : ``` start esx_basicneeds ``` + +# Legal +### License +esx_basicneeds - thirst and hunger system + +Copyright (C) 2015-2018 Jérémie N'gadi + +This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. + +This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details. + +You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/. \ No newline at end of file diff --git a/__resource.lua b/__resource.lua index e92f41dc..ef18c23b 100644 --- a/__resource.lua +++ b/__resource.lua @@ -25,3 +25,8 @@ client_scripts { 'config.lua', 'client/main.lua' } + +dependencies { + 'es_extended', + 'esx_status' +} diff --git a/client/main.lua b/client/main.lua index 87407b06..0cb1debd 100644 --- a/client/main.lua +++ b/client/main.lua @@ -12,11 +12,24 @@ end) AddEventHandler('esx_basicneeds:resetStatus', function() TriggerEvent('esx_status:set', 'hunger', 500000) TriggerEvent('esx_status:set', 'thirst', 500000) - end) -AddEventHandler('playerSpawned', function() +RegisterNetEvent('esx_basicneeds:healPlayer') +AddEventHandler('esx_basicneeds:healPlayer', function() + -- restore hunger & thirst + TriggerEvent('esx_status:set', 'hunger', 1000000) + TriggerEvent('esx_status:set', 'thirst', 1000000) + -- restore hp + local sourcePed = GetPlayerPed(-1) + SetEntityHealth(sourcePed, GetEntityMaxHealth(sourcePed)) +end) + +AddEventHandler('esx:onPlayerDeath', function() + IsDead = true +end) + +AddEventHandler('playerSpawned', function(spawn) if IsDead then TriggerEvent('esx_basicneeds:resetStatus') end @@ -29,33 +42,29 @@ AddEventHandler('esx_status:loaded', function(status) TriggerEvent('esx_status:registerStatus', 'hunger', 1000000, '#CFAD0F', function(status) return true - end, - function(status) - status.remove(200) + end, function(status) + status.remove(100) end ) TriggerEvent('esx_status:registerStatus', 'thirst', 1000000, '#0C98F1', function(status) return true - end, - function(status) - status.remove(250) + end, function(status) + status.remove(75) end ) Citizen.CreateThread(function() while true do - - Wait(1000) + Citizen.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 @@ -63,13 +72,10 @@ AddEventHandler('esx_status:loaded', function(status) else health = health - 1 end - end - end) TriggerEvent('esx_status:getStatus', 'thirst', function(status) - if status.val == 0 then if prevHealth <= 150 then @@ -77,35 +83,14 @@ AddEventHandler('esx_status:loaded', function(status) 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) @@ -114,24 +99,24 @@ end) RegisterNetEvent('esx_basicneeds:onEat') AddEventHandler('esx_basicneeds:onEat', function(prop_name) - if not IsAnimated then + 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) + 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 + Citizen.Wait(10) + end + 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) @@ -143,17 +128,17 @@ AddEventHandler('esx_basicneeds:onDrink', function(prop_name) 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) + 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) + Citizen.Wait(10) end TaskPlayAnim(playerPed, 'mp_player_intdrink', 'loop_bottle', 1.0, -1.0, 2000, 0, 1, true, true, true) - Wait(3000) - IsAnimated = false - ClearPedSecondaryTask(playerPed) + Citizen.Wait(3000) + IsAnimated = false + ClearPedSecondaryTask(playerPed) DeleteObject(prop) end) end -end) +end) \ No newline at end of file diff --git a/config.lua b/config.lua index 673e6276..741114de 100644 --- a/config.lua +++ b/config.lua @@ -1,5 +1,2 @@ Config = {} -Config.Locale = 'fr' - -Config.TickTime = 100 -Config.UpdateClientTime = 5000 +Config.Locale = 'fr' \ No newline at end of file diff --git a/esx_basicneeds.sql b/esx_basicneeds.sql index 6b9d3098..02d24aa6 100644 --- a/esx_basicneeds.sql +++ b/esx_basicneeds.sql @@ -1,6 +1,6 @@ USE `essentialmode`; -INSERT INTO `items` (name, label) VALUES - ('bread', 'Pain'), - ('water', 'Eau') -; +INSERT INTO `items` (`name`, `label`, `limit`) VALUES + ('bread', 'Pain', 10), + ('water', 'Eau', 5) +; \ No newline at end of file diff --git a/locales/br.lua b/locales/br.lua index 22625651..fbb6a826 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -1,6 +1,4 @@ Locales['br'] = { - - ['used_bread'] = 'Você comeu 1x pão', - ['used_water'] = 'Você tomou 1x água', - -} + ['used_bread'] = 'você comeu ~y~1x~s~ ~b~pão~s~', + ['used_water'] = 'você tomou ~y~1x~s~ ~b~água~s~', +} \ No newline at end of file diff --git a/locales/de.lua b/locales/de.lua index 9ee67348..53d6d981 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -1,6 +1,4 @@ Locales['de'] = { - - ['used_bread'] = 'Du hast 1x Brot gegessen', - ['used_water'] = 'Du hast 1x Wasser getrunken', - -} + ['used_bread'] = 'du hast ~y~1x~s~ ~b~Brot gegessen~s~', + ['used_water'] = 'du hast ~y~1x~s~ ~b~Wasser getrunken~s~', +} \ No newline at end of file diff --git a/locales/en.lua b/locales/en.lua index f5e83c22..14931fd6 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,6 +1,4 @@ Locales['en'] = { - - ['used_bread'] = 'you have used 1x bread', - ['used_water'] = 'you have used 1x water', - -} + ['used_bread'] = 'you have used ~y~1x~s~ ~b~bread~s~', + ['used_water'] = 'you have used ~y~1x~s~ ~b~water~s~', +} \ No newline at end of file diff --git a/locales/fi.lua b/locales/fi.lua index b8db6433..ec29041d 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -1,6 +1,4 @@ Locales['fi'] = { - - ['used_bread'] = 'sinä söit 1x Leipä', - ['used_water'] = 'sinä joit 1x Vesi', - -} + ['used_bread'] = 'sinä söit ~y~1x~s~ ~b~leipä~s~', + ['used_water'] = 'sinä joit ~y~1x~s~ ~b~vesi~s~', +} \ No newline at end of file diff --git a/locales/fr.lua b/locales/fr.lua index 3cdfd767..c388f04c 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -1,6 +1,4 @@ Locales['fr'] = { - - ['used_bread'] = 'vous avez utilisé 1x pain', - ['used_water'] = 'vous avez utilisé 1x eau', - -} + ['used_bread'] = 'vous avez utilisé ~y~1x~s~ ~b~pain~s~', + ['used_water'] = 'vous avez utilisé ~y~1x~s~ ~b~eau~s~', +} \ No newline at end of file diff --git a/locales/sv.lua b/locales/sv.lua new file mode 100644 index 00000000..29c4f001 --- /dev/null +++ b/locales/sv.lua @@ -0,0 +1,4 @@ +Locales['sv'] = { + ['used_bread'] = 'du käkade upp ~y~1x~s~ ~b~bröd~s~', + ['used_water'] = 'du drack ~y~1x~s~ ~b~vatten~s~', +} \ No newline at end of file diff --git a/localization/de_esx_basicneeds.sql b/localization/de_esx_basicneeds.sql index 2863dde8..0e097e34 100644 --- a/localization/de_esx_basicneeds.sql +++ b/localization/de_esx_basicneeds.sql @@ -1,6 +1,6 @@ USE `essentialmode`; -INSERT INTO `items` (name, label) VALUES - ('bread', 'Brot'), - ('water', 'Wasser') -; +INSERT INTO `items` (`name`, `label`, `limit`) VALUES + ('bread', 'Brot', 10), + ('water', 'Wasser', 5) +; \ No newline at end of file diff --git a/localization/fi_esx_basicneeds.sql b/localization/fi_esx_basicneeds.sql index 9f469e46..222cd54b 100644 --- a/localization/fi_esx_basicneeds.sql +++ b/localization/fi_esx_basicneeds.sql @@ -1,6 +1,6 @@ USE `essentialmode`; -INSERT INTO `items` (name, label) VALUES - ('bread', 'Leipä'), - ('water', 'Vesi') -; +INSERT INTO `items` (`name`, `label`, `limit`) VALUES + ('bread', 'Leipä', 10), + ('water', 'Vesi', 5) +; \ No newline at end of file diff --git a/localization/sv_esx_basicneeds.sql b/localization/sv_esx_basicneeds.sql new file mode 100644 index 00000000..a22ab46b --- /dev/null +++ b/localization/sv_esx_basicneeds.sql @@ -0,0 +1,6 @@ +USE `essentialmode`; + +INSERT INTO `items` (`name`, `label`, `limit`) VALUES + ('bread', 'Bröd', 10), + ('water', 'Vatten', 5) +; \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index 422a86f2..4d27c6cd 100644 --- a/server/main.lua +++ b/server/main.lua @@ -3,27 +3,49 @@ ESX = nil TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) ESX.RegisterUsableItem('bread', function(source) - - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) + local xPlayer = ESX.GetPlayerFromId(source) xPlayer.removeInventoryItem('bread', 1) TriggerClientEvent('esx_status:add', source, 'hunger', 200000) TriggerClientEvent('esx_basicneeds:onEat', source) TriggerClientEvent('esx:showNotification', source, _U('used_bread')) - end) ESX.RegisterUsableItem('water', function(source) - - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) + local xPlayer = ESX.GetPlayerFromId(source) xPlayer.removeInventoryItem('water', 1) TriggerClientEvent('esx_status:add', source, 'thirst', 200000) TriggerClientEvent('esx_basicneeds:onDrink', source) TriggerClientEvent('esx:showNotification', source, _U('used_water')) - end) + +TriggerEvent('es:addGroupCommand', 'heal', 'admin', function(source, args, user) + -- heal another player - don't heal source + if args[1] then + local target = tonumber(args[1]) + + -- is the argument a number? + if target ~= nil then + + -- is the number a valid player? + if GetPlayerName(target) then + print('esx_basicneeds: ' .. GetPlayerName(source) .. ' is healing a player!') + TriggerClientEvent('esx_basicneeds:healPlayer', target) + TriggerClientEvent('chatMessage', target, "HEAL", {223, 66, 244}, "You have been healed!") + else + TriggerClientEvent('chatMessage', source, "HEAL", {255, 0, 0}, "Player not found!") + end + else + TriggerClientEvent('chatMessage', source, "HEAL", {255, 0, 0}, "Incorrect syntax! You must provide a valid player ID") + end + else + -- heal source + print('esx_basicneeds: ' .. GetPlayerName(source) .. ' is healing!') + TriggerClientEvent('esx_basicneeds:healPlayer', source) + end +end, function(source, args, user) + TriggerClientEvent('chatMessage', source, "HEAL", {255, 0, 0}, "Insufficient Permissions.") +end, {help = "Heal a player, or yourself - restores thirst, hunger and health."}) \ No newline at end of file