player/xplayer guards
This commit is contained in:
1 parent
ce1903b7d6
commit
b77fbeffa8
3 files changed
+91
-12
No files matched your search
@@ -10,6 +10,7 @@ end
|
||||
|
||||
Framework.GetPlayerDob = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
local dob = xPlayer.get("dateofbirth")
|
||||
return dob
|
||||
end
|
||||
@@ -18,6 +19,7 @@ end
|
||||
-- Returns the citizen ID of the player.
|
||||
Framework.GetPlayerIdentifier = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.getIdentifier()
|
||||
end
|
||||
|
||||
@@ -25,6 +27,7 @@ end
|
||||
-- Returns the first and last name of the player.
|
||||
Framework.GetPlayerName = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.variables.firstName, xPlayer.variables.lastName
|
||||
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 {name = v.name, count = v.amount, metadata = v.info, slot = v.slot}
|
||||
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 = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
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.
|
||||
Framework.GetItemCount = function(src, item, _)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.getInventoryItem(item).count
|
||||
end
|
||||
|
||||
@@ -58,7 +64,9 @@ end
|
||||
-- Returns the entire inventory of the player as a table.
|
||||
-- returns {name = v.name, count = v.amount, _, _}
|
||||
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 = {}
|
||||
for _, v in pairs(playerItems) do
|
||||
if v.count > 0 then
|
||||
@@ -77,6 +85,7 @@ end
|
||||
-- Adds the specified metadata key and number value to the player's data.
|
||||
Framework.SetPlayerMetadata = function(src, metadata, value)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
xPlayer.setMeta(metadata, value, nil)
|
||||
return true
|
||||
end
|
||||
@@ -85,6 +94,7 @@ end
|
||||
-- Gets the specified metadata key and value to the player's data.
|
||||
Framework.GetPlayerMetadata = function(src, metadata)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.getMeta(metadata) or false
|
||||
end
|
||||
|
||||
@@ -95,6 +105,7 @@ end
|
||||
-- phone_number, pincode
|
||||
Framework.GetStatus = function(src, column)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.get(column) or nil
|
||||
end
|
||||
|
||||
@@ -132,6 +143,7 @@ end
|
||||
-- Returns the phone number of the player.
|
||||
Framework.GetPlayerPhone = function(src)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.get("phone_number")
|
||||
end
|
||||
|
||||
@@ -139,6 +151,7 @@ end
|
||||
-- Returns the job name, label, grade name, and grade level of the player.
|
||||
Framework.GetPlayerJob = function(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
|
||||
end
|
||||
|
||||
@@ -160,12 +173,14 @@ end
|
||||
-- Sets the player's job to the specified name and grade.
|
||||
Framework.SetPlayerJob = function(src, name, grade)
|
||||
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
|
||||
return xPlayer.setJob(name, grade, true)
|
||||
end
|
||||
|
||||
Framework.ToggleDuty = function(src, status)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
local name = xPlayer.getJob().name
|
||||
local grade = xPlayer.getJob().grade
|
||||
xPlayer.setJob(name, grade, status)
|
||||
@@ -175,6 +190,7 @@ end
|
||||
-- Adds the specified amount to the player's account balance of the specified type.
|
||||
Framework.AddAccountBalance = function(src, _type, amount)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.addAccountMoney(_type, amount)
|
||||
end
|
||||
|
||||
@@ -182,6 +198,7 @@ end
|
||||
-- Removes the specified amount from the player's account balance of the specified type.
|
||||
Framework.RemoveAccountBalance = function(src, _type, amount)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.removeAccountMoney(_type, amount)
|
||||
end
|
||||
|
||||
@@ -189,6 +206,7 @@ end
|
||||
-- Returns the player's account balance of the specified type.
|
||||
Framework.GetAccountBalance = function(src, _type)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.getAccount(_type).money
|
||||
end
|
||||
|
||||
@@ -196,6 +214,7 @@ end
|
||||
-- Adds the specified item to the player's inventory.
|
||||
Framework.AddItem = function(src, item, amount, slot, metadata)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.addInventoryItem(item, amount)
|
||||
end
|
||||
|
||||
@@ -203,6 +222,7 @@ end
|
||||
-- Removes the specified item from the player's inventory.
|
||||
Framework.RemoveItem = function(src, item, amount, slot, metadata)
|
||||
local xPlayer = ESX.GetPlayerFromId(src)
|
||||
if not xPlayer then return end
|
||||
return xPlayer.removeInventoryItem(item, amount)
|
||||
end
|
||||
|
||||
|
||||
Reference in new issue
Block a user