mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-19 06:46:04 +01:00
Support only one progressBar when crafting
This commit is contained in:
@@ -319,6 +319,9 @@ end
|
|||||||
--- metadata = { label = "Custom Pistol", image = "custom_pistol.png" },
|
--- metadata = { label = "Custom Pistol", image = "custom_pistol.png" },
|
||||||
--- })
|
--- })
|
||||||
--- ```
|
--- ```
|
||||||
|
|
||||||
|
Config.Crafting.SingleProgress = true -- Set false to use individual progress bars per craft
|
||||||
|
|
||||||
function makeItem(data)
|
function makeItem(data)
|
||||||
if CraftLock then return end
|
if CraftLock then return end
|
||||||
CraftLock = true
|
CraftLock = true
|
||||||
@@ -338,14 +341,17 @@ function makeItem(data)
|
|||||||
local crafted, crafting = true, true
|
local crafted, crafting = true, true
|
||||||
local cam = createTempCam(PlayerPedId(), data.coords)
|
local cam = createTempCam(PlayerPedId(), data.coords)
|
||||||
startTempCam(cam)
|
startTempCam(cam)
|
||||||
|
|
||||||
|
-- Calculate total bartime if SingleProgress is enabled
|
||||||
|
local totalBartime = bartime * craftAmount
|
||||||
|
|
||||||
|
-- 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
|
||||||
if not excludeKeys[k] then
|
if not excludeKeys[k] and type(v) == "table" then
|
||||||
if type(v) == "table" then
|
|
||||||
for l, b in pairs(v) do
|
for l, b in pairs(v) do
|
||||||
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")
|
||||||
crafted, crafting = false, false
|
|
||||||
stopTempCam()
|
stopTempCam()
|
||||||
ClearPedTasks(PlayerPedId())
|
ClearPedTasks(PlayerPedId())
|
||||||
if canReturn then craftingMenu(data) end
|
if canReturn then craftingMenu(data) end
|
||||||
@@ -368,9 +374,11 @@ function makeItem(data)
|
|||||||
end
|
end
|
||||||
Wait(200)
|
Wait(200)
|
||||||
end
|
end
|
||||||
if isInventoryOpen() then
|
end
|
||||||
print("^1Error^7: ^2Inventory is open, you tried to break things")
|
end
|
||||||
crafted, crafting = false, false
|
end
|
||||||
|
|
||||||
|
if not crafted then
|
||||||
stopTempCam()
|
stopTempCam()
|
||||||
ClearPedTasks(PlayerPedId())
|
ClearPedTasks(PlayerPedId())
|
||||||
if canReturn then craftingMenu(data) end
|
if canReturn then craftingMenu(data) end
|
||||||
@@ -378,7 +386,8 @@ function makeItem(data)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if crafted then
|
-- Handle SingleProgress option
|
||||||
|
if Config.Crafting.SingleProgress then
|
||||||
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 })
|
||||||
@@ -388,15 +397,9 @@ function makeItem(data)
|
|||||||
local s = data.sound
|
local s = data.sound
|
||||||
PlaySoundFromEntity(s.soundId, s.audioName, PlayerPedId(), s.audioRef, true, 0)
|
PlaySoundFromEntity(s.soundId, s.audioName, PlayerPedId(), s.audioRef, true, 0)
|
||||||
end
|
end
|
||||||
if isInventoryOpen() then
|
|
||||||
--print("^1Error^7: ^2Inventory is open, you tried to break things")
|
|
||||||
crafted, crafting = false, false
|
|
||||||
crafted, crafting, CraftLock = false, false, false
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if crafting and progressBar({
|
if crafting and progressBar({
|
||||||
label = bartext..((metadata and metadata.label) or Items[data.item].label),
|
label = bartext..((metadata and metadata.label) or Items[data.item].label).." x"..craftAmount,
|
||||||
time = bartime,
|
time = totalBartime,
|
||||||
cancel = true,
|
cancel = true,
|
||||||
dict = animDict,
|
dict = animDict,
|
||||||
anim = anim,
|
anim = anim,
|
||||||
@@ -404,22 +407,18 @@ function makeItem(data)
|
|||||||
icon = data.item,
|
icon = data.item,
|
||||||
request = true,
|
request = true,
|
||||||
}) then
|
}) then
|
||||||
|
data.craft.amount = craftAmount
|
||||||
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
|
||||||
CreateThread(function()
|
-- handle metadata and experience in a single go
|
||||||
if data.craft["hasCrafted"] ~= nil then
|
if data.craft["hasCrafted"] ~= nil then
|
||||||
debugPrint("^5Bridge^7: ^3hasCrafted ^2Found^7, ^2marking ^7'^4"..data.item.."^7' ^2as crafted for player^7")
|
|
||||||
data.craftable.craftedItems[data.item] = true
|
data.craftable.craftedItems[data.item] = true
|
||||||
triggerCallback(getScript()..":server:SetMetadata", "craftedItems", data.craftable.craftedItems)
|
triggerCallback(getScript()..":server:SetMetadata", "craftedItems", data.craftable.craftedItems)
|
||||||
end
|
end
|
||||||
Wait(100)
|
|
||||||
if data.craft["exp"] ~= nil then
|
if data.craft["exp"] ~= nil then
|
||||||
craftingLevel += data.craft["exp"].give
|
craftingLevel += data.craft["exp"].give * craftAmount
|
||||||
jsonPrint(data.craft["exp"])
|
|
||||||
debugPrint("^6Bridge^7: ^3EXP ^2found^7, ^2giving exp for ^7'^4"..data.item.."^7'")
|
|
||||||
triggerCallback(getScript()..":server:SetMetadata", "craftingLevel", craftingLevel)
|
triggerCallback(getScript()..":server:SetMetadata", "craftingLevel", craftingLevel)
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
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()
|
||||||
@@ -432,23 +431,54 @@ function makeItem(data)
|
|||||||
if data.requiredItemfunc then
|
if data.requiredItemfunc then
|
||||||
data.requiredItemfunc()
|
data.requiredItemfunc()
|
||||||
end
|
end
|
||||||
else
|
|
||||||
crafting = false
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
if craftProp then destroyProp(craftProp) end
|
if craftProp then destroyProp(craftProp) end
|
||||||
|
else
|
||||||
|
-- Run the original loop for multiple progress bars
|
||||||
|
for i = 1, craftAmount do
|
||||||
|
if crafting and progressBar({
|
||||||
|
label = bartext..((metadata and metadata.label) or Items[data.item].label),
|
||||||
|
time = bartime,
|
||||||
|
cancel = true,
|
||||||
|
dict = animDict,
|
||||||
|
anim = anim,
|
||||||
|
flag = 49,
|
||||||
|
icon = data.item,
|
||||||
|
request = true,
|
||||||
|
}) then
|
||||||
|
TriggerServerEvent(getScript()..":Crafting:GetItem", data.item, data.craft, data.stashName, metadata, currentToken)
|
||||||
|
currentToken = nil
|
||||||
|
if data.craft["hasCrafted"] ~= nil then
|
||||||
|
data.craftable.craftedItems[data.item] = true
|
||||||
|
triggerCallback(getScript()..":server:SetMetadata", "craftedItems", data.craftable.craftedItems)
|
||||||
|
end
|
||||||
|
if data.craft["exp"] ~= nil then
|
||||||
|
craftingLevel += data.craft["exp"].give
|
||||||
|
triggerCallback(getScript()..":server:SetMetadata", "craftingLevel", craftingLevel)
|
||||||
|
end
|
||||||
|
if data.craftable.Recipes[1].oneUse == true then
|
||||||
|
removeItem("craftrecipe", 1, nil, data.craftable.Recipes[1].slot)
|
||||||
|
local breakId = GetSoundId()
|
||||||
|
PlaySoundFromEntity(breakId, "Drill_Pin_Break", PlayerPedId(), "DLC_HEIST_FLEECA_SOUNDSET", 1, 0)
|
||||||
|
canReturn = false
|
||||||
|
end
|
||||||
|
if data.requiredItemfunc then
|
||||||
|
data.requiredItemfunc()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
Wait(500)
|
Wait(500)
|
||||||
end
|
|
||||||
stopTempCam()
|
stopTempCam()
|
||||||
CraftLock = false
|
CraftLock = false
|
||||||
if canReturn then craftingMenu(data) end
|
if canReturn then craftingMenu(data) end
|
||||||
ClearPedTasks(PlayerPedId())
|
ClearPedTasks(PlayerPedId())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
-- Server Event Handler: Crafted Item
|
-- Server Event Handler: Crafted Item
|
||||||
-------------------------------------------------------------
|
-------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user