diff --git a/fxmanifest.lua b/fxmanifest.lua index f4ceaf4..af94253 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,9 +4,10 @@ lua54 'yes' use_experimental_fxv2_oal 'yes' author 'The Order of the Sacred Framework' description 'A bridge made for the community to use as a base for their own projects. This bridge will allow a single format to work with nearly all commonly used systems while still offering expandability.' -version '0.1.4' +version '0.1.5' shared_scripts { + '@ox_lib/init.lua', 'settings/sharedConfig.lua', 'use/*.lua', 'modules/utility/shared/*.lua', diff --git a/modules/clothing/qb-clothing/server.lua b/modules/clothing/qb-clothing/server.lua index d7a283a..5083d20 100644 --- a/modules/clothing/qb-clothing/server.lua +++ b/modules/clothing/qb-clothing/server.lua @@ -1,6 +1,6 @@ if GetResourceState('qb-clothing') ~= 'started' then return end -RegisterServerEvent('qb-clothing:saveSkin', function(model, skin) +RegisterNetEvent('qb-clothing:saveSkin', function(model, skin) local src = source if model ~= nil and skin ~= nil then TriggerClientEvent('community_bridge:client:updateStoredClothing', src, skin) diff --git a/modules/framework/nd_core/client.lua b/modules/framework/nd_core/client.lua new file mode 100644 index 0000000..69f90ae --- /dev/null +++ b/modules/framework/nd_core/client.lua @@ -0,0 +1,61 @@ +if GetResourceState('ND_Core') ~= 'started' then return end + +local NDCore = exports["ND_Core"]:GetCoreObject() + +Framework = {} + +Framework.GetPlayerData = function() + return NDCore:getPlayer() +end + +Framework.GetPlayerMetaData = function(metadata) + return NDCore:getPlayer().metadata[metadata] +end + +--[[ +-- Unused by this framework +Framework.GetItemInfo = function(item) + +end + +Framework.GetPlayerInventory = function() + +end +--]] + +Framework.GetPlayerIdentifier = function() + return NDCore:getPlayer().id +end + +Framework.GetPlayerName = function() + return NDCore:getPlayer().fullname +end + +Framework.GetPlayerJob = function() + local player = NDCore:getPlayer().jobInfo + return player.name, player.label, player.rankname, player.rank +end + +Framework.GetIsPlayerDead = function() + local playerState = LocalPlayer.state + return playerState.dead +end + +RegisterNetEvent("ND:characterLoaded",function(character) + Wait(1500) + FillBridgeTables() + TriggerEvent('community_bridge:Client:OnPlayerLoaded') +end) + +RegisterNetEvent("ND:characterUnloaded",function() + ClearClientSideVariables() + TriggerEvent('community_bridge:Client:OnPlayerUnload') +end) + +RegisterNetEvent("ND:updateCharacter", function(character) + PlayerJobName = character.jobInfo.name + PlayerJobLabel = character.jobInfo.label + PlayerJobGradeName = character.jobInfo.rankName + PlayerJobGradeLevel = character.jobInfo.rank + TriggerEvent('community_bridge:Client:OnPlayerJobUpdate', PlayerJobName, PlayerJobLabel, PlayerJobGradeName, PlayerJobGradeLevel) +end) \ No newline at end of file diff --git a/modules/framework/nd_core/server.lua b/modules/framework/nd_core/server.lua new file mode 100644 index 0000000..3d38e92 --- /dev/null +++ b/modules/framework/nd_core/server.lua @@ -0,0 +1,187 @@ +--local NDCore = exports["ND_Core"]:GetCoreObject() +local NDCore = exports["ND_Core"] + +Framework = {} + +-- Framework.GetPlayerIdentifier(src) +-- Returns the citizen ID of the player. +Framework.GetPlayerIdentifier = function(src) + local player = NDCore:getPlayer(src) + return player.id +end + +-- Framework.GetPlayerName(src) +-- Returns the first and last name of the player. +Framework.GetPlayerName = function(src) + local player = NDCore:getPlayer(src) + return player.fullname +end + +--[[ +-- Unused by this framework +Framework.GetItem = function(src, item, metadata) + +end + +Framework.GetItemCount = function(src, item, metadata) + +end + +Framework.GetPlayerInventory = function(src) + +end + +Framework.AddItem = function(src, item, amount, slot, metadata) + +end + +Framework.RemoveItem = function(src, item, amount, slot, metadata) + +end + +Framework.SetMetadata = function(src, item, slot, metadata) + +end + + +Framework.Commands = {} +Framework.Commands.Add = function(name, help, arguments, argsrequired, callback, permission, ...) + +end + +--]] + +-- Framework.SetMetadata(src, metadata, value) +-- Adds the specified metadata key and number value to the player's data. +Framework.SetPlayerMetadata = function(src, metadata, value) + local player = NDCore:getPlayer(src) + player.setMetadata(metadata, value) + return true +end + +-- Framework.GetMetadata(src, metadata) +-- Gets the specified metadata key to the player's data. +Framework.GetPlayerMetadata = function(src, metadata) + local player = NDCore:getPlayer(src) + local playerData = player.getMetadata(metadata) + return playerData or false +end + +-- Framework.AddStress(src, value) +-- Adds the specified value to the player's stress level and updates the client HUD. +Framework.AddStress = function(src, value) + print("Not Bridged Yet") + return 0 +end + +-- Framework.RemoveStress(src, value) +-- Removes the specified value from the player's stress level and updates the client HUD. +Framework.RemoveStress = function(src, value) + print("Not Bridged Yet") + return 0 +end + +-- Framework.AddHunger(src, value) +-- Adds the specified value from the player's hunger level. +Framework.AddHunger = function(src, value) + -- Im stuck +end + +-- Framework.AddThirst(src, value) +-- Adds the specified value from the player's thirst level. +Framework.AddThirst = function(src, value) + -- Im stuck +end + +Framework.GetHunger = function(src) + local player = NDCore:getPlayer(src) + local metaData = player.metadata + local hunger = metaData.status.hunger.status + return hunger +end + +Framework.GetThirst = function(src) + local player = NDCore:getPlayer(src) + local metaData = player.metadata + local thirst = metaData.status.thirst.status + return thirst +end + +-- Framework.GetPlayerPhone(src) +-- Returns the phone number of the player. +Framework.GetPlayerPhone = function(src) + local player = NDCore:getPlayer(src) + return player.phonenumber +end + +-- Framework.GetPlayerGang(src) +-- Returns the gang name of the player. +Framework.GetPlayerGang = function(src) + print("Not Bridged Yet") + return "none" +end + +-- Framework.GetPlayersByJob(jobname) +-- returns a table of player sources that have the specified job name. +Framework.GetPlayersByJob = function(job) + local playerList = {} + local players = NDCore:getPlayers("job", job, false) + for playerSource, _ in pairs(players) do + table.insert(playerList, playerSource) + end + return playerList +end + +-- Framework.GetPlayerJob(src) +-- Returns the job name, label, grade name, and grade level of the player. +Framework.GetPlayerJob = function(src) + local player = NDCore:getPlayer(src) + local jobName, jobInfo = player.getJob() + return jobInfo.name, jobInfo.label, jobInfo.rankName, jobInfo.rank +end + +-- Framework.SetPlayerJob(src, name, grade) +-- Sets the player's job to the specified name and grade. +Framework.SetPlayerJob = function(src, name, grade) + local player = NDCore:getPlayer(src) + return player.setJob(name, grade) +end + +Framework.ToggleDuty = function(src, status) + print("Not Bridged Yet") + return false +end + +-- Framework.AddAccountBalance(src, _type, amount) +-- Adds the specified amount to the player's account balance of the specified type. +Framework.AddAccountBalance = function(src, _type, amount) + local player = NDCore:getPlayer(src) + if _type == 'money' then _type = 'cash' end + return player.addMoney(_type, amount, "") +end + +-- Framework.RemoveAccountBalance(src, _type, amount) +-- Removes the specified amount from the player's account balance of the specified type. +Framework.RemoveAccountBalance = function(src, _type, amount) + local player = NDCore:getPlayer(src) + if _type == 'money' then _type = 'cash' end + return player.deductMoney(_type, amount, "") +end + +-- Framework.GetAccountBalance(src, _type) +-- Returns the player's account balance of the specified type. +Framework.GetAccountBalance = function(src, _type) + local player = NDCore:getPlayer(src) + if _type == 'money' then _type = 'cash' end + return player.getData(_type) +end + +Framework.RegisterUsableItem = function(itemName, cb) + exports(itemName, function(event, item, inventory, slot, data) + local slotData = exports.ox_inventory:GetSlot(inventory.id, slot) + if event == 'usingItem' then + cb(inventory.id, item, slotData) + return false + end + end) +end \ No newline at end of file diff --git a/modules/framework/qb-core/client.lua b/modules/framework/qb-core/client.lua index fd33406..ad73bda 100644 --- a/modules/framework/qb-core/client.lua +++ b/modules/framework/qb-core/client.lua @@ -71,9 +71,12 @@ RegisterNetEvent('QBCore:Client:OnJobUpdate', function(data) end) RegisterNetEvent('QBCore:Client:OnGangUpdate', function(data) + -- Unsure what data is passed in this, but considering the gang data isnt updating I doubt this was tested. + --[[ PlayerJobName = data.name PlayerJobLabel = data.label PlayerJobGradeName = data.grade.name PlayerJobGradeLevel = data.grade.level TriggerEvent('community_bridge:Client:OnPlayerGangUpdate', PlayerGangName, PlayerGangLabel, PlayerGangGradeName, PlayerGangGradeLevel) + --]] end) \ No newline at end of file diff --git a/modules/input/_oxlib.lua b/modules/input/_oxlib.lua new file mode 100644 index 0000000..8b52b20 --- /dev/null +++ b/modules/input/_oxlib.lua @@ -0,0 +1,55 @@ +if GetResourceState('ox_lib') ~= 'started' or (BridgeClientConfig.InputSystem ~= "ox" and BridgeClientConfig.InputSystem ~= "auto") then return end + + + +function QBTypeToOxType(_type) + if _type == "text" then + return "input" + elseif _type == "password" then + return "input" + elseif _type == "number" then + return "number" + elseif _type == "radio" then + return "checkbox" + elseif _type == "checkbox" then + return "checkbox" + elseif _type == "select" then + return "select" + end +end + + +function QBToOxInput(data) + local returnData = {} + for i, v in pairs(data) do + local input = { + label = v.text, + name = i, + type = QBTypeToOxType(v.type), + required = v.isRequired, + default = v.placeholder, + } + if v.type == "select" then + input.options = {} + for i, v in pairs(v.options) do + table.insert(input.options, {value = v.value, label = v.text}) + end + elseif v.type == "checkbox" then + for i, v in pairs(v.options) do + table.insert(returnData, {value = v.value, label = v.text}) + end + end + table.insert(returnData, input) + end + return returnData +end + + +function OpenInput(title, data, isQBFormat, submitText) + local inputs = data.inputs + if isQBFormat then + return lib.inputDialog(title, QBToOxInput(inputs)) + else + return lib.inputDialog(title, data) + end +end \ No newline at end of file diff --git a/modules/input/_qb-input.lua b/modules/input/_qb-input.lua new file mode 100644 index 0000000..933fe0e --- /dev/null +++ b/modules/input/_qb-input.lua @@ -0,0 +1,69 @@ + +if GetResourceState('qb-input') ~= 'started' or (BridgeClientConfig.InputSystem ~= "qb" and BridgeClientConfig.InputSystem ~= "auto") then return end + + +-- ox to Qb +function OxTypeToQBType(_type) + if _type == "input" then + return "text" + elseif _type == "number" then + return "number" + elseif _type == "checkbox" then + return "checkbox" + elseif _type == "select" then + return "select" + elseif _type == "multi-select" then + return "select" + elseif _type == "slider" then + return "number" + elseif _type == "color" then + return "text" + elseif _type == "date" then + return "date" + elseif _type == "date-range" then + return "date" + elseif _type == "time" then + return "time" + elseif _type == "textarea" then + return "text" + end +end + +function OxToQBInput(data) + local returnData = {} + for i, v in pairs(data) do + local input = { + text = v.label, + name = i, + type = OxTypeToQBType(v.type), + isRequired = v.required, + placeholder = v.default, + } + if v.type == "select" then + input.text = "" + input.options = { + {value = v.value, text = v.label} + } + elseif v.type == "checkbox" then + input.text = "" + input.options = { + {value = v.value, text = v.label} + } + end + table.insert(returnData, input) + end + return returnData +end + +function OpenInput(title, data, isQBFormat, submitText) + print("Opening input", json.encode(data)) + local input = data.inputs + if not isQBFormat then + input = OxToQBInput(data) + end + return exports['qb-input']:ShowInput({ + header = title, + submitText = submitText or "Submit", + inputs = input + }) +end \ No newline at end of file diff --git a/modules/input/client.lua b/modules/input/client.lua index 8993def..e3067ac 100644 --- a/modules/input/client.lua +++ b/modules/input/client.lua @@ -79,104 +79,13 @@ if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 's Input = {} --- ox to Qb -function OxTypeToQBType(_type) - if _type == "input" then - return "text" - elseif _type == "number" then - return "number" - elseif _type == "checkbox" then - return "checkbox" - elseif _type == "select" then - return "select" - elseif _type == "multi-select" then - return "select" - elseif _type == "slider" then - return "number" - elseif _type == "color" then - return "text" - elseif _type == "date" then - return "date" - elseif _type == "date-range" then - return "date" - elseif _type == "time" then - return "time" - elseif _type == "textarea" then - return "text" - end -end -function OxToQBInput(data) - local returnData = {} - for i, v in pairs(data) do - local input = { - text = v.label, - name = i, - type = OxTypeToQBType(v.type), - isRequired = v.required, - placeholder = v.default, - } - if v.type == "select" then - input.text = "" - input.options = { - {value = v.value, text = v.label} - } - elseif v.type == "checkbox" then - input.text = "" - input.options = { - {value = v.value, text = v.label} - } - end - table.insert(returnData, input) - end - return returnData -end + + -- qb to ox -function QBTypeToOxType(_type) - if _type == "text" then - return "input" - elseif _type == "password" then - return "input" - elseif _type == "number" then - return "number" - elseif _type == "radio" then - return "checkbox" - elseif _type == "checkbox" then - return "checkbox" - elseif _type == "select" then - return "select" - end -end - - -function QBToOxInput(data) - local returnData = {} - for i, v in pairs(data) do - local input = { - label = v.text, - name = i, - type = QBTypeToOxType(v.type), - required = v.isRequired, - default = v.placeholder, - } - if v.type == "select" then - input.options = {} - for i, v in pairs(v.options) do - table.insert(input.options, {value = v.value, label = v.text}) - end - elseif v.type == "checkbox" then - for i, v in pairs(v.options) do - table.insert(returnData, {value = v.value, label = v.text}) - end - end - table.insert(returnData, input) - end - return returnData -end - --Open menu function Input.Open(title, data, isQBFormat, submitText) @@ -202,7 +111,7 @@ function Input.Open(title, data, isQBFormat, submitText) }) end end - return id + return OpenInput(title, data, isQBFormat, submitText) end --[[ diff --git a/modules/menu/_oxlib.lua b/modules/menu/_oxlib.lua index 3b602d7..a21207a 100644 --- a/modules/menu/_oxlib.lua +++ b/modules/menu/_oxlib.lua @@ -1,4 +1,4 @@ -if GetResourceState('ox_lib') ~= 'started' and (BridgeClientConfig.MenuSystem ~= "ox" or BridgeClientConfig.MenuSystem ~= "auto") then return end +if GetResourceState('ox_lib') ~= 'started' or (BridgeClientConfig.MenuSystem ~= "ox" and BridgeClientConfig.MenuSystem ~= "auto") then return end Menus = Menus or {} --- Converts a QB menu to an Ox menu. ---@param id string The menu ID. diff --git a/modules/menu/_qb-menu.lua b/modules/menu/_qb-menu.lua index 990c19c..e0fff1a 100644 --- a/modules/menu/_qb-menu.lua +++ b/modules/menu/_qb-menu.lua @@ -1,4 +1,5 @@ -if GetResourceState('qb-menu') ~= 'started' and (BridgeClientConfig.MenuSystem ~= "qb" or BridgeClientConfig.MenuSystem ~= "auto") then return end +if GetResourceState('qb-menu') ~= 'started' or (BridgeClientConfig.MenuSystem ~= "qb" and BridgeClientConfig.MenuSystem ~= "auto") then return end +print("Loading QB Menu") --- Converts an Ox menu to a QB menu. ---@param id string The menu ID. ---@param menu table The Ox menu data. @@ -16,7 +17,7 @@ function OxToQBMenu(id, menu) txt = v.description, icon = v.icon, } - + if v.onSelect then button.params = { event = "community_bridge:client:MenuCallback", diff --git a/modules/menu/client.lua b/modules/menu/client.lua index fe005d9..fa84ab0 100644 --- a/modules/menu/client.lua +++ b/modules/menu/client.lua @@ -1,12 +1,6 @@ Menus = Menus or {} Menu = {} -if GetResourceState('ox_lib') ~= 'started' and GetResourceState('qb-menu') ~= 'started' then return end - - - - - --- Opens a menu based on the configuration. ---@param data table The menu data. ---@param useQb boolean Whether to use QB menu syntax. diff --git a/modules/notify/client.lua b/modules/notify/client.lua index 1995499..67a810d 100644 --- a/modules/notify/client.lua +++ b/modules/notify/client.lua @@ -67,4 +67,12 @@ end RegisterNetEvent('community_bridge:Client:Notify', function(message, _type, time) Notify.SendNotify(message, _type, time) +end) + +RegisterNetEvent('community_bridge:Client:ShowHelpText', function(message, position) + Notify.ShowHelpText(message, position) +end) + +RegisterNetEvent('community_bridge:Client:HideHelpText', function() + Notify.HideHelpText() end) \ No newline at end of file diff --git a/modules/notify/server.lua b/modules/notify/server.lua index ebf5fbc..fd2c122 100644 --- a/modules/notify/server.lua +++ b/modules/notify/server.lua @@ -2,4 +2,12 @@ Notify = Notify or {} Notify.SendNotify = function(src, message, _type, time) TriggerClientEvent('community_bridge:Client:Notify', src, message, _type, time) +end + +Notify.ShowHelpText = function(src, message, position) + TriggerClientEvent('community_bridge:Client:ShowHelpText', src, message, position) +end + +Notify.HideHelpText = function(src) + TriggerClientEvent('community_bridge:Client:HideHelpText', src) end \ No newline at end of file diff --git a/modules/utility/server/supplement_events.lua b/modules/utility/server/supplement_events.lua index fbe2fa1..11181c0 100644 --- a/modules/utility/server/supplement_events.lua +++ b/modules/utility/server/supplement_events.lua @@ -1,4 +1,4 @@ -RegisterServerEvent("community_bridge:server:alert", function(data) +RegisterNetEvent("community_bridge:server:alert", function(data) local playersByJob = Framework.GetPlayersByJob(data.job) for _, src in pairs(playersByJob) do TriggerClientEvent("community_bridge:client:alert", src, data) diff --git a/settings/clientConfig.lua b/settings/clientConfig.lua index 02b8515..cb3776c 100644 --- a/settings/clientConfig.lua +++ b/settings/clientConfig.lua @@ -1,11 +1,10 @@ BridgeClientConfig = {} BridgeClientConfig.NotifySystem = "ox" -- Change this to your notification system (ox/qb/esx?) BridgeClientConfig.ZoneSystem = "ox" -- Change this to your dialog system (ox/poly) -BridgeClientConfig.InputSystem = "ox" -- Change this to your Input system (ox/qb) +BridgeClientConfig.InputSystem = "auto" -- Change this to your Input system (ox/qb) BridgeClientConfig.MenuSystem = "auto" -- Change this to your Menu system (ox/qb) BridgeClientConfig.ProgressBar = "ox" -- Change this to your preferred progress bar (ox/qb) BridgeClientConfig.DebugLevel = 3 -- Change this to your Debug level, 1 for none, 2 for some, 3 for all data BridgeClientConfig.ShowHelpText = "ox" -- -Require("init.lua", "ox_lib") return BridgeClientConfig \ No newline at end of file diff --git a/settings/serverConfig.lua b/settings/serverConfig.lua index 8f5c478..932de94 100644 --- a/settings/serverConfig.lua +++ b/settings/serverConfig.lua @@ -3,6 +3,5 @@ BridgeServerConfig.LogSystem = "builtin" -- "builtin", "qb", "ox" BridgeServerConfig.WebhookURL = "PUT_WEBHOOK_URL_HERE" BridgeServerConfig.WebhookImage = "https://cdn.discordapp.com/avatars/299410129982455808/31ce635662206e8bd0132c34ce9ce683?size=1024" BridgeServerConfig.MaxInventorySlots = 50 -Require("init.lua", "ox_lib") return BridgeServerConfig