Merge pull request #15 from jimathy/1.0.8

1.0.8 - Fixes crafting issues
This commit is contained in:
Jim Shield
2024-01-24 01:13:39 +00:00
committed by GitHub
4 changed files with 80 additions and 124 deletions

View File

@@ -6,49 +6,45 @@ if IsDuplicityVersion() then
end end
end end
local timeout = 0 local timeout, timing, stashItems = 0, false, {}
local timing = false
local stashItems = {}
function GetStashTimeout(stashName, stop) function GetStashTimeout(stashName, stop)
if stop then stashItems = {} timing = false timeout = 0 return end if stop then stashItems, timing, timeout = {}, false, 0 return end
if stashItems[1] then return true else if #stashItems > 0 then return true end
if timeout <= 0 then if timeout <= 0 then
stashItems = triggerCallback(GetCurrentResourceName()..':server:GetStashItems', stashName) stashItems = triggerCallback(GetCurrentResourceName()..':server:GetStashItems', stashName)
timeout = 15000 timeout = 10000
if not timing then if not timing then
CreateThread(function() CreateThread(function()
timing = true timing = true
while timeout > 0 do timeout -= 1000 Wait(1000) end while timeout > 0 do timeout -= 1000 Wait(1000) end
timing = false stashItems = {} timeout = 0 timing, stashItems, timeout = false, {}, 0
end) end)
end end
end end
return false return false
end
end end
local CraftLock = false local CraftLock = false
function craftingMenu(data) local hasjob = false function craftingMenu(data)
if CraftLock then return end if CraftLock then return end
if data.stashName and not GetStashTimeout(data.stashName) then if data.stashName and not GetStashTimeout(data.stashName) then
--triggerNotify(nil, "Chacking", "success") --triggerNotify(nil, "Chacking", "success")
end end
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
local Menu = {} local Menu, hasjob = {}, false
local Recipes = data.craftable.Recipes local Recipes = data.craftable.Recipes
for i = 1, #Recipes do for i = 1, #Recipes do
for k, v in pairs(Recipes[i]) do if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end
for k, v in pairs(Recipes[i]) do
if k ~= "amount" and k ~= "job" and k ~= "gang" then if k ~= "amount" and k ~= "job" and k ~= "gang" then
if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end if Recipes[i].job then
if Recipes[i].job then hasjob = false
for l, b in pairs(Recipes[i].job) do for l, b in pairs(Recipes[i].job) do
hasjob = hasJob(l, nil, b) hasjob = hasJob(l, nil, b)
if hasjob == true then break end if hasjob == true then break end
end end
end else hasjob = true end
local setheader, settext = "", "" local setheader, settext, disable = "", "", false
local disable = false if hasjob then
if Recipes[i].job and hasjob == false then else
local itemTable = {} local itemTable = {}
for l, b in pairs(Recipes[i][tostring(k)]) do for l, b in pairs(Recipes[i][tostring(k)]) do
settext = settext..(settext ~= "" and br or "")..(Items[l] and Items[l].label or "error - "..l)..(b > 1 and " x"..b or "") settext = settext..(settext ~= "" and br or "")..(Items[l] and Items[l].label or "error - "..l)..(b > 1 and " x"..b or "")
@@ -56,25 +52,20 @@ function craftingMenu(data) local hasjob = false
Wait(0) Wait(0)
end end
if Config.System.Debug then print("^6Bridge^7: ^2Checking"..(data.stashName and " ^7'^6"..data.stashName.."^7'" or "").." ^2ingredients^7 - ^6"..k.."^7") end if Config.System.Debug then print("^6Bridge^7: ^2Checking"..(data.stashName and " ^7'^6"..data.stashName.."^7'" or "").." ^2ingredients^7 - ^6"..k.."^7") end
if data.stashName then disable = not stashhasItem(stashItems, itemTable) if data.stashName ~= nil then disable = stashhasItem(stashItems, itemTable) else disable = hasItem(itemTable) end
else disable = not hasItem(itemTable) end
setheader = Items[tostring(k)].label..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "") setheader = Items[tostring(k)].label..(Recipes[i]["amount"] > 1 and " x"..Recipes[i]["amount"] or "")..(not disable and " ✔️" or "")
Menu[#Menu + 1] = { Menu[#Menu + 1] = {
isMenuHeader = disable, isMenuHeader = not disable,
icon = invImg(tostring(k)), icon = invImg(tostring(k)),
header = setheader, txt = settext, header = setheader, txt = settext,
onSelect = function() onSelect = function()
local transdata = { item = k, craft = data.craftable.Recipes[i], craftable = data.craftable, coords = data.coords, stashName = data.stashName, onBack = data.onBack } local transdata = { item = k, craft = data.craftable.Recipes[i], craftable = data.craftable, coords = data.coords, stashName = data.stashName, onBack = data.onBack }
if Config.Crafting.MultiCraft then if Config.Crafting.MultiCraft then multiCraft(transdata) else makeItem(transdata) end
multiCraft(transdata)
else
makeItem(transdata)
end
end, end,
} }
end end
end end
Wait(0)
end end
end end
openMenu(Menu, { header = data.craftable.Header, onBack = data.onBack or nil, canClose = true, onExit = function() end, }) openMenu(Menu, { header = data.craftable.Header, onBack = data.onBack or nil, canClose = true, onExit = function() end, })
@@ -118,25 +109,18 @@ function multiCraft(data) local Menu = {}
end end
function makeItem(data) function makeItem(data)
if not CraftLock then CraftLock = true else return end if CraftLock then return end
local bartime, bartext, animDict, anim = nil, nil, nil, nil CraftLock = true
if data.craftable.progressBar then
bartime = data.craftable.progressBar.time
bartext = data.craftable.progressBar.label
else
bartime = 5000
bartext = Loc[Config.Lan].progressbar["progress_make"]
end
animDict = data.craftable.Anims.animDict or "amb@prop_human_parking_meter@male@idle_a"
anim = data.craftable.Anims.anim or "idle_a"
local amount = (data.amount and data.amount ~= 1) and data.amount or 1 local bartime = data.craftable.progressBar and data.craftable.progressBar.time or 5000
local bartext = data.craftable.progressBar and data.craftable.progressBar.label or Loc[Config.Lan].progressbar["progress_make"]
local animDict = data.craftable.Anims.animDict or "amb@prop_human_parking_meter@male@idle_a"
local anim = data.craftable.Anims.anim or "idle_a"
local amount = data.amount and (data.amount ~= 1) and data.amount or 1
local crafted = true local crafted, crafting = true, true
local crafting = true local cam = createTempCam(PlayerPedId(), data.coords)
startTempCam(cam)
local cam = createTempCam(PlayerPedId(), data.coords)
startTempCam(cam)
for i = 1, amount do for i = 1, amount do
for k, v in pairs(data.craft) do for k, v in pairs(data.craft) do
@@ -154,9 +138,8 @@ function makeItem(data)
}) then }) then
--TriggerEvent('inventory:client:ItemBox', Items[l], "use", b) -- Show item box for each item --TriggerEvent('inventory:client:ItemBox', Items[l], "use", b) -- Show item box for each item
else else
crafted = false crafted, crafting = false, false
crafting = false break
break
end end
Wait(200) Wait(200)
end end
@@ -189,29 +172,25 @@ function makeItem(data)
end end
RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMake, craftable, stashName) RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMake, craftable, stashName)
local src = source local src, amount, stashItems = source, craftable and craftable.amount or 1, stashName and getStash(stashName)
local amount = 1
if stashName then if stashName then
local stashItems = getStash(stashName)
if craftable["amount"] then amount = craftable["amount"] end
local itemRemove = {} local itemRemove = {}
for k, v in pairs(craftable[ItemMake]) do for k, v in pairs(craftable[ItemMake] or {}) do
for l, b in pairs(stashItems) do for _, b in pairs(stashItems or {}) do
if k == b.name then if k == b.name then itemRemove[k] = v end
itemRemove[k] = v
end
end end
end end
stashRemoveItem(stashItems, stashName, itemRemove) stashRemoveItem(stashItems, stashName, itemRemove)
else else
if craftable then if craftable then
if craftable["amount"] then amount = craftable["amount"] end for k, v in pairs(craftable[ItemMake] or {}) do
for k, v in pairs(craftable[ItemMake]) do
TriggerEvent(GetCurrentResourceName()..":server:toggleItem", false, tostring(k), v, src) TriggerEvent(GetCurrentResourceName()..":server:toggleItem", false, tostring(k), v, src)
end end
end end
end end
TriggerEvent(GetCurrentResourceName()..":server:toggleItem", true, ItemMake, amount, src) TriggerEvent(GetCurrentResourceName()..":server:toggleItem", true, ItemMake, amount, src)
if GetResourceState("core_skills"):find("start") then exports["core_skills"]:AddExperience(src, 2) end
end) end)
--[[SHOPS]]-- --[[SHOPS]]--
@@ -232,23 +211,15 @@ function hasItem(items, amount, src) local amount = amount and amount or 1
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
if GetResourceState(OXInv):find("start") then if GetResourceState(OXInv):find("start") then
foundInv = OXInv foundInv = OXInv
if src then grabInv = exports.ox_inventory:GetInventoryItems(src) grabInv = src and exports.ox_inventory:GetInventoryItems(src) or exports[OXInv]:GetPlayerItems()
else grabInv = exports[OXInv]:GetPlayerItems()
end
elseif GetResourceState(QSInv):find("start") then elseif GetResourceState(QSInv):find("start") then
foundInv = QSInv foundInv = QSInv
if src then grabInv = exports[QSInv]:GetInventory(src) grabInv = src and exports[QSInv]:GetInventory(src) or exports[QSInv]:getUserInventory()
else grabInv = exports[QSInv]:getUserInventory()
end
elseif GetResourceState(OrigenInv):find("start") then elseif GetResourceState(OrigenInv):find("start") then
foundInv = OrigenInv foundInv = OrigenInv
if src then grabInv = src and exports[OrigenInv]:getPlayerInventory(src) or exports[OrigenInv]:getPlayerInventory()
grabInv = exports[OrigenInv]:getPlayerInventory(src)
else
grabInv = exports[OrigenInv]:getPlayerInventory()
end
elseif GetResourceState(CoreInv):find("start") then elseif GetResourceState(CoreInv):find("start") then
foundInv = CoreInv foundInv = CoreInv
@@ -269,15 +240,11 @@ function hasItem(items, amount, src) local amount = amount and amount or 1
elseif GetResourceState(CodeMInv):find("start") then elseif GetResourceState(CodeMInv):find("start") then
foundInv = CodeMInv foundInv = CodeMInv
if src then grabInv = exports[CodeMInv]:GetUserInventory(src) grabInv = src and exports[CodeMInv]:GetUserInventory(src) or exports[CodeMInv]:GetClientPlayerInventory()
else grabInv = exports[CodeMInv]:GetClientPlayerInventory()
end
elseif GetResourceState(QBInv):find("start") then elseif GetResourceState(QBInv):find("start") then
foundInv = QBInv foundInv = QBInv
if src then grabInv = Core.Functions.GetPlayer(src).PlayerData.items grabInv = src and Core.Functions.GetPlayer(src).PlayerData.items or Core.Functions.GetPlayerData().items
else grabInv = Core.Functions.GetPlayerData().items
end
else else
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7")
@@ -289,20 +256,14 @@ function hasItem(items, amount, src) local amount = amount and amount or 1
if not Items[item] then print("^4ERROR^7: ^2Script can't find ingredient item in Shared Items - ^1"..item.."^7") end if not Items[item] then print("^4ERROR^7: ^2Script can't find ingredient item in Shared Items - ^1"..item.."^7") end
local count = 0 local count = 0
for _, itemData in pairs(grabInv) do for _, itemData in pairs(grabInv) do
if itemData and (itemData.name == item) then if itemData and (itemData.name == item) then count += (itemData.count or itemData.amount or 1) end
--if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7: ^2Item^7: '^3"..tostring(item).."^7' ^2Slot^7: ^3"..itemData.slot.." ^7x(^3"..tostring(itemData.count or itemData.amount).."^7)", foundInv) end
count += ((itemData.count or itemData.amount) or 1)
end
end
if count >= amount then
if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amount.." ^5FOUND^7") end
hasTable[item] = { hasItem = true, count = count, }
else
if Config.System.Debug then print("^6Bridge^7: ^3HasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^1"..count.."^7/^3"..amount.." ^1NOT FOUND^7") end
hasTable[item] = { hasItem = false, count = count, }
end end
local foundMessage = "^6Bridge^7: ^3HasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amount
if count >= amount then foundMessage = foundMessage.." ^5FOUND^7" else foundMessage = foundMessage .." ^1NOT FOUND^7" end
if Config.System.Debug then print(foundMessage) end
hasTable[item] = { hasItem = count >= amount, count = count }
end end
for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end for k, v in pairs(hasTable) do if not v.hasItem then return false, hasTable end end
return true, hasTable return true, hasTable
end end
end end
@@ -321,49 +282,44 @@ function openStash(data)
lookEnt(data.coords) lookEnt(data.coords)
end end
function getStash(stashName) function getStash(stashName) local stashResource = ""
local stashItems, items = {}, {} local stashItems, items = {}, {}
if GetResourceState(OXInv):find("start") then if GetResourceState(OXInv):find("start") then stashResource = OXInv
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..OXInv) end
stashItems = exports[OXInv]:Inventory(stashName).items stashItems = exports[OXInv]:Inventory(stashName).items
elseif GetResourceState(QSInv):find("start") then elseif GetResourceState(QSInv):find("start") then stashResource = QSInv
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QSInv) end
stashItems = exports[QSInv]:GetStashItems(stashName) stashItems = exports[QSInv]:GetStashItems(stashName)
elseif GetResourceState(CoreInv):find("start") then elseif GetResourceState(CoreInv):find("start") then stashResource = CoreInv
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CoreInv) end
stashItems = exports[CoreInv]:getInventory(stashName) stashItems = exports[CoreInv]:getInventory(stashName)
elseif GetResourceState(CodeMInv):find("start") then elseif GetResourceState(CodeMInv):find("start") then stashResource = CodeMInv
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..CodeMInv) end
stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName) stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName)
elseif GetResourceState(OrigenInv):find("start") then elseif GetResourceState(OrigenInv):find("start") then stashResource = OrigenInv
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..OrigenInv) end
stashItems = exports[OrigenInv]:GetStash(stashName) stashItems = exports[OrigenInv]:GetStash(stashName)
elseif GetResourceState(QBInv):find("start") then elseif GetResourceState(QBInv):find("start") then stashResource = QBInv
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..QBInv) end
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName }) local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
if result then stashItems = json.decode(result) end if result then stashItems = json.decode(result) end
end end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..stashResource) end
if stashItems then if stashItems then
for _, item in pairs(stashItems) do for _, item in pairs(stashItems) do
local itemInfo = Items[item.name:lower()] local itemInfo = Items[item.name:lower()]
if itemInfo then if itemInfo then
items[#items+1] = { items[#items+1] = {
name = itemInfo["name"] ~= nil and itemInfo["slot"] or nil, name = itemInfo.name or nil,
amount = tonumber(item.amount) or tonumber(item.count), amount = tonumber(item.amount) or tonumber(item.count),
info = item.info ~= nil and item.info or "", info = item.info or "",
label = itemInfo["label"] ~= nil and itemInfo["slot"] or nil, label = itemInfo.label or nil,
description = itemInfo["description"] ~= nil and itemInfo["description"] or "", description = itemInfo.description or "",
weight = itemInfo["weight"] ~= nil and itemInfo["slot"] or nil, weight = itemInfo.weight or nil,
type = itemInfo["type"] ~= nil and itemInfo["slot"] or nil, type = itemInfo.type or nil,
unique = itemInfo["unique"] ~= nil and itemInfo["slot"] or nil, unique = itemInfo.unique or nil,
useable = itemInfo["useable"] ~= nil and itemInfo["slot"] or nil, useable = itemInfo.useable or nil,
image = itemInfo["image"] ~= nil and itemInfo["slot"] or nil, image = itemInfo.image or nil,
slot = itemInfo["slot"] ~= nil and itemInfo["slot"] or nil, slot = itemInfo.slot or nil,
} }
end end
end end

View File

@@ -1,6 +1,6 @@
name "Jim_Bridge" name "Jim_Bridge"
author "Jimathy" author "Jimathy"
version "1.0.7" version "1.0.8"
description "Framework Bridge By Jimathy" description "Framework Bridge By Jimathy"
fx_version "cerulean" fx_version "cerulean"
game "gta5" game "gta5"

View File

@@ -1 +1 @@
1.0.7 1.0.8

View File

@@ -1,6 +1,6 @@
Items, Vehicles, Jobs, Gangs, Core, ESX = {}, nil, nil, nil, nil, nil Items, Vehicles, Jobs, Gangs, Core, ESX = {}, nil, nil, nil, nil, nil
Exports.QBInv = GetResourceState("ps-inventory"):find("start") and "ps-inventory" or GetResourceState("lj-inventory"):find("start") and "lj-inventory" or "" Exports.QBInv = GetResourceState("ps-inventory"):find("start") and "ps-inventory" or GetResourceState("lj-inventory"):find("start") and "lj-inventory" or Exports.QBInv
OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport = Exports.OXLibExport or "", Exports.QBXExport or "", Exports.QBExport or "", Exports.ESXExport or "", Exports.OXCoreExport or "" OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport = Exports.OXLibExport or "", Exports.QBXExport or "", Exports.QBExport or "", Exports.ESXExport or "", Exports.OXCoreExport or ""