Player Functions
Functions available on the server player object. Use GetPlayer to retrieve the object.
GetPlayer
To first access the player functions, you need to get the player
source
Number
Source of the player
TMC.Functions.RegisterServerEvent("example:server:getPlayer", function(src)
local source = src
local player = TMC.Functions.GetPlayer(source)
end)
Money
AddMoney
Add money to the player in the selected place
type
String
Money type e.g. cash or bank
amount
Number
Amount to be added
reason
String
Reason (Shown on bank statements)
-- Returns if the payment was successful
local player = TMC.Functions.GetPlayer(source)
local success = player.Functions.AddMoney("cash", 1000, "Example Payment")
RemoveMoney
Remove money from the player in the selected place
type
String
Money type e.g. cash or bank
amount
Number
Amount to be removed
reason
String
Reason (Shown on bank statements)
-- Returns if the payment was successful (they had enough money)
local player = TMC.Functions.GetPlayer(source)
local success = player.Functions.RemoveMoney("bank", 1000, "Example Payment")
Jobs
AddJob
Add a job to the player
job
String
The job to add to the player
grade
Number
The grade to set the player to. If not set will default to 1
-- Returns if the job was added successfully
local player = TMC.Functions.GetPlayer(source)
local success = player.Functions.AddJob("police", 3)
RemoveJob
Remove a job to the player
job
String
The job to remove from the player
local player = TMC.Functions.GetPlayer(source)
player.Functions.RemoveJob("police")
HasJob
Returns a bool indicating if the player (character) has the defined job. If a grade is also defined, it'll return a bool indicating if the player (character) has the defined job and grade. If the player (character) doesn't have the job (and optionally, the grade) then it'll return a second string value indicating if the mismatch is the defined job or grade
job
String
The job name that the player must have
grade
Number
The grade number that the player must have
-- Example Player Job Data
-- { [1] = { ["grade"] = { ["level"] = 3,["name"] = Sergeant,} ,["onduty"] = true,["name"] = police,["isBusiness"] = false,["label"] = Law Enforcement,["isPolice"] = true,["payment"] = 870,}
local player = TMC.Functions.GetPlayer(source)
if player.Functions.HasJob("police") then
--
end
if player.Functions.HasJob("police", 3) then
--
end
local hasJob = player.Functions.HasJob("police", 3)
-- hasJob = true
local hasJob, reason = player.Functions.HasJob("ems", 3)
-- hasJob = false
-- reason = "job"
local hasJob, reason = player.Functions.HasJob("police", 5)
-- hasJob = false
-- reason = "grade"
HasGrade
Returns a bool indicating if the player (character) has the defined job and grade access
job
String
The job name that the player must have
grade
Number
The grade number that the player must have
maxGrade
Bool
This defines the grade floor and ceiling when checking for access
-- Example Job Grade Data
-- { [1] = "High Command Staff", [2] = "Command Staff", [3] = "Sergeant", [4] = "Senior Officer", [5] = "Officer" }
-- Example Player Job Data
-- { [1] = { ["grade"] = { ["level"] = 3,["name"] = Sergeant,} ,["onduty"] = true,["name"] = police,["isBusiness"] = false,["label"] = Law Enforcement,["isPolice"] = true,["payment"] = 870,}
local player = TMC.Functions.GetPlayer(source)
if player.Functions.HasGrade("police", 3, false) then
-- player has the police job and a grade level between 1 - 3
end
if player.Functions.HasGrade("police", 3, true) then
-- player has the police job and a grade level between 3 - 5
end
IsOnDuty
Returns either a bool or a string indicating if the player is on duty for any or the optionally defined job. If the player is on duty, it'll also return the grade level of the on-duty job
job
String
The job name that'll be used to check if the player is on duty
local player = TMC.Functions.GetPlayer(source)
if player.Functions.IsOnDuty() then
--
end
-- Example Player Job Data
-- { [1] = { ["grade"] = { ["level"] = 3,["name"] = Sergeant,} ,["onduty"] = true,["name"] = police,["isBusiness"] = false,["label"] = Law Enforcement,["isPolice"] = true,["payment"] = 870,}
if player.Functions.IsOnDuty("police") then
--
end
local job, grade = player.Functions.IsOnDuty()
-- job = "police"
-- grade = 3
if player.Functions.IsOnDuty() == "police" then
--
end
OnDutyBusiness
Returns either a bool or a string indicating if the player is on duty for a job that is a business
local player = TMC.Functions.GetPlayer(source)
if player.Functions.OnDutyBusiness() then
--
end
-- Example Player Job Data
-- { [1] = { ["grade"] = { ["level"] = 1,["name"] = Manager,} ,["onduty"] = true,["name"] = realtor,["isBusiness"] = true,["label"] = Dynasty 8,["isPolice"] = false,["payment"] = 300,}
local job = player.Functions.OnDutyBusiness()
-- job = "realtor"
if player.Functions.OnDutyBusiness() == "realtor" then
--
end
SetJobDuty
Returns a bool indicating if the player duty was set
job
String
The job to set duty for
onDuty
Bool
If the player should be set on duty
local player = TMC.Functions.GetPlayer(source)
if player.Functions.SetJobDuty("police", true) then
--
end
Items
AddItem
Add an item to the player's inventory
item
String
The item to add to the player
amount
Number
The amount of items to add
slot
Number
The specific slot to add the item to
info
Object
The info/metadata for the object
-- Returns if the item was added successfully
local player = TMC.Functions.GetPlayer(source)
local success = player.Functions.AddItem("apple", 2)
if player.Functions.AddItem("sim_card", 1, nil, { phoneNumber = "0123456789" }) then
--
end
RemoveItem
Remove an item to the player's inventory
item
String
The item to remove from the player
amount
Number
The amount of items to remove
slot
Number
The specific slot to remove the item from
-- Returns if the item was removed successfully
local player = TMC.Functions.GetPlayer(source)
local success = player.Functions.RemoveItem("apple", 2)
if player.Functions.RemoveItem("sim_card", 1, 5) then
--
end
UpdateItemInfo
Update the metadata/info of a specific item
slot
Number
The slot to update
slotIndex
Number
The slot index to update
info
Object
The updated item metadata (full object)
TMC.Functions.CreateUseableItem('itemName', function(source, item)
local player = TMC.Functions.GetPlayer(source)
if not item.info then item.info = {} end
if not item.info.useTracking then item.info.useTracking = 0 end
item.info.useTracking = item.info.useTracking + 1
player.Functions.UpdateItemInfo(item.slot, item.index, item.info)
end)
HasItem
Returns a bool indicating if the player (character) has the defined item
name
String
The item name to check for
local player = TMC.Functions.GetPlayer(source)
if player.Functions.HasItem("apple") then
--
end
Crypto
AddCrypto
Add cryptocurrency to the player
crypto
String
Crypto key (See laptop/configCrypto.lua)
amount
Number
Amount to be added
-- Returns if the payment was successful
local player = TMC.Functions.GetPlayer(source)
local success = player.Functions.AddCrypto("link", 1.5)
RemoveCrypto
Remove cryptocurrency from the player
cryptoe
String
Crypto key (See laptop/configCrypto.lua)
amount
Number
Amount to be removed
-- Returns if the payment was successful (they had enough crypto)
local player = TMC.Functions.GetPlayer(source)
local success = player.Functions.RemoveCrypto("link", 2.5)
Other
SetMetaData
Set metadata on the player object
metadataKey
String
The key to set within the player object
value
Any
The value to set
local player = TMC.Functions.GetPlayer(source)
player.Functions.SetMetaData("hunger", 50)
player.Functions.SetMetaData("customResourceInfo", {
Enabled = true,
Test = "Something"
})
SetReputation
Set the rep value for a player. Will initialise at a value of 0 if it doesn't exist
rep
String
The rep to set
value
Any
The value to set
local player = TMC.Functions.GetPlayer(source)
player.Functions.SetReputation("crafting", 50)
AddReputation
Adds the rep value to the existing rep for a player. Will initialise at a value of 0 if it doesn't exist
rep
String
The rep to add to
value
Any
The value to add
local player = TMC.Functions.GetPlayer(source)
player.Functions.AddReputation("crafting", 2)
GetFullName
Returns the full name of the player character
local player = TMC.Functions.GetPlayer(source)
local name = player.Functions.GetFullName()
Last updated