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)