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.
Variable | Type | Description |
---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
length | Number | The length of the string to generate |
RandomInt
Returns a random string at the specified length using numeric characters
Parameter | Required | Type | Description |
---|---|---|---|
length | Number | The length of the string to generate |
SplitStr
Returns an array of strings
Parameter | Required | Type | Description |
---|---|---|---|
str | String | The string that needs to be split | |
delimiter | String | A string defining the delimiter to use |
GenerateVIN
Returns a string
Parameter | Required | Type | Description |
---|---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
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.
Parameter | Required | Type | Description |
---|---|---|---|
value | Number | The value to clamp | |
min | Number | The minimum bound | |
max | Number | The maximum bound |
MathAverage
Returns the average for numbers passed in
Parameter | Required | Type | Description |
---|---|---|---|
data | Number Array | An array of numbers to calcualte the average of. |
TrueRandom
Returns a better random number
Parameter | Required | Type | Description |
---|---|---|---|
min | Number | A min value | |
max | Number | A max value |
RandomChance
Returns a bool indicating if the chance succeeded
Paramaeter | Required | Type | Description |
---|---|---|---|
min | Number | A min value | |
max | Number | A max value | |
chance | Number | The amount of chance |
MathRound
Rounds a number
Parameter | Required | Type | Description |
---|---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
value | Number | The number you'd like to convert |
MathTrim
Removes all whitespace around a number in a string
Parameter | Required | Type | Description |
---|---|---|---|
value | String | String to clear whitespace from |
Other
GetTime
Returns a moment formatted date string or epoch timestamp (in milliseconds).
Parameter | Required | Type | Description |
---|---|---|---|
timestamp | Number/String | An optional epoch timestamp or date string that should be used instead of current time. If not provided will default to the current time. | |
format | String | Moment date formatting to use. Defaults to return the epoch timestamp. |
Decode
Parameter | Required | Type | Description |
---|---|---|---|
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.
Parameter | Required | Type | Description |
---|---|---|---|
val | Any | The value to convert |
TablePrint
Has no return value. Prints object to console in a table format. Mainly used for debugging purposes.
Parameter | Required | Type | Description |
---|---|---|---|
val | Any | The value to print to console |
Shuffle
Returns the shuffled array
Parameter | Required | Type | Description |
---|---|---|---|
tab | Array | The array to shuffle |
Merge
Returns a combined object. Will overwrite object 1's value if the same key exists. Works recursively.
Parameter | Required | Type | Description |
---|---|---|---|
obj1 | Object | First object | |
obj2 | Object | Second object to merge over the top of object 1 |
Combine
Returns an array combined from the parameters
Parameter | Required | Type | Description |
---|---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
obj | Object | Object to make a copy of |
TableHas
Returns a bool checking if the array contains a specific value
Parameter | Required | Type | Description |
---|---|---|---|
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.
Parameter | Required | Type | Description |
---|---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
permission | String | Name of the permission rank |
IsDepRunning
Checks if a resource is currently running
Parameter | Required | Type | Description |
---|---|---|---|
resName | String | Name of the resource |
TableSortAlphabetical
Sorts a table alphabetically based on the keys
Parameter | Required | Type | Description |
---|---|---|---|
data | Array | Table of data to sort |
Jobs
GetJob
Returns a job object
Parameter | Required | Type | Description |
---|---|---|---|
job | String | The key for the job you want to find |
GetJobGrade
Returns a single grade from the job object
Parameter | Required | Type | Description |
---|---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
job | String | The key for the job |
OnlinePlayersWithJob
Returns a number
Parameter | Required | Type | Description |
---|---|---|---|
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.
Parameter | Required | Type | Description |
---|---|---|---|
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.
Parameter | Required | Type | Description |
---|---|---|---|
itemInfo | Object | The info object of a stackable or unique inventory item |
EnforceItemDecay
Forcibly updates an item decay information and returns array
Parameter | Required | Type | Description |
---|---|---|---|
itemInfo | Object | The info object an item | |
info | Object | The information to update from |
UnfreezeItem
Forcibly updates an item and removes feezer data
Parameter | Required | Type | Description |
---|---|---|---|
info | Object | The information to update from |
GetItemExpiry
Returns the time till decays for an item. Either returns false or item in seconds
Parameter | Required | Type | Description |
---|---|---|---|
info | Object | The information to read from |
TableCoordsToVec
Converts a table of coords to a vector
Parameter | Required | Type | Description |
---|---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
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
Parameter | Required | Type | Description |
---|---|---|---|
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