mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-19 06:46:04 +01:00
(Beta) Fixes for multiframework support
This commit is contained in:
@@ -50,6 +50,17 @@ function onPlayerLoaded(func, onStart)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--trying to add unload functions for when players switch ped
|
||||||
|
function onPlayerUnload(func)
|
||||||
|
AddEventHandler('QBCore:Client:OnPlayerUnload', function()
|
||||||
|
func()
|
||||||
|
end)
|
||||||
|
AddEventHandler('ox:playerLogout', function()
|
||||||
|
func()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Executes a function when the resource starts.
|
--- Executes a function when the resource starts.
|
||||||
---
|
---
|
||||||
--- This function wraps the `onResourceStart` event, allowing you to execute code when the resource starts.
|
--- This function wraps the `onResourceStart` event, allowing you to execute code when the resource starts.
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ local itemResource, jobResource, vehResource = "", "", ""
|
|||||||
-- Load item lists --
|
-- Load item lists --
|
||||||
-- Complies the items from ox_inventory, qb-core or esx into 'Items' and loads them in a layout similar to qb-core's Shared items.lua --
|
-- Complies the items from ox_inventory, qb-core or esx into 'Items' and loads them in a layout similar to qb-core's Shared items.lua --
|
||||||
-- For example this makes it so instead of QBCore.Shared.Items[item], you can load 'Item[item]' in the script --
|
-- For example this makes it so instead of QBCore.Shared.Items[item], you can load 'Item[item]' in the script --
|
||||||
if isStarted(OXInv) then itemResource = OXInv
|
if isStarted(OXInv) then
|
||||||
|
itemResource = OXInv
|
||||||
Items = exports[OXInv]:Items()
|
Items = exports[OXInv]:Items()
|
||||||
for k, v in pairs(Items) do
|
for k, v in pairs(Items) do
|
||||||
if v.client and v.client.image then
|
if v.client and v.client.image then
|
||||||
@@ -39,7 +40,8 @@ if isStarted(OXInv) then itemResource = OXInv
|
|||||||
Items[k].thirst = v.client and v.client.thirst or nil
|
Items[k].thirst = v.client and v.client.thirst or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif isStarted(QBExport) then itemResource = QBExport
|
elseif isStarted(QBExport) then
|
||||||
|
itemResource = QBExport
|
||||||
Core = Core or exports[QBExport]:GetCoreObject()
|
Core = Core or exports[QBExport]:GetCoreObject()
|
||||||
Items = Core and Core.Shared.Items or nil
|
Items = Core and Core.Shared.Items or nil
|
||||||
if isStarted(QBExport) and not isStarted(QBXExport) then
|
if isStarted(QBExport) and not isStarted(QBXExport) then
|
||||||
@@ -49,17 +51,42 @@ elseif isStarted(QBExport) then itemResource = QBExport
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif isStarted(ESXExport) then itemResource = ESXExport
|
elseif isStarted(ESXExport) then
|
||||||
|
itemResource = ESXExport
|
||||||
ESX = exports[ESXExport]:getSharedObject()
|
ESX = exports[ESXExport]:getSharedObject()
|
||||||
Items = ESX and ESX.Items or nil
|
--Items = ESX and ESX.Items or nil
|
||||||
|
while ESX == nil do
|
||||||
|
print("Waiting for ESX")
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
if isServer() then
|
||||||
|
Items = ESX.GetItems()
|
||||||
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource)
|
||||||
|
end
|
||||||
|
CreateThread(function()
|
||||||
|
while not ESX do Wait(0) end
|
||||||
|
if isServer() then
|
||||||
|
createCallback(getScript()..":getItems", function(source)
|
||||||
|
return Items
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
if not isServer() then
|
||||||
|
Items = triggerCallback(getScript()..":getItems")
|
||||||
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
-- If it fails to load items, then it will print the error below --
|
-- If it fails to load items, then it will print the error below --
|
||||||
-- If it loads them and debug is on, print how many items and where from --
|
-- If it loads them and debug is on, print how many items and where from --
|
||||||
|
if not isStarted(ESXExport) then
|
||||||
if not Items then
|
if not Items then
|
||||||
print("^4ERROR^7: ^2No Core Items detected ^7- ^2Check ^3exports^1.^2lua^7")
|
print("^4ERROR^7: ^2No Core Items detected ^7- ^2Check ^3exports^1.^2lua^7")
|
||||||
else
|
else
|
||||||
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource)
|
debugPrint("^6Bridge^7: ^2Loading ^6"..countTable(Items).." ^3Items^2 from ^7" .. itemResource)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Load Vehicles --
|
-- Load Vehicles --
|
||||||
-- Complies the vehicles from the detected frameworks into a table in the style of qb-cores shared vehicles.lua --
|
-- Complies the vehicles from the detected frameworks into a table in the style of qb-cores shared vehicles.lua --
|
||||||
|
|||||||
@@ -358,6 +358,24 @@ function DrawText3D(coord, text, highlight)
|
|||||||
ClearDrawOrigin()
|
ClearDrawOrigin()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- readd missing function for drawtext
|
||||||
|
function GetLineCountAndMaxLength(text)
|
||||||
|
local lineCount = 0
|
||||||
|
local maxLength = 0
|
||||||
|
for line in text:gmatch("[^\n]+") do
|
||||||
|
lineCount = lineCount + 1
|
||||||
|
local lineLength = string.len(line)
|
||||||
|
if lineLength > maxLength then
|
||||||
|
maxLength = lineLength
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- If there are no newline characters (or text is empty), treat it as a single line.
|
||||||
|
if lineCount == 0 then
|
||||||
|
lineCount = 1
|
||||||
|
end
|
||||||
|
return lineCount, maxLength
|
||||||
|
end
|
||||||
|
|
||||||
--- Displays a help message on the screen.
|
--- Displays a help message on the screen.
|
||||||
---
|
---
|
||||||
--- @param text string The text to display as a help message.
|
--- @param text string The text to display as a help message.
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ function createInput(title, opts)
|
|||||||
if opts[i].type == "number" then
|
if opts[i].type == "number" then
|
||||||
options[i] = {
|
options[i] = {
|
||||||
type = "number",
|
type = "number",
|
||||||
label = opts[i].text..(opts[i].txt and " - "..opts[i].txt or ""),
|
label = (opts[i].label or opts[i].text)..(opts[i].txt and " - "..opts[i].txt or ""),
|
||||||
isRequired = opts[i].isRequired,
|
isRequired = opts[i].isRequired,
|
||||||
name = opts[i].name,
|
name = opts[i].name,
|
||||||
options = opts[i].options,
|
options = opts[i].options,
|
||||||
@@ -85,14 +85,10 @@ function createInput(title, opts)
|
|||||||
end
|
end
|
||||||
dialog = exports[OXLibExport]:inputDialog(title, options)
|
dialog = exports[OXLibExport]:inputDialog(title, options)
|
||||||
return dialog
|
return dialog
|
||||||
end
|
elseif Config.System.Menu == "qb" then
|
||||||
|
|
||||||
if Config.System.Menu == "qb" then
|
|
||||||
dialog = exports['qb-input']:ShowInput({ header = title, submitText = "Accept", inputs = opts })
|
dialog = exports['qb-input']:ShowInput({ header = title, submitText = "Accept", inputs = opts })
|
||||||
return dialog
|
return dialog
|
||||||
end
|
elseif Config.System.Menu == "gta" then
|
||||||
|
|
||||||
if Config.System.Menu == "gta" then
|
|
||||||
WarMenu.CreateMenu(tostring(opts),
|
WarMenu.CreateMenu(tostring(opts),
|
||||||
title,
|
title,
|
||||||
" ",
|
" ",
|
||||||
@@ -152,5 +148,44 @@ function createInput(title, opts)
|
|||||||
end
|
end
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
|
elseif Config.System.Menu == "esx" then -- horrible input dialog, not even worth using, get OX
|
||||||
|
|
||||||
|
local results = {}
|
||||||
|
for i, opt in ipairs(opts) do
|
||||||
|
local prompt = opt.text or opt.label or "Enter value"
|
||||||
|
-- For radio/select types, append available options in the prompt.
|
||||||
|
if (opt.type == "radio" or opt.type == "select") and opt.options then
|
||||||
|
local choices = ""
|
||||||
|
for j, choice in ipairs(opt.options) do
|
||||||
|
choices = choices .. choice.text .. " (" .. tostring(choice.value) .. ")"
|
||||||
|
if j < #opt.options then choices = choices .. ", " end
|
||||||
|
end
|
||||||
|
prompt = prompt .. " [" .. choices .. "]"
|
||||||
|
elseif opt.type == "number" then
|
||||||
|
prompt = prompt .. " (number between " .. (opt.min or 0) .. " and " .. (opt.max or 100) .. ")"
|
||||||
|
end
|
||||||
|
|
||||||
|
local value = nil
|
||||||
|
ESX.UI.Menu.Open('dialog', getScript(), 'input_' .. i, {
|
||||||
|
title = prompt
|
||||||
|
}, function(data, menu)
|
||||||
|
value = data.value
|
||||||
|
menu.close()
|
||||||
|
end, function(data, menu)
|
||||||
|
menu.close()
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Wait until the player submits a value.
|
||||||
|
while value == nil do
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Convert to a number if needed.
|
||||||
|
if opt.type == "number" then
|
||||||
|
value = tonumber(value)
|
||||||
|
end
|
||||||
|
results[opt.name or i] = value
|
||||||
|
end
|
||||||
|
return results
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -475,6 +475,18 @@ function getPlayer(source)
|
|||||||
name = info.getName(),
|
name = info.getName(),
|
||||||
cash = info.getMoney(),
|
cash = info.getMoney(),
|
||||||
bank = info.getAccount("bank").money,
|
bank = info.getAccount("bank").money,
|
||||||
|
|
||||||
|
firstname = info.variables.firstName,
|
||||||
|
lastname = info.variables.lastName,
|
||||||
|
|
||||||
|
source = info.source,
|
||||||
|
job = info.job.name,
|
||||||
|
--jobBoss = info.job.isboss,
|
||||||
|
--gang = info.gang.name,
|
||||||
|
--gangBoss = info.gang.isboss,
|
||||||
|
onDuty = info.job.onDuty,
|
||||||
|
--account = info.charinfo.account,
|
||||||
|
--citizenId = info.citizenid,
|
||||||
}
|
}
|
||||||
|
|
||||||
elseif isStarted(OXCoreExport) then
|
elseif isStarted(OXCoreExport) then
|
||||||
@@ -492,9 +504,19 @@ function getPlayer(source)
|
|||||||
elseif isStarted(QBXExport) then
|
elseif isStarted(QBXExport) then
|
||||||
local info = exports[QBXExport]:GetPlayer(src)
|
local info = exports[QBXExport]:GetPlayer(src)
|
||||||
Player = {
|
Player = {
|
||||||
|
firstname = info.PlayerData.charinfo.firstname,
|
||||||
|
lastname = info.PlayerData.charinfo.lastname,
|
||||||
name = info.PlayerData.charinfo.firstname.." "..info.PlayerData.charinfo.lastname,
|
name = info.PlayerData.charinfo.firstname.." "..info.PlayerData.charinfo.lastname,
|
||||||
cash = exports[OXInv]:Search(src, 'count', "money"),
|
cash = exports[OXInv]:Search(src, 'count', "money"),
|
||||||
bank = info.Functions.GetMoney("bank"),
|
bank = info.Functions.GetMoney("bank"),
|
||||||
|
source = info.PlayerData.source,
|
||||||
|
job = info.PlayerData.job.name,
|
||||||
|
jobBoss = info.PlayerData.job.isboss,
|
||||||
|
gang = info.PlayerData.gang.name,
|
||||||
|
gangBoss = info.PlayerData.gang.isboss,
|
||||||
|
onDuty = info.PlayerData.job.onduty,
|
||||||
|
account = info.PlayerData.charinfo.account,
|
||||||
|
citizenId = info.PlayerData.citizenid,
|
||||||
}
|
}
|
||||||
|
|
||||||
elseif isStarted(QBExport) and not isStarted(QBXExport) then
|
elseif isStarted(QBExport) and not isStarted(QBXExport) then
|
||||||
@@ -541,13 +563,26 @@ function getPlayer(source)
|
|||||||
else
|
else
|
||||||
if isStarted(ESXExport) and ESX ~= nil then
|
if isStarted(ESXExport) and ESX ~= nil then
|
||||||
local info = ESX.GetPlayerData()
|
local info = ESX.GetPlayerData()
|
||||||
|
--jsonPrint(info)
|
||||||
local cash, bank = 0, 0
|
local cash, bank = 0, 0
|
||||||
for k, v in pairs(ESX.GetPlayerData().accounts) do
|
for k, v in pairs(ESX.GetPlayerData().accounts) do
|
||||||
if v.name == "money" then cash = v.money end
|
if v.name == "money" then cash = v.money end
|
||||||
if v.name == "bank" then bank = v.money end
|
if v.name == "bank" then bank = v.money end
|
||||||
end
|
end
|
||||||
Player = {
|
Player = {
|
||||||
name = ('%s %s'):format(info.firstName, info.lastName),
|
firstname = info.firstName,
|
||||||
|
lastname = info.lastName,
|
||||||
|
|
||||||
|
source = GetPlayerServerId(PlayerId()),
|
||||||
|
job = info.job.name,
|
||||||
|
--jobBoss = info.job.isboss,
|
||||||
|
--gang = info.gang.name,
|
||||||
|
--gangBoss = info.gang.isboss,
|
||||||
|
onDuty = info.job.onDuty,
|
||||||
|
--account = info.charinfo.account,
|
||||||
|
--citizenId = info.citizenid,
|
||||||
|
|
||||||
|
name = info.firstName.." "..info.lastName,
|
||||||
cash = cash,
|
cash = cash,
|
||||||
bank = bank,
|
bank = bank,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ local targetEntities = {}
|
|||||||
function createEntityTarget(entity, opts, dist)
|
function createEntityTarget(entity, opts, dist)
|
||||||
targetEntities[#targetEntities + 1] = entity
|
targetEntities[#targetEntities + 1] = entity
|
||||||
local entityCoords = GetEntityCoords(entity)
|
local entityCoords = GetEntityCoords(entity)
|
||||||
if Config.System.DontUseTarget then
|
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
|
||||||
debugPrint("^6Bridge^7: ^2Creating new ^3Entity^2 target with ^6DrawText ^7"..entity)
|
debugPrint("^6Bridge^7: ^2Creating new ^3Entity^2 target with ^6DrawText ^7"..entity)
|
||||||
local existingTarget = nil
|
local existingTarget = nil
|
||||||
for key, target in pairs(TextTargets) do
|
for key, target in pairs(TextTargets) do
|
||||||
@@ -138,7 +138,7 @@ local boxTargets = {}
|
|||||||
--- }, 1.5)
|
--- }, 1.5)
|
||||||
--- ```
|
--- ```
|
||||||
function createBoxTarget(data, opts, dist)
|
function createBoxTarget(data, opts, dist)
|
||||||
if Config.System.DontUseTarget then
|
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
|
||||||
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6DrawText ^7"..data[1])
|
debugPrint("^6Bridge^7: ^2Creating new ^3Box^2 target with ^6DrawText ^7"..data[1])
|
||||||
local existingTarget = nil
|
local existingTarget = nil
|
||||||
for key, target in pairs(TextTargets) do
|
for key, target in pairs(TextTargets) do
|
||||||
@@ -304,6 +304,59 @@ function createCircleTarget(data, opts, dist)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local targetEntities = {}
|
||||||
|
|
||||||
|
--- Creates a target for an entity with specified options and interaction distance.
|
||||||
|
---
|
||||||
|
--- This function supports different targeting systems (OX Target, QB Target, or custom DrawText3D targets)
|
||||||
|
--- based on the server configuration. It translates qb-target style options into the appropriate format
|
||||||
|
--- for the detected targeting system.
|
||||||
|
---
|
||||||
|
---@param entity number The entity ID to create a target for.
|
||||||
|
---@param opts table A table of option configurations for the target.
|
||||||
|
--- - **icon** (`string`): The icon to display for the option.
|
||||||
|
--- - **label** (`string`): The label text for the option.
|
||||||
|
--- - **item** (`string|nil`): (Optional) The item associated with the option.
|
||||||
|
--- - **job** (`string|nil`): (Optional) The job required to interact with the option.
|
||||||
|
--- - **gang** (`string|nil`): (Optional) The gang required to interact with the option.
|
||||||
|
--- - **action** (`function|nil`): (Optional) The function to execute when the option is selected.
|
||||||
|
---@param dist number The interaction distance for the target.
|
||||||
|
---
|
||||||
|
---@usage
|
||||||
|
--- ```lua
|
||||||
|
--- createEntityTarget(entityId, {
|
||||||
|
--- { icon = "fas fa-car", label = "Open Vehicle", action = openVehicle },
|
||||||
|
--- { icon = "fas fa-lock", label = "Lock Vehicle", action = lockVehicle }
|
||||||
|
--- }, 2.5)
|
||||||
|
--- ```
|
||||||
|
function createModelTarget(models, opts, dist)
|
||||||
|
if Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport)) then
|
||||||
|
--
|
||||||
|
elseif isStarted(OXTargetExport) then
|
||||||
|
debugPrint("^6Bridge^7: ^2Creating new ^3Model^2 target with ^6"..OXTargetExport)
|
||||||
|
local options = {}
|
||||||
|
for i = 1, #opts do
|
||||||
|
options[i] = {
|
||||||
|
icon = opts[i].icon,
|
||||||
|
label = opts[i].label,
|
||||||
|
item = opts[i].item or nil,
|
||||||
|
groups = opts[i].job or opts[i].gang,
|
||||||
|
onSelect = opts[i].action,
|
||||||
|
canInteract = function(_, distance)
|
||||||
|
return distance < dist and true or false
|
||||||
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
exports[OXTargetExport]:addModel(models, options)
|
||||||
|
elseif isStarted(QBTargetExport) then
|
||||||
|
debugPrint("^6Bridge^7: ^2Creating new ^3Entity^2 target with ^6"..QBTargetExport)
|
||||||
|
local options = { options = opts, distance = dist }
|
||||||
|
exports[QBTargetExport]:AddTargetModel(models, options)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- Simple function to remove an entity target created within the script --
|
-- Simple function to remove an entity target created within the script --
|
||||||
--- Removes a previously created entity target.
|
--- Removes a previously created entity target.
|
||||||
---
|
---
|
||||||
@@ -316,7 +369,7 @@ end
|
|||||||
function removeEntityTarget(entity)
|
function removeEntityTarget(entity)
|
||||||
if isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveTargetEntity(entity) end
|
if isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveTargetEntity(entity) end
|
||||||
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeLocalEntity(entity, nil) end
|
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeLocalEntity(entity, nil) end
|
||||||
if Config.System.DontUseTarget then TextTargets[entity] = nil end
|
if (Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport))) then TextTargets[entity] = nil end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Simple function to remove circle or box targets in the script --
|
-- Simple function to remove circle or box targets in the script --
|
||||||
@@ -334,11 +387,11 @@ end
|
|||||||
function removeZoneTarget(target)
|
function removeZoneTarget(target)
|
||||||
if isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveZone(target) end
|
if isStarted(QBTargetExport) then exports[QBTargetExport]:RemoveZone(target) end
|
||||||
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeZone(target, true) end
|
if isStarted(OXTargetExport) then exports[OXTargetExport]:removeZone(target, true) end
|
||||||
if Config.System.DontUseTarget then TextTargets[target] = nil end
|
if (Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport))) then TextTargets[target] = nil end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If no target script is found, default to DrawText3D targets -- * experimental *
|
-- If no target script is found, default to DrawText3D targets -- * experimental *
|
||||||
if Config.System.DontUseTarget and not isServer() then
|
if (Config.System.DontUseTarget or (not isStarted(OXTargetExport) and not isStarted(QBTargetExport))) and not isServer() then
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
local pedCoords = GetEntityCoords(PlayerPedId())
|
local pedCoords = GetEntityCoords(PlayerPedId())
|
||||||
|
|||||||
@@ -172,6 +172,11 @@ function registerCommand(command, options)
|
|||||||
elseif isStarted(QBExport) and not isStarted(QBXExport) then
|
elseif isStarted(QBExport) and not isStarted(QBXExport) then
|
||||||
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7 "..QBExport, command)
|
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7 "..QBExport, command)
|
||||||
Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] and options[5] or nil)
|
Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] and options[5] or nil)
|
||||||
|
elseif isStarted(ESXExport) then
|
||||||
|
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7 ESX Legacy", command)
|
||||||
|
ESX.RegisterCommand(command, options[5] or 'admin', function(xPlayer, args, showError)
|
||||||
|
options[4](xPlayer.source, args, showError)
|
||||||
|
end, false, { help = options[1] })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user