player/xplayer guards
This commit is contained in:
1 parent
ce1903b7d6
commit
b77fbeffa8
3 files changed
+91
-12
No files matched your search
@@ -9,14 +9,18 @@ Framework.GetFrameworkName = function()
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
-- Framework.GetPlayerIdentifier(src)
|
||||
-- Returns the citizen ID of the player.
|
||||
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
|
||||
return playerData.citizenid
|
||||
end
|
||||
@@ -24,7 +28,9 @@ end
|
||||
-- Framework.GetPlayerName(src)
|
||||
-- Returns the first and last name of the player.
|
||||
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
|
||||
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 {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||
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 = {}
|
||||
for _, v in pairs(playerInventory) do
|
||||
if v.name == item and (not metadata or v.info == metadata) then
|
||||
@@ -50,7 +58,9 @@ end
|
||||
-- Framework.GetItemCount(src, item, metadata)
|
||||
-- Returns the count of items matching the specified name and if passed metadata from the player's inventory.
|
||||
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
|
||||
for _, v in pairs(playerInventory) do
|
||||
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 {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||
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 = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
table.insert(repackedTable, {
|
||||
@@ -81,6 +93,7 @@ end
|
||||
-- Adds the specified metadata key and number value to the player's data.
|
||||
Framework.SetPlayerMetadata = function(src, metadata, value)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
player.Functions.SetMetaData(metadata, value)
|
||||
return true
|
||||
end
|
||||
@@ -89,6 +102,7 @@ end
|
||||
-- Gets the specified metadata key to the player's data.
|
||||
Framework.GetPlayerMetadata = function(src, metadata)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
return playerData.metadata[metadata] or false
|
||||
end
|
||||
@@ -97,6 +111,7 @@ end
|
||||
-- Adds the specified value to the player's stress level and updates the client HUD.
|
||||
Framework.AddStress = function(src, value)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newStress = playerData.metadata.stress + value
|
||||
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.
|
||||
Framework.RemoveStress = function(src, value)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newStress = (playerData.metadata.stress or 0) - value
|
||||
player.Functions.SetMetaData('stress', Math.Clamp(newStress, 0, 100))
|
||||
@@ -119,6 +135,7 @@ end
|
||||
-- Adds the specified value from the player's hunger level.
|
||||
Framework.AddHunger = function(src, value)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newHunger = (playerData.metadata.hunger or 0) + value
|
||||
player.Functions.SetMetaData('hunger', Math.Clamp(newHunger, 0, 100))
|
||||
@@ -130,6 +147,7 @@ end
|
||||
-- Adds the specified value from the player's thirst level.
|
||||
Framework.AddThirst = function(src, value)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newThirst = (playerData.metadata.thirst or 0) + value
|
||||
player.Functions.SetMetaData('thirst', Math.Clamp(newThirst, 0, 100))
|
||||
@@ -139,6 +157,7 @@ end
|
||||
|
||||
Framework.GetHunger = function(src)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newHunger = (playerData.metadata.hunger or 0)
|
||||
return newHunger
|
||||
@@ -146,6 +165,7 @@ end
|
||||
|
||||
Framework.GetThirst = function(src)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
local playerData = player.PlayerData
|
||||
local newThirst = (playerData.metadata.thirst or 0)
|
||||
return newThirst
|
||||
@@ -154,7 +174,9 @@ end
|
||||
-- Framework.GetPlayerPhone(src)
|
||||
-- Returns the phone number of the player.
|
||||
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
|
||||
end
|
||||
|
||||
@@ -187,11 +209,14 @@ end
|
||||
-- Sets the player's job to the specified name and grade.
|
||||
Framework.SetPlayerJob = function(src, name, grade)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
return player.Functions.SetJob(name, grade)
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
|
||||
@@ -199,6 +224,7 @@ end
|
||||
-- Adds the specified amount to the player's account balance of the specified type.
|
||||
Framework.AddAccountBalance = function(src, _type, amount)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return player.Functions.AddMoney(_type, amount)
|
||||
end
|
||||
@@ -207,6 +233,7 @@ end
|
||||
-- Removes the specified amount from the player's account balance of the specified type.
|
||||
Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
if _type == 'money' then _type = 'cash' end
|
||||
return player.Functions.RemoveMoney(_type, amount)
|
||||
end
|
||||
@@ -214,7 +241,9 @@ end
|
||||
-- Framework.GetAccountBalance(src, _type)
|
||||
-- Returns the player's account balance of the specified 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
|
||||
return playerData.money[_type]
|
||||
end
|
||||
@@ -223,6 +252,7 @@ end
|
||||
-- Adds the specified item to the player's inventory.
|
||||
Framework.AddItem = function(src, item, amount, slot, metadata)
|
||||
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})
|
||||
return player.Functions.AddItem(item, amount, slot, metadata)
|
||||
end
|
||||
@@ -231,6 +261,7 @@ end
|
||||
-- Removes the specified item from the player's inventory.
|
||||
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
||||
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})
|
||||
return player.Functions.RemoveItem(item, amount, slot)
|
||||
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
|
||||
Framework.SetMetadata = function(src, item, slot, metadata)
|
||||
local player = QBox:GetPlayer(src)
|
||||
if not player then return end
|
||||
player.Functions.RemoveItem(item, 1, slot)
|
||||
return player.Functions.AddItem(item, 1, slot, metadata)
|
||||
end
|
||||
|
||||
Reference in new issue
Block a user