From b04f812402c5413d4e1a43dd44c53421689d2a21 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Mon, 26 Feb 2024 18:52:44 +1100 Subject: [PATCH] feat: initial support for ox_core (#382) --- README.md | 2 ++ client/framework/ox/main.lua | 42 ++++++++++++++++++++++++++++++++++ fxmanifest.lua | 2 ++ server/framework/ox/main.lua | 36 +++++++++++++++++++++++++++++ shared/framework/framework.lua | 4 ++++ 5 files changed, 86 insertions(+) create mode 100644 client/framework/ox/main.lua create mode 100644 server/framework/ox/main.lua diff --git a/README.md b/README.md index 239f1f92..c01ab689 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,13 @@ Discord: https://discord.illenium.dev - qb-core - ESX +- ox_core ## Dependencies - [qb-core](https://github.com/qbcore-framework/qb-core) (Latest) (Only for qb-core based servers) - [es_extended](https://github.com/esx-framework/esx-legacy) (Latest) (Only for ESX based servers) +- [ox_core](https://github.com/overextended/ox_core) (experimental) (Only for ox_core based servers) - [ox_lib](https://github.com/overextended/ox_lib) - [qb-target](https://github.com/BerkieBb/qb-target) (Optional) (Only for qb-core based servers) diff --git a/client/framework/ox/main.lua b/client/framework/ox/main.lua new file mode 100644 index 00000000..e25dfb61 --- /dev/null +++ b/client/framework/ox/main.lua @@ -0,0 +1,42 @@ +if not Framework.Ox() then return end + +local Ox = require '@ox_core.lib.init' +local player = Ox.GetPlayer() + +RegisterNetEvent("ox:setActiveCharacter", function(character) + if character.isNew then + return InitializeCharacter(Framework.GetGender(true)) + end + + InitAppearance() +end) + +---@todo groups +-- RegisterNetEvent("ox:setGroup", function(group, grade) +-- end) + +function Framework.GetPlayerGender() + return player.get('gender') == 'female' and 'Female' or 'Male' +end + +function Framework.UpdatePlayerData() end + +function Framework.HasTracker() return false end + +function Framework.CheckPlayerMeta() + return LocalPlayer.state.isDead or IsPedCuffed(cache.ped) +end + +function Framework.IsPlayerAllowed(charId) + return charId == player.charId +end + +function Framework.GetRankInputValues() end + +function Framework.GetJobGrade() end + +function Framework.GetGangGrade() end + +function Framework.CachePed() end + +function Framework.RestorePlayerArmour() end diff --git a/fxmanifest.lua b/fxmanifest.lua index aee4b074..d86c5ba9 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -22,6 +22,7 @@ client_scripts { "client/framework/qb/migrate.lua", "client/framework/esx/compatibility.lua", "client/framework/esx/main.lua", + "client/framework/ox/main.lua", "client/target/target.lua", "client/target/qb.lua", "client/target/ox.lua", @@ -56,6 +57,7 @@ server_scripts { "server/framework/esx/migrate.lua", "server/framework/esx/callbacks.lua", "server/framework/esx/management.lua", + "server/framework/ox/main.lua", "server/util.lua", "server/server.lua", "server/permissions.lua" diff --git a/server/framework/ox/main.lua b/server/framework/ox/main.lua new file mode 100644 index 00000000..c151d29d --- /dev/null +++ b/server/framework/ox/main.lua @@ -0,0 +1,36 @@ +if not Framework.Ox() then return end + +local Ox = require '@ox_core.lib.init' + +function Framework.GetPlayerID(playerId) + return Ox.GetPlayer(playerId).charId +end + +function Framework.HasMoney(playerId, item, amount) + return exports.ox_inventory:GetItemCount(playerId, item) >= amount +end + +function Framework.RemoveMoney(playerId, type, amount) + return exports.ox_inventory:RemoveItem(playerId, type, amount) +end + +function Framework.GetJob() + return ---@todo +end + +function Framework.GetGang() + return ---@todo +end + +function Framework.SaveAppearance(appearance, charId) + Database.PlayerSkins.UpdateActiveField(charId, 0) + Database.PlayerSkins.DeleteByModel(charId, appearance.model) + Database.PlayerSkins.Add(charId, appearance.model, json.encode(appearance), 1) +end + +function Framework.GetAppearance(charId, model) + local result = Database.PlayerSkins.GetByCitizenID(charId, model) + if result then + return json.decode(result) + end +end diff --git a/shared/framework/framework.lua b/shared/framework/framework.lua index 0f9e796c..fb84f77b 100644 --- a/shared/framework/framework.lua +++ b/shared/framework/framework.lua @@ -7,3 +7,7 @@ end function Framework.QBCore() return GetResourceState("qb-core") ~= "missing" end + +function Framework.Ox() + return GetResourceState("ox_core") ~= "missing" +end