player/xplayer guards

This commit is contained in:
MrNewb committed 2025-03-03 02:05:53 -05:00
1 parent ce1903b7d6
commit b77fbeffa8
3 files changed
+91 -12

No files matched your search

+22 -2
View File
@@ -10,6 +10,7 @@ end
Framework.GetPlayerDob = function(src) Framework.GetPlayerDob = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
local dob = xPlayer.get("dateofbirth") local dob = xPlayer.get("dateofbirth")
return dob return dob
end end
@@ -18,6 +19,7 @@ end
-- Returns the citizen ID of the player. -- Returns the citizen ID of the player.
Framework.GetPlayerIdentifier = function(src) Framework.GetPlayerIdentifier = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.getIdentifier() return xPlayer.getIdentifier()
end end
@@ -25,6 +27,7 @@ end
-- Returns the first and last name of the player. -- Returns the first and last name of the player.
Framework.GetPlayerName = function(src) Framework.GetPlayerName = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.variables.firstName, xPlayer.variables.lastName return xPlayer.variables.firstName, xPlayer.variables.lastName
end end
@@ -32,7 +35,9 @@ end
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory. -- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetItem = function(src, item, _) Framework.GetItem = function(src, item, _)
local playerItems = ESX.GetPlayerFromId(src).getInventory() local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
local playerItems = xPlayer.getInventory()
local repackedTable = {} local repackedTable = {}
for _, v in pairs(playerItems) do for _, v in pairs(playerItems) do
if v.name == item then if v.name == item then
@@ -51,6 +56,7 @@ end
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory. -- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
Framework.GetItemCount = function(src, item, _) Framework.GetItemCount = function(src, item, _)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.getInventoryItem(item).count return xPlayer.getInventoryItem(item).count
end end
@@ -58,7 +64,9 @@ end
-- Returns the entire inventory of the player as a table. -- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, _, _} -- returns {name = v.name, count = v.amount, _, _}
Framework.GetPlayerInventory = function(src) Framework.GetPlayerInventory = function(src)
local playerItems = ESX.GetPlayerFromId(src).getInventory() local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
local playerItems = xPlayer.getInventory()
local repackedTable = {} local repackedTable = {}
for _, v in pairs(playerItems) do for _, v in pairs(playerItems) do
if v.count > 0 then if v.count > 0 then
@@ -77,6 +85,7 @@ end
-- Adds the specified metadata key and number value to the player's data. -- Adds the specified metadata key and number value to the player's data.
Framework.SetPlayerMetadata = function(src, metadata, value) Framework.SetPlayerMetadata = function(src, metadata, value)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
xPlayer.setMeta(metadata, value, nil) xPlayer.setMeta(metadata, value, nil)
return true return true
end end
@@ -85,6 +94,7 @@ end
-- Gets the specified metadata key and value to the player's data. -- Gets the specified metadata key and value to the player's data.
Framework.GetPlayerMetadata = function(src, metadata) Framework.GetPlayerMetadata = function(src, metadata)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.getMeta(metadata) or false return xPlayer.getMeta(metadata) or false
end end
@@ -95,6 +105,7 @@ end
-- phone_number, pincode -- phone_number, pincode
Framework.GetStatus = function(src, column) Framework.GetStatus = function(src, column)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.get(column) or nil return xPlayer.get(column) or nil
end end
@@ -132,6 +143,7 @@ end
-- Returns the phone number of the player. -- Returns the phone number of the player.
Framework.GetPlayerPhone = function(src) Framework.GetPlayerPhone = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.get("phone_number") return xPlayer.get("phone_number")
end end
@@ -139,6 +151,7 @@ end
-- Returns the job name, label, grade name, and grade level of the player. -- Returns the job name, label, grade name, and grade level of the player.
Framework.GetPlayerJob = function(src) Framework.GetPlayerJob = function(src)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.getJob().name, xPlayer.getJob().label, xPlayer.getJob().grade_label, xPlayer.getJob().grade return xPlayer.getJob().name, xPlayer.getJob().label, xPlayer.getJob().grade_label, xPlayer.getJob().grade
end end
@@ -160,12 +173,14 @@ end
-- Sets the player's job to the specified name and grade. -- Sets the player's job to the specified name and grade.
Framework.SetPlayerJob = function(src, name, grade) Framework.SetPlayerJob = function(src, name, grade)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
if not ESX.DoesJobExist(name, grade) then lib.print.error("Job Does Not Exsist In Framework :NAME "..name.." Grade:"..grade) return end if not ESX.DoesJobExist(name, grade) then lib.print.error("Job Does Not Exsist In Framework :NAME "..name.." Grade:"..grade) return end
return xPlayer.setJob(name, grade, true) return xPlayer.setJob(name, grade, true)
end end
Framework.ToggleDuty = function(src, status) Framework.ToggleDuty = function(src, status)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
local name = xPlayer.getJob().name local name = xPlayer.getJob().name
local grade = xPlayer.getJob().grade local grade = xPlayer.getJob().grade
xPlayer.setJob(name, grade, status) xPlayer.setJob(name, grade, status)
@@ -175,6 +190,7 @@ end
-- Adds the specified amount to the player's account balance of the specified type. -- Adds the specified amount to the player's account balance of the specified type.
Framework.AddAccountBalance = function(src, _type, amount) Framework.AddAccountBalance = function(src, _type, amount)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.addAccountMoney(_type, amount) return xPlayer.addAccountMoney(_type, amount)
end end
@@ -182,6 +198,7 @@ end
-- Removes the specified amount from the player's account balance of the specified type. -- Removes the specified amount from the player's account balance of the specified type.
Framework.RemoveAccountBalance = function(src, _type, amount) Framework.RemoveAccountBalance = function(src, _type, amount)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.removeAccountMoney(_type, amount) return xPlayer.removeAccountMoney(_type, amount)
end end
@@ -189,6 +206,7 @@ end
-- Returns the player's account balance of the specified type. -- Returns the player's account balance of the specified type.
Framework.GetAccountBalance = function(src, _type) Framework.GetAccountBalance = function(src, _type)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.getAccount(_type).money return xPlayer.getAccount(_type).money
end end
@@ -196,6 +214,7 @@ end
-- Adds the specified item to the player's inventory. -- Adds the specified item to the player's inventory.
Framework.AddItem = function(src, item, amount, slot, metadata) Framework.AddItem = function(src, item, amount, slot, metadata)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.addInventoryItem(item, amount) return xPlayer.addInventoryItem(item, amount)
end end
@@ -203,6 +222,7 @@ end
-- Removes the specified item from the player's inventory. -- Removes the specified item from the player's inventory.
Framework.RemoveItem = function(src, item, amount, slot, metadata) Framework.RemoveItem = function(src, item, amount, slot, metadata)
local xPlayer = ESX.GetPlayerFromId(src) local xPlayer = ESX.GetPlayerFromId(src)
if not xPlayer then return end
return xPlayer.removeInventoryItem(item, amount) return xPlayer.removeInventoryItem(item, amount)
end end
+28 -1
View File
@@ -13,6 +13,7 @@ end
-- Returns the citizen ID of the player. -- Returns the citizen ID of the player.
Framework.GetPlayerIdentifier = function(src) Framework.GetPlayerIdentifier = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.citizenid return playerData.citizenid
end end
@@ -21,12 +22,14 @@ end
-- Returns the first and last name of the player. -- Returns the first and last name of the player.
Framework.GetPlayerName = function(src) Framework.GetPlayerName = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname return playerData.charinfo.firstname, playerData.charinfo.lastname
end end
Framework.GetPlayerDob = function(src) Framework.GetPlayerDob = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.birthdate return playerData.charinfo.birthdate
end end
@@ -36,6 +39,7 @@ end
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetItem = function(src, item, metadata) Framework.GetItem = function(src, item, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
local repackedTable = {} local repackedTable = {}
@@ -56,6 +60,7 @@ end
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory. -- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
Framework.GetItemCount = function(src, item, metadata) Framework.GetItemCount = function(src, item, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
local count = 0 local count = 0
@@ -72,6 +77,7 @@ end
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetPlayerInventory = function(src) Framework.GetPlayerInventory = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
local repackedTable = {} local repackedTable = {}
@@ -88,6 +94,7 @@ end
Framework.GetItemBySlot = function(src, slot) Framework.GetItemBySlot = function(src, slot)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local playerInventory = playerData.items local playerInventory = playerData.items
local repack = {} local repack = {}
@@ -112,6 +119,7 @@ end
-- Adds the specified metadata key and number value to the player's data. -- Adds the specified metadata key and number value to the player's data.
Framework.SetPlayerMetadata = function(src, metadata, value) Framework.SetPlayerMetadata = function(src, metadata, value)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
player.Functions.SetMetaData(metadata, value) player.Functions.SetMetaData(metadata, value)
return true return true
end end
@@ -120,6 +128,7 @@ end
-- Gets the specified metadata key to the player's data. -- Gets the specified metadata key to the player's data.
Framework.GetPlayerMetadata = function(src, metadata) Framework.GetPlayerMetadata = function(src, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.metadata[metadata] or false return playerData.metadata[metadata] or false
end end
@@ -128,6 +137,7 @@ end
-- Adds the specified value to the player's stress level and updates the client HUD. -- Adds the specified value to the player's stress level and updates the client HUD.
Framework.AddStress = function(src, value) Framework.AddStress = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = playerData.metadata.stress + value local newStress = playerData.metadata.stress + value
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100)) player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
@@ -139,6 +149,7 @@ end
-- Removes the specified value from the player's stress level and updates the client HUD. -- Removes the specified value from the player's stress level and updates the client HUD.
Framework.RemoveStress = function(src, value) Framework.RemoveStress = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = (playerData.metadata.stress or 0) - value local newStress = (playerData.metadata.stress or 0) - value
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100)) player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
@@ -150,6 +161,7 @@ end
-- Adds the specified value from the player's hunger level. -- Adds the specified value from the player's hunger level.
Framework.AddHunger = function(src, value) Framework.AddHunger = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) + value local newHunger = (playerData.metadata.hunger or 0) + value
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100)) player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
@@ -161,6 +173,7 @@ end
-- Adds the specified value from the player's thirst level. -- Adds the specified value from the player's thirst level.
Framework.AddThirst = function(src, value) Framework.AddThirst = function(src, value)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) + value local newThirst = (playerData.metadata.thirst or 0) + value
player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100)) player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100))
@@ -170,6 +183,7 @@ end
Framework.GetHunger = function(src) Framework.GetHunger = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) local newHunger = (playerData.metadata.hunger or 0)
return newHunger return newHunger
@@ -177,6 +191,7 @@ end
Framework.GetThirst = function(src) Framework.GetThirst = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) local newThirst = (playerData.metadata.thirst or 0)
return newThirst return newThirst
@@ -186,6 +201,7 @@ end
-- Returns the phone number of the player. -- Returns the phone number of the player.
Framework.GetPlayerPhone = function(src) Framework.GetPlayerPhone = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.charinfo.phone return playerData.charinfo.phone
end end
@@ -194,6 +210,7 @@ end
-- Returns the gang name of the player. -- Returns the gang name of the player.
Framework.GetPlayerGang = function(src) Framework.GetPlayerGang = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.gang.name return playerData.gang.name
end end
@@ -216,6 +233,7 @@ end
-- Returns the job name, label, grade name, and grade level of the player. -- Returns the job name, label, grade name, and grade level of the player.
Framework.GetPlayerJob = function(src) Framework.GetPlayerJob = function(src)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level return playerData.job.name, playerData.job.label, playerData.job.grade.name, playerData.job.grade.level
end end
@@ -224,11 +242,13 @@ end
-- Sets the player's job to the specified name and grade. -- Sets the player's job to the specified name and grade.
Framework.SetPlayerJob = function(src, name, grade) Framework.SetPlayerJob = function(src, name, grade)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
return player.Functions.SetJob(name, grade) return player.Functions.SetJob(name, grade)
end end
Framework.ToggleDuty = function(src, status) Framework.ToggleDuty = function(src, status)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
player.Functions.SetJobDuty(status) player.Functions.SetJobDuty(status)
TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty) TriggerEvent('QBCore:Server:SetDuty', src, player.PlayerData.job.onduty)
end end
@@ -237,6 +257,7 @@ end
-- Adds the specified amount to the player's account balance of the specified type. -- Adds the specified amount to the player's account balance of the specified type.
Framework.AddAccountBalance = function(src, _type, amount) Framework.AddAccountBalance = function(src, _type, amount)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.AddMoney(_type, amount) return player.Functions.AddMoney(_type, amount)
end end
@@ -245,6 +266,7 @@ end
-- Removes the specified amount from the player's account balance of the specified type. -- Removes the specified amount from the player's account balance of the specified type.
Framework.RemoveAccountBalance = function(src, _type, amount) Framework.RemoveAccountBalance = function(src, _type, amount)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.RemoveMoney(_type, amount) return player.Functions.RemoveMoney(_type, amount)
end end
@@ -252,7 +274,9 @@ end
-- Framework.GetAccountBalance(src, _type) -- Framework.GetAccountBalance(src, _type)
-- Returns the player's account balance of the specified type. -- Returns the player's account balance of the specified type.
Framework.GetAccountBalance = function(src, _type) Framework.GetAccountBalance = function(src, _type)
local playerData = QBCore.Functions.GetPlayer(src).PlayerData local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return playerData.money[_type] return playerData.money[_type]
end end
@@ -261,6 +285,7 @@ end
-- Adds the specified item to the player's inventory. -- Adds the specified item to the player's inventory.
Framework.AddItem = function(src, item, amount, slot, metadata) Framework.AddItem = function(src, item, amount, slot, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata})
return player.Functions.AddItem(item, amount, slot, metadata) return player.Functions.AddItem(item, amount, slot, metadata)
end end
@@ -269,6 +294,7 @@ end
-- Removes the specified item from the player's inventory. -- Removes the specified item from the player's inventory.
Framework.RemoveItem = function(src, item, amount, slot, metadata) Framework.RemoveItem = function(src, item, amount, slot, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
return player.Functions.RemoveItem(item, amount, slot or nil) return player.Functions.RemoveItem(item, amount, slot or nil)
end end
@@ -278,6 +304,7 @@ end
-- Notes, this is kinda a jank workaround. with the framework aside from updating the entire table theres not really a better way -- Notes, this is kinda a jank workaround. with the framework aside from updating the entire table theres not really a better way
Framework.SetMetadata = function(src, item, slot, metadata) Framework.SetMetadata = function(src, item, slot, metadata)
local player = QBCore.Functions.GetPlayer(src) local player = QBCore.Functions.GetPlayer(src)
if not player then return end
local slotFinder = Framework.GetPlayerInventory(src) local slotFinder = Framework.GetPlayerInventory(src)
local freeSlot = Table.FindFirstUnoccupiedSlot(slotFinder) local freeSlot = Table.FindFirstUnoccupiedSlot(slotFinder)
local itemSlot = slot or nil local itemSlot = slot or nil
+41 -9
View File
@@ -9,14 +9,18 @@ Framework.GetFrameworkName = function()
end end
Framework.GetPlayerDob = function(src) Framework.GetPlayerDob = function(src)
local playerData = QBox:GetPlayer(src).PlayerData local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.birthdate return playerData.charinfo.birthdate
end end
-- Framework.GetPlayerIdentifier(src) -- Framework.GetPlayerIdentifier(src)
-- Returns the citizen ID of the player. -- Returns the citizen ID of the player.
Framework.GetPlayerIdentifier = function(src) Framework.GetPlayerIdentifier = function(src)
local playerData = QBox:GetPlayer(src).PlayerData local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if not playerData then return false end if not playerData then return false end
return playerData.citizenid return playerData.citizenid
end end
@@ -24,7 +28,9 @@ end
-- Framework.GetPlayerName(src) -- Framework.GetPlayerName(src)
-- Returns the first and last name of the player. -- Returns the first and last name of the player.
Framework.GetPlayerName = function(src) Framework.GetPlayerName = function(src)
local playerData = QBox:GetPlayer(src).PlayerData local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.firstname, playerData.charinfo.lastname return playerData.charinfo.firstname, playerData.charinfo.lastname
end end
@@ -32,7 +38,9 @@ end
-- Returns a table of items matching the specified name and if passed metadata from the player's inventory. -- Returns a table of items matching the specified name and if passed metadata from the player's inventory.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetItem = function(src, item, metadata) Framework.GetItem = function(src, item, metadata)
local playerInventory = QBox:GetPlayer(src).PlayerData.items local player = QBox:GetPlayer(src)
if not player then return end
local playerInventory = player.PlayerData.items
local repackedTable = {} local repackedTable = {}
for _, v in pairs(playerInventory) do for _, v in pairs(playerInventory) do
if v.name == item and (not metadata or v.info == metadata) then if v.name == item and (not metadata or v.info == metadata) then
@@ -50,7 +58,9 @@ end
-- Framework.GetItemCount(src, item, metadata) -- Framework.GetItemCount(src, item, metadata)
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory. -- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
Framework.GetItemCount = function(src, item, metadata) Framework.GetItemCount = function(src, item, metadata)
local playerInventory = QBox:GetPlayer(src).PlayerData.items local player = QBox:GetPlayer(src)
if not player then return end
local playerInventory = player.PlayerData.items
local count = 0 local count = 0
for _, v in pairs(playerInventory) do for _, v in pairs(playerInventory) do
if v.name == item and (not metadata or v.info == metadata) then if v.name == item and (not metadata or v.info == metadata) then
@@ -64,7 +74,9 @@ end
-- Returns the entire inventory of the player as a table. -- Returns the entire inventory of the player as a table.
-- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot} -- returns {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
Framework.GetPlayerInventory = function(src) Framework.GetPlayerInventory = function(src)
local playerItems = QBox:GetPlayer(src).PlayerData.items local player = QBox:GetPlayer(src)
if not player then return end
local playerItems = player.PlayerData.items
local repackedTable = {} local repackedTable = {}
for _, v in pairs(playerItems) do for _, v in pairs(playerItems) do
table.insert(repackedTable, { table.insert(repackedTable, {
@@ -81,6 +93,7 @@ end
-- Adds the specified metadata key and number value to the player's data. -- Adds the specified metadata key and number value to the player's data.
Framework.SetPlayerMetadata = function(src, metadata, value) Framework.SetPlayerMetadata = function(src, metadata, value)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
player.Functions.SetMetaData(metadata, value) player.Functions.SetMetaData(metadata, value)
return true return true
end end
@@ -89,6 +102,7 @@ end
-- Gets the specified metadata key to the player's data. -- Gets the specified metadata key to the player's data.
Framework.GetPlayerMetadata = function(src, metadata) Framework.GetPlayerMetadata = function(src, metadata)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
return playerData.metadata[metadata] or false return playerData.metadata[metadata] or false
end end
@@ -97,6 +111,7 @@ end
-- Adds the specified value to the player's stress level and updates the client HUD. -- Adds the specified value to the player's stress level and updates the client HUD.
Framework.AddStress = function(src, value) Framework.AddStress = function(src, value)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = playerData.metadata.stress + value local newStress = playerData.metadata.stress + value
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100)) player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
@@ -108,6 +123,7 @@ end
-- Removes the specified value from the player's stress level and updates the client HUD. -- Removes the specified value from the player's stress level and updates the client HUD.
Framework.RemoveStress = function(src, value) Framework.RemoveStress = function(src, value)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newStress = (playerData.metadata.stress or 0) - value local newStress = (playerData.metadata.stress or 0) - value
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100)) player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
@@ -119,6 +135,7 @@ end
-- Adds the specified value from the player's hunger level. -- Adds the specified value from the player's hunger level.
Framework.AddHunger = function(src, value) Framework.AddHunger = function(src, value)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) + value local newHunger = (playerData.metadata.hunger or 0) + value
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100)) player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
@@ -130,6 +147,7 @@ end
-- Adds the specified value from the player's thirst level. -- Adds the specified value from the player's thirst level.
Framework.AddThirst = function(src, value) Framework.AddThirst = function(src, value)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) + value local newThirst = (playerData.metadata.thirst or 0) + value
player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100)) player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100))
@@ -139,6 +157,7 @@ end
Framework.GetHunger = function(src) Framework.GetHunger = function(src)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0) local newHunger = (playerData.metadata.hunger or 0)
return newHunger return newHunger
@@ -146,6 +165,7 @@ end
Framework.GetThirst = function(src) Framework.GetThirst = function(src)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0) local newThirst = (playerData.metadata.thirst or 0)
return newThirst return newThirst
@@ -154,7 +174,9 @@ end
-- Framework.GetPlayerPhone(src) -- Framework.GetPlayerPhone(src)
-- Returns the phone number of the player. -- Returns the phone number of the player.
Framework.GetPlayerPhone = function(src) Framework.GetPlayerPhone = function(src)
local playerData = QBox:GetPlayer(src).PlayerData local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
return playerData.charinfo.phone return playerData.charinfo.phone
end end
@@ -187,11 +209,14 @@ end
-- Sets the player's job to the specified name and grade. -- Sets the player's job to the specified name and grade.
Framework.SetPlayerJob = function(src, name, grade) Framework.SetPlayerJob = function(src, name, grade)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
return player.Functions.SetJob(name, grade) return player.Functions.SetJob(name, grade)
end end
Framework.ToggleDuty = function(src, status) Framework.ToggleDuty = function(src, status)
local playerData = QBox:GetPlayer(src).PlayerData local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
QBox:SetJobDuty(playerData.citizenid, status) QBox:SetJobDuty(playerData.citizenid, status)
end end
@@ -199,6 +224,7 @@ end
-- Adds the specified amount to the player's account balance of the specified type. -- Adds the specified amount to the player's account balance of the specified type.
Framework.AddAccountBalance = function(src, _type, amount) Framework.AddAccountBalance = function(src, _type, amount)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.AddMoney(_type, amount) return player.Functions.AddMoney(_type, amount)
end end
@@ -207,6 +233,7 @@ end
-- Removes the specified amount from the player's account balance of the specified type. -- Removes the specified amount from the player's account balance of the specified type.
Framework.RemoveAccountBalance = function(src, _type, amount) Framework.RemoveAccountBalance = function(src, _type, amount)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return player.Functions.RemoveMoney(_type, amount) return player.Functions.RemoveMoney(_type, amount)
end end
@@ -214,7 +241,9 @@ end
-- Framework.GetAccountBalance(src, _type) -- Framework.GetAccountBalance(src, _type)
-- Returns the player's account balance of the specified type. -- Returns the player's account balance of the specified type.
Framework.GetAccountBalance = function(src, _type) Framework.GetAccountBalance = function(src, _type)
local playerData = QBox:GetPlayer(src).PlayerData local player = QBox:GetPlayer(src)
if not player then return end
local playerData = player.PlayerData
if _type == 'money' then _type = 'cash' end if _type == 'money' then _type = 'cash' end
return playerData.money[_type] return playerData.money[_type]
end end
@@ -223,6 +252,7 @@ end
-- Adds the specified item to the player's inventory. -- Adds the specified item to the player's inventory.
Framework.AddItem = function(src, item, amount, slot, metadata) Framework.AddItem = function(src, item, amount, slot, metadata)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "add", item = item, count = amount, slot = slot, metadata = metadata})
return player.Functions.AddItem(item, amount, slot, metadata) return player.Functions.AddItem(item, amount, slot, metadata)
end end
@@ -231,6 +261,7 @@ end
-- Removes the specified item from the player's inventory. -- Removes the specified item from the player's inventory.
Framework.RemoveItem = function(src, item, amount, slot, metadata) Framework.RemoveItem = function(src, item, amount, slot, metadata)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata}) TriggerClientEvent("community_bridge:client:inventory:updateInventory", src, {action = "remove", item = item, count = amount, slot = slot, metadata = metadata})
return player.Functions.RemoveItem(item, amount, slot) return player.Functions.RemoveItem(item, amount, slot)
end end
@@ -240,6 +271,7 @@ end
-- Notes, this is kinda a jank workaround. with the framework aside from updating the entire table theres not really a better way -- Notes, this is kinda a jank workaround. with the framework aside from updating the entire table theres not really a better way
Framework.SetMetadata = function(src, item, slot, metadata) Framework.SetMetadata = function(src, item, slot, metadata)
local player = QBox:GetPlayer(src) local player = QBox:GetPlayer(src)
if not player then return end
player.Functions.RemoveItem(item, 1, slot) player.Functions.RemoveItem(item, 1, slot)
return player.Functions.AddItem(item, 1, slot, metadata) return player.Functions.AddItem(item, 1, slot, metadata)
end end