Compare commits

..

54 Commits

Author SHA1 Message Date
Jim Shield
23c2e1472e Merge pull request #19 from jimathy/1.0.11
1.0.11
2024-01-30 19:21:33 +00:00
Jim Shield
6367c9ed3b remove loadmodel debug timeout print 2024-01-30 18:47:23 +00:00
Jim Shield
2d299a6a4a chargePlayer & fundPlayer server events/fixes 2024-01-30 18:40:26 +00:00
Jim Shield
ced629d4dc dupewarn info addition 2024-01-30 18:39:51 +00:00
Jim Shield
714121d272 crafting menu workarounds for missing info 2024-01-30 18:38:57 +00:00
Jim Shield
14c140cf85 load model and prop fixes 2024-01-29 22:23:23 +00:00
Jim Shield
881aec7c04 remove ox_lib model check as it was erroring out 2024-01-29 13:27:00 +00:00
Jim Shield
85b31e7e1d getRandomReward added for reward item support 2024-01-29 13:23:02 +00:00
Jim Shield
66c9287202 v1.0.11 - Version Bump 2024-01-28 19:24:19 +00:00
Jim Shield
f0f59b8568 remove debug print 2024-01-28 19:19:58 +00:00
Jim Shield
e03efa6687 update stopAnim to choose ped 2024-01-28 19:19:24 +00:00
Jim Shield
5a22651961 fix ConsumeSuccess and other typos 2024-01-28 19:18:55 +00:00
Jim Shield
236689452e custom stash slot sizes at "register" 2024-01-28 19:17:57 +00:00
Jim Shield
b686f267e1 Remove debug print 2024-01-28 01:44:53 +00:00
Jim Shield
096e323409 Merge pull request #18 from jimathy/1.0.10
1.0.10
2024-01-27 14:27:44 +00:00
Jim Shield
b71ec14615 sendPhoneMail - mutli phone support 2024-01-27 12:55:56 +00:00
Jim Shield
5a2304b785 quick linting 2024-01-26 20:31:46 +00:00
Jim Shield
6f413c555d add basic canCarry function 2024-01-26 20:31:10 +00:00
Jim Shield
fbc92aea41 update common functions to be smurter 2024-01-26 19:02:02 +00:00
Jim Shield
7b31343991 Merge pull request #17 from jimathy/1.0.9
1.0.9
2024-01-25 18:42:19 +00:00
Jim Shield
872cb39715 Fix crafting from pockets and add debugs 2024-01-25 18:40:42 +00:00
Jim Shield
dd35674307 i hate github 2024-01-25 18:31:34 +00:00
Jim Shield
1d102e94b4 Fix loading of ESX Core shared info 2024-01-25 18:31:00 +00:00
Jim Shield
c18932443a Testing fixing stashes 2024-01-25 17:32:40 +00:00
Jim Shield
7563b4abdf Merge pull request #16 from SirOMGitsYOU/patch-1
Fix Typo
2024-01-25 10:56:55 +00:00
Peter
20509e5cc2 Fix Typo
Update wrapper.lua - Fixed a typo on line 141 prevents this update from loading.
2024-01-24 23:33:39 +00:00
Jim Shield
43e30e95bc Tidy up and make ESX timeout longer 2024-01-24 17:10:44 +00:00
Jim Shield
9efff1060b Merge pull request #15 from jimathy/1.0.8
1.0.8 - Fixes crafting issues
2024-01-24 01:13:39 +00:00
Jim Shield
3b608e2b4f Update wrapper.lua 2024-01-24 01:13:30 +00:00
Jim Shield
bfed10c019 more fixes and optmization 2024-01-23 22:39:46 +00:00
Jim Shield
4bb29b8f14 cheeky little core_skills addition 2024-01-23 22:05:07 +00:00
Jim Shield
6eca0dd1d1 Cut down code and optimize crafting functions 2024-01-23 22:04:30 +00:00
Jim Shield
cc96bcde34 Fix stashCrafting not finding items 2024-01-23 22:03:27 +00:00
Jim Shield
ab61e40567 Merge pull request #14 from jimathy/1.0.7
1.0.7
2024-01-23 19:02:13 +00:00
Jim Shield
e17e2fb865 bit'o linting 2024-01-23 19:01:03 +00:00
Jim Shield
a6bd82a41c Fixes for ox showMenu support 2024-01-23 19:00:39 +00:00
Jim Shield
fac495c0ef Change how core information is grabbed 2024-01-23 19:00:04 +00:00
Jim Shield
15bea85bfb Version Bump v1.0.7 2024-01-23 18:59:02 +00:00
Jim Shield
f889080bc0 Merge pull request #13 from jimathy/1.0.6
1.0.6
2024-01-23 00:37:55 +00:00
Jim Shield
7d62358558 ox input default "select" 2024-01-23 00:37:18 +00:00
Jim Shield
f7a7e89c56 lib.showMenu support 2024-01-23 00:36:04 +00:00
Jim Shield
5f6720d37b Merge pull request #12 from solareon/patch-1
fix: job crafting restrictions
2024-01-23 00:34:15 +00:00
solareon
e541201a08 fix: skip amount and job tables 2024-01-22 22:39:16 +00:00
Solareon
2bf04f69cf fix: hasjob
Fixes broken crafting because the wrapper function is called hasJob with a capital J while the variable is called hasjob
2024-01-22 12:50:03 -07:00
Jim Shield
8479aea1b0 Origen inv experimental support 2024-01-22 17:14:56 +00:00
Jim Shield
d17a1da5b2 CoreInv Fully Supported 2024-01-22 16:55:58 +00:00
Jim Shield
f1ff06c098 CoreInv hasItem events updated 2024-01-22 15:31:04 +00:00
Jim Shield
df785043e8 CoreInv add/remove Item fixes 2024-01-22 14:51:51 +00:00
Jim Shield
5ae4799a5f add auto check for ps/lj-inv 2024-01-22 14:41:38 +00:00
Jim Shield
8cf4a6bd23 Version Bump - 1.0.6 2024-01-22 14:35:52 +00:00
Jim Shield
3e067c8492 Merge pull request #9 from jimathy/1.0.5
1.0.5
2024-01-21 22:28:03 +00:00
Jim Shield
6847639c65 Fix version checking system being dumb 2024-01-21 17:24:32 +00:00
Jim Shield
0592c3ebc8 Fix stashRemoveItem for QS-Inv 2024-01-21 17:24:10 +00:00
Jim Shield
2ca1cbd110 fxmanifest.lua - Version Bump v1.0.5 2024-01-21 17:20:15 +00:00
6 changed files with 597 additions and 307 deletions

View File

@@ -6,75 +6,82 @@ if IsDuplicityVersion() then
end
end
local timeout = 0
local timing = false
local stashItems = {}
local timeout, timing, stashItems = 0, false, {}
function GetStashTimeout(stashName, stop)
if stop then stashItems = {} timing = false timeout = 0 return end
if stashItems[1] then return true else
if timeout <= 0 then
stashItems = triggerCallback(GetCurrentResourceName()..':server:GetStashItems', stashName)
timeout = 15000
if not timing then
CreateThread(function()
timing = true
while timeout > 0 do timeout -= 1000 Wait(1000) end
timing = false stashItems = {} timeout = 0
end)
end
end
return false
end
if stop then stashItems, timing, timeout = {}, false, 0 return end
if #stashItems > 0 then return true end
if timeout <= 0 then
stashItems = triggerCallback(GetCurrentResourceName()..':server:GetStashItems', stashName)
timeout = 10000
if not timing then
CreateThread(function()
timing = true
while timeout > 0 do timeout -= 1000 Wait(1000) end
timing, stashItems, timeout = false, {}, 0
end)
end
end
return false
end
local CraftLock = false
function craftingMenu(data) local hasjob = false
function craftingMenu(data)
if CraftLock then return end
if data.stashName and not GetStashTimeout(data.stashName) then
--triggerNotify(nil, "Chacking", "success")
end
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
local Menu = {}
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
local Menu, hasjob = {}, false
local Recipes = data.craftable.Recipes
local tempCarryTable = {}
for i = 1, #Recipes do
for k, v in pairs(Recipes[i]) do
for k in pairs(Recipes[i]) do
if k ~= "amount" and k ~= "job" and k ~= "gang" then
tempCarryTable[k] = Recipes[i].amount or 1
end
end
end
local canCarryTable = triggerCallback(GetCurrentResourceName()..':server:canCarry', tempCarryTable)
for i = 1, #Recipes 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 not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end
if Recipes[i].job then hasjob = false
if Recipes[i].job then
for l, b in pairs(Recipes[i].job) do
hasjob = hasJob(l, nil, b)
if hasJob == true then break end
if hasjob == true then break end
end
end
local setheader, settext = "", ""
local disable = false
if Recipes[i].job and hasjob == false then else
else hasjob = true end
local setheader, settext, disable = "", "", false
if hasjob then
local itemTable = {}
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 "")
itemTable[l] = b
Wait(0)
end
while not canCarryTable do Wait(0) 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)
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)] and Items[tostring(k)].label or "error - " .. tostring(k)) .. (Recipes[i]["amount"] > 1 and " x" .. Recipes[i]["amount"] or "")
if not disable then
if not canCarryTable[k] then setheader = setheader .. " 📦"
else setheader = setheader .. " ✔️" end
elseif not canCarryTable[k] then setheader = setheader .. " 📦" end
Menu[#Menu + 1] = {
isMenuHeader = disable,
isMenuHeader = disable or not canCarryTable[k],
icon = invImg(tostring(k)),
header = setheader, txt = settext,
header = setheader,
txt = settext,
onSelect = function()
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
multiCraft(transdata)
else
makeItem(transdata)
end
if Config.Crafting.MultiCraft then multiCraft(transdata) else makeItem(transdata) end
end,
}
end
end
Wait(0)
end
end
openMenu(Menu, { header = data.craftable.Header, onBack = data.onBack or nil, canClose = true, onExit = function() end, })
@@ -118,61 +125,55 @@ function multiCraft(data) local Menu = {}
end
function makeItem(data)
if not CraftLock then CraftLock = true else return end
local bartime, bartext, animDict, anim = nil, nil, nil, nil
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"
if CraftLock then return end
CraftLock = true
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 and Loc[Config.Lan].progressbar["progress_make"]) or "Making a"
local animDict = data.craftable.Anims and data.craftable.Anims.animDict or "amb@prop_human_parking_meter@male@idle_a"
local anim = data.craftable.Anims and data.craftable.Anims.anim or "idle_a"
local amount = data.amount and (data.amount ~= 1) and data.amount or 1
local crafted = true
local crafting = true
local cam = createTempCam(PlayerPedId(), data.coords)
startTempCam(cam)
local crafted, crafting = true, true
local cam = createTempCam(PlayerPedId(), data.coords)
startTempCam(cam)
for i = 1, amount do
for _, v in pairs(data.craft) do
if type(v) == "table" then
for l, b in pairs(v) do
if crafting and progressBar({
label = "Using "..b.." "..Items[l].label,
time = 1000,
cancel = true,
dict = 'pickup_object',
anim = "putdown_low",
flag = 48,
icon = l,
}) then
--TriggerEvent('inventory:client:ItemBox', Items[l], "use", b) -- Show item box for each item
else
crafted = false
crafting = false
break
for k, v in pairs(data.craft) do
if k ~= "amount" and k ~= "job" then
if type(v) == "table" then
for l, b in pairs(v) do
if crafting and progressBar({
label = "Using "..b.." "..Items[l].label,
time = 1000,
cancel = true,
dict = 'pickup_object',
anim = "putdown_low",
flag = 48,
icon = l,
}) then
--TriggerEvent('inventory:client:ItemBox', Items[l], "use", b) -- Show item box for each item
else
crafted, crafting = false, false
break
end
Wait(200)
end
Wait(200)
end
if crafted then
if crafting and progressBar({
label = bartext..Items[data.item].label,
time = bartime,
cancel = true,
dict = animDict,
anim = anim,
flag = 8,
icon = data.item,
}) then
TriggerServerEvent(GetCurrentResourceName()..":Crafting:GetItem", data.item, data.craft, data.stashName)
else
crafting = false
break
if crafted then
if crafting and progressBar({
label = bartext..Items[data.item].label,
time = bartime,
cancel = true,
dict = animDict,
anim = anim,
flag = 8,
icon = data.item,
}) then
TriggerServerEvent(GetCurrentResourceName()..":Crafting:GetItem", data.item, data.craft, data.stashName)
else
crafting = false
break
end
end
end
end
@@ -187,29 +188,24 @@ function makeItem(data)
end
RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMake, craftable, stashName)
local src = source
local amount = 1
local src, amount, stashItems = source, craftable and craftable.amount or 1, stashName and getStash(stashName)
if stashName then
local stashItems = getStash(stashName)
if craftable["amount"] then amount = craftable["amount"] end
local itemRemove = {}
for k, v in pairs(craftable[ItemMake]) do
for l, b in pairs(stashItems) do
if k == b.name then
itemRemove[k] = v
end
for k, v in pairs(craftable[ItemMake] or {}) do
for _, b in pairs(stashItems or {}) do
if k == b.name then itemRemove[k] = v end
end
end
stashRemoveItem(stashItems, stashName, itemRemove)
else
if craftable then
if craftable["amount"] then amount = craftable["amount"] end
for k, v in pairs(craftable[ItemMake]) do
for k, v in pairs(craftable[ItemMake] or {}) do
TriggerEvent(GetCurrentResourceName()..":server:toggleItem", false, tostring(k), v, src)
end
end
end
TriggerEvent(GetCurrentResourceName()..":server:toggleItem", true, ItemMake, amount, src)
if GetResourceState("core_skills"):find("start") then exports["core_skills"]:AddExperience(src, 2) end
end)
--[[SHOPS]]--
@@ -230,33 +226,43 @@ 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 GetResourceState(OXInv):find("start") then
foundInv = OXInv
if src then grabInv = exports.ox_inventory:GetInventoryItems(src)
else grabInv = exports[OXInv]:GetPlayerItems()
end
if src then grabInv = exports[OXInv]:GetInventoryItems(src)
else grabInv = exports[OXInv]:GetPlayerItems() end
elseif GetResourceState(QSInv):find("start") then
foundInv = QSInv
if src then grabInv = exports[QSInv]:GetInventory(src)
else grabInv = exports[QSInv]:getUserInventory()
end
else grabInv = exports[QSInv]:getUserInventory() end
elseif GetResourceState(OrigenInv):find("start") then
foundInv = OrigenInv
if src then grabInv = exports[OrigenInv]:getPlayerInventory(src)
else grabInv = exports[OrigenInv]:getPlayerInventory() end
elseif GetResourceState(CoreInv):find("start") then
foundInv = CoreInv
if src then grabInv = exports['core_inventory']:getInventory('primary-'..src)
else grabInv = exports[CoreInv]:getInventory('primary-'..GetPlayerServerId(PlayerPedId()))
if src then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
elseif GetResourceState(ESXExport):find("start") then
local Player = ESX.GetPlayerFromId(src)
grabInv = Player.getInventory(false)
end
else
local p = promise.new()
Core.Functions.TriggerCallback('core_inventory:server:getInventory', function(cb) p:resolve(cb) end)
local result = Citizen.Await(p)
if type(result) == "string" then result = json.decode(result) end
grabInv = result
end
elseif GetResourceState(CodeMInv):find("start") then
foundInv = CodeMInv
if src then grabInv = exports[CodeMInv]:GetUserInventory(src)
else grabInv = exports[CodeMInv]:GetClientPlayerInventory()
end
grabInv = src and exports[CodeMInv]:GetUserInventory(src) or exports[CodeMInv]:GetClientPlayerInventory()
elseif GetResourceState(QBInv):find("start") then
foundInv = QBInv
if src then grabInv = Core.Functions.GetPlayer(src).PlayerData.items
else grabInv = Core.Functions.GetPlayerData().items
end
grabInv = src and Core.Functions.GetPlayer(src).PlayerData.items or Core.Functions.GetPlayerData().items
else
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7")
@@ -268,20 +274,15 @@ 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
local count = 0
for _, itemData in pairs(grabInv) do
if itemData and (itemData.name == item) then
--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, }
if itemData and (itemData.name == item) then count += (itemData.count or itemData.amount or 1) end
end
foundInv = foundInv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6")
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
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
end
end
@@ -300,38 +301,46 @@ function openStash(data)
lookEnt(data.coords)
end
function getStash(stashName)
function getStash(stashName) local stashResource = ""
local stashItems, items = {}, {}
if GetResourceState(OXInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7ox_inventory") end
if GetResourceState(OXInv):find("start") then stashResource = OXInv
stashItems = exports[OXInv]:Inventory(stashName).items
elseif GetResourceState(QSInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end
elseif GetResourceState(QSInv):find("start") then stashResource = QSInv
stashItems = exports[QSInv]:GetStashItems(stashName)
elseif GetResourceState(CodeMInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qs-inventory") end
elseif GetResourceState(CoreInv):find("start") then stashResource = CoreInv
stashItems = exports[CoreInv]:getInventory(stashName)
elseif GetResourceState(CodeMInv):find("start") then stashResource = CodeMInv
stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName)
elseif GetResourceState(QBInv):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7qb-inventory") end
elseif GetResourceState(OrigenInv):find("start") then stashResource = OrigenInv
stashItems = exports[OrigenInv]:GetStashItems(stashName)
elseif GetResourceState(QBInv):find("start") then stashResource = QBInv
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
if result then stashItems = json.decode(result) end
end
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..stashResource) end
if stashItems then
for _, item in pairs(stashItems) do
local itemInfo = Items[item.name:lower()]
if itemInfo then
items[item.slot] = {
name = itemInfo["name"],
local indexNum = #items+1 -- Added to help recreate missing slot numbers
items[(item.slot and item.slot) or indexNum] = {
name = itemInfo.name or nil,
amount = tonumber(item.amount) or tonumber(item.count),
info = item.info ~= nil and item.info or "",
label = itemInfo["label"],
description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
weight = itemInfo["weight"],
type = itemInfo["type"],
unique = itemInfo["unique"],
useable = itemInfo["useable"],
image = itemInfo["image"],
slot = item.slot,
info = item.info or "",
label = itemInfo.label or nil,
description = itemInfo.description or "",
weight = itemInfo.weight or nil,
type = itemInfo.type or nil,
unique = itemInfo.unique or nil,
useable = itemInfo.useable or nil,
image = itemInfo.image or nil,
slot = (item.slot and item.slot) or indexNum,
}
end
end
@@ -346,11 +355,32 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
exports[OXInv]:RemoveItem(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OXInv, k, v) end
end
elseif GetResourceState(QSInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do
if stashItems[l].name == k then
if (stashItems[l].amount - v) <= 0 then
if Config.System.Debug then
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
end
stashItems[l] = nil
else
if Config.System.Debug then
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
end
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
end
end
end
end
elseif GetResourceState(CoreInv):find("start") then
for k, v in pairs(items) do
exports[QSInv]:RemoveItemIntoStash(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QSInv, k, v) end
exports[CoreInv]:removeItemExact(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..CoreInv, k, v) end
end
elseif GetResourceState(CodeMInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do
@@ -372,6 +402,13 @@ function stashRemoveItem(stashItems, stashName, items) local amount = amount and
if Config.System.Debug then
print("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'")
end
elseif GetResourceState(OrigenInv):find("start") then
for k, v in pairs(items) do
exports[OrigenInv]:RemoveItem(stashName, k, v)
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OrigenInv, k, v) end
end
elseif GetResourceState(QBInv):find("start") then
for k, v in pairs(items) do
for l in pairs(stashItems) do
@@ -401,7 +438,15 @@ end
RegisterNetEvent(GetCurrentResourceName()..":server:stashRemoveItem", stashRemoveItem)
function stashhasItem(stashItems, items, amount)
local invs = {OXInv, QSInv, CoreInv, CodeMInv, OrigenInv, QBInv}
local foundInv = ""
for _, inv in ipairs(invs) do
if GetResourceState(inv):find("start") then
foundInv = inv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6")
break
end
end
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
local hasTable = {}
for item, amount in pairs(items) do
@@ -411,14 +456,105 @@ function stashhasItem(stashItems, items, amount)
count += (itemData.amount or 1)
end
end
if count >= amount then
if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^5FOUND '"..item.."' ^3"..count.."^7/^3"..amount.."^7") end
hasTable[item] = { hasItem = true, count = count, }
else
if Config.System.Debug then print("^6Bridge^7: ^3stashHasItem^7: ^1NOT FOUND^7 '"..item.."' ^1"..count.."^7/^3"..amount.."^7") end
hasTable[item] = { hasItem = false, count = count, }
end
local debugMsg = string.format("^6Bridge^7: ^3stashHasItem^7[^6%s^7]: %s '%s' ^3%d^7/^3%d^7", foundInv, (count >= amount and "^5FOUND^7" or "^1NOT FOUND^7"), item, count, amount)
if Config.System.Debug then print(debugMsg) end
hasTable[item] = { hasItem = (count >= amount), count = count }
end
for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end
return true, hasTable
end
if IsDuplicityVersion() then
if GetResourceState(OXLibExport):find("start") then
createCallback(GetCurrentResourceName()..':server:canCarry', function(source, itemTable) local result = canCarry(itemTable, source) return result end)
else
createCallback(GetCurrentResourceName()..':server:canCarry', function(source, cb, itemTable) local result = canCarry(itemTable, source) cb(result) end)
end
end
function canCarry(itemTable, src)
local resultTable = {}
if src then
if GetResourceState(OXInv):find("start") then
for k, v in pairs(itemTable) do
resultTable[k] = exports[OXInv]:CanCarryItem(src, k, v)
end
elseif GetResourceState(QSInv):find("start") then
for k, v in pairs(itemTable) do
resultTable[k] = exports[OXInv]:CanCarryItem(src, k, v)
end
elseif GetResourceState(CoreInv):find("start") then
--??
elseif GetResourceState(CodeMInv):find("start") then
for k, v in pairs(itemTable) do
local weight = Items[k].weight
resultTable[k] = exports[CodeMInv]:CanCarryItem(src, weight, v)
end
elseif GetResourceState(OrigenInv):find("start") then
for k, v in pairs(itemTable) do
resultTable[k] = exports[OrigenInv]:canCarryItem(src, k, v)
end
elseif GetResourceState(QBInv):find("start") then
local Player = Core.Functions.GetPlayer(src)
local items = Player.PlayerData.items
local weight, totalWeight = 0, 0
if not items then return false end
for _, item in pairs(items) do weight += item.weight * item.amount end
totalWeight = tonumber(weight)
for k, v in pairs(itemTable) do
local itemInfo = Items[k]
if not itemInfo and not Player.Offline then
triggerNotify(nil, 'Item does not exist', 'error', src)
resultTable[k] = true
else
resultTable[k] = (totalWeight + (Items[k]['weight'] * v)) <= 120000
end
end
end
end
return resultTable
end
function getRandomReward(itemName) -- intended for job scripts
if Config.Rewards.RewardPool then
local reward = false
if type(Config.Rewards.RewardItem) == "string" then Config.Rewards.RewardItem = { Config.Rewards.RewardItem } end
for k, v in pairs(Config.Rewards.RewardItem) do
if v == itemName then reward = true break end
end
if reward then
removeItem(itemName, 1)
local totalRarity = 0
for i=1, #Config.Rewards.RewardPool do
totalRarity += Config.Rewards.RewardPool[i].rarity
end
if Config.System.Debug then
print("^6Bridge^7: ^3getRandomReward^7: ^2Total Rarity ^7'^6"..totalRarity.."^7'")
end
local randomNum = math.random(1, totalRarity)
if Config.System.Debug then
print("^6Bridge^7: ^3getRandomReward^7: ^2Random Number ^7'^6"..randomNum.."^7'")
end
local currentRarity = 0
for i=1, #Config.Rewards.RewardPool do
currentRarity += Config.Rewards.RewardPool[i].rarity
if randomNum <= currentRarity then
if Config.System.Debug then
print("^6Bridge^7: ^3getRandomReward^7: ^2Selected toy ^7'^6"..Config.Rewards.RewardPool[i].item.."^7'")
end
addItem(Config.Rewards.RewardPool[i].item, 1)
return
end
end
end
end
end

View File

@@ -7,8 +7,9 @@ Exports = {
OXInv = "ox_inventory",
QBInv = "qb-inventory",
QSInv = "qs-inventory",
CoreInv = "core-inventory",
CoreInv = "core_inventory",
CodeMInv = "codem-inventory",
OrigenInv = "origen_inventory",
OXLibExport = "ox_lib",

View File

@@ -8,20 +8,45 @@ function jobCheck(job)
return canDo
end
local time = 100
local time = 500
function loadModel(model)
if not HasModelLoaded(model) then if Config.System.Debug then print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") end
while not HasModelLoaded(model) do if time > 0 then time -= 1 RequestModel(model)
else time = 1000 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") break end
Wait(10) end
if not IsModelValid(model) then print("^6Bridge^7: ^1ERROR^7: ^2Model^7 - '^6"..model.."^7' ^2does not exist in server") return
else
if not HasModelLoaded(model) then
if Config.System.Debug then print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") end
while not HasModelLoaded(model) and time > 0 do time -= 1 RequestModel(model) Wait(0) end
if not HasModelLoaded(model) then time = 500 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") end
end
end
end
function unloadModel(model) if Config.System.Debug then print("^6Bridge^7: ^2Removing Model from memory cache^7: '^6"..model.."^7'") end SetModelAsNoLongerNeeded(model) end
function loadAnimDict(animDict)
if not DoesAnimDictExist(animDict) then print("^6Bridge^7: ^1ERROR^7: ^2Anim Dictionary^7 - '^6"..animDict.."^7' ^2does not exist in server") return
else
if Config.System.Debug then print("^6Bridge^7: ^2Loading Anim Dictionary^7: '^6"..animDict.."^7'") end
while not HasAnimDictLoaded(animDict) do RequestAnimDict(animDict) Wait(5) end
end
end
function unloadAnimDict(animDict) if Config.System.Debug then print("^6Bridge^7: ^2Removing Anim Dictionary from memory cache^7: '^6"..animDict.."^7'") end RemoveAnimDict(animDict) end
function loadPtfxDict(ptFxName)
if not HasNamedPtfxAssetLoaded(ptFxName) then
if Config.System.Debug then
print("^6Bridge^7: ^2Loading Ptfx Dictionary^7: '^6"..ptFxName.."^7'")
end
while not HasNamedPtfxAssetLoaded(ptFxName) do RequestNamedPtfxAsset(ptFxName) Wait(5) end
end
end
function unloadModel(model) if Config.System.Debug then print("^6Bridge^7: ^2Removing Model^7: '^6"..model.."^7'") end SetModelAsNoLongerNeeded(model) end
function loadAnimDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Loading Anim Dictionary^7: '^6"..dict.."^7'") end while not HasAnimDictLoaded(dict) do RequestAnimDict(dict) Wait(5) end end
function unloadAnimDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Removing Anim Dictionary^7: '^6"..dict.."^7'") end RemoveAnimDict(dict) end
function loadPtfxDict(dict) if Config.System.Debug then if not HasNamedPtfxAssetLoaded(dict) then print("^6Bridge^7: ^2Loading Ptfx Dictionary^7: '^6"..dict.."^7'") end end while not HasNamedPtfxAssetLoaded(dict) do RequestNamedPtfxAsset(dict) Wait(5) end end
function unloadPtfxDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Removing Ptfx Dictionary^7: '^6"..dict.."^7'") end RemoveNamedPtfxAsset(dict) end
function loadTextureDict(dict) if Config.System.Debug then print("^6Bridge^7: ^2Loading Texture Dictionary^7: '^6"..dict.."^7'") end while not HasStreamedTextureDictLoaded(dict) do RequestNamedPtfxAsset(dict) Wait(5) end end
function loadTextureDict(dict)
if not HasStreamedTextureDictLoaded(dict) then
if Config.System.Debug then
print("^6Bridge^7: ^2Loading Texture Dictionary^7: '^6"..dict.."^7'")
end
while not HasStreamedTextureDictLoaded(dict) do RequestNamedPtfxAsset(dict) Wait(5) end
end
end
function countTable(table) local i = 0 for keys in pairs(table) do i += 1 end return i end
@@ -32,8 +57,8 @@ function playAnim(animDict, animName, duration, flag, ped)
TaskPlayAnim(ped and ped or PlayerPedId(), animDict, animName, 8.0, -8.0, duration or 30000, flag or 50, 1, false, false, false)
end
function stopAnim(animDict, animName)
StopAnimTask(PlayerPedId(), animName, animDict)
function stopAnim(animDict, animName, ped)
StopAnimTask(ped and ped or PlayerPedId(), animName, animDict)
unloadAnimDict(animDict)
end
@@ -60,7 +85,7 @@ local Peds = {}
local Props = {}
function makePed(model, coords, freeze, collision, scenario, anim, synced)
loadModel(model)
local ped = CreatePed(0, model, coords.x, coords.y, coords.z-1.03, coords.w, synced and synced or true, false)
local ped = CreatePed(0, model, coords.x, coords.y, coords.z-1.03, coords.w, synced or true, false)
SetEntityInvincible(ped, true)
SetBlockingOfNonTemporaryEvents(ped, true)
FreezeEntityPosition(ped, freeze and freeze or true)
@@ -82,7 +107,7 @@ end
function makeProp(data, freeze, synced)
loadModel(data.prop)
local prop = CreateObject(data.prop, data.coords.x, data.coords.y, data.coords.z-1.03, synced or false, synced or false, false)
local prop = CreateObject(data.prop, data.coords.x, data.coords.y, data.coords.z-1.03, freeze or false, synced or false, false)
SetEntityHeading(prop, data.coords.w + 180.0)
FreezeEntityPosition(prop, freeze and freeze or 0)
if Config.System.Debug then
@@ -193,22 +218,12 @@ end
function ensureNetToVeh(vehNetID)
if Config.System.Debug then print("^6Bridge^7: ^3ensureNetToVeh^7: ^2Requesting NetworkDoesNetworkIdExist^7(^6"..vehNetID.."^7)") end
local timeout = 100
while not NetworkDoesNetworkIdExist(vehNetID) and timeout > 0 do
timeout -= 1
Wait(10)
end
if not NetworkDoesNetworkIdExist(vehNetID) then
return 0
end
while not NetworkDoesNetworkIdExist(vehNetID) and timeout > 0 do timeout -= 1 Wait(10) end
if not NetworkDoesNetworkIdExist(vehNetID) then return 0 end
timeout = 100
local vehicle = NetToVeh(vehNetID)
while not DoesEntityExist(vehicle) and vehicle ~= 0 and timeout > 0 do
timeout -= 1
Wait(10)
end
if not DoesEntityExist(vehicle) then
return 0
end
while not DoesEntityExist(vehicle) and vehicle ~= 0 and timeout > 0 do timeout -= 1 Wait(10) end
if not DoesEntityExist(vehicle) then return 0 end
return vehicle
end
@@ -504,7 +519,7 @@ end)
RegisterNetEvent(GetCurrentResourceName()..":server:setNeed", function(type, amount) local src = source
if type == "thirst" then
setThirst(src, amount)
elseif type == "thirst" then
elseif type == "hunger" then
setHunger(src, amount)
end
end)
@@ -513,7 +528,7 @@ function setThirst(src, thirst)
if GetResourceState(ESXExport):find("start") then
TriggerClientEvent('esx_status:add', src, 'thirst', thirst)
elseif GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
local Player = QBCore.Functions.GetPlayer(src)
local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('thirst', thirst)
TriggerClientEvent("hud:client:UpdateNeeds", src, thirst, Player.PlayerData.metadata.thirst)
end
@@ -523,7 +538,7 @@ function setHunger(src, hunger)
if GetResourceState(ESXExport):find("start") then
TriggerClientEvent('esx_status:add', src, 'hunger', hunger)
elseif GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
local Player = QBCore.Functions.GetPlayer(src)
local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('hunger', hunger)
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.hunger)
end
@@ -541,8 +556,8 @@ end
-- [[CONSUME]] --
function ConsumeSuccess(itemName, type)
ExecuteCommand("e c")
toggleItem(false, itemName, 1)
if GetResourceState(ESXEport):find("start") then
removeItem(itemName, 1)
if GetResourceState(ESXExport):find("start") then
if Items[itemName].hunger then
TriggerServerEvent(GetCurrentResourceName()..":server:setNeed", "hunger", Items[itemName].hunger * 10000)
end
@@ -558,17 +573,22 @@ function ConsumeSuccess(itemName, type)
end
end
if type == "alcohol" then alcoholCount += 1
if alcoholCount > 1 and alcoholCount < 4 then TriggerEvent("evidence:client:SetStatus", "alcohol", 200) elseif alcoholCount >= 4 then TriggerEvent("evidence:client:SetStatus", "heavyalcohol", 200) AlienEffect() end
if alcoholCount > 1 and alcoholCount < 4 then
TriggerEvent("evidence:client:SetStatus", "alcohol", 200)
elseif alcoholCount >= 4 then
TriggerEvent("evidence:client:SetStatus", "heavyalcohol", 200)
AlienEffect()
end
end
if Config.RewardItem == itemName then toggleItem(true, Config.RewardPool[math.random(1, #Config.RewardPool)], 1) end
getRandomReward(itemName) -- check if a reward item should be given
end
function addItem(item, amount, info)
TriggerServerEvent(GetCurrentResourceName()..":server:toggleItem", true, item, amount)
TriggerServerEvent(GetCurrentResourceName()..":server:toggleItem", true, item, amount, nil, info)
end
function removeItem(item, amount)
TriggerServerEvent(GetCurrentResourceName()..":server:toggleItem", false, item, amount)
TriggerServerEvent(GetCurrentResourceName()..":server:toggleItem", false, item, amount, nil, info)
end
RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give, item, amount, newsrc)
@@ -586,21 +606,35 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OXInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QSInv):find("start") then
local success = exports[QSInv]:RemoveItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CoreInv):find("start") then
local success = exports[CoreInv]:removeItemExact('primary-'..src, item, amount)
elseif GetResourceState(CoreInv):find("start") then
if GetResourceState(QBExport):find("start") then
Core.Functions.GetPlayer(src).Functions.RemoveItem(item, amount, nil)
elseif GetResourceState(ESXExport):find("start") then
ESX.GetPlayerFromId(src).removeInventoryItem(item, count)
end
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CodeMInv):find("start") then
elseif GetResourceState(OrigenInv):find("start") then
local success = exports[OrigenInv]:RemoveItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OrigenInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CodeMInv):find("start") then
local success = exports[CodeMInv]:RemoveItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CodeMInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QBInv):find("start") then
while remamount > 0 do
if Core.Functions.GetPlayer(src).Functions.RemoveItem(item, 1) then end
@@ -616,7 +650,7 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7")
end
else
dupeWarn(src, item) -- if not boot the player
dupeWarn(src, item, amount) -- if not boot the player
end
else
local amount = amount and amount or 1
@@ -625,21 +659,35 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OXInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QSInv):find("start") then
local success = exports[QSInv]:AddItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QSInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CoreInv):find("start") then
local success = exports[CoreInv]:addItem('primary-'..src, item, amount)
if Config.System.Debug then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
Core.Functions.GetPlayer(src).Functions.AddItem(item, amount, nil, nil)
elseif GetResourceState(ESXExport):find("start") then
ESX.GetPlayerFromId(src).addInventoryItem(item, amount)
end
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CoreInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(CodeMInv):find("start") then
local success = exports[CodeMInv]:AddItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..CodeMInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(OrigenInv):find("start") then
local success = exports[OrigenInv]:AddItem(src, item, amount)
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..OrigenInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
elseif GetResourceState(QBInv):find("start") then
if Core.Functions.GetPlayer(src).Functions.AddItem(item, amount or 1) then
--if Config.Crafting.showItemBox then
@@ -649,6 +697,7 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
if Config.System.Debug then
print("^6Bridge^7: ^3"..addremove.."^7[^6"..QBInv.."^7] ^2Player^7("..src..") ^6"..Items[item].label.."^7("..item..") x^5"..(amount and amount or "1").."^7")
end
else
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7")
end
@@ -656,10 +705,10 @@ RegisterNetEvent(GetCurrentResourceName()..":server:toggleItem", function(give,
end)
--Item Exploit protection
function dupeWarn(src, item)
function dupeWarn(src, item, amount)
print("^5DupeWarn^7: (^1"..tostring(src).."^7) ^2Tried to remove item ^7('^3"..item.."^7')^2 but it wasn't there^7")
if Config.System.Debug == false then
DropPlayer(src, src.." ^1Kicked for attempting to duplicate items")
DropPlayer(src, src.." ^1Kicked for suspected duplicating items:"..item)
end
print("^5DupeWarn:^7: (^1"..tostring(src).."^7) ^2Dropped from server - exploit protection detected an item not being found in players inventory^7")
end
@@ -685,12 +734,12 @@ local function CheckVersion()
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/'..GetCurrentResourceName()..'/master/version.txt', function(err, freeVersion, headers)
if not freeVersion then print("^1Currently unable to run a version check for ^7'^3"..GetCurrentResourceName().."^7' ("..currentVersion.."^7)") return end
local currentVersion = "^3"..GetResourceMetadata(GetCurrentResourceName(), 'version'):gsub("%.", "^7.^3").."^7"
freeVersion = "^3"..freeVersion:sub(1, -2):gsub("%.", "^7.^3").."^7"
freeVersion = "^3"..freeVersion:sub(1, -2):gsub("%.", "^7.^3"):gsub("%\r", "").."^7"
print("^6Version Check^7: ^2Running^7: "..currentVersion.." ^2Latest^7: "..freeVersion)
print(freeVersion == currentVersion and "^7'^3"..GetCurrentResourceName().."^7' - ^6You are running the latest version.^7 ("..currentVersion..")" or "^7'^3"..GetCurrentResourceName().."^7' - ^1You are currently running an outdated version^7, ^1please update^7!")
end)
else
newestVersion = "^3"..newestVersion:sub(1, -2):gsub("%.", "^7.^3").."^7"
newestVersion = "^3"..newestVersion:sub(1, -2):gsub("%.", "^7.^3"):gsub("%\r", "").."^7"
print("^6Version Check^7: ^2Running^7: "..currentVersion.." ^2Latest^7: "..newestVersion)
print(newestVersion == currentVersion and '^6You are running the latest version.^7 ('..currentVersion..')' or "^1You are currently running an outdated version^7, ^1please update^7!")
end

View File

@@ -1,6 +1,6 @@
name "Jim_Bridge"
author "Jimathy"
version "1.0.4"
version "1.0.11"
description "Framework Bridge By Jimathy"
fx_version "cerulean"
game "gta5"
@@ -11,4 +11,4 @@ files {
'functions.lua',
'wrapper.lua',
'crafting.lua',
}
}

View File

@@ -1 +1 @@
1.0.5
1.0.11

View File

@@ -1,29 +1,21 @@
Items, Vehicles, Jobs, Gangs, Core, ESX = {}, nil, nil, nil, nil, nil
OXLibExport = Exports and Exports.OXLibExport or ""
Exports.QBInv = GetResourceState("ps-inventory"):find("start") and "ps-inventory" or GetResourceState("lj-inventory"):find("start") and "lj-inventory" or Exports.QBInv
QBXExport = Exports and Exports.QBXExport or ""
QBExport = Exports and Exports.QBExport or ""
ESXExport = Exports and Exports.ESXExport or ""
OXCoreExport = Exports and Exports.OXCoreExport or ""
OXLibExport, QBXExport, QBExport, ESXExport, OXCoreExport = Exports.OXLibExport or "", Exports.QBXExport or "", Exports.QBExport or "", Exports.ESXExport or "", Exports.OXCoreExport or ""
OXInv = Exports and Exports.OXInv or ""
QBInv = Exports and Exports.QBInv or ""
QSInv = Exports and Exports.QSInv or ""
CoreInv = Exports and Exports.CoreInv or ""
CodeMInv = Exports and Exports.CodeMInv or ""
OXInv, QBInv, QSInv, CoreInv, CodeMInv, OrigenInv = Exports.OXInv or "", Exports.QBInv or "", Exports.QSInv or "", Exports.CoreInv or "", Exports.CodeMInv or "", Exports.OrigenInv or ""
QBMenuExport = Exports and Exports.QBMenuExport or ""
QBMenuExport = Exports.QBMenuExport or ""
QBTargetExport = Exports and Exports.QBTargetExport or ""
OXTargetExport = Exports and Exports.OXTargetExport or ""
QBTargetExport, OXTargetExport = Exports.QBTargetExport or "", Exports.OXTargetExport or ""
function CheckBridgeVersion()
if IsDuplicityVersion() then
local currentVersion = "^3"..GetResourceMetadata("jim_bridge", 'version'):gsub("%.", "^7.^3").."^7"
PerformHttpRequest('https://raw.githubusercontent.com/jimathy/jim_bridge/master/version.txt', function(err, newestVersion, headers)
if not newestVersion then print("^1Currently unable to run a version check for ^7'^3jim_bridge^7' ("..currentVersion.."^7)") return end
newestVersion = "^3"..newestVersion:sub(1, -2):gsub("%.", "^7.^3").."^7"
newestVersion = "^3"..newestVersion:sub(1, -2):gsub("%.", "^7.^3"):gsub("%\r", "").."^7"
print(newestVersion == currentVersion and "^7'^3jim_bridge^7' - ^6You are running the latest version.^7 ("..currentVersion..")" or "^7'^3jim_bridge^7' - ^1You are currently running an outdated version^7, ^1please update^7!")
end)
end
@@ -34,54 +26,59 @@ for k, v in pairs(Exports) do
if GetResourceState(v):find("start") then print("^6Bridge^7: '^3"..v.."^7' ^2export found ^7") end
end
local itemResource, vehResource, jobResource = "", "", ""
-- Load item lists
if GetResourceState(OXInv):find("start") then
print("^6Bridge^7: ^2Loading ^3Items^2 from ^7"..OXInv)
if GetResourceState(OXInv):find("start") then itemResource = OXInv
Items = exports[OXInv]:Items()
for k, v in pairs(Items) do
if v.client then
if v.client.image then Items[k].image = (Items[k].client.image):gsub("nui://"..OXInv.."/web/images/","")
else Items[k].image = k..".png" end
if v.client.hunger then Items[k].hunger = v.client.hunger end
if v.client.thirst then Items[k].thirst = v.client.thirst end
if v.client and v.client.image then
Items[k].image = (v.client.image):gsub("nui://"..OXInv.."/web/images/", "")
else
Items[k].image = k..".png"
end
Items[k].hunger = v.client and v.client.hunger or nil
Items[k].thirst = v.client and v.client.thirst or nil
end
elseif GetResourceState(QBExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Items^2 from ^7"..QBExport)
elseif GetResourceState(QBExport):find("start") then itemResource = QBExport
Core = Core or exports[QBExport]:GetCoreObject()
Items = Core.Shared.Items
elseif GetResourceState(ESXExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Items^2 from ^7"..ESXExport)
Items = Core and Core.Shared.Items or nil
elseif GetResourceState(ESXExport):find("start") then itemResource = ESXExport
ESX = exports[ESXExport]:getSharedObject()
Items = ESX.Items
else
Items = ESX and ESX.Items or nil
end
if not Items then
print("^4ERROR^7: ^2No Core Items detected ^7- ^2Check ^3exports^1.^2lua^7")
else
print("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource)
end
-- Load Vehicles
if GetResourceState(QBXExport):find("start") then
if GetResourceState(QBXExport):find("start") or GetResourceState(QBExport):find("start") then vehResource = QBExport
Core = Core or exports[QBExport]:GetCoreObject()
print("^6Bridge^7: ^2Loading ^3Vehicles^2 from ^7"..QBXExport)
Vehicles = exports[QBXExport]:GetVehiclesByHash()
elseif GetResourceState(QBExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Vehicles^2 from ^7"..QBExport)
Core = Core or exports[QBExport]:GetCoreObject()
RegisterNetEvent('QBCore:Client:UpdateObject', function()
Core = Core or exports[QBExport]:GetCoreObject()
end)
Vehicles = Core.Shared.Vehicles
if GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then
RegisterNetEvent('QBCore:Client:UpdateObject', function()
Core = Core or exports[QBExport]:GetCoreObject()
end)
end
Vehicles = Core and Core.Shared.Vehicles
print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..QBExport)
elseif GetResourceState(OXCoreExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Vehicles^2 from ^7"..OXCoreExport)
Vehicles = {}
for k, v in pairs(Ox.GetVehicleData()) do
Vehicles = Vehicles or {}
Vehicles[k] = { model = k, price = v.price, name = v.name, brand = v.make }
end
print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..OXCoreExport)
elseif GetResourceState(ESXExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Vehicles^2 from ^7"..ESXExport)
--print("^6Bridge^7: ^2Loading ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..ESXExport)
CreateThread(function()
if IsDuplicityVersion() then
createCallback(GetCurrentResourceName()..":getVehiclesPrices", function(source)
Vehicles = MySQL.query.await('SELECT model, price, name FROM vehicles')
print("^6Bridge^7: ^3Found ^6"..countTable(Vehicles).." ^3Vehicles^2 from ^7"..ESXExport)
return Vehicles
end)
end
@@ -98,37 +95,33 @@ else
end
-- Load Jobs
if GetResourceState(QBXExport):find("start") then
local jobResource = ""
if GetResourceState(QBXExport):find("start") then jobResource = QBXExport
Core = Core or exports[QBExport]:GetCoreObject()
print("^6Bridge^7: ^2Loading ^3Jobs^7/^3Gangs^2 from ^7"..QBXExport)
Jobs = exports[QBXExport]:GetJobs()
Gangs = exports[QBXExport]:GetGangs()
Jobs, Gangs = exports[QBXExport]:GetJobs(), exports[QBXExport]:GetGangs()
elseif GetResourceState(OXCoreExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Jobs^7/^3Gangs^2 from ^7"..OXCoreExport)
elseif GetResourceState(OXCoreExport):find("start") then jobResource = OXExport
CreateThread(function()
if IsDuplicityVersion() then
createCallback(GetCurrentResourceName()..":getOxGroups", function(source)
Jobs = MySQL.query.await('SELECT * FROM `ox_groups`')
return Jobs
Jobs = MySQL.query.await('SELECT * FROM `ox_groups`') return Jobs
end)
else
local TempJobs = triggerCallback(GetCurrentResourceName()..":getOxGroups")
Jobs = TempJobs and {}
for k, v in pairs(TempJobs) do
local grades = {}
for i = 1, #v.grades do grades[i] = { name = grades[i], isboss = (i == #v.grades)} end
Jobs = Jobs or {}
Jobs[v.name] = { label = v.label, grades = grades, }
for i = 1, #v.grades do grades[i] = { name = v.grades[i], isboss = (i == #v.grades)} end
Jobs[v.name] = { label = v.label, grades = grades }
end
Gangs = Jobs
end
end)
elseif GetResourceState(QBExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Jobs^7/^3Gangs^2 from ^7"..QBExport)
elseif GetResourceState(QBExport):find("start") then jobResource = QBExport
Core = Core or Core or exports[QBExport]:GetCoreObject()
RegisterNetEvent('QBCore:Client:UpdateObject', function() Core = Core or exports[QBExport]:GetCoreObject() end)
Jobs = Core.Shared.Jobs
Gangs = Core.Shared.Gangs
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
elseif GetResourceState(ESXExport):find("start") then
print("^6Bridge^7: ^2Loading ^3Jobs^7/^3Gangs^2 from ^7"..ESXExport)
@@ -153,29 +146,21 @@ elseif GetResourceState(ESXExport):find("start") then
Gangs = Jobs
end
end)
else
print("^4ERROR^7: ^2No Job/Gang ifo detected ^7- ^2Check ^3exports^1.^2lua^7")
end
if not GetResourceState(ESXExport):find("start") and Jobs then
print("^6Bridge^7: ^2Loading ^6"..countTable(Jobs).." ^3Jobs^2 from ^7"..jobResource, "^6Bridge^7: ^2Loading ^6"..countTable(Gangs).." ^3Gangs^2 from ^7"..jobResource)
end
function makeBossRoles(role)
local boss = {}
if Jobs and Jobs[role] then
for grade in pairs(Jobs[role].grades) do
if Jobs[role].grades[grade].isboss then
if boss[role] then
if boss[role] > tonumber(grade) then boss[role] = tonumber(grade) end
else boss[role] = tonumber(grade) end
end
end
elseif Gangs and Gangs[role] then
for grade in pairs(Gangs[role].grades) do
if Gangs[role].grades[grade].isboss then
if boss[role] then
if boss[role] > tonumber(grade) then boss[role] = tonumber(grade) end
else boss[role] = tonumber(grade) end
end
end
end
local boss = {}
local data = Jobs and Jobs[role] or Gangs and Gangs[role]
if data then
for grade, info in pairs(data.grades) do
if info.isboss then
boss[role] = boss[role] and math.min(boss[role], tonumber(grade)) or tonumber(grade)
end
end
end
return boss
end
@@ -191,11 +176,7 @@ function createPoly(data) local Location = nil
if Config.System.Debug then print("^6Bridge^7: ^2Creating new poly with ^7PolyZone "..data.name) end
Location = PolyZone:Create(data.points, { name = data.name, debugPoly = data.debug })
Location:onPlayerInOut(function(isPointInside)
if isPointInside then
data.onEnter()
else
data.onExit()
end
if isPointInside then data.onEnter() else data.onExit() end
end)
else
print("^4ERROR^7: ^2No PolyZone creation script detected ^7- ^2Check ^3exports^1.^2lua^7")
@@ -223,19 +204,26 @@ end
function openMenu(Menu, data)
if Config.System.Menu == "ox" then
if data.onBack then
local index = nil
if data.onBack and not data.onSelected then
table.insert(Menu, 1, { icon = "fas fa-circle-arrow-left",
title = "Return",
onSelect = data.onBack,
label = "Return"
})
end
for k in pairs(Menu) do
if data.onSelected and Menu[k].arrow then
Menu[k].icon = "fas fa-angle-right"
end
if not Menu[k].title then
if Menu[k].header ~= nil and Menu[k].header ~= "" then
Menu[k].title = Menu[k].header
Menu[k].label = Menu[k].header
if Menu[k].txt then Menu[k].description = Menu[k].txt else Menu[k].description = "" end
else
Menu[k].title = Menu[k].txt
Menu[k].label = Menu[k].txt
end
end
if Menu[k].params then
@@ -246,8 +234,35 @@ function openMenu(Menu, data)
Menu[k].disabled = true
end
end
lib.registerContext({id = 'Menu', title = data.header..br..br..(data.headertxt and data.headertxt or ""), position = 'top-right', options = Menu, canClose = data.canClose and data.canClose or nil, onExit = data.onExit and data.onExit or nil, })
lib.showContext("Menu")
local menuID = 'Menu'
(data.onSelected and lib.registerMenu or lib.registerContext)({
id = menuID,
title = data.header..br..br..(data.headertxt and data.headertxt or ""),
position = 'top-right',
options = Menu,
canClose = data.canClose and data.canClose or nil,
onClose = (data.onBack and data.onBack) or (data.onExit and data.onExit) or nil,
onExit = data.onExit and data.onExit or nil,
onSelected = data.onSelected and (function(selected) index = selected end) or nil,
}, (data.onSelected and (function(x, y, args)
if Menu[x].refresh then
if Menu[x].onSelect then
Menu[x].onSelect()
end
lib.showMenu(menuID, index)
else
if Menu[x].onSelect then
Menu[x].onSelect()
else
lib.showMenu(menuID, index)
end
end
end) or nil))
if data.onSelected then
lib.showMenu(menuID, 1)
else
lib.showContext(menuID)
end
elseif Config.System.Menu == "qb" then
if data.onBack then
table.insert(Menu, 1, { icon = "fas fa-circle-arrow-left",
@@ -750,7 +765,7 @@ function createInput(title, opts)
isRequired = opts[i].isRequired,
label = opts[i].label or opts[i].text,
name = opts[i].name,
default = opts[i].options[1].value,
default = opts[i].default or opts[i].options[1].value,
options = opts[i].options,
}
end
@@ -988,31 +1003,58 @@ AddStateBagChangeHandler(GetCurrentResourceName()..':setVehicleProperties', '',
end
end)
RegisterNetEvent(GetCurrentResourceName()..":server:ChargePlayer", function(cost, type) local src = source
if Config.System.Debug then print("^6Bridge^7: ^2Charging ^2Player: '^6"..cost.."^7'", type) end
RegisterNetEvent(GetCurrentResourceName()..":server:ChargePlayer", function(cost, type, newsrc)
local src = newsrc or source
local fundResource = ""
if type == "cash" then
if GetResourceState(OXInv):find("start") then
if GetResourceState(OXInv):find("start") then fundResource = OXInv
exports[OXInv]:RemoveItem(src, "money", cost)
if Config.System.Debug then print("^6Bridge^7: ^2Charging ^2Player: '^6"..cost.."^7'", type, OXInv) end
elseif GetResourceState(QBExport):find("start") then
elseif GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost)
if Config.System.Debug then print("^6Bridge^7: ^2Charging ^2Player: '^6"..cost.."^7'", type, QBExport) end
elseif GetResourceState(ESXExport):find("start") then
elseif GetResourceState(ESXExport):find("start") then fundResource = ESXExport
local Player = ESX.GetPlayerFromId(src)
Player.removeMoney(cost, "")
if Config.System.Debug then print("^6Bridge^7: ^2Charging ^2Player: '^6"..cost.."^7'", type, ESXExport) end
end
end
if type == "bank" then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost)
if Config.System.Debug then print("^6Bridge^7: ^2Charging ^2Player: '^6"..cost.."^7'", type, QBExport) end
elseif GetResourceState(ESXExport):find("start") then
elseif GetResourceState(ESXExport):find("start") then fundResource = ESXExport
local Player = ESX.GetPlayerFromId(src)
Player.removeMoney(cost, "")
if Config.System.Debug then print("^6Bridge^7: ^2Charging ^2Player: '^6"..cost.."^7'", type, ESXExport) end
end
end
if fundResource == "" then print("error - check exports.lua")
else
if Config.System.Debug then print("^6Bridge^7: ^2Charging ^2Player^7: '^6"..cost.."^7'", type, fundResource) end
end
end)
RegisterNetEvent(GetCurrentResourceName()..":server:FundPlayer", function(fund, type, newsrc)
local src = newsrc or source
local fundResource = ""
if type == "cash" then
if GetResourceState(OXInv):find("start") then fundResource = OXInv
exports[OXInv]:AddItem(src, "money", fund)
elseif GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund)
elseif GetResourceState(ESXExport):find("start") then fundResource = ESXExport
local Player = ESX.GetPlayerFromId(src)
Player.addMoney(fund, "")
end
end
if type == "bank" then
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund)
elseif GetResourceState(ESXExport):find("start") then fundResource = ESXExport
local Player = ESX.GetPlayerFromId(src)
Player.addMoney(fund, "")
end
end
if fundResource == "" then print("error - check exports.lua")
else
if Config.System.Debug then print("^6Bridge^7: ^2Funding ^2Player^7: '^2"..fund.."^7'", type, fundResource) end
end
end)
function createUseableItem(item, funct)
@@ -1109,6 +1151,7 @@ function hasJob(job, source, grade) local hasJob, duty = false, true
if ganginfo.name == job then hasJob = true
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end
end
elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then
local info = nil
Core.Functions.GetPlayerData(function(PlayerData)
@@ -1124,6 +1167,7 @@ function hasJob(job, source, grade) local hasJob, duty = false, true
hasJob = true
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end
end
else
print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3exports^1.^2lua^7")
end
@@ -1142,6 +1186,7 @@ function getPlayer(source) local Player = {}
cash = info.getMoney(),
bank = info.getAccount("bank").money,
}
elseif GetResourceState(OXCoreExport):find("start") then
local file = ('imports/%s.lua'):format('server')
local import = LoadResourceFile('ox_core', file)
@@ -1153,6 +1198,7 @@ function getPlayer(source) local Player = {}
cash = exports[OXInv]:Search(src, 'count', "money"),
bank = 0,
}
elseif GetResourceState(QBXExport):find("start") then
local info = exports[QBXExport]:GetPlayer(src)
Player = {
@@ -1160,6 +1206,7 @@ function getPlayer(source) local Player = {}
cash = exports[OXInv]:Search(src, 'count', "money"),
bank = info.Functions.GetMoney("bank"),
}
elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then
if Core.Functions.GetPlayer ~= nil then -- support older qb-core functions
local info = Core.Functions.GetPlayer(src).PlayerData
@@ -1176,6 +1223,7 @@ function getPlayer(source) local Player = {}
bank = info.money["bank"],
}
end
else
print("^4ERROR^7: ^2No Core detected for getPlayer() ^7- ^2Check ^3exports^1.^2lua^7")
end
@@ -1221,6 +1269,60 @@ function getPlayer(source) local Player = {}
return Player
end
function sendPhoneMail(data) local phoneResource = ""
if GetResourceState("gksphone"):find("start") then phoneResource = "gksphone"
exports["gksphone"]:SendNewMail(data)
elseif GetResourceState("yflip-phone"):find("start") then phoneResource = "yflip-phone"
TriggerServerEvent(GetCurrentResourceName()..":yflip:SendMail", data)
elseif GetResourceState("qs-smartphone"):find("start") then phoneResource = "qs-smartphone"
TriggerServerEvent('qs-smartphone:server:sendNewMail', data)
elseif GetResourceState("qs-smartphone-pro"):find("start") then phoneResource = "qs-smartphone-pro"
TriggerServerEvent('phone:sendNewMail', data)
elseif GetResourceState("roadphone"):find("start") then phoneResource = "roadphone"
data.message = data.message:gsub("%<br>", "\n")
exports['roadphone']:sendMail(data)
elseif GetResourceState("lb-phone"):find("start") then phoneResource = "lb-phone"
TriggerServerEvent(GetCurrentResourceName()..":lbphone:SendMail", data)
elseif GetResourceState("qb-phone"):find("start") then phoneResource = "qb-phone"
TriggerServerEvent('qb-phone:server:sendNewMail', data)
end
if phoneResource ~= "" then if Config.System.Debug then print("^6Bridge^7[^3"..phoneResource.."^7]: ^2Sending mail to player") end
else print("^6Bridge^7: ^1ERROR ^2Sending mail to player ^7 - ^2No supported phone found") end
end
RegisterNetEvent(GetCurrentResourceName()..":lbphone:SendMail", function(data)
local src = source
local phoneNumber = exports["lb-phone"]:GetEquippedPhoneNumber(src)
local emailAddress = exports["lb-phone"]:GetEmailAddress(phoneNumber)
exports["lb-phone"]:SendMail({
to = emailAddress,
subject = data.subject,
message = data.message,
--[[attachments = {
"https://cdn.discordapp.com/attachments/1035667053115363349/1042500877426110474/upload.png",
},]]
actions = data.buttons,
})
end)
RegisterNetEvent(GetCurrentResourceName()..":yflip:SendMail", function(data)
local src = source
exports["yflip-phone"]:SendMail({
title = data.subject,
sender = data.sender,
senderDisplayName = data.sender,
content = data.message,
actions = data.buttons,
}, 'source', src)
end)
function registerCommand(command, options)
if GetResourceState(OXLibExport):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command) end
@@ -1236,11 +1338,13 @@ function invImg(item)
if item ~= "" and Items[item] then
if GetResourceState(OXInv):find("start") then
imgLink = "nui://"..OXInv.."/web/images/"..(Items[item].image or "")
elseif GetResourceState(QSInv and QSInv or ""):find("start") then
elseif GetResourceState(QSInv):find("start") then
imgLink = "nui://"..QSInv.."/html/images/"..(Items[item].image or "")
elseif GetResourceState(CoreInv and CoreInv or ""):find("start") then
elseif GetResourceState(CoreInv):find("start") then
imgLink = "nui://"..CoreInv.."/html/img/"..(Items[item].image or "")
elseif GetResourceState(QBInv and QBInv or ""):find("start") then
elseif GetResourceState(OrigenInv):find("start") then
imgLink = "nui://"..OrigenInv.."/html/img/"..(Items[item].image or "")
elseif GetResourceState(QBInv):find("start") then
imgLink = "nui://"..QBInv.."/html/images/"..(Items[item].image or "")
else
print("^4ERROR^7: ^2No Inventory detected for invImg ^7- ^2Check ^3exports^1.^2lua^7")
@@ -1249,13 +1353,13 @@ function invImg(item)
return imgLink
end
function registerStash(name, label)
function registerStash(name, label, slots, weight)
if GetResourceState(OXInv):find("start") then
--print("Registering OX Stash:", name, label)
exports[OXInv]:RegisterStash(name, label, 50, 4000000)
exports[OXInv]:RegisterStash(name, label, slots or 50, weight or 4000000)
elseif GetResourceState(QSInv):find("start") then
--print("Registering QS Stash:", name, label)
exports[QSInv]:RegisterStash(name, 50, 4000000)
exports[QSInv]:RegisterStash(name, slots or 50, weight or 4000000)
end
end
-- IN NO WAY PERFECT --
-- IN NO WAY PERFECT --