> For the complete documentation index, see [llms.txt](https://docs.tmc.bj/v2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tmc.bj/v2/tmc-core-object/common-functions.md).

# Common Functions

{% hint style="info" %}
Did you know there are useful static variables set up on the main TMC object for you to use! See below.
{% endhint %}

<table><thead><tr><th width="194.33333333333331">Variable</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>TMC.IsDev</td><td>Bool</td><td>Used to determine if the server is running in development mode</td></tr><tr><td>TMC.GameType</td><td>String</td><td>Stores the current game type. I.e. gta5 or rdr3</td></tr><tr><td>TMC.IsGTA5</td><td>Bool</td><td>Is the game type gta5</td></tr><tr><td>TMC.IsRDR3</td><td>Bool</td><td>Is the game type rdr3</td></tr></tbody></table>

## String

### RandomStr

Returns a random string at the specified length using uppercase and lowercase letters

<table><thead><tr><th width="86.33333333333331">Parameter</th><th width="122" data-type="checkbox">Required</th><th width="128">Type</th><th>Description</th></tr></thead><tbody><tr><td>length</td><td>true</td><td>Number</td><td>The length of the string to generate</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local randomStr = TMC.Common.RandomStr(100)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let randomStr = TMC.Common.RandomStr(100);
```

{% endcode %}

### RandomInt

Returns a random string at the specified length using numeric characters

<table><thead><tr><th width="142">Parameter</th><th width="136" data-type="checkbox">Required</th><th width="134">Type</th><th>Description</th></tr></thead><tbody><tr><td>length</td><td>true</td><td>Number</td><td>The length of the string to generate</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local randomInt = TMC.Common.RandomInt(10)
-- Example output: 9274735819
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let randomInt = TMC.Common.RandomInt(10);
// Example output: 01864963759
```

{% endcode %}

### SplitStr

Returns an array of strings

<table><thead><tr><th width="141">Parameter</th><th width="112" data-type="checkbox">Required</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td>str</td><td>true</td><td>String</td><td>The string that needs to be split</td></tr><tr><td>delimiter</td><td>true</td><td>String</td><td>A string defining the delimiter to use</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local fields = TMC.Common.SplitStr('this|is|a|test', '|')
-- { 'this', 'is', 'a', 'test' }
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let fields = TMC.Common.SplitStr('this|is|a|test', '|');
// [ 'this', 'is', 'a', 'test' ]
```

{% endcode %}

### GenerateVIN

Returns a string

<table><thead><tr><th width="136">Parameter</th><th width="113" data-type="checkbox">Required</th><th width="76">Type</th><th>Description</th></tr></thead><tbody><tr><td>local</td><td>false</td><td>Bool</td><td>If the car is a local or a player owned vehicle. Determines a small identifier within the VIN.</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local spawnedVehVIN = TMC.Common.GenerateVIN(true)
local vehicleShopPurchase = TMC.Common.GenerateVIN()
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let spawnedVehVIN = TMC.Common.GenerateVIN(true)
let vehicleShopPurchase = TMC.Common.GenerateVIN()
```

{% endcode %}

### GenerateBankAccount

Returns a formatted bank account number

{% code title="Lua" %}

```lua
local newAccNumber = TMC.Common.GenerateBankAccount()
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let newAccNumber = TMC.Common.GenerateBankAccount();
```

{% endcode %}

### TrimPlate

Returns a string containing the plate passed in without any spaces

<table><thead><tr><th width="132.33333333333331">Parameter</th><th width="114" data-type="checkbox">Required</th><th width="112">Type</th><th>Description</th></tr></thead><tbody><tr><td>plate</td><td>true</td><td>String</td><td>The plate to trim</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local trimmedPlate = TMC.Common.TrimPlate('  1234  ')
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let trimmedPlate = TMC.Common.TrimPlate('  1234  ');
```

{% endcode %}

## Math

### Clamp

Returns a value within a range of values between a defined minimum bound and a maximum bound.

<table><thead><tr><th width="133.33333333333331">Parameter</th><th width="115" data-type="checkbox">Required</th><th width="121">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>true</td><td>Number</td><td>The value to clamp</td></tr><tr><td>min</td><td>false</td><td>Number</td><td>The minimum bound</td></tr><tr><td>max</td><td>false</td><td>Number</td><td>The maximum bound</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local valToClamp = math.random(100)
local val = TMC.Common.Clamp(valToClamp, 20, 80)
local valMax = TMC.Common.Clamp(valToClamp, nil, 80)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let valToClamp = Math.random() * 100;
let val = TMC.Common.Clamp(valToClamp, 20, 80);
let valMax = TMC.Common.Clamp(valToClamp, undefined, 80);
```

{% endcode %}

### MathAverage

Returns the average for numbers passed in

<table><thead><tr><th width="149.33333333333331">Parameter</th><th width="119" data-type="checkbox">Required</th><th width="145">Type</th><th>Description</th></tr></thead><tbody><tr><td>data</td><td>true</td><td>Number Array</td><td>An array of numbers to calcualte the average of.</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local avg = TMC.Common.MathAverage({ 10, 20, 15, 50, 35 })
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let avg = TMC.Common.MathAverage([ 10, 20, 15, 50, 35 ]);
```

{% endcode %}

### TrueRandom

Returns a better random number

<table><thead><tr><th width="139">Parameter</th><th width="116" data-type="checkbox">Required</th><th width="106">Type</th><th>Description</th></tr></thead><tbody><tr><td>min</td><td>false</td><td>Number</td><td>A min value</td></tr><tr><td>max</td><td>false</td><td>Number</td><td>A max value</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local rand = TMC.Common.TrueRandom(1, 1000)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let rand = TMC.Common.TrueRandom(1, 1000);
```

{% endcode %}

### RandomChance

Returns a bool indicating if the chance succeeded

<table><thead><tr><th width="145">Paramaeter</th><th width="117" data-type="checkbox">Required</th><th width="102">Type</th><th>Description</th></tr></thead><tbody><tr><td>min</td><td>true</td><td>Number</td><td>A min value</td></tr><tr><td>max</td><td>true</td><td>Number</td><td>A max value</td></tr><tr><td>chance</td><td>true</td><td>Number</td><td>The amount of chance</td></tr></tbody></table>

{% code title="Lua" %}

```lua
if TMC.Common.RandomChance(1, 100, 20) then
    -- reward
end
```

{% endcode %}

{% code title="Javascript" %}

```javascript
if (TMC.Common.RandomChance(1, 100, 20) {
    // reward
}
```

{% endcode %}

### MathRound

Rounds a number

<table><thead><tr><th width="194">Parameter</th><th width="98" data-type="checkbox">Required</th><th width="167">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>true</td><td>Number</td><td>The number you would like to round</td></tr><tr><td>numDecimalPlaces</td><td>false</td><td>Number</td><td>The amount of decimal places you would like to include, this defaults to 0</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local roundedNumber = TMC.Common.MathRound(10.5)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let roundedNumber = TMC.Common.MathRound(10.5)
```

{% endcode %}

### MathGroupDigits

Groups a number together into a human-readable format. For example, convert 10000 to 10,000

<table><thead><tr><th width="194">Parameter</th><th width="113" data-type="checkbox">Required</th><th width="102">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>true</td><td>Number</td><td>The number you'd like to convert</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local groupedNumber = TMC.Common.MathGroupDigits(10000)
```

{% endcode %}

<pre class="language-javascript" data-title="Javascript"><code class="lang-javascript"><strong>let groupedNumber = TMC.Common.MathGroupDigits(10000)
</strong></code></pre>

### MathTrim

Removes all whitespace around a number in a string

<table><thead><tr><th width="194">Parameter</th><th width="113" data-type="checkbox">Required</th><th width="102">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>true</td><td>String</td><td>String to clear whitespace from</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local trimmedNumber = TMC.Common.MathTrim(" 5000 ")
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let trimmedNumber = TMC.Common.MathTrim(" 5000 ")
```

{% endcode %}

## Other

### GetTime <a href="#tmc.common.gettime" id="tmc.common.gettime"></a>

Returns a moment formatted date string or epoch timestamp (in milliseconds).

<table><thead><tr><th width="150">Parameter</th><th width="116" data-type="checkbox">Required</th><th width="145">Type</th><th>Description</th></tr></thead><tbody><tr><td>timestamp</td><td>false</td><td>Number/String</td><td>An optional <a href="https://www.unixtimestamp.com/">epoch timestamp</a> or date string that should be used instead of current time. If not provided will default to the current time.</td></tr><tr><td>format</td><td>false</td><td>String</td><td><a href="https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/">Moment date formatting</a> to use. Defaults to return the epoch timestamp.</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local currentTime = TMC.Common.GetTime()
local currentTimeFormatted = TMC.Common.GetTime(nil, 'YYYY/MM/DD')
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let currentTime = TMC.Common.GetTime()
let currentTimeFormatted = TMC.Common.GetTime(undefined, 'YYYY/MM/DD');
```

{% endcode %}

### Decode

<table><thead><tr><th width="159">Parameter</th><th width="103" data-type="checkbox">Required</th><th width="160">Type</th><th>Description</th></tr></thead><tbody><tr><td>val</td><td>true</td><td>Any</td><td>Will decode json if valid json is passed. Useful when you don't trust the data source.</td></tr></tbody></table>

{% code title="Lua" %}

```lua
-- Both will have the same result
local obj = TMC.Common.Decode('{ "test": true }')
local obj2 = TMC.Common.Decode({ test = true })
```

{% endcode %}

{% code title="Javascript" %}

```javascript
// Both will have the same result
let obj = TMC.Common.Decode('{ "test": true }');
let obj2 = TMC.Common.Decode({ test: true });
```

{% endcode %}

### 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.

<table><thead><tr><th width="145.33333333333331">Parameter</th><th width="118" data-type="checkbox">Required</th><th width="111">Type</th><th>Description</th></tr></thead><tbody><tr><td>val</td><td>true</td><td>Any</td><td>The value to convert</td></tr></tbody></table>

{% code title="Lua" %}

```lua
TMC.Common.Dump({ test = true })
-- Outputs: { [test] = true }
```

{% endcode %}

{% code title="Javascript" %}

```javascript
TMC.Common.Dump({ test: true });
// Outputs: { [test] = true }
```

{% endcode %}

### TablePrint

Has no return value. Prints object to console in a table format. Mainly used for debugging purposes.

<table><thead><tr><th width="159">Parameter</th><th width="118" data-type="checkbox">Required</th><th width="105">Type</th><th>Description</th></tr></thead><tbody><tr><td>val</td><td>true</td><td>Any</td><td>The value to print to console</td></tr></tbody></table>

{% code title="Lua" %}

```lua
TMC.Common.TablePrint({ test = true, test2 = { innerTest = false } })
-- Outputs to console:
--[[
Table:
    test = true
    test2:
        innerTest = false
]]
```

{% endcode %}

{% code title="Javascript" %}

```javascript
TMC.Common.Dump({ test: true, test2: { innerTest: false } });
// Outputs to console:
///Table:
///    test = true
///    test2:
///        innerTest = false
```

{% endcode %}

### Shuffle

Returns the shuffled array

<table><thead><tr><th width="127">Parameter</th><th width="110.33333333333331" data-type="checkbox">Required</th><th width="93">Type</th><th>Description</th></tr></thead><tbody><tr><td>tab</td><td>true</td><td>Array</td><td>The array to shuffle</td></tr></tbody></table>

{% code title="Lua" %}

```lua
TMC.Common.Shuffle({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 })
```

{% endcode %}

{% code title="Javascript" %}

```javascript
TMC.Common.Shuffle([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]);
```

{% endcode %}

### Merge

Returns a combined object. Will overwrite object 1's value if the same key exists. Works recursively.

<table><thead><tr><th width="142.33333333333331">Parameter</th><th width="106" data-type="checkbox">Required</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td>obj1</td><td>true</td><td>Object</td><td>First object</td></tr><tr><td>obj2</td><td>true</td><td>Object</td><td>Second object to merge over the top of object 1</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local res = TMC.Common.Merge({ one = 1, two = 2, test = 3 }, { three = 3, test = 4 })
-- Result: { one = 1, two = 2, three = 3, test = 4 }
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let res = TMC.Common.Merge({ one: 1, two: 2, test: 3 }, { three: 3, test: 4 });
// Result: { one: 1, two: 2, three: 3, test: 4 }
```

{% endcode %}

### Combine

Returns an array combined from the parameters&#x20;

<table><thead><tr><th width="129">Parameter</th><th width="106" data-type="checkbox">Required</th><th width="82">Type</th><th>Description</th></tr></thead><tbody><tr><td>arr1</td><td>true</td><td>Array</td><td>First array to combine</td></tr><tr><td>arr2</td><td>true</td><td>Array</td><td>Second array to combine</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local newArr = TMC.Common.Combine({ 1, 2, 3 }, { 4, 5, 6, 1 })
-- Result: { 1, 2, 3, 4, 5, 6, 1 }
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let newArr = TMC.Common.Combine([ 1, 2, 3 ], [ 4, 5, 6, 1 ]);
// Result: [ 1, 2, 3, 4, 5, 6, 1 ]
```

{% endcode %}

### CopyTable

Returns an object with the same data as the parameter passed in

<table><thead><tr><th width="134">Parameter</th><th width="112" data-type="checkbox">Required</th><th width="85">Type</th><th>Description</th></tr></thead><tbody><tr><td>obj</td><td>true</td><td>Object</td><td>Object to make a copy of</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local res = TMC.Common.CopyTable({ one = 1, two = 2, test = 3 })
-- Result: { one = 1, two = 2, three = 3 }
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let res = TMC.Common.CopyTable({ one: 1, two: 2, test: 3 });
// Result: { one: 1, two: 2, three: 3 }
```

{% endcode %}

### TableHas

Returns a bool checking if the array contains a specific value

<table><thead><tr><th width="138.33333333333331">Parameter</th><th width="104" data-type="checkbox">Required</th><th width="85">Type</th><th>Description</th></tr></thead><tbody><tr><td>arr</td><td>true</td><td>Array</td><td>The array to search</td></tr><tr><td>val</td><td>true</td><td>Any</td><td>The value to search for within the array</td></tr></tbody></table>

{% code title="Lua" %}

```lua
if TMC.Common.TableHas({ 1, 5, 10 }, 10) then
end
```

{% endcode %}

{% code title="Javascript" %}

```javascript
if (TMC.Common.TableHas([ 1, 5, 10 ], 10) {}
```

{% endcode %}

### 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.

<table><thead><tr><th width="132.33333333333331">Parameter</th><th width="103" data-type="checkbox">Required</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>coords</td><td>true</td><td>Vector3</td><td>The position on the map to get the grid number for</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local zoneId = TMC.Common.GetGridZoneAtCoords(vector3(100.0, 100.0, 50.0))
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let zoneId = TMC.Common.GetGridZoneAtCoords(Vector3(100.0, 100.0, 50.0));
```

{% endcode %}

### GetPermissionRank

Returns the permission rank id from the name.

{% hint style="info" %}
&#x20;If the rank can't be found, it defaults to 1
{% endhint %}

<table><thead><tr><th width="132.33333333333331">Parameter</th><th width="103" data-type="checkbox">Required</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>permission</td><td>true</td><td>String</td><td>Name of the permission rank</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local rankId = TMC.Common.GetPermissionRank("helper")
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let rankId = TMC.Common.GetPermissionRank("helper")
```

{% endcode %}

### IsDepRunning

Checks if a resource is currently running

<table><thead><tr><th width="132.33333333333331">Parameter</th><th width="103" data-type="checkbox">Required</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>resName</td><td>true</td><td>String</td><td>Name of the resource</td></tr></tbody></table>

{% code title="Lua" %}

```lua
if not TMC.Common.IsDepRunning("dispatch") then
    print("Dispatch isn't running!")
end
```

{% endcode %}

{% code title="Javascript" %}

```javascript
if(!TMC.Common.IsDepRunning("dispatch")) {
    console.log("Dispatch isn't running!")
}
```

{% endcode %}

### TableSortAlphabetical

Sorts a table alphabetically based on the keys

<table><thead><tr><th width="132.33333333333331">Parameter</th><th width="106" data-type="checkbox">Required</th><th width="95">Type</th><th>Description</th></tr></thead><tbody><tr><td>data</td><td>true</td><td>Array</td><td>Table of data to sort</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local table = {
    ["Josh"] = 5,
    ["Chris"] = 20,
    ["Alex"] = 1,
    ["Richard"] = 50
}

local sortedTable = TMC.Common.TableSortAlphabetical(table)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let table = {
    "Josh": 5,
    "Chris": 20,
    "Alex": 1,
    "Richard": 50
}

let sortedTable = TMC.Common.TableSortAlphabetical(table)
```

{% endcode %}

## Jobs

### GetJob

Returns a [job](/v2/object-models/job.md) object

<table><thead><tr><th width="133">Parameter</th><th width="103" data-type="checkbox">Required</th><th width="100">Type</th><th>Description</th></tr></thead><tbody><tr><td>job</td><td>true</td><td>String</td><td>The key for the job you want to find</td></tr></tbody></table>

{% code title="" %}

```lua
local job = TMC.Common.GetJob('police')
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let job = TMC.Common.GetJob('police');
```

{% endcode %}

### GetJobGrade

Returns a single grade from the [job](/v2/object-models/job.md) object

<table><thead><tr><th width="125">Parameter</th><th width="104" data-type="checkbox">Required</th><th width="94">Type</th><th>Description</th></tr></thead><tbody><tr><td>job</td><td>true</td><td>String</td><td>The key for the job you want to find</td></tr><tr><td>grade</td><td>true</td><td>Number</td><td>The number of the grade you want to find</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local jobGrade = TMC.Functions.GetJobGrade('police', 2)c
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let jobGrade = TMC.Functions.GetJobGrade('police', 2);
```

{% endcode %}

### JobLabel

Returns the job label as a string

<table><thead><tr><th width="133">Parameter</th><th width="108" data-type="checkbox">Required</th><th width="90">Type</th><th>Description</th></tr></thead><tbody><tr><td>job</td><td>true</td><td>String</td><td>The key for the job</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local jobLabel = TMC.Common.JobLabel('police')
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let jobLabel = TMC.Common.JobLabel('police');
```

{% endcode %}

### OnlinePlayersWithJob

Returns a number

<table><thead><tr><th width="134.33333333333331">Parameter</th><th width="109" data-type="checkbox">Required</th><th width="98">Type</th><th>Description</th></tr></thead><tbody><tr><td>job</td><td>true</td><td>String</td><td>The job key</td></tr><tr><td>onDuty</td><td>true</td><td>Bool</td><td>Must be true, offDuty player checks are not supported at this time</td></tr><tr><td>grade</td><td>false</td><td>Number</td><td>If provided will check for players with at least the grade specified</td></tr></tbody></table>

{% code title="Lua" %}

```lua
if TMC.Common.OnlinePlayersWithJob('police', true, 3) > 0 or TMC.Common.OnlinePlayersWithJob('sheriff', true) > 0 then
    print('At least 1 sheriff or grade 3 and above police is on duty')
end
```

{% endcode %}

{% code title="Javascript" %}

```javascript
if (TMC.Common.OnlinePlayersWithJob('police', true, 3) > 0 || TMC.Common.OnlinePlayersWithJob('sheriff', true) > 0) {
    console.log('At least 1 sheriff or grade 3 and above police is on duty');
}
```

{% endcode %}

## Inventory

### GenerateInventory

Returns an array of pre-populated item slots in the correct format.

<table><thead><tr><th width="135.33333333333331">Parameter</th><th width="112" data-type="checkbox">Required</th><th width="97">Type</th><th>Description</th></tr></thead><tbody><tr><td>slots</td><td>true</td><td>Number</td><td>The number of slots to generate in the inventory</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local inv = TMC.Common.GenerateInventory(40)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let inv = TMC.Common.GenerateInventory(40);
```

{% endcode %}

### GetItemQuality

Returns a number for the quality of an item calculated based on the decay.

<table><thead><tr><th width="136.33333333333331">Parameter</th><th width="107" data-type="checkbox">Required</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td>itemInfo</td><td>true</td><td>Object</td><td>The info object of a stackable or unique inventory item</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local quality = TMC.Common.GetItemQuality(item.info)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let quality = TMC.Common.GetItemQuality(item.info);
```

{% endcode %}

### EnforceItemDecay

Forcibly updates an item decay information and returns array

<table><thead><tr><th width="136.33333333333331">Parameter</th><th width="107" data-type="checkbox">Required</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td>itemInfo</td><td>true</td><td>Object</td><td>The info object an item</td></tr><tr><td>info</td><td>true</td><td>Object</td><td>The information to update from</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local updateInformation = TMC.Common.EnforceItemDecay(newDecay, item.info)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let updateInformation = TMC.Common.EnforceItemDecay(newDecay, item.info)
```

{% endcode %}

### UnfreezeItem

Forcibly updates an item and removes feezer data

<table><thead><tr><th width="136.33333333333331">Parameter</th><th width="102" data-type="checkbox">Required</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td>info</td><td>true</td><td>Object</td><td>The information to update from</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local updateInformation = TMC.Common.UnfreezeItem(item.info)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let updateInformation = TMC.Common.UnfreezeItem(item.info)
```

{% endcode %}

### GetItemExpiry

Returns the time till decays for an item. Either returns false or item in seconds

<table><thead><tr><th width="136.33333333333331">Parameter</th><th width="101" data-type="checkbox">Required</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td>info</td><td>true</td><td>Object</td><td>The information to read from</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local expiry = TMC.Common.GetItemExpiry(item.info)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let expiry = TMC.Common.GetItemExpiry(item.info)
```

{% endcode %}

### TableCoordsToVec

Converts a table of coords to a vector

<table><thead><tr><th width="136.33333333333331">Parameter</th><th width="101" data-type="checkbox">Required</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td>tab</td><td>true</td><td>Object</td><td>Table of coords</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local coords = [
    x = 10,
    y = 10,
    z = 10,
    w = 10
]

local convertedCoords = TMC.Common.TableCoordsToVec(coords)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let coords = {
    x: 10,
    y: 10,
    z: 10,
    w: 10
}

let convertedCoords = TMC.Common.TableCoordsToVec(coords)
```

{% endcode %}

## Status Effects

{% hint style="warning" %}
These functions will not affect the value if you are not running the Status Effect resource.
{% endhint %}

### TryApplyLuck

Based on the player's current luck adjust the value accordingly

<table><thead><tr><th width="164.33333333333331">Parameter</th><th width="112" data-type="checkbox">Required</th><th width="97">Type</th><th>Description</th></tr></thead><tbody><tr><td>value</td><td>true</td><td>Number</td><td>The number to minipulate</td></tr><tr><td>negativeCheck</td><td>false</td><td>Bool</td><td>Decrease the value if luck check passes</td></tr><tr><td>src</td><td>false</td><td>Number</td><td>Source of the player (Required if called from server)</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local value = TMC.Common.TryApplyLuck(20)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let value = TMC.Common.TryApplyLuck(20)
```

{% endcode %}

### RandomChanceWithLuck

Alike `TMC.Common.RandomChance` however with weighting based on current luck

<table><thead><tr><th width="167.33333333333331">Parameter</th><th width="112" data-type="checkbox">Required</th><th width="97">Type</th><th>Description</th></tr></thead><tbody><tr><td>min</td><td>true</td><td>Number</td><td>Minimum number possible</td></tr><tr><td>max</td><td>true</td><td>Number</td><td>Maximum number possible</td></tr><tr><td>chance</td><td>true</td><td>Number</td><td>Amoiunt of chance</td></tr><tr><td>negativeCheck</td><td>false</td><td>Bool</td><td>Decrease the value if luck check passes</td></tr><tr><td>maxPercentage</td><td>false</td><td>Number</td><td>Maximum percentage chance possible (Defaults to 0.3)</td></tr><tr><td>src</td><td>false</td><td>Number</td><td>Source of the player (Required if called from server)</td></tr></tbody></table>

{% code title="Lua" %}

```lua
local value = TMC.Common.RandomChanceWithLuck(20, true, 0.5)
```

{% endcode %}

{% code title="Javascript" %}

```javascript
let value = TMC.Common.RandomChanceWithLuck(20, true, 0.5)
```

{% endcode %}
