Common Functions
Common functions are shared and available to use within both server and client script files.
Did you know there are useful static variables set up on the main TMC object for you to use! See below.
TMC.IsDev
Bool
Used to determine if the server is running in development mode
TMC.GameType
String
Stores the current game type. I.e. gta5 or rdr3
TMC.IsGTA5
Bool
Is the game type gta5
TMC.IsRDR3
Bool
Is the game type rdr3
String
RandomStr
Returns a random string at the specified length using uppercase and lowercase letters
length
Number
The length of the string to generate
RandomInt
Returns a random string at the specified length using numeric characters
length
Number
The length of the string to generate
SplitStr
Returns an array of strings
str
String
The string that needs to be split
delimiter
String
A string defining the delimiter to use
GenerateVIN
Returns a string
local
Bool
If the car is a local or a player owned vehicle. Determines a small identifier within the VIN.
GenerateBankAccount
Returns a formatted bank account number
TrimPlate
Returns a string containing the plate passed in without any spaces
plate
String
The plate to trim
Math
Clamp
Returns a value within a range of values between a defined minimum bound and a maximum bound.
value
Number
The value to clamp
min
Number
The minimum bound
max
Number
The maximum bound
MathAverage
Returns the average for numbers passed in
data
Number Array
An array of numbers to calcualte the average of.
TrueRandom
Returns a better random number
min
Number
A min value
max
Number
A max value
RandomChance
Returns a bool indicating if the chance succeeded
min
Number
A min value
max
Number
A max value
chance
Number
The amount of chance
MathRound
Rounds a number
value
Number
The number you would like to round
numDecimalPlaces
Number
The amount of decimal places you would like to include, this defaults to 0
MathGroupDigits
Groups a number together into a human-readable format. For example, convert 10000 to 10,000
value
Number
The number you'd like to convert
MathTrim
Removes all whitespace around a number in a string
value
String
String to clear whitespace from
Other
GetTime
Returns a moment formatted date string or epoch timestamp (in milliseconds).
timestamp
Number/String
format
String
Decode
val
Any
Will decode json if valid json is passed. Useful when you don't trust the data source.
Dump
Returns a nicely formatted string based on value passed in. Similar to json.encode. Will also automatically output to console. Mainly used for debugging purposes.
val
Any
The value to convert
TablePrint
Has no return value. Prints object to console in a table format. Mainly used for debugging purposes.
val
Any
The value to print to console
Shuffle
Returns the shuffled array
tab
Array
The array to shuffle
Merge
Returns a combined object. Will overwrite object 1's value if the same key exists. Works recursively.
obj1
Object
First object
obj2
Object
Second object to merge over the top of object 1
Combine
Returns an array combined from the parameters
arr1
Array
First array to combine
arr2
Array
Second array to combine
CopyTable
Returns an object with the same data as the parameter passed in
obj
Object
Object to make a copy of
TableHas
Returns a bool checking if the array contains a specific value
arr
Array
The array to search
val
Any
The value to search for within the array
GetGridZoneAtCoords
Returns a number based on the coords passed in. This would be used as a way to divide the map up into a grid.
coords
Vector3
The position on the map to get the grid number for
GetPermissionRank
Returns the permission rank id from the name.
If the rank can't be found, it defaults to 1
permission
String
Name of the permission rank
IsDepRunning
Checks if a resource is currently running
resName
String
Name of the resource
TableSortAlphabetical
Sorts a table alphabetically based on the keys
data
Array
Table of data to sort
Jobs
GetJob
Returns a job object
job
String
The key for the job you want to find
GetJobGrade
Returns a single grade from the job object
job
String
The key for the job you want to find
grade
Number
The number of the grade you want to find
JobLabel
Returns the job label as a string
job
String
The key for the job
OnlinePlayersWithJob
Returns a number
job
String
The job key
onDuty
Bool
Must be true, offDuty player checks are not supported at this time
grade
Number
If provided will check for players with at least the grade specified
Inventory
GenerateInventory
Returns an array of pre-populated item slots in the correct format.
slots
Number
The number of slots to generate in the inventory
GetItemQuality
Returns a number for the quality of an item calculated based on the decay.
itemInfo
Object
The info object of a stackable or unique inventory item
EnforceItemDecay
Forcibly updates an item decay information and returns array
itemInfo
Object
The info object an item
info
Object
The information to update from
UnfreezeItem
Forcibly updates an item and removes feezer data
info
Object
The information to update from
GetItemExpiry
Returns the time till decays for an item. Either returns false or item in seconds
info
Object
The information to read from
TableCoordsToVec
Converts a table of coords to a vector
tab
Object
Table of coords
Status Effects
These functions will not affect the value if you are not running the Status Effect resource.
TryApplyLuck
Based on the player's current luck adjust the value accordingly
value
Number
The number to minipulate
negativeCheck
Bool
Decrease the value if luck check passes
src
Number
Source of the player (Required if called from server)
RandomChanceWithLuck
Alike TMC.Common.RandomChance
however with weighting based on current luck
min
Number
Minimum number possible
max
Number
Maximum number possible
chance
Number
Amoiunt of chance
negativeCheck
Bool
Decrease the value if luck check passes
maxPercentage
Number
Maximum percentage chance possible (Defaults to 0.3)
src
Number
Source of the player (Required if called from server)
Last updated