Compare commits

..

5 Commits

Author SHA1 Message Date
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
5 changed files with 181 additions and 15 deletions

View File

@@ -33,6 +33,15 @@ function craftingMenu(data)
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, hasjob = {}, false local Menu, hasjob = {}, false
local Recipes = data.craftable.Recipes local Recipes = data.craftable.Recipes
local tempCarryTable = {}
for i = 1, #Recipes 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 for i = 1, #Recipes do
if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end
for k, v in pairs(Recipes[i]) do for k, v in pairs(Recipes[i]) do
@@ -51,14 +60,21 @@ function craftingMenu(data)
itemTable[l] = b itemTable[l] = b
Wait(0) Wait(0)
end end
while not canCarryTable do Wait(0) end
print(json.encode(canCarryTable, {indent = true}))
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 then disable = not stashhasItem(stashItems, itemTable)
else disable = not hasItem(itemTable) end else disable = not hasItem(itemTable) end
setheader = (Items[tostring(k)] and Items[tostring(k)].label or "error - "..tostring(k))..(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] = { Menu[#Menu + 1] = {
isMenuHeader = disable, isMenuHeader = disable or not canCarryTable[k],
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 multiCraft(transdata) else makeItem(transdata) end if Config.Crafting.MultiCraft then multiCraft(transdata) else makeItem(transdata) end
@@ -174,7 +190,6 @@ end
RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMake, craftable, stashName) RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMake, craftable, stashName)
local src, amount, stashItems = source, craftable and craftable.amount or 1, stashName and getStash(stashName) local src, amount, stashItems = source, craftable and craftable.amount or 1, stashName and getStash(stashName)
if stashName then if stashName then
local itemRemove = {} local itemRemove = {}
for k, v in pairs(craftable[ItemMake] or {}) do for k, v in pairs(craftable[ItemMake] or {}) do
@@ -448,3 +463,61 @@ function stashhasItem(stashItems, items, amount)
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 v.hasItem == false then return false, hasTable end end
return true, hasTable return true, hasTable
end 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)
print("checking if player can carry")
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

View File

@@ -10,18 +10,51 @@ end
local time = 100 local time = 100
function loadModel(model) function loadModel(model)
if not HasModelLoaded(model) then if Config.System.Debug then print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'") end if not IsModelValid(model) then print("^6Bridge^7: ^1ERROR^7: ^2Model^7 - '^6"..model.."^7' ^2does not exist in server") return
while not HasModelLoaded(model) do if time > 0 then time -= 1 RequestModel(model) else
else time = 1000 print("^6Bridge^7: ^3LoadModel^7: ^2Timed out loading model ^7'^6"..model.."^7'") break end if not HasModelLoaded(model) then
Wait(10) end if Config.System.Debug then
print("^6Bridge^7: ^2Loading Model^7: '^6"..model.."^7'")
end
if lib then lib.requestModel(model, time)
else while not HasModelLoaded(model) and time > 0 do time -= 1 end end
if not HasModelLoaded(model) then time = 100 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
if lib then lib.requestAnimDict(animDict, 100)
else while not HasAnimDictLoaded(animDict) do RequestAnimDict(animDict) Wait(5) end 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
if not HasNamedPtfxAssetLoaded(ptFxName) then
print("^6Bridge^7: ^2Loading Ptfx Dictionary^7: '^6"..ptFxName.."^7'")
end
end
if lib then lib.requestNamedPtfxAsset(ptFxName, 100)
else while not HasNamedPtfxAssetLoaded(ptFxName) do RequestNamedPtfxAsset(ptFxName) Wait(5) end end
end 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 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
if lib then lib.requestStreamedTextureDict(textureDict, timeout)
else while not HasStreamedTextureDictLoaded(dict) do RequestNamedPtfxAsset(dict) Wait(5) end end
end
end
function countTable(table) local i = 0 for keys in pairs(table) do i += 1 end return i end function countTable(table) local i = 0 for keys in pairs(table) do i += 1 end return i end

View File

@@ -1,6 +1,6 @@
name "Jim_Bridge" name "Jim_Bridge"
author "Jimathy" author "Jimathy"
version "1.0.9" version "1.0.10"
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.9 1.0.10

View File

@@ -1124,6 +1124,7 @@ function hasJob(job, source, grade) local hasJob, duty = false, true
if ganginfo.name == job then hasJob = true if ganginfo.name == job then hasJob = true
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end if grade and not (grade <= ganginfo.grade.level) then hasJob = false end
end end
elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then
local info = nil local info = nil
Core.Functions.GetPlayerData(function(PlayerData) Core.Functions.GetPlayerData(function(PlayerData)
@@ -1139,6 +1140,7 @@ function hasJob(job, source, grade) local hasJob, duty = false, true
hasJob = true hasJob = true
if grade and not (grade <= ganginfo.grade.level) then hasJob = false end if grade and not (grade <= ganginfo.grade.level) then hasJob = false end
end end
else else
print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3exports^1.^2lua^7")
end end
@@ -1157,6 +1159,7 @@ function getPlayer(source) local Player = {}
cash = info.getMoney(), cash = info.getMoney(),
bank = info.getAccount("bank").money, bank = info.getAccount("bank").money,
} }
elseif GetResourceState(OXCoreExport):find("start") then elseif GetResourceState(OXCoreExport):find("start") then
local file = ('imports/%s.lua'):format('server') local file = ('imports/%s.lua'):format('server')
local import = LoadResourceFile('ox_core', file) local import = LoadResourceFile('ox_core', file)
@@ -1168,6 +1171,7 @@ function getPlayer(source) local Player = {}
cash = exports[OXInv]:Search(src, 'count', "money"), cash = exports[OXInv]:Search(src, 'count', "money"),
bank = 0, bank = 0,
} }
elseif GetResourceState(QBXExport):find("start") then elseif GetResourceState(QBXExport):find("start") then
local info = exports[QBXExport]:GetPlayer(src) local info = exports[QBXExport]:GetPlayer(src)
Player = { Player = {
@@ -1175,6 +1179,7 @@ function getPlayer(source) local Player = {}
cash = exports[OXInv]:Search(src, 'count', "money"), cash = exports[OXInv]:Search(src, 'count', "money"),
bank = info.Functions.GetMoney("bank"), bank = info.Functions.GetMoney("bank"),
} }
elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then elseif GetResourceState(QBExport):find("start") and not GetResourceState(QBXExport):find("start") then
if Core.Functions.GetPlayer ~= nil then -- support older qb-core functions if Core.Functions.GetPlayer ~= nil then -- support older qb-core functions
local info = Core.Functions.GetPlayer(src).PlayerData local info = Core.Functions.GetPlayer(src).PlayerData
@@ -1191,6 +1196,7 @@ function getPlayer(source) local Player = {}
bank = info.money["bank"], bank = info.money["bank"],
} }
end end
else else
print("^4ERROR^7: ^2No Core detected for getPlayer() ^7- ^2Check ^3exports^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for getPlayer() ^7- ^2Check ^3exports^1.^2lua^7")
end end
@@ -1236,6 +1242,60 @@ function getPlayer(source) local Player = {}
return Player return Player
end 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) function registerCommand(command, options)
if GetResourceState(OXLibExport):find("start") then if GetResourceState(OXLibExport):find("start") then
if Config.System.Debug then print("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command) end if Config.System.Debug then print("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command) end