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