Discord + +Copyright (C) 2024 bitpredator + +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. + +ATTENTION: +You are not authorized to change the name of the resource and the resources within it. + +If you want to contribute you can open a pull request. + +You are not authorized to sell this software (this is free project). + +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/server-data/resources/[bpt_addons]/bpt_basicneeds/bpt_basicneeds.sql b/server-data/resources/[bpt_addons]/bpt_basicneeds/bpt_basicneeds.sql new file mode 100644 index 000000000..7d602553c --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/bpt_basicneeds.sql @@ -0,0 +1,4 @@ +INSERT INTO `items` (`name`, `label`, `weight`) VALUES + ('bread', 'Bread', 1), + ('water', 'Water', 1) +; \ No newline at end of file diff --git a/server-data/resources/[bpt_addons]/bpt_basicneeds/client/main.lua b/server-data/resources/[bpt_addons]/bpt_basicneeds/client/main.lua new file mode 100644 index 000000000..23134e146 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/client/main.lua @@ -0,0 +1,132 @@ +local IsDead = false +local IsAnimated = false + +AddEventHandler("bpt_basicneeds:resetStatus", function() + TriggerEvent("bpt_status:set", "hunger", 500000) + TriggerEvent("bpt_status:set", "thirst", 500000) +end) + +RegisterNetEvent("bpt_basicneeds:healPlayer") +AddEventHandler("bpt_basicneeds:healPlayer", function() + -- restore hunger & thirst + TriggerEvent("bpt_status:set", "hunger", 1000000) + TriggerEvent("bpt_status:set", "thirst", 1000000) + + -- restore hp + local playerPed = PlayerPedId() + SetEntityHealth(playerPed, GetEntityMaxHealth(playerPed)) +end) + +AddEventHandler("esx:onPlayerDeath", function() + IsDead = true +end) + +AddEventHandler("esx:onPlayerSpawn", function(spawn) + if IsDead then + TriggerEvent("bpt_basicneeds:resetStatus") + end + + IsDead = false +end) + +AddEventHandler("bpt_status:loaded", function(status) + TriggerEvent("bpt_status:registerStatus", "hunger", 1000000, "#CFAD0F", function(status) + return Config.Visible + end, function(status) + status.remove(100) + end) + + TriggerEvent("bpt_status:registerStatus", "thirst", 1000000, "#0C98F1", function(status) + return Config.Visible + end, function(status) + status.remove(75) + end) +end) + +AddEventHandler("bpt_status:onTick", function(data) + local playerPed = PlayerPedId() + local prevHealth = GetEntityHealth(playerPed) + local health = prevHealth + + for k, v in pairs(data) do + if v.name == "hunger" and v.percent == 0 then + if prevHealth <= 150 then + health = health - 5 + else + health = health - 1 + end + elseif v.name == "thirst" and v.percent == 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) + +AddEventHandler("bpt_basicneeds:isEating", function(cb) + cb(IsAnimated) +end) + +RegisterNetEvent("bpt_basicneeds:onUse") +AddEventHandler("bpt_basicneeds:onUse", function(type, prop_name, anim) + if not IsAnimated then + local anim = anim + IsAnimated = true + if type == "food" then + prop_name = prop_name or "prop_cs_burger_01" + anim = anim + elseif type == "drink" then + prop_name = prop_name or "prop_ld_flow_bottle" + anim = anim + end + + 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(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 + ClearPedSecondaryTask(playerPed) + DeleteObject(prop) + end) + end) + end +end) + +-- Backwards compatibility +RegisterNetEvent("bpt_basicneeds:onEat") +AddEventHandler("bpt_basicneeds:onEat", function(prop_name) + local Invoke = GetInvokingResource() + + print(("[^3WARNING^7] ^5%s^7 used ^5bpt_basicneeds:onEat^7, this method is deprecated and should not be used! Refer to ^5https://bitpredator.github.io/bptdevelopment/docs/FiveM/bpt_basicneeds/events/oneat^7 for more info!"):format(Invoke)) + + if not prop_name then + prop_name = "prop_cs_burger_01" + end + TriggerEvent("bpt_basicneeds:onUse", "food", prop_name) +end) + +RegisterNetEvent("bpt_basicneeds:onDrink") +AddEventHandler("bpt_basicneeds:onDrink", function(prop_name) + local Invoke = GetInvokingResource() + + print(("[^3WARNING^7] ^5%s^7 used ^5bpt_basicneeds:onDrink^7, this method is deprecated and should not be used! Refer to ^5https://bitpredator.github.io/bptdevelopment/docs/FiveM/bpt_basicneeds/events/ondrink^7 for more info!"):format(Invoke)) + + if not prop_name then + prop_name = "prop_ld_flow_bottle" + end + TriggerEvent("bpt_basicneeds:onUse", "drink", prop_name) +end) diff --git a/server-data/resources/[bpt_addons]/bpt_basicneeds/config.lua b/server-data/resources/[bpt_addons]/bpt_basicneeds/config.lua new file mode 100644 index 000000000..9ec75b7e1 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/config.lua @@ -0,0 +1,21 @@ +Config = {} +Config.Locale = GetConvar("esx:locale", "en") +Config.Visible = true + +Config.Items = { + ["bread"] = { + type = "food", + prop = "prop_cs_burger_01", + status = 200000, + remove = true, + anim = { dict = "mp_player_inteat@burger", name = "mp_player_int_eat_burger_fp", settings = { 8.0, -8, -1, 49, 0, 0, 0, 0 } }, + }, + + ["water"] = { + type = "drink", + prop = "prop_ld_flow_bottle", + status = 100000, + remove = true, + anim = { dict = "mp_player_intdrink", name = "loop_bottle", settings = { 1.0, -1.0, 2000, 0, 1, true, true, true } }, + }, +} diff --git a/server-data/resources/[bpt_addons]/bpt_basicneeds/fxmanifest.lua b/server-data/resources/[bpt_addons]/bpt_basicneeds/fxmanifest.lua new file mode 100644 index 000000000..6d7999591 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/fxmanifest.lua @@ -0,0 +1,28 @@ +fx_version("adamant") + +game("gta5") + +description("Adds a Hunger & Thrist system") +lua54("yes") +version("1.0.1") + +shared_script("@es_extended/imports.lua") + +server_scripts({ + "@es_extended/locale.lua", + "locales/*.lua", + "config.lua", + "server/main.lua", +}) + +client_scripts({ + "@es_extended/locale.lua", + "locales/*.lua", + "config.lua", + "client/main.lua", +}) + +dependencies({ + "es_extended", + "bpt_status", +}) diff --git a/server-data/resources/[bpt_addons]/bpt_basicneeds/locales/en.lua b/server-data/resources/[bpt_addons]/bpt_basicneeds/locales/en.lua new file mode 100644 index 000000000..bef090aa4 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/locales/en.lua @@ -0,0 +1,5 @@ +Locales["en"] = { + ["used_food"] = "You have eaten 1x %s", + ["used_drink"] = "You have drinked 1x %s", + ["got_healed"] = "You have been healed.", +} diff --git a/server-data/resources/[bpt_addons]/bpt_basicneeds/locales/it.lua b/server-data/resources/[bpt_addons]/bpt_basicneeds/locales/it.lua new file mode 100644 index 000000000..65c268b77 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/locales/it.lua @@ -0,0 +1,5 @@ +Locales["it"] = { + ["used_bread"] = "hai usato 1x panino", + ["used_water"] = "hai usato 1x acqua", + ["got_healed"] = "Sei stato curato.", +} diff --git a/server-data/resources/[bpt_addons]/bpt_basicneeds/localization/it_bpt_basicneeds.sql b/server-data/resources/[bpt_addons]/bpt_basicneeds/localization/it_bpt_basicneeds.sql new file mode 100644 index 000000000..98af83699 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/localization/it_bpt_basicneeds.sql @@ -0,0 +1,4 @@ +INSERT INTO `items` (`name`, `label`, `weight`) VALUES + ('bread', 'Pane', 1), + ('water', 'Acqua', 1) +; \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/README.md b/server-data/resources/[esx_addons]/esx_basicneeds/README.md deleted file mode 100644 index 9f17f5307..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/README.md +++ /dev/null @@ -1,32 +0,0 @@ -## Requirements -- bpt_status - -## Installation - -### Manually -- 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) 2022-2024 bitpredator - -ATTENTION: You are not authorized to change the name of the resource and the resources within it. - -If you want to contribute you can open a pull request. - -You are not authorized to sell this software (this is free project). - -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/server-data/resources/[esx_addons]/esx_basicneeds/client/main.lua b/server-data/resources/[esx_addons]/esx_basicneeds/client/main.lua deleted file mode 100644 index a04012c94..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/client/main.lua +++ /dev/null @@ -1,72 +0,0 @@ -local IsDead = false -local IsAnimated = false - -AddEventHandler('esx_basicneeds:resetStatus', function() - TriggerEvent('bpt_status:set', 'hunger', 500000) - TriggerEvent('bpt_status:set', 'thirst', 500000) -end) - -RegisterNetEvent('esx_basicneeds:healPlayer') -AddEventHandler('esx_basicneeds:healPlayer', function() - -- restore hunger & thirst - TriggerEvent('bpt_status:set', 'hunger', 1000000) - TriggerEvent('bpt_status:set', 'thirst', 1000000) - - -- restore hp - local playerPed = PlayerPedId() - SetEntityHealth(playerPed, GetEntityMaxHealth(playerPed)) -end) - -AddEventHandler('esx:onPlayerDeath', function() - IsDead = true -end) - -AddEventHandler('esx:onPlayerSpawn', function() - if IsDead then - TriggerEvent('esx_basicneeds:resetStatus') - end - - IsDead = false -end) - -AddEventHandler('bpt_status:loaded', function() - TriggerEvent('bpt_status:registerStatus', 'hunger', 1000000, '#CFAD0F', function() - return Config.Visible - end, function(status) - status.remove(100) - end) - - TriggerEvent('bpt_status:registerStatus', 'thirst', 1000000, '#0C98F1', function() - return Config.Visible - end, function(status) - status.remove(75) - end) -end) - -AddEventHandler('bpt_status:onTick', function(data) - local playerPed = PlayerPedId() - local prevHealth = GetEntityHealth(playerPed) - local health = prevHealth - - for _, v in pairs(data) do - if v.name == 'hunger' and v.percent == 0 then - if prevHealth <= 150 then - health = health - 5 - else - health = health - 1 - end - elseif v.name == 'thirst' and v.percent == 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) - -AddEventHandler('esx_basicneeds:isEating', function(cb) - cb(IsAnimated) -end) \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/config.lua b/server-data/resources/[esx_addons]/esx_basicneeds/config.lua deleted file mode 100644 index 9c86897f6..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/config.lua +++ /dev/null @@ -1,3 +0,0 @@ -Config = {} -Config.Locale = 'en' -Config.Visible = false \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/fxmanifest.lua b/server-data/resources/[esx_addons]/esx_basicneeds/fxmanifest.lua deleted file mode 100644 index bf614cc29..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/fxmanifest.lua +++ /dev/null @@ -1,28 +0,0 @@ -fx_version 'adamant' - -game 'gta5' - -description 'Basic Needs' -lua54 'yes' -version '0.0.5' - -shared_script '@es_extended/imports.lua' - -server_scripts { - '@es_extended/locale.lua', - 'locales/*.lua', - 'config.lua', - 'server/main.lua' -} - -client_scripts { - '@es_extended/locale.lua', - 'locales/*.lua', - 'config.lua', - 'client/main.lua' -} - -dependencies { - 'es_extended', - 'bpt_status' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/da.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/da.lua deleted file mode 100644 index 15c31d5a8..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/da.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['da'] = { - ['got_healed'] = 'Du er blevet helbredt.' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/de.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/de.lua deleted file mode 100644 index 94d91f9d5..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/de.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['de'] = { - ['got_healed'] = 'Du wurdest geheilt.' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/en.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/en.lua deleted file mode 100644 index 3f490d0a1..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/en.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['en'] = { - ['got_healed'] = 'You have been healed.' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/es.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/es.lua deleted file mode 100644 index 06d9abb57..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/es.lua +++ /dev/null @@ -1,4 +0,0 @@ -Locales['es'] = { - ['used_bread'] = 'Has usado 1x pan', - ['used_water'] = 'Has usado 1x agua', -} \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/fi.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/fi.lua deleted file mode 100644 index 92702f41d..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/fi.lua +++ /dev/null @@ -1,4 +0,0 @@ -Locales['fi'] = { - ['used_bread'] = 'sinä söit 1x leipä', - ['used_water'] = 'sinä joit 1x vesi', -} \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/fr.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/fr.lua deleted file mode 100644 index 728539d77..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/fr.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['fr'] = { - ['got_healed'] = 'Vous avez été soigné.' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/hu.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/hu.lua deleted file mode 100644 index 1277cbaca..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/hu.lua +++ /dev/null @@ -1,4 +0,0 @@ -Locales['hu'] = { - ['used_bread'] = 'Megettél egy kenyeret.', - ['used_water'] = 'Megittál egy vizet.', -} \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/it.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/it.lua deleted file mode 100644 index d23eb7668..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/it.lua +++ /dev/null @@ -1,5 +0,0 @@ -Locales['it'] = { - ['used_bread'] = 'hai usato 1x panino', - ['used_water'] = 'hai usato 1x acqua', - ['got_healed'] = 'Sei stato curato.' -} \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/nl.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/nl.lua deleted file mode 100644 index 23bb68a10..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/nl.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['nl'] = { - ['used_eat'] = 'je hebt een %s gegeten', -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/pl.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/pl.lua deleted file mode 100644 index 6ce6b3af6..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/pl.lua +++ /dev/null @@ -1,4 +0,0 @@ -Locales['pl'] = { - ['used_bread'] = 'zjadłeś/aś 1x chleb', - ['used_water'] = 'wypiłeś/aś 1x woda', -} \ No newline at end of file diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/sl.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/sl.lua deleted file mode 100644 index 031851624..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/sl.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['sl'] = { - ['got_healed'] = 'Vi ste bili Pozdravljeni.' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/sr.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/sr.lua deleted file mode 100644 index 336eda766..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/sr.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['sr'] = { - ['got_healed'] = 'Vi ste izlečeni.' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/locales/zh-cn.lua b/server-data/resources/[esx_addons]/esx_basicneeds/locales/zh-cn.lua deleted file mode 100644 index 2ed1e6073..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/locales/zh-cn.lua +++ /dev/null @@ -1,3 +0,0 @@ -Locales['zh-cn'] = { - ['got_healed'] = '已重置饥饿+饥渴双值.' -} diff --git a/server-data/resources/[esx_addons]/esx_basicneeds/server/main.lua b/server-data/resources/[esx_addons]/esx_basicneeds/server/main.lua deleted file mode 100644 index 6cbd0c7e1..000000000 --- a/server-data/resources/[esx_addons]/esx_basicneeds/server/main.lua +++ /dev/null @@ -1,14 +0,0 @@ -ESX.RegisterCommand('heal', 'admin', function(_, args) - args.playerId.triggerEvent('esx_basicneeds:healPlayer') - args.playerId.showNotification(_U('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'} -}}) - -AddEventHandler('txAdmin:events:healedPlayer', function(eventData) - if GetInvokingResource() ~= "monitor" or type(eventData) ~= "table" or type(eventData.id) ~= "number" then - return - end - - TriggerClientEvent('esx_basicneeds:healPlayer', eventData.id) -end) \ No newline at end of file