|
1 | 1 | -- IsDuplicityVersion - is used to determine if the function is called by the server or the client (true == from server) |
2 | 2 |
|
3 | 3 | --------------------- SHARED FUNCTIONS --------------------- |
4 | | -Core = nil |
5 | | ----@return table Core The core object of the framework |
| 4 | +local Core = nil |
| 5 | +--- @return table Core The core object of the framework |
6 | 6 | function GetCoreObject() |
7 | 7 | if not Core then |
8 | | - if Config.Framework == 'esx' then |
9 | | - Core = exports['es_extended']:getSharedObject() |
10 | | - elseif Config.Framework == 'qb' then |
11 | | - Core = exports['qb-core']:GetCoreObject() |
| 8 | + if Config.Framework == "esx" then |
| 9 | + Core = exports["es_extended"]:getSharedObject() |
| 10 | + elseif Config.Framework == "qb" or Config.Framework == "qbx" then |
| 11 | + Core = exports["qb-core"]:GetCoreObject() |
12 | 12 | end |
13 | 13 | end |
14 | 14 | return Core |
15 | 15 | end |
16 | 16 |
|
17 | | -Core = Config.Framework ~= 'none' and GetCoreObject() or nil |
| 17 | +Core = Config.Framework ~= "none" and GetCoreObject() or nil |
18 | 18 |
|
19 | | ----@param text string The text to show in the notification |
20 | | ----@param notificationType string The type of notification to show ex: 'success', 'error', 'info' |
21 | | ----@param src - number|nil The source of the player - only required when called from server side |
| 19 | +--- @param text string The text to show in the notification |
| 20 | +--- @param notificationType string The type of notification to show ex: 'success', 'error', 'info' |
| 21 | +--- @param src - number|nil The source of the player - only required when called from server side |
22 | 22 | function Notify(text, notificationType, src) |
23 | 23 | if IsDuplicityVersion() then |
24 | | - if Config.Notify == 'esx' then |
| 24 | + if Config.Notify == "esx" then |
25 | 25 | TriggerClientEvent("esx:showNotification", src, text) |
26 | | - elseif Config.Notify == 'qb' then |
27 | | - TriggerClientEvent('QBCore:Notify', src, text, notificationType) |
28 | | - elseif Config.Notify == 'ox' then |
| 26 | + elseif Config.Notify == "qb" then |
| 27 | + TriggerClientEvent("QBCore:Notify", src, text, notificationType) |
| 28 | + elseif Config.Notify == "ox" then |
29 | 29 | TriggerClientEvent("ox_lib:notify", src, { |
30 | 30 | description = text, |
31 | | - type = notificationType |
| 31 | + type = notificationType, |
32 | 32 | }) |
33 | 33 | end |
34 | 34 | else |
35 | | - if Config.Notify == 'esx' then |
| 35 | + if Config.Notify == "esx" then |
36 | 36 | Core.ShowNotification(text) |
37 | | - elseif Config.Notify == 'qb' then |
| 37 | + elseif Config.Notify == "qb" then |
38 | 38 | Core.Functions.Notify(text, notificationType) |
39 | | - elseif Config.Notify == 'ox' then |
| 39 | + elseif Config.Notify == "ox" then |
40 | 40 | lib.notify({ |
41 | 41 | description = text, |
42 | | - type = notificationType |
| 42 | + type = notificationType, |
43 | 43 | }) |
44 | 44 | end |
45 | 45 | end |
46 | 46 | end |
47 | 47 |
|
48 | | ----@param source number|nil The source of the player |
49 | | ----@return table PlayerData The player data of the player |
| 48 | +--- @param source number|nil The source of the player |
| 49 | +--- @return table PlayerData The player data of the player |
50 | 50 | function GetPlayerData(source) |
51 | 51 | local Core = GetCoreObject() |
52 | 52 | if IsDuplicityVersion() then |
53 | | - if Config.Framework == 'esx' then |
| 53 | + if Config.Framework == "esx" then |
54 | 54 | return Core.GetPlayerFromId(source) |
55 | | - elseif Config.Framework == 'qb' then |
56 | | - return Core.Functions.GetPlayer(source) |
| 55 | + elseif Config.Framework == "qb" then |
| 56 | + return Core.Functions.GetPlayer(source).PlayerData |
| 57 | + elseif Config.Framework == "qbx" then |
| 58 | + return exports.qbx_core:GetPlayer(source).PlayerData |
57 | 59 | end |
58 | 60 | else |
59 | | - if Config.Framework == 'esx' then |
| 61 | + if Config.Framework == "esx" then |
60 | 62 | return Core.GetPlayerData() |
61 | | - elseif Config.Framework == 'qb' then |
| 63 | + elseif Config.Framework == "qb" then |
62 | 64 | return Core.Functions.GetPlayerData() |
| 65 | + elseif Config.Framework == "qbx" then |
| 66 | + return exports.qbx_core:GetPlayerData() |
63 | 67 | end |
64 | 68 | end |
65 | 69 | end |
66 | 70 |
|
67 | 71 | --------------------- CLIENT FUNCTIONS --------------------- |
68 | 72 |
|
69 | 73 | -- Returns the item metadata |
70 | | ----@param itemData table The item data from using the item |
71 | | ----@return table The metadata of the item |
72 | | -function GetItemMetadata(itemData) |
73 | | - if Config.Inventory == 'esx' then |
| 74 | +--- @param itemData table The item data from using the item |
| 75 | +--- @return table The metadata of the item |
| 76 | +function GetItemMetadata(itemData) |
| 77 | + if Config.Inventory == "esx" then |
74 | 78 | -- ESX inventory does not support metadata by default, recommended to use ox_inventory instead |
75 | 79 | print("GetItemMetadata is missing an implementation in the framework file for esx") |
76 | | - elseif Config.Inventory == 'qb' then |
| 80 | + elseif Config.Inventory == "qb" then |
77 | 81 | return itemData.info |
78 | | - elseif Config.Inventory == 'ox' then |
| 82 | + elseif Config.Inventory == "ox" then |
79 | 83 | return itemData.metadata |
| 84 | + else |
| 85 | + warn("Invalid Config.Inventory: <" .. tostring(Config.Inventory) .. ">. Update GetItemMetadata in framework.lua.") |
80 | 86 | end |
81 | 87 | end |
82 | 88 |
|
83 | 89 | --------------------- SERVER FUNCTIONS --------------------- |
84 | 90 |
|
85 | 91 | -- Registers a useable item |
86 | | ----@param itemName string The name of the item to register |
87 | | ----@param callbackFn function The function to call when the item is used |
| 92 | +--- @param itemName string The name of the item to register |
| 93 | +--- @param callbackFn function The function to call when the item is used |
88 | 94 | function CreateUseableItem(itemName, callbackFn) |
89 | 95 | if not IsDuplicityVersion() then return end |
90 | | - if Config.Framework == 'esx' then |
| 96 | + if Config.Framework == "esx" then |
91 | 97 | -- ESX returns the itemName as the second parameter, itemdata as the third parameter when calling the callback function |
92 | 98 | -- We are interested in the itemData for our callback |
93 | | - local function ESXCallback(source, itemName, itemData) |
| 99 | + local function ESXCallback(source, itemName, itemData) |
94 | 100 | callbackFn(source, itemData) |
95 | 101 | end |
96 | 102 |
|
97 | 103 | return Core.RegisterUsableItem(itemName, ESXCallback) |
98 | | - elseif Config.Framework == 'qb' then |
| 104 | + elseif Config.Framework == "qb" then |
99 | 105 | return Core.Functions.CreateUseableItem(itemName, callbackFn) |
| 106 | + |
| 107 | + elseif Config.Framework == "qbx" then |
| 108 | + return exports.qbx_core:CreateUseableItem(itemName, callbackFn) |
| 109 | + else |
| 110 | + warn("Invalid Config.Framework: <" .. tostring(Config.Framework) .. ">. Update CreateUseableItem in framework.lua.") |
100 | 111 | end |
101 | 112 | end |
102 | 113 |
|
103 | 114 | -- Adds item to the players inventory |
104 | | ----@param source number The source of the player |
105 | | ----@param itemName string The name of the item to add |
106 | | ----@param amount number The amount of the item to add |
107 | | ----@param info table Metadata to add to the item |
| 115 | +--- @param source number The source of the player |
| 116 | +--- @param itemName string The name of the item to add |
| 117 | +--- @param amount number The amount of the item to add |
| 118 | +--- @param info table Metadata to add to the item |
108 | 119 | function AddItem(source, itemName, amount, info) |
109 | 120 | if not IsDuplicityVersion() then return end |
110 | | - if Config.Inventory == 'esx' then |
| 121 | + if Config.Inventory == "esx" then |
111 | 122 | local xPlayer = Core.GetPlayerFromId(source) |
112 | 123 | return xPlayer.addInventoryItem(itemName, amount) |
113 | | - elseif Config.Inventory == 'qb' then |
| 124 | + elseif Config.Inventory == "qb" then |
114 | 125 | local Player = Core.Functions.GetPlayer(source) |
115 | | - TriggerClientEvent('inventory:client:ItemBox', source, Core.Shared.Items[itemName], "add") |
116 | | - return Player.Functions.AddItem(itemName, amount, nil, info) |
117 | | - elseif Config.Inventory == 'ox' then |
| 126 | + TriggerClientEvent("inventory:client:ItemBox", source, Core.Shared.Items[itemName], "add") |
| 127 | + return Player.Functions.AddItem(itemName, amount, nil, info) |
| 128 | + elseif Config.Inventory == "ox" then |
118 | 129 | exports.ox_inventory:AddItem(source, itemName, amount, info) |
| 130 | + else |
| 131 | + warn("Invalid Config.Inventory: <" .. tostring(Config.Inventory) .. ">. Update AddItem in framework.lua.") |
119 | 132 | end |
120 | 133 | end |
0 commit comments