From a0cc7de9a5ea64b6ea1562d29217f374bade7394 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Mon, 10 Jun 2024 17:34:50 +0200 Subject: [PATCH] convert: esx_basicneeds > bpt_basicneeds --- .../bpt_basicneeds/server/main.lua | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 server-data/resources/[bpt_addons]/bpt_basicneeds/server/main.lua diff --git a/server-data/resources/[bpt_addons]/bpt_basicneeds/server/main.lua b/server-data/resources/[bpt_addons]/bpt_basicneeds/server/main.lua new file mode 100644 index 000000000..09a9554d0 --- /dev/null +++ b/server-data/resources/[bpt_addons]/bpt_basicneeds/server/main.lua @@ -0,0 +1,36 @@ +CreateThread(function() + 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 + if v.type == "food" then + TriggerClientEvent("bpt_status:add", source, "hunger", v.status) + TriggerClientEvent("bpt_basicneeds:onUse", source, v.type, v.prop, v.anim) + xPlayer.showNotification(TranslateCap("used_food", ESX.GetItemLabel(k))) + elseif v.type == "drink" then + TriggerClientEvent("bpt_status:add", source, "thirst", v.status) + TriggerClientEvent("bpt_basicneeds:onUse", source, v.type, v.prop, v.anim) + xPlayer.showNotification(TranslateCap("used_drink", ESX.GetItemLabel(k))) + else + print(string.format("^1[ERROR]^0 %s has no correct type defined.", k)) + end + end) + end +end) + +ESX.RegisterCommand("heal", "admin", function(xPlayer, args, showError) + args.playerId.triggerEvent("bpt_basicneeds:healPlayer") + 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" }, +} }) + +AddEventHandler("txAdmin:events:healedPlayer", function(eventData) + if GetInvokingResource() ~= "monitor" or type(eventData) ~= "table" or type(eventData.id) ~= "number" then + return + end + + TriggerClientEvent("bpt_basicneeds:healPlayer", eventData.id) +end)