Rework SingleProgress slightly

Realised it wasn't doing the math to take the correct amount of required items, so this fixes it

also if `SingleProgress` is enabled, it won't show the "Ingredient Progress bars" any more
This commit is contained in:
Jim Shield
2025-09-27 12:34:46 +01:00
parent ee15f3b076
commit 178040348e
2 changed files with 51 additions and 44 deletions

View File

@@ -323,6 +323,7 @@ end
--- ``` --- ```
function makeItem(data) function makeItem(data)
local Ped = PlayerPedId()
if CraftLock then return end if CraftLock then return end
CraftLock = true CraftLock = true
data.stashName = data.stashTable or data.stashName data.stashName = data.stashTable or data.stashName
@@ -339,12 +340,13 @@ function makeItem(data)
local canReturn = true local canReturn = true
local crafted, crafting = true, true local crafted, crafting = true, true
local cam = createTempCam(PlayerPedId(), data.coords) local cam = createTempCam(Ped, data.coords)
startTempCam(cam) startTempCam(cam)
-- Calculate total bartime if SingleProgress is enabled -- Calculate total bartime if SingleProgress is enabled
local totalBartime = bartime * craftAmount local totalBartime = (bartime * craftAmount)
if not Config.Crafting.SingleProgress then -- if SingleProgress is disabled, dont do ingredient progressbars
-- Run ingredient check and usage separately first -- Run ingredient check and usage separately first
for i = 1, craftAmount do for i = 1, craftAmount do
for k, v in pairs(data.craft) do for k, v in pairs(data.craft) do
@@ -353,14 +355,14 @@ function makeItem(data)
if isInventoryOpen() then if isInventoryOpen() then
print("^1Error^7: ^2Inventory is open, you tried to break things") print("^1Error^7: ^2Inventory is open, you tried to break things")
stopTempCam() stopTempCam()
ClearPedTasks(PlayerPedId()) ClearPedTasks(Ped)
if canReturn then craftingMenu(data) end if canReturn then craftingMenu(data) end
CraftLock = false CraftLock = false
return return
end end
if crafting and progressBar({ if crafting and progressBar({
label = "Using "..b.." "..getItemLabel(l), label = "Using "..b.." "..getItemLabel(l),
time = 1000, time = 800,
cancel = true, cancel = true,
dict = 'pickup_object', dict = 'pickup_object',
anim = "putdown_low", anim = "putdown_low",
@@ -377,10 +379,11 @@ function makeItem(data)
end end
end end
end end
end
if not crafted then if not crafted then
stopTempCam() stopTempCam()
ClearPedTasks(PlayerPedId()) ClearPedTasks(Ped)
if canReturn then craftingMenu(data) end if canReturn then craftingMenu(data) end
CraftLock = false CraftLock = false
return return
@@ -391,11 +394,11 @@ function makeItem(data)
local craftProp = nil local craftProp = nil
if prop then if prop then
craftProp = makeProp({ prop = prop.model, coords = vec4(0, 0, 0, 0), true, true }) craftProp = makeProp({ prop = prop.model, coords = vec4(0, 0, 0, 0), true, true })
AttachEntityToEntity(craftProp, PlayerPedId(), GetPedBoneIndex(PlayerPedId(), prop.bone), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 1, true) AttachEntityToEntity(craftProp, Ped, GetPedBoneIndex(Ped, prop.bone), prop.pos.x, prop.pos.y, prop.pos.z, prop.rot.x, prop.rot.y, prop.rot.z, true, true, false, true, 1, true)
end end
if data.sound then if data.sound then
local s = data.sound local s = data.sound
PlaySoundFromEntity(s.soundId, s.audioName, PlayerPedId(), s.audioRef, true, 0) PlaySoundFromEntity(s.soundId, s.audioName, Ped, s.audioRef, true, 0)
end end
if crafting and progressBar({ if crafting and progressBar({
label = bartext..((metadata and metadata.label) or getItemLabel(data.item)).." x"..craftAmount, label = bartext..((metadata and metadata.label) or getItemLabel(data.item)).." x"..craftAmount,
@@ -408,6 +411,10 @@ function makeItem(data)
request = true, request = true,
}) then }) then
data.craft.amount = craftAmount data.craft.amount = craftAmount
for k, v in pairs(data.craft[data.item]) do
-- multiply igredient requirement in sent crafting table for removal
data.craft[data.item][k] = (v * craftAmount)
end
TriggerServerEvent(getScript()..":Crafting:GetItem", data.item, data.craft, data.stashName, metadata, currentToken) TriggerServerEvent(getScript()..":Crafting:GetItem", data.item, data.craft, data.stashName, metadata, currentToken)
currentToken = nil -- clear client cached token currentToken = nil -- clear client cached token
-- handle metadata and experience in a single go -- handle metadata and experience in a single go
@@ -422,7 +429,7 @@ function makeItem(data)
if data.craftable.Recipes[1].oneUse == true then if data.craftable.Recipes[1].oneUse == true then
removeItem("craftrecipe", 1, nil, data.craftable.Recipes[1].slot) removeItem("craftrecipe", 1, nil, data.craftable.Recipes[1].slot)
local breakId = GetSoundId() local breakId = GetSoundId()
PlaySoundFromEntity(breakId, "Drill_Pin_Break", PlayerPedId(), "DLC_HEIST_FLEECA_SOUNDSET", 1, 0) PlaySoundFromEntity(breakId, "Drill_Pin_Break", Ped, "DLC_HEIST_FLEECA_SOUNDSET", 1, 0)
canReturn = false canReturn = false
end end
if data.sound then if data.sound then
@@ -459,7 +466,7 @@ function makeItem(data)
if data.craftable.Recipes[1].oneUse == true then if data.craftable.Recipes[1].oneUse == true then
removeItem("craftrecipe", 1, nil, data.craftable.Recipes[1].slot) removeItem("craftrecipe", 1, nil, data.craftable.Recipes[1].slot)
local breakId = GetSoundId() local breakId = GetSoundId()
PlaySoundFromEntity(breakId, "Drill_Pin_Break", PlayerPedId(), "DLC_HEIST_FLEECA_SOUNDSET", 1, 0) PlaySoundFromEntity(breakId, "Drill_Pin_Break", Ped, "DLC_HEIST_FLEECA_SOUNDSET", 1, 0)
canReturn = false canReturn = false
end end
if data.requiredItemfunc then if data.requiredItemfunc then
@@ -475,7 +482,7 @@ function makeItem(data)
stopTempCam() stopTempCam()
CraftLock = false CraftLock = false
if canReturn then craftingMenu(data) end if canReturn then craftingMenu(data) end
ClearPedTasks(PlayerPedId()) ClearPedTasks(Ped)
end end

View File

@@ -2390,17 +2390,17 @@ if isServer() then
end end
RegisterNetEvent(getScript()..":openGrabBox", function(data) RegisterNetEvent(getScript()..":openGrabBox", function(data)
local Ped = PlayerPedId()
local id = data.metadata and data.metadata.id or data.info and data.info.id or ""
if isStarted(OXInv) then if isStarted(OXInv) then
return return
end end
local id = ""
if data.metadata then
id = data.metadata.id
elseif data.info then
id = data.info.id
end
openStash({ openStash({
stash = id, stash = id,
coords = GetEntityCoords(Ped)
}) })
end) end)