From a0c83c0e1f727188875555be01eece2f9ae85599 Mon Sep 17 00:00:00 2001 From: Atikur Rahaman Santo <55808925+ARSSANTO@users.noreply.github.com> Date: Fri, 26 Aug 2022 06:10:20 +0600 Subject: [PATCH] feat: Notify config progressbar config & canrun while consume in config --- README.md | 1 + client/client.lua | 57 +++++++++++++++++++---------------------------- config.lua | 26 +++++++++++---------- server/server.lua | 15 ++++++++++++- 4 files changed, 52 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 35666a7..9c9e82a 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ To add an item, you only need to add a new item table in the Config.Consumables ```lua ["heartstopper"] = { emote = "burger", -- Select an emote from below, it has to be in here + canRun = false, --To restrict a player can run while consuming on particuller item eg. default is false make it true if you wanna restrict running time = math.random(5000, 6000), -- Amount of time it takes to consume the item stress = math.random(1,2), -- Amount of stress relief, can be 0 heal = 0, -- Set amount to heal by after consuming diff --git a/client/client.lua b/client/client.lua index ec77a32..11da423 100644 --- a/client/client.lua +++ b/client/client.lua @@ -36,7 +36,6 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) if type == "drink" or type == "alcohol" then string = "Drinking " end if type == "food" then string = "Eating " end if type == "drug" then string = "Using " end - if consuming then cancelled = true if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Event already started^7, ^1Cancelling^7.") end @@ -45,7 +44,6 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) consuming = not consuming return end - --Emote Stuff if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Grabbing Emote Animation Options^7...") end if emote.AnimationOptions then @@ -56,20 +54,20 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) elseif emote.AnimationOptions.EmoteMoving == false then MovementType = 0 elseif emote.AnimationOptions.EmoteStuck then MovementType = 50 end - else MovementType = 0 end if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Checking if player is in a vehicle^7...") end local InVehicle = IsPedInAnyVehicle(PlayerPedId(), true) if InVehicle == 1 then MovementType = 51 end - --Load and Start animation if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Playing Animation^7...") end loadAnimDict(animDict) TaskPlayAnim(PlayerPedId(), animDict, anim, 1.0, 1.0, -1, MovementType, 0, 0, 0, 0) - - triggerNotify(nil, string..QBCore.Shared.Items[itemName].label.."..", "success") + if Config.UseProgbar then + QBCore.Functions.Progressbar('jimmy_consume_', string..QBCore.Shared.Items[itemName].label.."..", time, false, false, {disableMovement = false,disableCarMovement = false,disableMouse = false,disableCombat = true,}, {}, {}, {}, function()end) + else + triggerNotify(nil, string..QBCore.Shared.Items[itemName].label.."..", "success") + end consuming = true - CreateThread(function() --Prop Spawning if model then @@ -80,56 +78,51 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) destroyProp(attachProp) end end) - while consuming do if time <= 0 then consuming = false end - if IsControlJustPressed(0, 21) then - consuming = false - cancelled = true - LocalPlayer.state:set("inv_busy", false, true) - end - Wait(10) - time = time - 10 + if not Config.Consumables[itemName].canRun then + if IsControlJustPressed(0, 21) then + consuming = false + cancelled = true + LocalPlayer.state:set("inv_busy", false, true) + if Config.UseProgbar then + TriggerEvent("progressbar:client:cancel") + else + triggerNotify(nil, "Cancelled "..string, "error") + end + end + end + Wait(10) + time = time - 10 end - StopEntityAnim(PlayerPedId(), anim, animDict, 1.0) unloadAnimDict(animDict) - if not cancelled then - toggleItem(false, itemName, 1) - - if QBCore.Shared.Items[itemName].thirst then - TriggerServerEvent("QBCore:Server:SetMetaData", "thirst", QBCore.Functions.GetPlayerData().metadata["thirst"] + QBCore.Shared.Items[itemName].thirst) end - if QBCore.Shared.Items[itemName].hunger then - TriggerServerEvent("QBCore:Server:SetMetaData", "hunger", QBCore.Functions.GetPlayerData().metadata["hunger"] + QBCore.Shared.Items[itemName].hunger) end - + if QBCore.Shared.Items[itemName].thirst then TriggerServerEvent("jim-consumables:server:addThirst", QBCore.Functions.GetPlayerData().metadata["thirst"] + QBCore.Shared.Items[itemName].thirst) end + if QBCore.Shared.Items[itemName].hunger then TriggerServerEvent("jim-consumables:server:addHunger", QBCore.Functions.GetPlayerData().metadata["hunger"] + QBCore.Shared.Items[itemName].hunger) end if not QBCore.Shared.Items[itemName].thirst and not QBCore.Shared.Items[itemName].hunger then local hunger = 0 local thirst = 0 if Config.Consumables[itemName].stats then if Config.Consumables[itemName].stats.hunger then hunger = Config.Consumables[itemName].stats.hunger end - TriggerServerEvent("QBCore:Server:SetMetaData", "hunger", QBCore.Functions.GetPlayerData().metadata["hunger"] + hunger) + TriggerServerEvent("jim-consumables:server:addHunger", QBCore.Functions.GetPlayerData().metadata["hunger"] + hunger) if Config.Consumables[itemName].stats.thirst then thirst = Config.Consumables[itemName].stats.thirst end - TriggerServerEvent("QBCore:Server:SetMetaData", "thirst", QBCore.Functions.GetPlayerData().metadata["thirst"] + thirst) + TriggerServerEvent("jim-consumables:server:addThirst", QBCore.Functions.GetPlayerData().metadata["thirst"] + thirst) end end - if stress and stress ~= 0 then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Reliving ^6"..stress.." ^2stress^7.") end TriggerServerEvent('hud:server:RelieveStress', stress) end - if heal and heal ~= 0 then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Healing player by^7: ^6"..heal) end SetEntityHealth(PlayerPedId(), GetEntityHealth(PlayerPedId()) + heal) end - if armor and armor ~= 0 then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Adding ^6"..armor.." ^2armour^7.") end TriggerServerEvent('hospital:server:SetArmor', (GetPedArmour(PlayerPedId()) + armor)) SetPedArmour(PlayerPedId(), (GetPedArmour(PlayerPedId()) + armor)) end - if type == "alcohol" then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Current ^4alcoholCount^7: ^6"..(alcoholCount + 1)) end alcoholCount = alcoholCount + 1 @@ -140,9 +133,7 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) CreateThread(function() AlienEffect() end) -- Used as overdosing/too drunk effect end end - stats = Config.Consumables[itemName].stats or nil - if Config.Consumables[itemName].stats then if stats.screen then -- Screen effect activation if stats.screen == "turbo" then CreateThread(function() TurboEffect() end) end @@ -151,7 +142,6 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) if stats.screen == "weed" then CreateThread(function() WeedEffect() end) end if stats.screen == "trevor" then CreateThread(function() TrevorEffect() end) end end - if stats.canOD then if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Current ^4drugCount^7: ^6"..(drugCount + 1)) end drugCount = drugCount + 1 @@ -186,7 +176,6 @@ RegisterNetEvent('jim-consumables:Consume', function(itemName) end cancelled = false consuming = false - if Config.Debug then print("^5Debug^7: ^3Consume^7: ^2Finished, unlocking inventory^7...") end LocalPlayer.state:set("inv_busy", false, true) TriggerEvent('inventory:client:busy:status', false) TriggerEvent('canUseInventoryAndHotbar:toggle', false) end) diff --git a/config.lua b/config.lua index e63268f..7dcf167 100644 --- a/config.lua +++ b/config.lua @@ -6,22 +6,24 @@ print("^2Jim^7-^2Consumables v^41^7.^43 ^7- ^2Consumables Script by ^1Jimathy^7" Config = { Debug = false, + Notify = 'qb', + UseProgbar = false, Consumables = { -- Default QB food and drink item override --Effects can be applied here, like stamina on coffee for example - ["vodka"] = { emote = "vodkab", time = math.random(5000, 6000), stress = 0, heal = 0, armor = 0, type = "alcohol", stats = { effect = "stress", time = 5000, amount = 2, thirst = math.random(10,20), canOD = true }}, - ["beer"] = { emote = "beer", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "alcohol", stats = { thirst = math.random(10,20), canOD = true }}, - ["whiskey"] = { emote = "whiskey", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "alcohol", stats = { thirst = math.random(10,20), canOD = true }}, - - ["sandwich"] = { emote = "sandwich", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, - ["twerks_candy"] = { emote = "egobar", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, - ["snikkel_candy"] = { emote = "egobar", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, - ["tosti"] = { emote = "sandwich", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, - - ["coffee"] = { emote = "coffee", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "drink", stats = { effect = "stamina", time = 10000, thirst = math.random(10,20), }}, - ["water_bottle"] = { emote = "drink", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "drink", stats = { thirst = math.random(10,20), }}, - ["kurkakola"] = { emote = "ecola", time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "drink", stats = { thirst = math.random(10,20), }}, + ["vodka"] = { emote = "vodkab", canRun = false, time = math.random(5000, 6000), stress = 0, heal = 0, armor = 0, type = "alcohol", stats = { effect = "stress", time = 5000, amount = 2, thirst = math.random(10,20), canOD = true }}, + ["beer"] = { emote = "beer", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "alcohol", stats = { thirst = math.random(10,20), canOD = true }}, + ["whiskey"] = { emote = "whiskey", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "alcohol", stats = { thirst = math.random(10,20), canOD = true }}, + + ["sandwich"] = { emote = "sandwich", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, + ["twerks_candy"] = { emote = "egobar", canRun = true, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, + ["snikkel_candy"] = { emote = "egobar", canRun = true, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, + ["tosti"] = { emote = "sandwich", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "food", stats = { hunger = math.random(10,20), }}, + + ["coffee"] = { emote = "coffee", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "drink", stats = { effect = "stamina", time = 10000, thirst = math.random(10,20), }}, + ["water_bottle"] = { emote = "drink", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "drink", stats = { thirst = math.random(10,20), }}, + ["kurkakola"] = { emote = "ecola", canRun = false, time = math.random(5000, 6000), stress = math.random(2, 4), heal = 0, armor = 0, type = "drink", stats = { thirst = math.random(10,20), }}, --[[---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- Items that effect status changes, like bleeding can cause problems as they are all handled in their own scripts diff --git a/server/server.lua b/server/server.lua index 038b0c5..0057029 100644 --- a/server/server.lua +++ b/server/server.lua @@ -6,7 +6,6 @@ for k, v in pairs(Config.Consumables) do if not Config.Emotes[v.emote] then print("Emote check - '"..k.."' requested emote '"..v.emote.."' - not found in config.lua") end end - RegisterNetEvent('jim-consumables:server:toggleItem', function(give, item, amount) local src = source if give == 0 or give == false then @@ -18,4 +17,18 @@ RegisterNetEvent('jim-consumables:server:toggleItem', function(give, item, amoun TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], "add", amount or 1) end end +end) + +RegisterNetEvent('jim-consumables:server:addThirst', function(amount) + local Player = QBCore.Functions.GetPlayer(source) + if not Player then return end + Player.Functions.SetMetaData('thirst', amount) + TriggerClientEvent('hud:client:UpdateNeeds', source, Player.PlayerData.metadata.hunger, amount) +end) + +RegisterNetEvent('jim-consumables:server:addHunger', function(amount) + local Player = QBCore.Functions.GetPlayer(source) + if not Player then return end + Player.Functions.SetMetaData('hunger', amount) + TriggerClientEvent('hud:client:UpdateNeeds', source, amount, Player.PlayerData.metadata.thirst) end) \ No newline at end of file