Better support for RedM's RSG Core

Nothing public uses this yet, but its very similar to QBCore which makes it very for me to support

Nothing special to note, just improves the integration for future ventures into RedM
This commit is contained in:
Jim Shield
2025-05-01 17:49:37 +01:00
parent 65c9c6c586
commit b81ada265b
8 changed files with 132 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
function parseVersion(version) local function parseVersion(version)
local parts = {} local parts = {}
for num in version:gmatch("%d+") do for num in version:gmatch("%d+") do
table.insert(parts, tonumber(num)) table.insert(parts, tonumber(num))
@@ -6,7 +6,7 @@ function parseVersion(version)
return parts return parts
end end
function compareVersions(current, newest) local function compareVersions(current, newest)
local currentParts = parseVersion(current) local currentParts = parseVersion(current)
local newestParts = parseVersion(newest) local newestParts = parseVersion(newest)
for i = 1, math.max(#currentParts, #newestParts) do for i = 1, math.max(#currentParts, #newestParts) do

View File

@@ -120,12 +120,10 @@ elseif isStarted(RSGExport) then
itemResource = RSGExport itemResource = RSGExport
Core = Core or exports[RSGExport]:GetCoreObject() Core = Core or exports[RSGExport]:GetCoreObject()
Items = Core and Core.Shared.Items or nil Items = Core and Core.Shared.Items or nil
if isStarted(RSGExport) and not isStarted(QBXExport) then RegisterNetEvent('RSGCore:Client:UpdateObject', function()
RegisterNetEvent('QBCore:Client:UpdateObject', function() Core = Core or exports[RSGExport]:GetCoreObject()
Core = Core or exports[RSGExport]:GetCoreObject() Items = Core and Core.Shared.Items or nil
Items = Core and Core.Shared.Items or nil end)
end)
end
end end
@@ -190,12 +188,10 @@ elseif isStarted(ESXExport) then
elseif isStarted(RSGExport) then elseif isStarted(RSGExport) then
Core = Core or exports[RSGExport]:GetCoreObject() Core = Core or exports[RSGExport]:GetCoreObject()
Vehicles = Core and Core.Shared.Vehicles Vehicles = Core and Core.Shared.Vehicles
if isStarted(RSGExport) then RegisterNetEvent('RSGCore:Client:UpdateObject', function()
RegisterNetEvent('RSGExport:Client:UpdateObject', function() Core = Core or exports[RSGExport]:GetCoreObject()
Core = Core or exports[RSGExport]:GetCoreObject() Vehicles = Core and Core.Shared.Vehicles
Vehicles = Core and Core.Shared.Vehicles end)
end)
end
vehResource = RSGExport vehResource = RSGExport
end end
if vehResource == nil then if vehResource == nil then
@@ -276,12 +272,10 @@ elseif isStarted(RSGExport) then
jobResource = RSGExport jobResource = RSGExport
Core = Core or exports[RSGExport]:GetCoreObject() Core = Core or exports[RSGExport]:GetCoreObject()
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
if isStarted(RSGExport) and not isStarted(QBXExport) then RegisterNetEvent('RSGCore:Client:UpdateObject', function()
RegisterNetEvent('QBCore:Client:UpdateObject', function() Core = exports[RSGExport]:GetCoreObject()
Core = exports[RSGExport]:GetCoreObject() Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs
Jobs, Gangs = Core.Shared.Jobs, Core.Shared.Gangs end)
end)
end
end end
if jobResource == nil then if jobResource == nil then

View File

@@ -31,15 +31,22 @@ validTokens = {}
--- ``` --- ```
function createUseableItem(item, funct) function createUseableItem(item, funct)
if isStarted(ESXExport) then if isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^2Registering item as ^3Usable^2 with ^7es_extended", item) debugPrint("^6Bridge^7: ^2Registering item as ^3Usable^2 with ^7es_extended^7", item)
while not ESX do Wait(0) end while not ESX do Wait(0) end
ESX.RegisterUsableItem(item, funct) ESX.RegisterUsableItem(item, funct)
elseif isStarted(QBExport) and not isStarted(QBXExport) then elseif isStarted(QBExport) and not isStarted(QBXExport) then
debugPrint("^6Bridge^7: ^2Registering item as ^3Usable^2 with ^7qb-core", item) debugPrint("^6Bridge^7: ^2Registering item as ^3Usable^2 with ^7qb-core^7", item)
Core.Functions.CreateUseableItem(item, funct) Core.Functions.CreateUseableItem(item, funct)
elseif isStarted(QBXExport) then elseif isStarted(QBXExport) then
debugPrint("^6Bridge^7: ^2Registering item as ^3Usable^2 with ^7qbx_core", item) debugPrint("^6Bridge^7: ^2Registering item as ^3Usable^2 with ^7qbx_core^7", item)
exports[QBXExport]:CreateUseableItem(item, funct) exports[QBXExport]:CreateUseableItem(item, funct)
elseif isStarted(RSGExport) then
debugPrint("^6Bridge^7: ^2Registering item as ^3Usable^2 with ^1rsg-core^7", item)
Core.Functions.CreateUseableItem(item, funct)
else else
print("^4ERROR^7: No supported framework detected for registering usable item: ^3"..item.."^7") print("^4ERROR^7: No supported framework detected for registering usable item: ^3"..item.."^7")
end end

View File

@@ -95,6 +95,8 @@ function toggleDuty()
onDuty = not onDuty onDuty = not onDuty
if isStarted(QBExport) or isStarted(QBXExport) then if isStarted(QBExport) or isStarted(QBXExport) then
TriggerServerEvent("QBCore:ToggleDuty") TriggerServerEvent("QBCore:ToggleDuty")
elseif isStarted(RSGExport) then
TriggerServerEvent("RSGCore:ToggleDuty")
else else
if onDuty then if onDuty then
triggerNotify(nil, "Now on duty", "success") triggerNotify(nil, "Now on duty", "success")

View File

@@ -32,6 +32,9 @@ function GetPlayer(source)
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
debugPrint("^6Bridge^7: ^3GetPlayer^7() OXCoreExport") debugPrint("^6Bridge^7: ^3GetPlayer^7() OXCoreExport")
return exports[OXCoreExport]:GetPlayer(source) return exports[OXCoreExport]:GetPlayer(source)
elseif isStarted(RSGExport) then
debugPrint("^6Bridge^7: ^3GetPlayer^7() RSGExport")
return exports[RSGExport]:GetCoreObject().Functions.GetPlayer(source)
end end
return nil return nil
end end
@@ -58,7 +61,7 @@ function GetMetadata(player, key)
return triggerCallback(getScript()..":server:GetMetadata", key) return triggerCallback(getScript()..":server:GetMetadata", key)
else else
if isStarted(QBExport) or isStarted(QBXExport) then if isStarted(QBExport) or isStarted(QBXExport) then
debugPrint("^6Bridge^7: ^3GetMetadata^7() QBExport or QBXExport", key) debugPrint("^6Bridge^7: ^3GetMetadata^7() QBExport/QBXExport", key)
return player.PlayerData.metadata[key] return player.PlayerData.metadata[key]
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^3GetMetadata^7() ESXExport", key) debugPrint("^6Bridge^7: ^3GetMetadata^7() ESXExport", key)
@@ -66,6 +69,9 @@ function GetMetadata(player, key)
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
debugPrint("^6Bridge^7: ^3GetMetadata^7() OXCoreExport", key) debugPrint("^6Bridge^7: ^3GetMetadata^7() OXCoreExport", key)
return player.get(key) return player.get(key)
elseif isStarted(RSGExport) then
debugPrint("^6Bridge^7: ^3GetMetadata^7() RSGExport", key)
return player.PlayerData.metadata[key]
end end
end end
return nil return nil
@@ -118,6 +124,9 @@ function SetMetadata(player, key, value)
elseif isStarted(OXCoreExport) then elseif isStarted(OXCoreExport) then
debugPrint("^6Bridge^7: ^3SetMetadata^7() using OXCoreExport") debugPrint("^6Bridge^7: ^3SetMetadata^7() using OXCoreExport")
player.set(key, value) player.set(key, value)
elseif isStarted(RSGExport) then
debugPrint("^6Bridge^7: ^3SetMetadata^7() using RSGExport")
player.Functions.SetMetaData(key, value)
end end
end end

View File

@@ -111,10 +111,16 @@ end)
function setThirst(src, thirst) function setThirst(src, thirst)
if isStarted(ESXExport) then if isStarted(ESXExport) then
TriggerClientEvent('esx_status:add', src, 'thirst', thirst) TriggerClientEvent('esx_status:add', src, 'thirst', thirst)
elseif isStarted(QBExport) or isStarted(QBXExport) then elseif isStarted(QBExport) or isStarted(QBXExport) then
local Player = Core.Functions.GetPlayer(src) local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('thirst', thirst) Player.Functions.SetMetaData('thirst', thirst)
TriggerClientEvent("hud:client:UpdateNeeds", src, thirst, Player.PlayerData.metadata.thirst) TriggerClientEvent("hud:client:UpdateNeeds", src, thirst, Player.PlayerData.metadata.thirst)
elseif isStarted(RSGExport) then
local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('thirst', thirst)
TriggerClientEvent("hud:client:UpdateNeeds", src, thirst, Player.PlayerData.metadata.thirst)
end end
end end
@@ -130,10 +136,16 @@ end
function setHunger(src, hunger) function setHunger(src, hunger)
if isStarted(ESXExport) then if isStarted(ESXExport) then
TriggerClientEvent('esx_status:add', src, 'hunger', hunger) TriggerClientEvent('esx_status:add', src, 'hunger', hunger)
elseif isStarted(QBExport) or isStarted(QBXExport) then elseif isStarted(QBExport) or isStarted(QBXExport) then
local Player = Core.Functions.GetPlayer(src) local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('hunger', hunger) Player.Functions.SetMetaData('hunger', hunger)
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.hunger) TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.hunger)
elseif isStarted(RSGExport) then
local Player = Core.Functions.GetPlayer(src)
Player.Functions.SetMetaData('hunger', hunger)
TriggerClientEvent("hud:client:UpdateNeeds", src, hunger, Player.PlayerData.metadata.hunger)
end end
end end
@@ -161,20 +173,31 @@ function chargePlayer(cost, moneyType, newsrc)
if moneyType == "cash" then if moneyType == "cash" then
if isStarted(OXInv) then fundResource = OXInv if isStarted(OXInv) then fundResource = OXInv
exports[OXInv]:RemoveItem(src, "money", cost) exports[OXInv]:RemoveItem(src, "money", cost)
elseif isStarted(QBExport) or isStarted(QBXExport) then elseif isStarted(QBExport) or isStarted(QBXExport) then
fundResource = QBExport fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost) Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost)
elseif isStarted(RSGExport) then elseif isStarted(RSGExport) then
fundResource = QBExport fundResource = RSGExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost) Core.Functions.GetPlayer(src).Functions.RemoveMoney("cash", cost)
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
fundResource = ESXExport fundResource = ESXExport
ESX.GetPlayerFromId(src).removeMoney(cost, "") ESX.GetPlayerFromId(src).removeMoney(cost, "")
end end
elseif moneyType == "bank" then elseif moneyType == "bank" then
if isStarted(QBExport) or isStarted(QBXExport) then fundResource = QBExport if isStarted(QBExport) or isStarted(QBXExport) then
fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost) Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost)
elseif isStarted(ESXExport) then fundResource = ESXExport
elseif isStarted(RSGExport) then
fundResource = RSGExport
Core.Functions.GetPlayer(src).Functions.RemoveMoney("bank", cost)
elseif isStarted(ESXExport) then
fundResource = ESXExport
ESX.GetPlayerFromId(src).removeMoney(cost, "") ESX.GetPlayerFromId(src).removeMoney(cost, "")
end end
end end
@@ -212,17 +235,29 @@ function fundPlayer(fund, moneyType, newsrc)
if isStarted(OXInv) then if isStarted(OXInv) then
fundResource = OXInv fundResource = OXInv
exports[OXInv]:AddItem(src, "money", fund) exports[OXInv]:AddItem(src, "money", fund)
elseif isStarted(QBExport) or isStarted(QBXExport) then elseif isStarted(QBExport) or isStarted(QBXExport) then
fundResource = QBExport fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund) Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund)
elseif isStarted(RSGExport) then
fundResource = RSGExport
Core.Functions.GetPlayer(src).Functions.AddMoney("cash", fund)
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
fundResource = ESXExport fundResource = ESXExport
PlayESX.GetPlayerFromId(src).addMoney(fund, "") ESX.GetPlayerFromId(src).addMoney(fund, "")
end end
elseif moneyType == "bank" then elseif moneyType == "bank" then
if isStarted(QBExport) or isStarted(QBXExport) then if isStarted(QBExport) or isStarted(QBXExport) then
fundResource = QBExport fundResource = QBExport
Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund) Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund)
elseif isStarted(RSGExport) then
fundResource = RSGExport
Core.Functions.GetPlayer(src).Functions.AddMoney("bank", fund)
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
fundResource = ESXExport fundResource = ESXExport
ESX.GetPlayerFromId(src).addMoney(fund, "") ESX.GetPlayerFromId(src).addMoney(fund, "")
@@ -380,6 +415,35 @@ function hasJob(job, source, grade)
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end end
end end
elseif isStarted(RSGExport) then
if Core.Functions.GetPlayer then
local player = Core.Functions.GetPlayer(src)
if not player then print("Player not found for src: "..src) end
local jobinfo = player.PlayerData.job
if jobinfo.name == job then
hasJobFlag = true
duty = player.PlayerData.job.onduty
if grade and not (grade <= jobinfo.grade.level) then hasJobFlag = false end
end
local ganginfo = player.PlayerData.gang
if ganginfo.name == job then
hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end
else
local jobinfo = exports[RSGExport]:GetPlayer(src).PlayerData.job
if jobinfo.name == job then
hasJobFlag = true
duty = exports[RSGExport]:GetPlayer(src).PlayerData.job.onduty
if grade and not (grade <= jobinfo.grade.level) then hasJobFlag = false end
end
local ganginfo = exports[RSGExport]:GetPlayer(src).PlayerData.gang
if ganginfo.name == job then
hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end
end
else else
print("^4ERROR^7: ^2No Core detected for hasJob ^7- ^2Check ^3starter^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for hasJob ^7- ^2Check ^3starter^1.^2lua^7")
end end
@@ -425,6 +489,22 @@ function hasJob(job, source, grade)
hasJobFlag = true hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end end
elseif isStarted(RSGExport) then
local info = nil
Core.Functions.GetPlayerData(function(PlayerData) info = PlayerData end)
local jobinfo = info.job
if jobinfo.name == job then
hasJobFlag = true
duty = jobinfo.onduty
if grade and not (grade <= jobinfo.grade.level) then hasJobFlag = false end
end
local ganginfo = info.gang
if ganginfo.name == job then
hasJobFlag = true
if grade and not (grade <= ganginfo.grade.level) then hasJobFlag = false end
end
else else
print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3starter^1.^2lua^7") print("^4ERROR^7: ^2No Core detected for hasJob() ^7- ^2Check ^3starter^1.^2lua^7")
end end

View File

@@ -108,6 +108,7 @@ function getVehicleProperties(vehicle)
if isStarted(QBExport) and not isStarted(QBXExport) then if isStarted(QBExport) and not isStarted(QBXExport) then
properties = Core.Functions.GetVehicleProperties(vehicle) properties = Core.Functions.GetVehicleProperties(vehicle)
debugPrint("^6Bridge^7: ^2Getting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..properties.model.."^7] - [^3"..properties.plate.."^7]") debugPrint("^6Bridge^7: ^2Getting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..properties.model.."^7] - [^3"..properties.plate.."^7]")
elseif isStarted(OXLibExport) then elseif isStarted(OXLibExport) then
properties = lib.getVehicleProperties(vehicle) properties = lib.getVehicleProperties(vehicle)
debugPrint("^6Bridge^7: ^2Getting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..properties.model.."^7] - [^3"..properties.plate.."^7]") debugPrint("^6Bridge^7: ^2Getting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..properties.model.."^7] - [^3"..properties.plate.."^7]")
@@ -134,6 +135,7 @@ function setVehicleProperties(vehicle, props)
if isStarted(QBExport) and not isStarted(QBXExport) then if isStarted(QBExport) and not isStarted(QBXExport) then
Core.Functions.SetVehicleProperties(vehicle, props) Core.Functions.SetVehicleProperties(vehicle, props)
debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]") debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..QBExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]")
elseif isStarted(OXLibExport) then elseif isStarted(OXLibExport) then
lib.setVehicleProperties(vehicle, props, false) lib.setVehicleProperties(vehicle, props, false)
debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]") debugPrint("^6Bridge^7: ^2Setting Vehicle Properties ^7[^6"..OXLibExport.."^7] - [^3"..vehicle.."^7] - [^3"..GetEntityModel(vehicle).."^7/^3"..props.model.."^7] - [^3"..props.plate.."^7]")

View File

@@ -21,17 +21,25 @@
--- }) --- })
--- ``` --- ```
function registerCommand(command, options) function registerCommand(command, options)
if isStarted(OXLibExport) then if isStarted(OXLibExport) then
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command) debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..OXLibExport, command)
lib.addCommand(command, { help = options[1], restricted = options[5] and "group."..options[5] or nil }, options[4]) lib.addCommand(command, { help = options[1], restricted = options[5] and "group."..options[5] or nil }, options[4])
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] or nil) Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] or nil)
elseif isStarted(RSGExport) then
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7"..RSGExport, command)
Core.Commands.Add(command, options[1], options[2], options[3], options[4], options[5] or nil)
elseif isStarted(ESXExport) then elseif isStarted(ESXExport) then
debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7ESX Legacy", command) debugPrint("^6Bridge^7: ^2Registering ^3Command^2 with ^7ESX Legacy", command)
ESX.RegisterCommand(command, options[5] or 'admin', function(xPlayer, args, showError) ESX.RegisterCommand(command, options[5] or 'admin', function(xPlayer, args, showError)
options[4](xPlayer.source, args, showError) options[4](xPlayer.source, args, showError)
end, false, { help = options[1] }) end, false, { help = options[1] })
end end
end end
@@ -59,6 +67,7 @@ function registerStash(name, label, slots, weight, owner, coords)
if isStarted(OXInv) then if isStarted(OXInv) then
debugPrint("^6Bridge^7: ^2Registering ^3OX ^2Stash^7:", name, label, owner or nil) debugPrint("^6Bridge^7: ^2Registering ^3OX ^2Stash^7:", name, label, owner or nil)
exports[OXInv]:RegisterStash(name, label, slots or 50, weight or 4000000, owner or nil) exports[OXInv]:RegisterStash(name, label, slots or 50, weight or 4000000, owner or nil)
elseif isStarted(QSInv) then elseif isStarted(QSInv) then
debugPrint("^6Bridge^7: ^2Registering ^3QS ^2Stash^7:", name, label) debugPrint("^6Bridge^7: ^2Registering ^3QS ^2Stash^7:", name, label)
exports[QSInv]:RegisterStash(name, label, slots or 50, weight or 4000000) exports[QSInv]:RegisterStash(name, label, slots or 50, weight or 4000000)
@@ -74,6 +83,7 @@ function registerStash(name, label, slots, weight, owner, coords)
elseif isStarted(TgiannInv) then elseif isStarted(TgiannInv) then
debugPrint("^6Bridge^7: ^2Registering ^3TgiannInv ^2Stash^7:", name, label) debugPrint("^6Bridge^7: ^2Registering ^3TgiannInv ^2Stash^7:", name, label)
exports[TgiannInv]:RegisterStash(name, label, slots or 50, weight or 4000000) exports[TgiannInv]:RegisterStash(name, label, slots or 50, weight or 4000000)
end end
end end