mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-19 06:46:04 +01:00
general fixes and updates
This commit is contained in:
@@ -48,7 +48,7 @@ if not isServer() then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if isAnimal then
|
if isAnimal then
|
||||||
debugPrint("^6Debug^7: ^2Ped is Animal^1")
|
debugPrint("^6Bridge^7: ^2Ped is Animal^1")
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ end
|
|||||||
--- addItem("health_potion", 2, { quality = "high" })
|
--- addItem("health_potion", 2, { quality = "high" })
|
||||||
--- ```
|
--- ```
|
||||||
function addItem(item, amount, info, src)
|
function addItem(item, amount, info, src)
|
||||||
if not Items[item] then print("^6Debug^7: ^1Error^7 - ^2Tried to give ^7'^3"..item.."^7'^2 but it doesn't exist") return end
|
if not Items[item] then print("^6Bridge^7: ^1Error^7 - ^2Tried to give ^7'^3"..item.."^7'^2 but it doesn't exist") return end
|
||||||
if src then
|
if src then
|
||||||
TriggerEvent(getScript()..":server:toggleItem", true, item, amount, src, info)
|
TriggerEvent(getScript()..":server:toggleItem", true, item, amount, src, info)
|
||||||
else
|
else
|
||||||
@@ -96,7 +96,7 @@ end
|
|||||||
--- removeItem("health_potion", 1)
|
--- removeItem("health_potion", 1)
|
||||||
--- ```
|
--- ```
|
||||||
function removeItem(item, amount, src, slot)
|
function removeItem(item, amount, src, slot)
|
||||||
if not Items[item] then print("^6Debug^7: ^1Error^7 - ^2Tried to remove ^7'^3"..item.."^7'^2 but it doesn't exist") return end
|
if not Items[item] then print("^6Bridge^7: ^1Error^7 - ^2Tried to remove ^7'^3"..item.."^7'^2 but it doesn't exist") return end
|
||||||
if src then
|
if src then
|
||||||
TriggerEvent(getScript()..":server:toggleItem", false, item, amount, src, nil, slot)
|
TriggerEvent(getScript()..":server:toggleItem", false, item, amount, src, nil, slot)
|
||||||
else
|
else
|
||||||
@@ -120,7 +120,7 @@ end
|
|||||||
--- TriggerServerEvent("script:server:toggleItem", true, "health_potion", 1)
|
--- TriggerServerEvent("script:server:toggleItem", true, "health_potion", 1)
|
||||||
--- ```
|
--- ```
|
||||||
RegisterNetEvent(getScript()..":server:toggleItem", function(give, item, amount, newsrc, info, slot)
|
RegisterNetEvent(getScript()..":server:toggleItem", function(give, item, amount, newsrc, info, slot)
|
||||||
if not Items[item] then print("^6Debug^7: ^1Error^7 - ^2Tried to "..(tostring(give) == "true" and "add" or "remove").." ^7'^3"..item.."^7'^2 but it doesn't exist") return end
|
if not Items[item] then print("^6Bridge^7: ^1Error^7 - ^2Tried to "..(tostring(give) == "true" and "add" or "remove").." ^7'^3"..item.."^7'^2 but it doesn't exist") return end
|
||||||
local src = newsrc or source
|
local src = newsrc or source
|
||||||
local addremove = (tostring(give) == "true" and "addItem" or "removeItem")
|
local addremove = (tostring(give) == "true" and "addItem" or "removeItem")
|
||||||
debugPrint("^6Bridge^7: ^3toggleItem ^2triggered^7: ^6"..addremove.."^7 - '"..tostring(item).."' x"..(tostring(amount) or "1"))
|
debugPrint("^6Bridge^7: ^3toggleItem ^2triggered^7: ^6"..addremove.."^7 - '"..tostring(item).."' x"..(tostring(amount) or "1"))
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
|
|
||||||
function GetPlayer(source)
|
function GetPlayer(source)
|
||||||
if isStarted(QBExport) then
|
if isStarted(QBExport) then
|
||||||
debugPrint("^6Debug^7: ^3GetPlayer^7() QBExport")
|
debugPrint("^6Bridge^7: ^3GetPlayer^7() QBExport")
|
||||||
return exports[QBExport]:GetCoreObject().Functions.GetPlayer(source)
|
return exports[QBExport]:GetCoreObject().Functions.GetPlayer(source)
|
||||||
elseif isStarted(QBXExport) then
|
elseif isStarted(QBXExport) then
|
||||||
debugPrint("^6Debug^7: ^3GetPlayer^7() QBOXExport")
|
debugPrint("^6Bridge^7: ^3GetPlayer^7() QBOXExport")
|
||||||
return exports[QBXExport]:GetCoreObject().Functions.GetPlayer(source)
|
return exports[QBXExport]:GetCoreObject().Functions.GetPlayer(source)
|
||||||
elseif isStarted(ESXExport) then
|
elseif isStarted(ESXExport) then
|
||||||
debugPrint("^6Debug^7: ^3GetPlayer^7() ESXExport")
|
debugPrint("^6Bridge^7: ^3GetPlayer^7() ESXExport")
|
||||||
return exports[ESXExport]:GetPlayerFromId(source)
|
return exports[ESXExport]:GetPlayerFromId(source)
|
||||||
elseif isStarted(OXCoreExport) then
|
elseif isStarted(OXCoreExport) then
|
||||||
debugPrint("^6Debug^7: ^3GetPlayer^7() OXCoreExport")
|
debugPrint("^6Bridge^7: ^3GetPlayer^7() OXCoreExport")
|
||||||
return exports[OXCoreExport]:GetPlayer(source)
|
return exports[OXCoreExport]:GetPlayer(source)
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@@ -19,17 +19,17 @@ end
|
|||||||
-- Get Metadata
|
-- Get Metadata
|
||||||
function GetMetadata(player, key)
|
function GetMetadata(player, key)
|
||||||
if not player then -- This would be called client side
|
if not player then -- This would be called client side
|
||||||
debugPrint("^6Debug^7: ^3GetMetadata^7() calling server")
|
debugPrint("^6Bridge^7: ^3GetMetadata^7() calling server: "..key)
|
||||||
return triggerCallback(getScript()..":server:GetMetadata", key)
|
return triggerCallback(getScript()..":server:GetMetadata", key)
|
||||||
else
|
else
|
||||||
if isStarted(QBExport) or isStarted(QBXExport) then
|
if isStarted(QBExport) or isStarted(QBXExport) then
|
||||||
debugPrint("^6Debug^7: ^3GetMetadata^7() QBExport or QBXExport")
|
debugPrint("^6Bridge^7: ^3GetMetadata^7() QBExport or QBXExport", key)
|
||||||
return player.PlayerData.metadata[key]
|
return player.PlayerData.metadata[key]
|
||||||
elseif isStarted(ESXExport) then
|
elseif isStarted(ESXExport) then
|
||||||
debugPrint("^6Debug^7: ^3GetMetadata^7() ESXExport")
|
debugPrint("^6Bridge^7: ^3GetMetadata^7() ESXExport", key)
|
||||||
return player.getMeta(key)
|
return player.getMeta(key)
|
||||||
elseif isStarted(OXCoreExport) then
|
elseif isStarted(OXCoreExport) then
|
||||||
debugPrint("^6Debug^7: ^3GetMetadata^7() OXCoreExport")
|
debugPrint("^6Bridge^7: ^3GetMetadata^7() OXCoreExport", key)
|
||||||
return player.get(key)
|
return player.get(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -37,7 +37,7 @@ function GetMetadata(player, key)
|
|||||||
end
|
end
|
||||||
|
|
||||||
createCallback(getScript()..":server:GetMetadata", function(source, key)
|
createCallback(getScript()..":server:GetMetadata", function(source, key)
|
||||||
debugPrint("^6Debug^7: ^3GetMetadata^7() Callback", source)
|
debugPrint("^6Bridge^7: ^3GetMetadata^7() Callback", source, key)
|
||||||
local player = GetPlayer(source)
|
local player = GetPlayer(source)
|
||||||
local Metadata = {}
|
local Metadata = {}
|
||||||
if not player then
|
if not player then
|
||||||
@@ -51,6 +51,7 @@ createCallback(getScript()..":server:GetMetadata", function(source, key)
|
|||||||
elseif type(key) == "string" then
|
elseif type(key) == "string" then
|
||||||
return GetMetadata(player, key)
|
return GetMetadata(player, key)
|
||||||
end
|
end
|
||||||
|
|
||||||
jsonPrint(Metadata)
|
jsonPrint(Metadata)
|
||||||
return Metadata
|
return Metadata
|
||||||
end)
|
end)
|
||||||
@@ -58,18 +59,18 @@ end)
|
|||||||
-- Set Metadata
|
-- Set Metadata
|
||||||
function SetMetadata(player, key, value)
|
function SetMetadata(player, key, value)
|
||||||
--if player == nil then -- This would be called client side
|
--if player == nil then -- This would be called client side
|
||||||
-- debugPrint("^6Debug^7: ^3SetMetadata^7() calling server")
|
-- debugPrint("^6Bridge^7: ^3SetMetadata^7() calling server")
|
||||||
-- triggerCallback(getScript()..":server:SetMetadata", { key, value })
|
-- triggerCallback(getScript()..":server:SetMetadata", { key, value })
|
||||||
-- else
|
-- else
|
||||||
debugPrint("^6Debug^7: ^3SetMetadata^7() setting metadata")
|
debugPrint("^6Bridge^7: ^3SetMetadata^7() setting metadata")
|
||||||
if isStarted(QBExport) or isStarted(QBXExport) then
|
if isStarted(QBExport) or isStarted(QBXExport) then
|
||||||
debugPrint("^6Debug^7: ^3SetMetadata^7() QBExport or QBXExport")
|
debugPrint("^6Bridge^7: ^3SetMetadata^7() QBExport or QBXExport")
|
||||||
player.Functions.SetMetaData(key, value)
|
player.Functions.SetMetaData(key, value)
|
||||||
elseif isStarted(ESXExport) then
|
elseif isStarted(ESXExport) then
|
||||||
debugPrint("^6Debug^7: ^3SetMetadata^7() ESXExport")
|
debugPrint("^6Bridge^7: ^3SetMetadata^7() ESXExport")
|
||||||
player.setMeta(key, value)
|
player.setMeta(key, value)
|
||||||
elseif isStarted(OXCoreExport) then
|
elseif isStarted(OXCoreExport) then
|
||||||
debugPrint("^6Debug^7: ^3SetMetadata^7() OXCoreExport")
|
debugPrint("^6Bridge^7: ^3SetMetadata^7() OXCoreExport")
|
||||||
player.set(key, value)
|
player.set(key, value)
|
||||||
end
|
end
|
||||||
--end
|
--end
|
||||||
|
|||||||
@@ -1,41 +1,62 @@
|
|||||||
|
local stash
|
||||||
if isServer() then
|
if isServer() then
|
||||||
createCallback(getScript()..':server:GetStashItems', function(source, stashName) local stash = getStash(stashName) return stash end)
|
createCallback(getScript()..':server:GetStashItems',
|
||||||
|
function(source, stashName)
|
||||||
|
stash = getStash(stashName) return stash
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local stashCache ={}
|
local stashCache ={}
|
||||||
function GetStashTimeout(stashName, stop)
|
function GetStashTimeout(stashName, stop)
|
||||||
if stop then stashCache = {} return end
|
if stop then
|
||||||
local stash = stashCache[stashName]
|
stashCache = {}
|
||||||
|
return
|
||||||
|
end
|
||||||
|
stash = stashCache[stashName]
|
||||||
if not stash then
|
if not stash then
|
||||||
|
debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache ^1not ^2found^7, ^2need to grab from server^7")
|
||||||
stashCache[stashName] = { items = {}, timeout = 0 }
|
stashCache[stashName] = { items = {}, timeout = 0 }
|
||||||
stash = stashCache[stashName]
|
stash = stashCache[stashName]
|
||||||
|
else
|
||||||
|
debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache found^7")
|
||||||
end
|
end
|
||||||
if #stash.items > 0 then return true end
|
if countTable(stashCache[stashName].items) > 0 then
|
||||||
if stash.timeout <= 0 then
|
debugPrint("^6Bridge^7: '^3"..stashName.." ^2Items found in cache, skipping recheck")
|
||||||
stash.items = triggerCallback(getScript()..':server:GetStashItems', stashName)
|
return true
|
||||||
stash.timeout = 10000
|
end
|
||||||
|
if stashCache[stashName].timeout <= 0 then
|
||||||
|
stashCache[stashName].items = triggerCallback(getScript()..':server:GetStashItems', stashName)
|
||||||
|
stashCache[stashName].timeout = 15000
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while stash.timeout > 0 do stash.timeout -= 1000 Wait(1000) end
|
while stash.timeout > 0 do
|
||||||
|
stashCache[stashName].timeout -= 1000
|
||||||
|
Wait(1000)
|
||||||
|
end
|
||||||
|
debugPrint("^6Bridge^7: ^2Local Stash ^7'^3"..stashName.."^7'^2 cache timed out^7, ^3Clearing^7")
|
||||||
stashCache[stashName] = nil
|
stashCache[stashName] = nil
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function checkHasItem(stashes, itemTable)
|
function checkHasItem(stashes, itemTable)
|
||||||
if not stashes then return hasItem(itemTable), nil end
|
if not stashes then
|
||||||
|
return hasItem(itemTable), nil
|
||||||
|
end
|
||||||
if type(stashes) == "table" then
|
if type(stashes) == "table" then
|
||||||
local succeses = 0
|
local succeses = 0
|
||||||
local itemCount = 0
|
local itemCount = countTable(itemTable)
|
||||||
for _, item in pairs(itemTable) do itemCount += 1 end
|
--for _, item in pairs(itemTable) do itemCount += 1 end
|
||||||
for _, name in pairs(stashes) do
|
for _, name in pairs(stashes) do
|
||||||
|
Wait(10) -- add delay because qb doesn't appreciate multiple callbacks for stashes
|
||||||
GetStashTimeout(name)
|
GetStashTimeout(name)
|
||||||
for item, amount in pairs(itemTable) do
|
for item, amount in pairs(itemTable) do
|
||||||
debugPrint("^6Bridge^7: ^2Checking"..(name and " ^7'^6"..name.."^7'" or "").." ^2ingredients^7 - ^6"..item.."^7")
|
debugPrint("^6Bridge^7: ^2Checking"..(name and " ^7'^6"..name.."^7'" or "").." ^2ingredients^7 - ^6"..item.."^7")
|
||||||
if stashhasItem(stashCache[name].items, item, amount) then
|
if stashhasItem(stashCache[name].items, item, amount) then
|
||||||
succeses += 1
|
succeses += 1
|
||||||
if succeses == itemCount then return true, name end
|
if succeses == itemCount then
|
||||||
|
return true, name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -44,7 +65,6 @@ function checkHasItem(stashes, itemTable)
|
|||||||
GetStashTimeout(stashes)
|
GetStashTimeout(stashes)
|
||||||
return stashhasItem(stashCache[stashes].items, itemTable), stashes
|
return stashhasItem(stashCache[stashes].items, itemTable), stashes
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, nil
|
return false, nil
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -75,7 +95,9 @@ RegisterNetEvent(getScript()..':server:OpenStashQB', function(data)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
function getStash(stashName) local stashResource = ""
|
function getStash(stashName) local stashResource = ""
|
||||||
if type(stashName) ~= "string" then return print("Stash name was not a string %s(%s)", stashName, type(stashName)) end
|
if type(stashName) ~= "string" then
|
||||||
|
return print("Stash name was not a string %s(%s)", stashName, type(stashName))
|
||||||
|
end
|
||||||
local stashItems, items = {}, {}
|
local stashItems, items = {}, {}
|
||||||
if isStarted(OXInv) then stashResource = OXInv
|
if isStarted(OXInv) then stashResource = OXInv
|
||||||
stashItems = exports[OXInv]:Inventory(stashName).items
|
stashItems = exports[OXInv]:Inventory(stashName).items
|
||||||
@@ -124,6 +146,7 @@ function getStash(stashName) local stashResource = ""
|
|||||||
end
|
end
|
||||||
debugPrint("^6Bridge^7: ^3GetStashItems^7: ^2Stash information for ^7'^6"..stashName.."^7' ^2retrieved^7")
|
debugPrint("^6Bridge^7: ^3GetStashItems^7: ^2Stash information for ^7'^6"..stashName.."^7' ^2retrieved^7")
|
||||||
end
|
end
|
||||||
|
jsonPrint(items)
|
||||||
return items
|
return items
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -230,7 +230,6 @@ function registerShop(name, label, items, society)
|
|||||||
)
|
)
|
||||||
elseif isStarted(QBInv) and QBInvNew then
|
elseif isStarted(QBInv) and QBInvNew then
|
||||||
debugPrint("^6Bridge^7: ^2Registering ^3QB ^2Store^7:", name, label)
|
debugPrint("^6Bridge^7: ^2Registering ^3QB ^2Store^7:", name, label)
|
||||||
print(json.encode(items, {indent = true}))
|
|
||||||
exports[QBInv]:CreateShop({
|
exports[QBInv]:CreateShop({
|
||||||
name = name,
|
name = name,
|
||||||
label = label,
|
label = label,
|
||||||
|
|||||||
Reference in New Issue
Block a user