mirror of
https://github.com/jimathy/jim-consumables.git
synced 2026-08-16 22:16:02 +01:00
Fix stats overriding itself
The `stats` table was being overridden by the function to calculate random times for certain settings replacing the table with only `hunger` and `thirst` Separated them now things like screen effects work again Also refactored some sections to reduce amount of `if` statements
This commit is contained in:
@@ -32,7 +32,6 @@ onPlayerLoaded(function()
|
|||||||
syncConsumables()
|
syncConsumables()
|
||||||
end, true)
|
end, true)
|
||||||
|
|
||||||
|
|
||||||
RegisterNetEvent(getScript()..':Consume', function(itemName)
|
RegisterNetEvent(getScript()..':Consume', function(itemName)
|
||||||
if not hasItem(itemName, 1) then
|
if not hasItem(itemName, 1) then
|
||||||
print("^5Debug^7: ^1Error^7: ^2Item not found in inventory^7, ^2stopping^7..")
|
print("^5Debug^7: ^1Error^7: ^2Item not found in inventory^7, ^2stopping^7..")
|
||||||
@@ -114,10 +113,10 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
local type = Consumables[itemName].type or ""
|
local type = Consumables[itemName].type or ""
|
||||||
local pack = Consumables[itemName].pack or nil
|
local pack = Consumables[itemName].pack or nil
|
||||||
local string = "Using "
|
local string = "Using "
|
||||||
local notifType = ""
|
|
||||||
local canRun = Consumables[itemName].canRun
|
local canRun = Consumables[itemName].canRun
|
||||||
|
local stats = Consumables[itemName].stats
|
||||||
|
|
||||||
local time, stress, heal, armor, stats = GenerateRandomValues({
|
local time, stress, heal, armor, needStats = GenerateRandomValues({
|
||||||
time = Consumables[itemName].time or { 5000, 6000 },
|
time = Consumables[itemName].time or { 5000, 6000 },
|
||||||
stress = Consumables[itemName].stress or 0,
|
stress = Consumables[itemName].stress or 0,
|
||||||
heal = Consumables[itemName].heal or 0,
|
heal = Consumables[itemName].heal or 0,
|
||||||
@@ -187,6 +186,7 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
consuming = true
|
consuming = true
|
||||||
|
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
--Prop Spawning
|
--Prop Spawning
|
||||||
if model then
|
if model then
|
||||||
@@ -198,7 +198,9 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
if IsModelValid(model2) == 1 then
|
if IsModelValid(model2) == 1 then
|
||||||
attachProp2 = makeProp({ prop = model2, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1)
|
attachProp2 = makeProp({ prop = model2, coords = vector4(0.0,0.0,0.0,0.0)}, 1, 1)
|
||||||
AttachEntityToEntity(attachProp2, Player, bone2, P7, P8, P9, P10, P11, P12, true, true, false, true, 1, true)
|
AttachEntityToEntity(attachProp2, Player, bone2, P7, P8, P9, P10, P11, P12, true, true, false, true, 1, true)
|
||||||
else print("^5Debug^7: ^3PropSpawn^7: ^2Second prop model isn't valid/found^7.") end
|
else
|
||||||
|
print("^5Debug^7: ^3PropSpawn^7: ^2Second prop model isn't valid/found^7.")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
while consuming do Wait(50) end
|
while consuming do Wait(50) end
|
||||||
if DoesEntityExist(attachProp) then
|
if DoesEntityExist(attachProp) then
|
||||||
@@ -214,13 +216,14 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
while consuming do
|
while consuming do
|
||||||
local drawTable = debugMode and
|
local drawTable = debugMode and
|
||||||
{ "[BackSpace] Stop Consuming",
|
{ "[BackSpace] Stop Consuming",
|
||||||
"Time: "..tostring(time),
|
"Time: "..tostring(time),
|
||||||
"Type: "..(type or ""),
|
"Type: "..(type or ""),
|
||||||
"Hunger: "..(stats.hunger or 0).."%",
|
"Hunger: "..(needStats.hunger or 0).."%",
|
||||||
"Thirst: "..(stats.thirst or 0).."%",
|
"Thirst: "..(needStats.thirst or 0).."%",
|
||||||
"Stress: "..(stress or 0).."%",
|
"Stress: "..(stress or 0).."%",
|
||||||
"Heal: "..(heal or 0).."%",
|
"Heal: "..(heal or 0).."%",
|
||||||
"Armour: "..(armor or 0).."%",
|
"Armour: "..(armor or 0).."%",
|
||||||
@@ -250,6 +253,7 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
hideText()
|
hideText()
|
||||||
removeItem(itemName, 1)
|
removeItem(itemName, 1)
|
||||||
if returnItem ~= nil then
|
if returnItem ~= nil then
|
||||||
|
debugPrint("returnItem detected")
|
||||||
currentToken = triggerCallback(AuthEvent)
|
currentToken = triggerCallback(AuthEvent)
|
||||||
addItem(returnItem.item, returnItem.amount)
|
addItem(returnItem.item, returnItem.amount)
|
||||||
end
|
end
|
||||||
@@ -257,6 +261,7 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
-- Reward Item calculations
|
-- Reward Item calculations
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
if RewardItem then
|
if RewardItem then
|
||||||
|
debugPrint("Reward Item detected")
|
||||||
for i = 1, Consumables[itemName].amounttogive do
|
for i = 1, Consumables[itemName].amounttogive do
|
||||||
local rarity = math.random(1, 4) -- rarity calculation
|
local rarity = math.random(1, 4) -- rarity calculation
|
||||||
while true do
|
while true do
|
||||||
@@ -273,17 +278,15 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
if stats then
|
if needStats then
|
||||||
if stats.hunger then
|
if needStats.hunger then
|
||||||
--stats.hunger = math.random(stats.hunger - 5, stats.hunger + 5)
|
TriggerServerEvent(getScript()..":server:addNeed", Core.Functions.GetPlayerData().metadata["hunger"] + needStats.hunger, "hunger")
|
||||||
TriggerServerEvent(getScript()..":server:addNeed", Core.Functions.GetPlayerData().metadata["hunger"] + stats.hunger, "hunger")
|
|
||||||
end
|
end
|
||||||
if stats.thirst then
|
if needStats.thirst then
|
||||||
--stats.thirst = math.random(stats.thirst - 5, stats.thirst + 5)
|
TriggerServerEvent(getScript()..":server:addNeed", Core.Functions.GetPlayerData().metadata["thirst"] + needStats.thirst, "thirst")
|
||||||
TriggerServerEvent(getScript()..":server:addNeed", Core.Functions.GetPlayerData().metadata["thirst"] + stats.thirst, "thirst")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
debugPrint("^5Debug^7: ^2Hunger^7: [^6"..(stats.hunger or 0).."^7] ^2Thrist^7: [^6"..(stats.thirst or 0).."^7]" )
|
debugPrint("^5Debug^7: ^2Hunger^7: [^6"..(needStats.hunger or 0).."^7] ^2Thrist^7: [^6"..(needStats.thirst or 0).."^7]" )
|
||||||
if stress and stress ~= 0 then
|
if stress and stress ~= 0 then
|
||||||
debugPrint("^5Debug^7: ^3Consume^7: ^2Relieving ^6"..stress.." ^2stress^7.")
|
debugPrint("^5Debug^7: ^3Consume^7: ^2Relieving ^6"..stress.." ^2stress^7.")
|
||||||
TriggerServerEvent('hud:server:RelieveStress', stress)
|
TriggerServerEvent('hud:server:RelieveStress', stress)
|
||||||
@@ -303,7 +306,9 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
TriggerEvent("evidence:client:SetStatus", "alcohol", 200)
|
TriggerEvent("evidence:client:SetStatus", "alcohol", 200)
|
||||||
elseif alcoholCount >= 4 then
|
elseif alcoholCount >= 4 then
|
||||||
TriggerEvent("evidence:client:SetStatus", "heavyalcohol", 200)
|
TriggerEvent("evidence:client:SetStatus", "heavyalcohol", 200)
|
||||||
CreateThread(function() AlienEffect() end) -- Used as overdosing/too drunk effect
|
CreateThread(function()
|
||||||
|
AlienEffect()
|
||||||
|
end) -- Used as overdosing/too drunk effect
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if pack then
|
if pack then
|
||||||
@@ -312,26 +317,20 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
end
|
end
|
||||||
if stats then
|
if stats then
|
||||||
if stats.screen then -- Screen effect activation
|
if stats.screen then -- Screen effect activation
|
||||||
if stats.screen == "turbo" then
|
debugPrint(stats.screen)
|
||||||
CreateThread(function() TurboEffect() end)
|
local statFunctions = {
|
||||||
end
|
["turbo"] = TurboEffect,
|
||||||
if stats.screen == "focus" then
|
["focus"] = FocusEffect,
|
||||||
CreateThread(function() FocusEffect() end)
|
["rampage"] = RampageEffect,
|
||||||
end
|
["weed"] = WeedEffect,
|
||||||
if stats.screen == "rampage" then
|
["trevor"] = TrevorEffect,
|
||||||
CreateThread(function() RampageEffect() end)
|
["nightvision"] = NightVisionEffect,
|
||||||
end
|
["thermal"] = ThermalEffect,
|
||||||
if stats.screen == "weed" then
|
}
|
||||||
CreateThread(function() WeedEffect() end)
|
if statFunctions[stats.screen] then
|
||||||
end
|
CreateThread(function()
|
||||||
if stats.screen == "trevor" then
|
statFunctions[stats.screen]()
|
||||||
CreateThread(function() TrevorEffect() end)
|
end)
|
||||||
end
|
|
||||||
if stats.screen == "nightvision" then
|
|
||||||
CreateThread(function() NightVisionEffect() end)
|
|
||||||
end
|
|
||||||
if stats.screen == "thermal" then
|
|
||||||
CreateThread(function() ThermalEffect() end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if stats.canOD then
|
if stats.canOD then
|
||||||
@@ -345,33 +344,72 @@ RegisterNetEvent(getScript()..':Consume', function(itemName)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if stats.effect == "heal" then
|
if stats.effect then
|
||||||
if isStarted("ps-buffs") then
|
local effectTable = {
|
||||||
debugPrint("^5Debug^7: ^3Consume^7: ^4PS^7-^4Buffs ^2found^7, ^2hooking in to get buffs and applying ^6Health Buff ^2for ^6"..stats.time.."^7ms")
|
["heal"] = function(stats)
|
||||||
exports["ps-buffs"]:AddHealthBuff((tonumber(stats.time) or 10000), (stats.amount or 6))
|
if isStarted("ps-buffs") then
|
||||||
else
|
debugPrint("^5Debug^7: ^3Consume^7: ^4PS^7-^4Buffs ^2found^7, ^2hooking in to get buffs and applying ^6Health Buff ^2for ^6"..stats.time.."^7ms")
|
||||||
CreateThread(function()
|
exports["ps-buffs"]:AddHealthBuff((tonumber(stats.time) or 10000), (stats.amount or 6))
|
||||||
HealEffect({(tonumber(stats.time) or 10000), (stats.amount or 6)})
|
else
|
||||||
end)
|
CreateThread(function()
|
||||||
|
HealEffect({(tonumber(stats.time) or 10000), (stats.amount or 6)})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["stamina"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then
|
||||||
|
debugPrint("^5Debug^7: ^3Consume^7: ^4PS^7-^4Buffs ^2found^7, ^2hooking in to get buffs and applying ^6Stamina Buff ^2for ^6"..stats.time.."^7ms")
|
||||||
|
exports["ps-buffs"]:StaminaBuffEffect((tonumber(stats.time) or 10000), (stats.amount or 6))
|
||||||
|
else
|
||||||
|
CreateThread(function()
|
||||||
|
StaminaEffect({(tonumber(stats.time) or 10000), (stats.amount or 6)})
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["armor"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
||||||
|
exports["ps-buffs"]:AddArmorBuff((tonumber(stats.time) or 10000), (stats.amount or 6))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["stress"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
||||||
|
exports["ps-buffs"]:AddStressBuff((tonumber(stats.time) or 10000), (stats.amount or 6))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["swimming"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
||||||
|
exports["ps-buffs"]:SwimmingBuffEffect((tonumber(stats.time) or 10000), (stats.amount or 6))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["hacking"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
||||||
|
exports["ps-buffs"]:AddBuff("hacking", (tonumber(stats.time) or 10000))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["intelligence"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
||||||
|
exports["ps-buffs"]:AddBuff("intelligence", (tonumber(stats.time) or 10000))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["luck"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
||||||
|
exports["ps-buffs"]:AddBuff("luck", (tonumber(stats.time) or 10000))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
["strength"] = function(stats)
|
||||||
|
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
||||||
|
exports["ps-buffs"]:AddBuff("strength", (tonumber(stats.time) or 10000))
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
|
||||||
|
if effectTable[stats.effect] then
|
||||||
|
effectTable[stats.effect](stats)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if stats.effect == "stamina" then
|
if stats.widepupils then
|
||||||
if isStarted("ps-buffs") then
|
TriggerEvent("evidence:client:SetStatus", "widepupils", 200)
|
||||||
debugPrint("^5Debug^7: ^3Consume^7: ^4PS^7-^4Buffs ^2found^7, ^2hooking in to get buffs and applying ^6Stamina Buff ^2for ^6"..stats.time.."^7ms")
|
|
||||||
exports["ps-buffs"]:StaminaBuffEffect((tonumber(stats.time) or 10000), (stats.amount or 6))
|
|
||||||
else CreateThread(function() StaminaEffect({(tonumber(stats.time) or 10000), (stats.amount or 6)}) end) end
|
|
||||||
end
|
|
||||||
if isStarted("ps-buffs") then --PS-BUFFS ONLY
|
|
||||||
if stats.effect then debugPrint("^5Debug^7: ^3Consume^7: ^4PS^7-^4Buffs ^2found^7, ^2hooking in to get buffs and applying ^6"..stats.effect.." Buff ^2for ^6"..(stats.time or "nil").."^7ms") end
|
|
||||||
if stats.effect == "armor" then exports["ps-buffs"]:AddArmorBuff((tonumber(stats.time) or 10000), (stats.amount or 6)) end
|
|
||||||
if stats.effect == "stress" then exports["ps-buffs"]:AddStressBuff((tonumber(stats.time) or 10000), (stats.amount or 6)) end
|
|
||||||
if stats.effect == "swimming" then exports["ps-buffs"]:SwimmingBuffEffect((tonumber(stats.time) or 10000), (stats.amount or 6)) end
|
|
||||||
if stats.effect == "hacking" then exports["ps-buffs"]:AddBuff("hacking", (tonumber(stats.time) or 10000)) end
|
|
||||||
if stats.effect == "intelligence" then exports["ps-buffs"]:AddBuff("intelligence", (tonumber(stats.time) or 10000)) end
|
|
||||||
if stats.effect == "luck" then exports["ps-buffs"]:AddBuff("luck", (tonumber(stats.time) or 10000)) end
|
|
||||||
if stats.effect == "strength" then exports["ps-buffs"]:AddBuff("strength", (tonumber(stats.time) or 10000)) end
|
|
||||||
end
|
end
|
||||||
if stats.widepupils then TriggerEvent("evidence:client:SetStatus", "widepupils", 200) end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
cancelled = false
|
cancelled = false
|
||||||
@@ -383,13 +421,25 @@ end)
|
|||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
Wait(10)
|
Wait(10)
|
||||||
if alcoholCount > 0 then Wait(1000 * 60 * 15) alcoholCount -= 1 else Wait(1000) end
|
if alcoholCount > 0 then
|
||||||
if drugCount > 0 then Wait(1000 * 60 * 15) drugCount -= 1 else Wait(1000) end
|
Wait(1000 * 60 * 15)
|
||||||
|
alcoholCount -= 1
|
||||||
|
else
|
||||||
|
Wait(1000)
|
||||||
|
end
|
||||||
|
if drugCount > 0 then
|
||||||
|
Wait(1000 * 60 * 15)
|
||||||
|
drugCount -= 1
|
||||||
|
else
|
||||||
|
Wait(1000)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
onResourceStop(function()
|
onResourceStop(function()
|
||||||
|
|
||||||
lockInv(false)
|
lockInv(false)
|
||||||
|
|
||||||
StopEffects()
|
StopEffects()
|
||||||
|
|
||||||
end, true)
|
end, true)
|
||||||
Reference in New Issue
Block a user