1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-08-04 04:28:47 +02:00
parent 875c8448e1
commit c81ae4bb6d
219 changed files with 8036 additions and 7 deletions

View file

@ -0,0 +1,139 @@
local Core = {}
local shared = exports["es_extended"]:getSharedObject()
local Utils = require 'utils'
local merge = Utils.table_merge
RegisterNetEvent('esx:playerLoaded', function(...)
TriggerEvent('bl_bridge:server:playerLoaded', source, ...)
end)
AddEventHandler("esx:playerLoaded", function(playerId, xPlayer)
TriggerEvent('bl_bridge:server:playerLoaded', playerId, xPlayer)
end)
AddEventHandler('esx:setAccountMoney', function(player, accountName, money)
TriggerEvent('bl_bridge:server:updateMoney', player, accountName == 'money' and 'cash' or accountName, money, 'set')
end)
AddEventHandler('esx:removeAccountMoney', function(source, accountName, money)
TriggerEvent('bl_bridge:server:updateMoney', source, accountName == 'money' and 'cash' or accountName, money, 'remove')
end)
AddEventHandler('esx:addAccountMoney', function(source, accountName, money)
TriggerEvent('bl_bridge:server:updateMoney', source, accountName == 'money' and 'cash' or accountName, money, 'add')
end)
local inventoryFunctions = Framework.inventory
local coreFunctionsOverride = {
getBalance = {
originalMethod = 'getAccount',
modifier = {
effect = function(originalFun, type)
return originalFun(type == 'cash' and 'money' or type).money
end
}
},
removeBalance = {
originalMethod = 'removeAccountMoney',
modifier = {
effect = function(originalFun, type, amount)
return originalFun(type == 'cash' and 'money' or type, amount)
end
}
},
setBalance = {
originalMethod = 'setAccountMoney',
modifier = {
effect = function(originalFun, type, amount)
return originalFun(type == 'cash' and 'money' or type, amount)
end
}
},
addBalance = {
originalMethod = 'addAccountMoney',
modifier = {
effect = function(originalFun, type, amount)
return originalFun(type == 'cash' and 'money' or type, amount)
end
}
},
setJob = {
originalMethod = 'setJob',
},
job = {
originalMethod = 'getJob',
modifier = {
executeFunc = true,
effect = function(data)
local job = data()
return {name = job.name, label = job.label, onDuty = true, isBoss = false, grade = {name = job.grade, label = job.grade_label, salary = job.grade_salary}}
end
}
},
charinfo = {
originalMethod = 'variables',
modifier = {
executeFunc = true,
effect = function(data)
return {firstname = data.firstName, lastname = data.lastName}
end
}
},
name = {
originalMethod = 'getName',
modifier = {
executeFunc = true,
}
},
id = {
originalMethod = 'identifier',
modifier = {
executeFunc = true,
effect = function(str)
return str
end
}
},
gender = {
originalMethod = 'variables',
modifier = {
executeFunc = true,
effect = function(data)
return data.sex == 'm' and 'male' or 'female'
end
}
},
dob = {
originalMethod = 'variables',
modifier = {
executeFunc = true,
effect = function(data)
local dob = data.dateofbirth
if type(dob) ~= 'string' then return end
local month, day, year = dob:match("(%d+)/(%d+)/(%d+)")
return ('%s/%s/%s'):format(month, day, year)
end
}
},
}
local totalFunctionsOverride = inventoryFunctions and merge(inventoryFunctions.methods, coreFunctionsOverride) or coreFunctionsOverride
function Core.CommandAdd(name, permission, cb, suggestion, flags)
shared.RegisterCommand(name, permission, cb, flags.allowConsole, suggestion)
end
Core.RegisterUsableItem = inventoryFunctions?.registerUsableItem or function(name, cb)
shared.RegisterUsableItem(name, cb)
end
function Core.GetPlayer(src)
local player = shared.GetPlayerFromId(src)
if not player then return end
local wrappedPlayer = Utils.retreiveStringIndexedData(player, totalFunctionsOverride, src)
return wrappedPlayer
end
Core.Players = shared.Players
return Core

View file

@ -0,0 +1,134 @@
local Core = {}
local shared = exports.ND_Core
local Utils = require 'utils'
local retreiveStringIndexedData = Utils.retreiveStringIndexedData
local merge = Utils.table_merge
local inventoryFunctions = Framework.inventory
AddEventHandler("ND:characterLoaded", function(character)
TriggerEvent('bl_bridge:server:playerLoaded', character.source, character)
end)
AddEventHandler("ND:moneyChange", function(source, account, amount, action, reason)
TriggerEvent('bl_bridge:server:updateMoney', source, account, amount, action)
end)
local playerFunctionsOverride = {
getBalance = {
originalMethod = 'getData',
modifier = {
executeFunc = true,
effect = function(data, type)
local balance = data(type)
return balance
end
}
},
removeBalance = {
originalMethod = 'deductMoney',
},
addBalance = {
originalMethod = 'addMoney',
},
setBalance = {
originalMethod = 'setMetadata',
modifier = {
effect = function(originalFun, type, amount)
return originalFun(type, amount)
end
}
},
setJob = {
originalMethod = 'setJob',
},
job = {
originalMethod = 'getJob',
modifier = {
executeFunc = true,
effect = function(originalFun)
local _, jobInfo = originalFun()
return {name = jobInfo.name, label = jobInfo.label, onDuty = jobInfo.isJob, isBoss = true, grade = {name = jobInfo.rank, label = jobInfo.rankName, salary = 0}}
end
}
},
charinfo = {
originalMethod = 'getData',
modifier = {
executeFunc = true,
effect = function(data)
return {firstname = data('firstname'), lastname = data('lastname')}
end
}
},
name = {
originalMethod = 'getData',
modifier = {
executeFunc = true,
effect = function(data)
return data('fullname')
end
}
},
id = {
originalMethod = 'getData',
modifier = {
executeFunc = true,
effect = function(data)
return data('id')
end
}
},
gender = {
originalMethod = 'getData',
modifier = {
executeFunc = true,
effect = function(data)
return string.lower(data('gender'))
end
}
},
dob = {
originalMethod = 'getData',
modifier = {
executeFunc = true,
effect = function(data)
local year, month, day = data('dob'):match("(%d+)-(%d+)-(%d+)")
return ('%s/%s/%s'):format(month, day, year) -- DD/MM/YYYY
end
}
},
}
function Core.players()
local data = {}
for k, v in ipairs(shared.getPlayers()) do
local jobInfo = v.jobInfo
data[k] = {
job = {name = jobInfo.name, label = jobInfo.label, onDuty = jobInfo.isJob, isBoss = true, grade = {name = jobInfo.rank, label = jobInfo.rankName, salary = 0}},
charinfo = { firstname = v.firstname, lastname = v.lastname }
}
end
return data
end
function Core.CommandAdd(name, permission, cb, suggestion, flags)
RegisterCommand(name, cb, permission)
end
Core.RegisterUsableItem = inventoryFunctions?.registerUsableItem
local totalFunctionsOverride = inventoryFunctions and merge(inventoryFunctions.methods, playerFunctionsOverride) or playerFunctionsOverride
function Core.GetPlayer(src)
local player = shared:getPlayer(src)
if not player then return end
local wrappedPlayer = retreiveStringIndexedData(player, totalFunctionsOverride, src)
return wrappedPlayer
end
function Core.hasPerms(...)
return false
end
return Core

View file

@ -0,0 +1,243 @@
assert(GetFramework('inventory') == 'ox_inventory', 'Needs ox_inventory')
local Core = {}
local Utils = require 'utils'
local Ox = require '@ox_core/lib/init'
local retreiveStringIndexedData = Utils.retreiveStringIndexedData
local merge = Utils.table_merge
local inventoryFunctions = Framework.inventory
local ox_inv = exports.ox_inventory
AddEventHandler('ox:playerLoaded', function(playerId, ...)
TriggerEvent('bl_bridge:server:playerLoaded', playerId, ...) -- TODO: sync event data across other framworks
end)
AddEventHandler('ox:playerLogout', function(playerId, ...)
TriggerEvent('bl_bridge:client:playerUnloaded', playerId, ...) -- TODO: sync event data across other framworks
end)
ox_inv:registerHook('swapItems', function(payload)
local toInv = payload.toInventory
local fromInv = payload.fromInventory
if toInv == fromInv then return end -- swap in same inv, means the amount will stay the same
local count = payload.count
if type(toInv) == 'number' and payload.toType == 'player' then
TriggerEvent('bl_bridge:server:updateMoney', toInv, 'cash', count, 'add')
end
if type(fromInv) == 'number' and payload.fromType == 'player' then
TriggerEvent('bl_bridge:server:updateMoney', fromInv, 'cash', count, 'remove')
end
return true
end, {
itemFilter = {
money = true,
},
})
ox_inv:registerHook('createItem', function(payload)
if type(payload.inventoryId) ~= 'number' then return end
TriggerEvent('bl_bridge:server:updateMoney', payload.inventoryId, 'cash', payload.count, 'add')
return true
end, {
itemFilter = {
money = true,
},
})
local group = {
originalMethod = 'get',
modifier = {
passSource = true,
executeFunc = true,
effect = function(get, source)
local activeGroup = get('activeGroup')
if not activeGroup then return end
local job = Ox.GetGroup(activeGroup)
if type(job) ~= 'table' then return end
local grade = Ox.GetPlayer(source).getGroup(activeGroup)
return {name = job.name, label = job.label, onDuty = true, isBoss = job.accountRoles[tostring(grade)] == 'owner', type = job.type, grade = { name = grade, label = job.grades[grade], salary = 0 } }
end
}
}
local playerFunctionsOverride = {
getBalance = {
originalMethod = 'getAccount',
modifier = {
passSource = true,
---@param getAccount function OxAccount
---@param source number
---@param moneyType MoneyType
effect = function(getAccount, source, moneyType)
return moneyType == 'cash' and ox_inv:GetItemCount(source, 'money') or (getAccount()?.get('balance') or 0)
end,
}
},
removeBalance = {
originalMethod = 'getAccount',
modifier = {
passSource = true,
---@param getAccount function OxAccount
---@param source number
---@param moneyType MoneyType
---@param amount number
effect = function(getAccount, source, moneyType, amount)
if moneyType == 'bank' then
getAccount()?.removeBalance({
amount = amount
})
else
ox_inv:RemoveItem(source, 'money', amount)
end
end,
}
},
addBalance = {
originalMethod = 'getAccount',
modifier = {
passSource = true,
---@param getAccount function OxAccount
---@param source number
---@param moneyType MoneyType
---@param amount number
effect = function(getAccount, source, moneyType, amount)
if moneyType == 'bank' then
getAccount()?.addBalance({
amount = amount
})
else
ox_inv:AddItem(source, 'money', amount)
end
end,
}
},
setBalance = {
originalMethod = 'getAccount',
modifier = {
passSource = true,
---@param getAccount function OxAccount
---@param source number
---@param moneyType MoneyType
---@param amount number|string
effect = function(getAccount, source, moneyType, amount)
---@diagnostic disable-next-line: cast-local-type
amount = tonumber(amount)
if not amount then return end
local currentAmount = moneyType == 'cash' and ox_inv:GetItemCount(source, 'money') or (getAccount()?.get('balance') or 0)
if currentAmount == amount then return end
if currentAmount > amount then
if moneyType == 'cash' then
ox_inv:RemoveItem(source, 'money', currentAmount - amount)
else
getAccount()?.removeBalance({
amount = amount
})
end
else
if moneyType == 'cash' then
ox_inv:AddItem(source, 'money', amount - currentAmount)
else
getAccount()?.addBalance({
amount = amount
})
end
end
end
}
},
setJob = {
originalMethod = 'setGroup',
modifier = {
passSource = true,
---@param setGroup function
---@param source number
---@param job string
---@param grade number
effect = function(setGroup, source, job, grade)
setGroup(job, grade)
Ox.GetPlayer(source).setActiveGroup(job)
end
}
},
job = group, -- future TODO: make job and gang as groups
gang = group,
charinfo = {
originalMethod = 'get',
modifier = {
---@param get function
---@return CharInfo
effect = function(get)
return { firstname = get('firstName'), lastname = get('lastName') }
end
}
},
name = {
originalMethod = 'get',
modifier = {
---@param get function
---@return string --fullname
effect = function(get)
return ('%s %s'):format(get('firstName'), get('lastName'))
end
}
},
id = {
originalMethod = 'charId',
},
gender = {
originalMethod = 'get',
modifier = {
---@param get function
---@return string --gender
effect = function(get)
return get('gender')
end
}
},
dob = {
originalMethod = 'get',
modifier = {
---@param get function
---@return string --DD/MM/YYYY
effect = function(get)
return get('dateOfBirth')
end
}
},
}
function Core.players()
return Ox.Players
end
function Core.CommandAdd(name, permission, cb, suggestion, flags)
print('?') -- todo
end
Core.RegisterUsableItem = inventoryFunctions?.registerUsableItem or function()
print('how dare you use ox_core without ox_inventory? get a brain!')
end
local totalFunctionsOverride = inventoryFunctions and merge(inventoryFunctions.methods, playerFunctionsOverride) or
playerFunctionsOverride
function Core.GetPlayer(src)
local player = Ox.GetPlayer(src)
if not player then return end
return retreiveStringIndexedData(player, totalFunctionsOverride, src)
end
function Core.hasPerms(...)
return Ox.Functions.HasPermission(...)
end
return Core

View file

@ -0,0 +1,151 @@
local Core = {}
local shared = exports['qb-core']:GetCoreObject()
local Utils = require 'utils'
local retreiveStringIndexedData = Utils.retreiveStringIndexedData
local merge = Utils.table_merge
local inventoryFunctions = Framework.inventory
RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function(...)
TriggerEvent('bl_bridge:server:playerLoaded', source, ...)
end)
AddEventHandler('QBCore:Server:OnMoneyChange', function(src, moneyType, amount, operation, reason)
TriggerEvent('bl_bridge:server:updateMoney', src, moneyType, amount, operation)
end)
local playerFunctionsOverride = {
Functions = {
getBalance = {
originalMethod = 'GetMoney',
},
removeBalance = {
originalMethod = 'RemoveMoney',
},
addBalance = {
originalMethod = 'AddMoney',
},
setBalance = {
originalMethod = 'SetMoney',
},
setJob = {
originalMethod = 'SetJob',
},
},
PlayerData = {
job = {
originalMethod = 'job',
modifier = {
executeFunc = true,
---@param data table
---@return GroupData
effect = function(data)
local job = data
return {name = job.name, label = job.label, onDuty = job.onduty, isBoss = job.isboss, type = job.type, grade = { name = job.grade.level, label = job.grade.name, salary = job.payment } }
end
}
},
gang = {
originalMethod = 'gang',
modifier = {
executeFunc = true,
---@param data table
---@return GroupData
effect = function(data)
local gang = data
return {name = gang.name, label = gang.label, isBoss = gang.isboss, grade = {name = gang.grade.level, label = gang.grade.label}}
end
}
},
charinfo = {
originalMethod = 'charinfo',
modifier = {
executeFunc = true,
---@param data table
---@return CharInfo
effect = function(data)
return {firstname = data.firstname, lastname = data.lastname}
end
}
},
name = {
originalMethod = 'name',
},
id = {
originalMethod = 'citizenid',
},
gender = {
originalMethod = 'charinfo',
modifier = {
executeFunc = true,
---@param data {gender: number}
---@return string
effect = function(data)
local gender = data.gender
gender = gender == 1 and 'female' or 'male'
return gender
end
}
},
dob = {
originalMethod = 'charinfo',
modifier = {
executeFunc = true,
---@param data {birthdate: string}
---@return string
effect = function(data)
local year, month, day = data.birthdate:match("(%d+)-(%d+)-(%d+)")
return ('%s/%s/%s'):format(month, day, year) -- DD/MM/YYYY
end
}
},
items = {
originalMethod = 'items',
},
}
}
function Core.players()
local data = {}
for k,v in ipairs(shared.Players) do
local playerData = v.PlayerData
local job = playerData.job
local gang = playerData.gang
local charinfo = playerData.charinfo
data[k] = {
job = {name = job.name, label = job.label, onDuty = job.onduty, type = job.type, isBoss = job.isboss, grade = {name = job.grade.level, label = job.grade.name, salary = job.payment}},
gang = {name = gang.name, label = gang.label, isBoss = gang.isboss, grade = {name = gang.grade.level, label = gang.grade.label}},
charinfo = {firstname = charinfo.firstname, lastname = charinfo.lastname}
}
end
return data
end
function Core.CommandAdd(name, permission, cb, suggestion, flags)
if type(name) == 'table' then
for _,command in ipairs(name) do
shared.Commands.Add(command, suggestion.help, suggestion.arguments, flags.argsrequired, cb, permission)
end
return
end
shared.Commands.Add(name, suggestion.help, suggestion.arguments, flags.argsrequired, cb, permission)
end
Core.RegisterUsableItem = inventoryFunctions and inventoryFunctions.registerUsableItem or function(name, cb)
shared.Functions.CreateUseableItem(name, function(source, item)
cb(source, item and item.slot, item and item.info)
end)
end
local totalFunctionsOverride = inventoryFunctions and merge(inventoryFunctions.methods, playerFunctionsOverride) or playerFunctionsOverride
function Core.GetPlayer(src)
local player = shared.Functions.GetPlayer(src)
if not player then return end
return retreiveStringIndexedData(player, totalFunctionsOverride, src)
end
function Core.hasPerms(...)
return shared.Functions.HasPermission(...)
end
return Core

View file

@ -0,0 +1,134 @@
local Core = {}
local Utils = require 'utils'
local retreiveStringIndexedData = Utils.retreiveStringIndexedData
local merge = Utils.table_merge
local inventoryFunctions = Framework.inventory
RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function(...)
TriggerEvent('bl_bridge:server:playerLoaded', source, ...)
end)
AddEventHandler('QBCore:Server:OnMoneyChange', function(src, moneyType, amount, operation, reason)
TriggerEvent('bl_bridge:server:updateMoney', src, moneyType, amount, operation)
end)
local playerFunctionsOverride = {
Functions = {
getBalance = {
originalMethod = 'GetMoney',
},
removeBalance = {
originalMethod = 'RemoveMoney',
},
addBalance = {
originalMethod = 'AddMoney',
},
setBalance = {
originalMethod = 'SetMoney',
},
setJob = {
originalMethod = 'SetJob',
},
},
PlayerData = {
job = {
originalMethod = 'job',
modifier = {
executeFunc = true,
effect = function(originalFun)
local job = originalFun
return {name = job.name, label = job.label, onDuty = job.onduty, isBoss = job.isboss, type = job.type, grade = { name = job.grade.level, label = job.grade.name, salary = job.payment } }
end
}
},
gang = {
originalMethod = 'gang',
modifier = {
executeFunc = true,
effect = function(data)
local gang = data
return {name = gang.name, label = gang.label, isBoss = gang.isboss, grade = {name = gang.grade.level, label = gang.grade.label}}
end
}
},
charinfo = {
originalMethod = 'charinfo',
modifier = {
executeFunc = true,
effect = function(data)
return {firstname = data.firstname, lastname = data.lastname}
end
}
},
name = {
originalMethod = 'name',
},
id = {
originalMethod = 'citizenid',
},
gender = {
originalMethod = 'charinfo',
modifier = {
executeFunc = true,
effect = function(data)
local gender = data.gender
gender = gender == 1 and 'female' or 'male'
return gender
end
}
},
dob = {
originalMethod = 'charinfo',
modifier = {
executeFunc = true,
effect = function(data)
local year, month, day = data.birthdate:match("(%d+)-(%d+)-(%d+)")
return ('%s/%s/%s'):format(month, day, year) -- DD/MM/YYYY
end
}
},
items = {
originalMethod = 'items',
},
}
}
function Core.players()
local data = {}
for k,v in ipairs(exports.qbx_core:GetQBPlayers()) do
local playerData = v.PlayerData
local job = playerData.job
local gang = playerData.gang
local charinfo = playerData.charinfo
data[k] = {
job = {name = job.name, label = job.label, onDuty = job.onduty, type = job.type, isBoss = job.isboss, grade = {name = job.grade.level, label = job.grade.name, salary = job.payment}},
gang = {name = gang.name, label = gang.label, isBoss = gang.isboss, grade = {name = gang.grade.level, label = gang.grade.label}},
charinfo = {firstname = charinfo.firstname, lastname = charinfo.lastname}
}
end
return data
end
function Core.CommandAdd(name, permission, cb, suggestion, flags)
RegisterCommand(name, cb, permission)
end
Core.RegisterUsableItem = inventoryFunctions?.registerUsableItem or function(name, cb)
exports.qbx_core:CreateUseableItem(name, function(source, item)
cb(source, item and item.slot, item and item.info)
end)
end
local totalFunctionsOverride = inventoryFunctions and merge(inventoryFunctions.methods, playerFunctionsOverride) or playerFunctionsOverride
function Core.GetPlayer(src)
local player = exports.qbx_core:GetPlayer(src)
if not player then return end
return retreiveStringIndexedData(player, totalFunctionsOverride, src)
end
function Core.hasPerms(...)
return exports.qbx_core:HasPermission(...)
end
return Core

View file

@ -0,0 +1,29 @@
local overrideFunction = {}
overrideFunction.methods = {
addItem = {
originalMethod = 'addInventoryItem',
},
removeItem = {
originalMethod = 'removeInventoryItem',
},
getItem = {
originalMethod = 'getInventoryItem',
},
setMetaData = { -- not exist :()
},
canCarryItem = {
originalMethod = 'canCarryItem',
},
items = {
originalMethod = 'getInventory',
modifier = {
effect = function(originalFun)
return originalFun.items
end
}
},
}
return overrideFunction

View file

@ -0,0 +1,67 @@
local retreiveExportsData = require 'utils'.retreiveExportsData
local overrideFunction = {}
local origen_inventory = exports.origen_inventory
overrideFunction.methods = retreiveExportsData(origen_inventory, {
addItem = {
originalMethod = 'addItem',
modifier = {
passSource = true,
}
},
removeItem = {
originalMethod = 'removeItem',
modifier = {
passSource = true,
effect = function(originalFun, source, name, count, slot)
return originalFun(source, name, count, nil, slot)
end,
}
},
setMetaData = {
originalMethod = 'setMetadata',
modifier = {
passSource = true,
}
},
canCarryItem = {
originalMethod = 'canCarryItem',
modifier = {
passSource = true,
}
},
getItem = {
originalMethod = 'getItem',
modifier = {
passSource = true,
}
},
items = {
originalMethod = 'getItems',
modifier = {
executeFunc = true,
passSource = true,
}
},
})
function overrideFunction.registerUsableItem(name, cb)
exports.origen_inventory:CreateUseableItem(name, function(source, item)
cb(source, item and item.slot, item and item.info)
end)
end
function overrideFunction.registerInventory(id, data)
local type, name, items in data
if type == 'shop' and origen_inventory.registerShop then
origen_inventory:registerShop(id, {
name = name or 'Shop',
inventory = items or {},
})
elseif type == 'stash' then
local maxWeight, slots in data
origen_inventory:registerStash(id, name or 'Stash', slots or 10, maxWeight or 20000)
end
end
return overrideFunction

View file

@ -0,0 +1,73 @@
local retreiveExportsData = require 'utils'.retreiveExportsData
local overrideFunction = {}
local ox_inventory = exports.ox_inventory
overrideFunction.methods = retreiveExportsData(ox_inventory, {
addItem = {
originalMethod = 'AddItem',
modifier = {
passSource = true,
}
},
removeItem = {
originalMethod = 'RemoveItem',
modifier = {
passSource = true,
effect = function(originalFun, source, name, count, slot)
return originalFun(source, name, count, nil, slot)
end,
}
},
setMetaData = {
originalMethod = 'SetMetadata',
modifier = {
passSource = true,
}
},
canCarryItem = {
originalMethod = 'CanCarryItem',
modifier = {
passSource = true,
}
},
getItem = {
originalMethod = 'GetSlotWithItem',
modifier = {
passSource = true,
}
},
items = {
originalMethod = 'GetInventoryItems',
modifier = {
executeFunc = true,
passSource = true,
}
},
})
local registeredItems = {}
AddEventHandler('ox_inventory:usedItem', function(playerId, itemName, slotId, metadata)
local itemEffect = registeredItems[itemName]
if not itemEffect then return end
itemEffect(playerId, slotId, metadata)
end)
function overrideFunction.registerUsableItem(name, cb)
registeredItems[name] = cb
end
function overrideFunction.registerInventory(id, data)
local type, name, items in data
if type == 'shop' then
ox_inventory:RegisterShop(id, {
name = name or 'Shop',
inventory = items or {},
})
elseif type == 'stash' then
local maxWeight, slots in data
ox_inventory:RegisterStash(id, name or 'Stash', slots or 10, maxWeight or 20000)
end
end
return overrideFunction

View file

@ -0,0 +1,118 @@
local utils = require 'utils'
local retreiveExportsData = utils.retreiveExportsData
local overrideFunction = {}
local registeredInventories = {}
local inventoryName = GetFramework('inventory')
local inventory = exports[inventoryName]
overrideFunction.methods = retreiveExportsData(inventory, {
addItem = {
originalMethod = 'AddItem',
modifier = {
passSource = true,
effect = function(originalFun, src, name, amount, metadata, slot)
TriggerClientEvent('inventory:client:ItemBox', src, name, "add", amount)
TriggerClientEvent('qb-inventory:client:ItemBox', src, name, "add", amount)
return originalFun(src, name, amount, slot, metadata)
end
}
},
removeItem = {
originalMethod = 'RemoveItem',
modifier = {
passSource = true,
effect = function(originalFun, src, name, amount, slot)
TriggerClientEvent('inventory:client:ItemBox', src, name, "remove", amount)
TriggerClientEvent('qb-inventory:client:ItemBox', src, name, "remove", amount)
return originalFun(src, name, amount, slot)
end
}
},
setMetaData = {
originalMethod = 'SetItemData',
modifier = {
passSource = true,
effect = function(originalFun, src, slot, data)
local item = inventory:GetItemBySlot(src, slot)
if not item then return end
if type(data) ~= 'table' then return end
originalFun(src, item.name, 'info', data)
end
}
},
canCarryItem = {
originalMethod = inventoryName == 'qb-inventory' and inventory.CanAddItem and 'CanAddItem' or 'HasItem',
modifier = {
passSource = true,
}
},
getItem = {
originalMethod = 'GetItemByName',
modifier = {
passSource = true,
effect = function(originalFun, src, itemName)
local data = originalFun(src, itemName)
if not data then
return false, 'Item not exist or you don\'t have it'
end
return {
label = data.label,
name = data.name,
weight = data.weight,
slot = data.slot,
close = data.shouldClose,
stack = not data.unique,
metadata = data.info ~= '' and data.info or {},
count = data.amount or 1
}
end
}
},
})
function overrideFunction.registerInventory(id, data)
local type, name, items, slots, maxWeight in data
for k,v in ipairs(items or {}) do
v.amount = v.amount or 1
v.slot = k
end
registeredInventories[('%s-%s'):format(type, id)] = {
label = name,
items = items,
slots = slots or #items,
maxweight = maxWeight
}
if type == 'shop' and inventory.CreateShop then
inventory:CreateShop({
name = name,
label = name,
slots = slots or #items,
items = items
})
end
end
utils.register('bl_bridge:validInventory', function(src, invType, invId)
local inventoryData = registeredInventories[('%s-%s'):format(invType, invId)]
if not inventoryData then return end
local isShop = invType == 'shop'
if isShop and inventory.OpenShop then
return inventory:OpenShop(src, inventoryData.label)
elseif not isShop and inventory.OpenInventory then
return inventory:OpenInventory(src, inventoryData.label, {
label = inventoryData.label,
slots = inventoryData.slots,
maxweight = inventoryData.maxweight,
})
end
return inventoryData
end)
return overrideFunction

View file

@ -0,0 +1,93 @@
local utils = require 'utils'
local retreiveExportsData = utils.retreiveExportsData
local overrideFunction = {}
local registeredInventories = {}
local qs_inventory = exports['qs-inventory']
overrideFunction.methods = retreiveExportsData(qs_inventory, {
addItem = {
originalMethod = 'AddItem',
modifier = {
passSource = true,
effect = function(originalFun, src, name, amount, metadata, slot)
return originalFun(src, name, amount, slot, metadata)
end
}
},
removeItem = {
originalMethod = 'RemoveItem',
modifier = {
passSource = true,
}
},
setMetaData = {
originalMethod = 'SetItemMetadata',
modifier = {
passSource = true,
}
},
canCarryItem = {
originalMethod = 'CanCarryItem',
modifier = {
passSource = true,
}
},
getItem = {
originalMethod = 'GetItemByName',
modifier = {
passSource = true, -- Src doesn't actually seem to be passed to originalFunc
effect = function(originalFunc, src, itemName)
local data = originalFunc(src, itemName)
if not data then
return false, 'Item does not exist or you don\'t have it'
end
return {
label = data.label,
name = data.name,
weight = data.weight,
slot = data.slot,
close = data.shouldClose,
stack = not data.unique,
metadata = data.info ~= '' and data.info or {},
count = data.amount or 1
}
end
}
},
items = {
originalMethod = 'GetInventory',
modifier = {
passSource = true,
}
},
})
function overrideFunction.registerInventory(id, data)
local type, name, items, slots, maxWeight in data
for k,v in ipairs(items) do
v.amount = v.amount or 10
v.slot = k
end
registeredInventories[('%s-%s'):format(type, id)] = {
label = name,
items = items,
slots = slots or #items,
maxweight = maxWeight
}
end
function overrideFunction.registerUsableItem(name, cb)
qs_inventory:CreateUsableItem(name, function(source, item)
cb(source, item and item.slot, item and item.info)
end)
end
utils.register('bl_bridge:validInventory', function(_, invType, invId)
local inventory = registeredInventories[('%s-%s'):format(invType, invId)]
if not inventory then return end
return inventory
end)
return overrideFunction

View file

@ -0,0 +1,11 @@
---@diagnostic disable: lowercase-global
---@param source number Source of player
---@param data NotificationParams Notification data
function notify(source, data)
local title, type, duration in data
if type == 'inform' then type = 'info' end
TriggerClientEvent('esx:showNotification', source, title, type, duration)
end
return notify

View file

@ -0,0 +1,9 @@
---@diagnostic disable: lowercase-global
---@param source number Source of player
---@param data NotificationParams Notification data
local function notify(source, data)
TriggerClientEvent('ox_lib:notify', source, data)
end
return notify

View file

@ -0,0 +1,11 @@
---@diagnostic disable: lowercase-global
---@param source number Source of player
---@param data NotificationParams Notification data
function notify(source, data)
local title, type, duration in data
if type == 'inform' then type = 'info' end
TriggerClientEvent('QBCore:Notify', source, title, type, duration)
end
return notify