Modding API Functions

A searchable list of all functions available in the Trailmakers Modding API.

Audio

4 functions

tm.audio.PlayAudioAtPosition

function tm.audio.PlayAudioAtPosition( audioName , position , keepObjectDuration )
Play audio at a position. This is more cost friendly but you can not stop or move the sound
Parameter Type Description
audioName AudioName Name of the audio to play. See `AudioName` type alias
position ModVector3 Position of the audio
keepObjectDuration number Duration of the audio

tm.audio.PlayAudioAtGameobject

function tm.audio.PlayAudioAtGameobject( audioName , modGameObject )
Play audio on a GameObject
Parameter Type Description
audioName AudioName Name of the audio to play. See `AudioName` type alias
modGameObject ModGameObject GameObject on which the audio should be played

tm.audio.StopAllAudioAtGameobject

function tm.audio.StopAllAudioAtGameobject( modGameObject )
Stop all audio on a GameObject
Parameter Type Description
modGameObject ModGameObject

tm.audio.GetAudioNames

function tm.audio.GetAudioNames() → string[]
Returns a list of all playable audio names

GetDocs

1 functions

tm.GetDocs

function tm.GetDocs() → string
Generates official Trailmakers Mods API Lua Docs

Input

2 functions

tm.input.RegisterFunctionToKeyDownCallback

function tm.input.RegisterFunctionToKeyDownCallback( playerId , functionName , keyName )
Registers a function to the callback of when the given player presses the given key
Parameter Type Description
playerId PlayerID Player for which the function will be registered. See `PlayerID` type alias
functionName string Name of the function to register. Must be in the global scope. This function will be executed with the `PlayerID` of the player who triggered it as its only parameter
keyName InputKey Name of the key to use. See `InputKey` type alias

tm.input.RegisterFunctionToKeyUpCallback

function tm.input.RegisterFunctionToKeyUpCallback( playerId , functionName , keyName )
Registers a function to the callback of when the given player releases the given key
Parameter Type Description
playerId PlayerID Player for which the function will be registered. See `PlayerID` type alias
functionName string Name of the function to register. Must be in the global scope. This function will be executed with the `PlayerID` of the player who triggered it as its only parameter
keyName InputKey Name of the key to use. See `InputKey` type alias

ModBlock

65 functions

ModBlock.GetPosition

function ModBlock.GetPosition() → ModVector3
Gets the position of the transform (world space)

ModBlock.GetRotation

function ModBlock.GetRotation() → ModVector3
Gets the rotation of the transform (local space)

ModBlock.GetScale

function ModBlock.GetScale() → ModVector3
Gets the scale of the transform (local space)

ModBlock.TransformPoint

function ModBlock.TransformPoint( point ) → ModVector3
Returns the point's position in world space (Adds the current pos with input vector)
Parameter Type Description
point ModVector3

ModBlock.TransformDirection

function ModBlock.TransformDirection( direction ) → ModVector3
Returns the direction's world space direction
Parameter Type Description
direction ModVector3

ModBlock.Forward

function ModBlock.Forward() → ModVector3
Returns a normalized vector Forward in world space

ModBlock.Back

function ModBlock.Back() → ModVector3
Returns a normalized vector Back in world space

ModBlock.Left

function ModBlock.Left() → ModVector3
Returns a normalized vector Left in world space

ModBlock.Right

function ModBlock.Right() → ModVector3
Returns a normalized vector Right in world space

ModBlock.Up

function ModBlock.Up() → ModVector3
Returns a normalized vector Up in world space

ModBlock.Down

function ModBlock.Down() → ModVector3
Returns a normalized vector Down in world space

ModBlock.GetName

function ModBlock.GetName() → string
Get the internal name of the block's type

ModBlock.SetColor

Deprecated
function ModBlock.SetColor( r , g , b )
[In buildmode only] Set the block's primary color [DEPRECATED USE `.SetPrimaryColor()` INSTEAD]
Parameter Type Description
r number
g number
b number

ModBlock.SetPrimaryColor

function ModBlock.SetPrimaryColor( r , g , b )
Set the block's primary color
Parameter Type Description
r number
g number
b number

ModBlock.SetPrimaryColor

function ModBlock.SetPrimaryColor( color )
Set the block's primary color
Parameter Type Description
color ModColor

ModBlock.SetSecondaryColor

function ModBlock.SetSecondaryColor( r , g , b )
Set the block's secondary color
Parameter Type Description
r number
g number
b number

ModBlock.SetSecondaryColor

function ModBlock.SetSecondaryColor( color )
Set the block's secondary color
Parameter Type Description
color ModColor

ModBlock.SetMass

function ModBlock.SetMass( mass )
[In buildmode only] Set the block's mass. Units are `5kg`
Parameter Type Description
mass number

ModBlock.GetMass

function ModBlock.GetMass() → number
Get the block's mass. Units are `5kg`

ModBlock.GetPrimaryColor

function ModBlock.GetPrimaryColor() → ModColor
Get the block's primary color

ModBlock.GetSecondaryColor

function ModBlock.GetSecondaryColor() → ModColor
Get the block's secondary color

ModBlock.SetBuoyancy

function ModBlock.SetBuoyancy( buoyancy )
[In buildmode only] Set the block's buoyancy
Parameter Type Description
buoyancy number

ModBlock.GetBuoyancy

function ModBlock.GetBuoyancy() → number
Get the block's buoyancy

ModBlock.SetHealth

Deprecated
function ModBlock.SetHealth( hp )
Set the block's health [DEPRECATED USE `.SetStartHealth()` INSTEAD]
Parameter Type Description
hp number

ModBlock.SetStartHealth

function ModBlock.SetStartHealth( hp )
Set the block's start health
Parameter Type Description
hp number

ModBlock.ResetStartHealth

function ModBlock.ResetStartHealth()
Reset the block's start health to its original value

ModBlock.GetStartHealth

function ModBlock.GetStartHealth() → number
Get the block's start health

ModBlock.GetFullHealth

function ModBlock.GetFullHealth() → number
Get the blocks full health

ModBlock.Revive

function ModBlock.Revive()
Fully revives the block to its full health

ModBlock.DoDamageAmount

function ModBlock.DoDamageAmount( damageAmount , damageDealerPlayerId , damageType )
Give damage to a block
Parameter Type Description
damageAmount number The amount of damage to deal
damageDealerPlayerId PlayerID | -1 The player that dealt the damage, -1 for no player. See `PlayerID` type alias
damageType ModDamageType (Optional) The type of damage to deal, defaults to `Generic`

ModBlock.InstantKill

function ModBlock.InstantKill()
Instant kill the block

ModBlock.IsDamaged

function ModBlock.IsDamaged() → boolean
Returns true if the block has been damaged

ModBlock.IsDead

function ModBlock.IsDead() → boolean
Returns true if the block is dead

ModBlock.GetCurrentHealth

function ModBlock.GetCurrentHealth() → number
Get the block's current health

ModBlock.GetHealthFraction

function ModBlock.GetHealthFraction() → number
Get the block health fraction normalised from 0 to its full health

ModBlock.GetBlockMetaData

function ModBlock.GetBlockMetaData() → ModBlockMetaData
Get the block's BlockMetaData

ModBlock.GetDrag

function ModBlock.GetDrag( aerodynamicBoxIndex ) → AerodynamicBox
Get the drag values of an aerodynamic box
Parameter Type Description
aerodynamicBoxIndex integer

ModBlock.GetDragAll

function ModBlock.GetDragAll() → AerodynamicBox[]
Get the drag values for all aerodynamic boxes

ModBlock.SetDrag

function ModBlock.SetDrag( aerodynamicBoxIndex , forward , back , up , down , left , right )
Expensive operation! Set the drag values of an aerodynamic box
Parameter Type Description
aerodynamicBoxIndex integer
forward number
back number
up number
down number
left number
right number

ModBlock.SetDragAll

function ModBlock.SetDragAll( forward , back , up , down , left , right )
Expensive operation! Set all of the aerodynamic boxes to the defined drag values
Parameter Type Description
forward number
back number
up number
down number
left number
right number

ModBlock.ResetDrag

function ModBlock.ResetDrag( aerodynamicBoxIndex )
Reset the drag of a aerodynamic box to default values
Parameter Type Description
aerodynamicBoxIndex integer

ModBlock.ResetDragAll

function ModBlock.ResetDragAll()
Reset the drag values of all aerodynamic boxes to default values

ModBlock.GetDefaultDrag

function ModBlock.GetDefaultDrag( aerodynamicBoxIndex ) → AerodynamicBox
Get the default drag values of a aerodynamic box
Parameter Type Description
aerodynamicBoxIndex integer

ModBlock.GetDefaultDragAll

function ModBlock.GetDefaultDragAll() → AerodynamicBox[]
Get the default drag values of all aerodynamic boxex

ModBlock.GetNumberOfAerodynamicBoxes

function ModBlock.GetNumberOfAerodynamicBoxes() → number
Get number of aerodynamic boxes

ModBlock.AddForce

function ModBlock.AddForce( x , y , z )
Add a force to the given block as an impulse. Units are `5kg * m/s²`
Parameter Type Description
x number
y number
z number

ModBlock.AddTorque

function ModBlock.AddTorque( x , y , z )
Add a torque to the given block as an impulse
Parameter Type Description
x number
y number
z number

ModBlock.SetEnginePower

function ModBlock.SetEnginePower( power )
Sets engine power (only works on engine blocks)
Parameter Type Description
power number

ModBlock.GetEnginePower

function ModBlock.GetEnginePower() → number
Gets engine power (only works on engine blocks)

ModBlock.SetJetPower

function ModBlock.SetJetPower( power )
Sets jet power (only works on jet blocks)
Parameter Type Description
power number

ModBlock.GetJetPower

function ModBlock.GetJetPower() → number
Gets jet power (only works on jet blocks)

ModBlock.SetPropellerPower

function ModBlock.SetPropellerPower( power )
Sets propeller power (only works on propeller blocks)
Parameter Type Description
power number

ModBlock.GetPropellerPower

function ModBlock.GetPropellerPower() → number
Gets propeller power (only works on propeller blocks)

ModBlock.SetGyroPower

function ModBlock.SetGyroPower( power )
Sets gyro power (only works on gyro blocks)
Parameter Type Description
power number

ModBlock.GetGyroPower

function ModBlock.GetGyroPower() → number
Gets gyro power (only works on gyro blocks)

ModBlock.IsEngineBlock

function ModBlock.IsEngineBlock() → boolean
Whether a block is an Engine block or not

ModBlock.IsJetBlock

function ModBlock.IsJetBlock() → boolean
Whether a block is an Jet block or not

ModBlock.IsPropellerBlock

function ModBlock.IsPropellerBlock() → boolean
Whether a block is an Propeller block or not

ModBlock.IsPlayerSeatBlock

function ModBlock.IsPlayerSeatBlock() → boolean
Whether a block is a seat block or not

ModBlock.IsGyroBlock

function ModBlock.IsGyroBlock() → boolean
Whether a block is a gyro block or not

ModBlock.Exists

function ModBlock.Exists() → boolean
Returns true if the block exists. Keep in mind that when you repair your structure, your destroyed blocks will be replaced with different ones, making the old ones useless

ModBlock.GetStructure

function ModBlock.GetStructure() → ModStructure
Returns the structure a block belongs to

ModBlock.Equals

function ModBlock.Equals( other ) → boolean
Returns true if both blocks are the same (same block reference), false if not (can be done with the normal `==` operator)
Parameter Type Description
other ModBlock

ModBlock.ToString

function ModBlock.ToString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModBlock`

ModBlock.toString

function ModBlock.toString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModBlock`

ModColor

24 functions

ModColor.Create

function ModColor.Create() → ModColor
Creates a new color initialized to `RGBA(0, 0, 0, 0)`

ModColor.Create

function ModColor.Create( r , g , b , a ) → ModColor
Creates a new color from RGBA components
Parameter Type Description
r number Red component (0 to 1)
g number Green component (0 to 1)
b number Blue component (0 to 1)
a number (Optional) Alpha component (transparency). If `nil`, 1 is used

ModColor.ToString

function ModColor.ToString() → string
Returns a formatted string of a color in the form `RGBA(r, g, b, a)`

ModColor.toString

function ModColor.toString() → string
Returns a formatted string of a color in the form `RGBA(r, g, b, a)`

ModColor.R

function ModColor.R() → number
Returns the red channel of the ModColor

ModColor.G

function ModColor.G() → number
Returns the green channel of the ModColor

ModColor.B

function ModColor.B() → number
Returns the blue channel of the ModColor

ModColor.A

function ModColor.A() → number
Returns the alpha channel of the ModColor

ModColor.White

function ModColor.White() → ModColor
Returns a ModColor set to white `RGBA(1.000, 1.000, 1.000, 1.000)`

ModColor.Black

function ModColor.Black() → ModColor
Returns a ModColor set to black `RGBA(0.000, 0.000, 0.000, 1.000)`

ModColor.Red

function ModColor.Red() → ModColor
Returns a ModColor set to red `RGBA(1.000, 0.000, 0.000, 1.000)`

ModColor.Green

function ModColor.Green() → ModColor
Returns a ModColor set to green `RGBA(0.000, 1.000, 0.000, 1.000)`

ModColor.Blue

function ModColor.Blue() → ModColor
Returns a ModColor set to blue `RGBA(0.000, 0.000, 1.000, 1.000)`

ModColor.Yellow

function ModColor.Yellow() → ModColor
Returns a ModColor set to yellow `RGBA(1.000, 0.922, 0.016, 1.000)`

ModColor.Cyan

function ModColor.Cyan() → ModColor
Returns a ModColor set to cyan `RGBA(0.000, 1.000, 1.000, 1.000)`

ModColor.Magenta

function ModColor.Magenta() → ModColor
Returns a ModColor set to magenta `RGBA(1.000, 0.000, 1.000, 1.000)`

ModColor.Gray

function ModColor.Gray() → ModColor
Returns a ModColor set to gray `RGBA(0.500, 0.500, 0.500, 1.000)`

ModColor.Clear

function ModColor.Clear() → ModColor
Returns a ModColor set to clear `RGBA(0.000, 0.000, 0.000, 0.000)`

ModColor.Lerp

function ModColor.Lerp( a , b , t ) → ModColor
Linear interpolation between two ModColor
Parameter Type Description
a ModColor
b ModColor
t number Position in the interpolation (0=a, 1=b)

ModColor.HSVToRGB

function ModColor.HSVToRGB( hue , saturation , value ) → ModColor
Creates a new color from HSV components
Parameter Type Description
hue number Hue component (0 to 1)
saturation number Saturation component (0 to 1)
value number Value component (0 to 1)

ModColor.op_Equality

function ModColor.op_Equality( first , second ) → boolean
Returns true if both colors are the same, false if not (can be done with the normal `==` operator)
Parameter Type Description
first ModColor
second ModColor

ModColor.Equals

function ModColor.Equals( otherColor ) → boolean
Returns true if both colors are the same, false if not (can be done with the normal `==` operator)
Parameter Type Description
otherColor ModColor

ModColor.op_Inequality

function ModColor.op_Inequality( first , second ) → boolean
Returns true if both colors are not the same, false if not (can be done with the normal `~=` operator)
Parameter Type Description
first ModColor
second ModColor

ModColor.GetHashCode

function ModColor.GetHashCode() → number
Returns the hash code of the color

ModGameObject

20 functions

ModGameObject.Despawn

function ModGameObject.Despawn()
Despawns the object. This can not be done on players

ModGameObject.GetTransform

function ModGameObject.GetTransform() → ModTransform
Returns the GameObject's Transform

ModGameObject.SetIsVisible

function ModGameObject.SetIsVisible( isVisible )
Sets visibility of the GameObject
Parameter Type Description
isVisible boolean

ModGameObject.GetIsVisible

function ModGameObject.GetIsVisible() → boolean
Gets the visibility of the GameObject

ModGameObject.GetIsRigidbody

function ModGameObject.GetIsRigidbody() → boolean
Returns true if the GameObject or any of its children are rigidbodies

ModGameObject.SetIsStatic

function ModGameObject.SetIsStatic( isStatic )
Sets the GameObject's and its children's rigidbodies to be static or not
Parameter Type Description
isStatic boolean

ModGameObject.GetIsStatic

function ModGameObject.GetIsStatic() → boolean
Returns true if the GameObject, and all of its children, are static

ModGameObject.SetIsTrigger

function ModGameObject.SetIsTrigger( isTrigger )
Determines whether the GameObject lets other GameObjects pass through its colliders or not
Parameter Type Description
isTrigger boolean

ModGameObject.Exists

function ModGameObject.Exists() → boolean
Returns true if the GameObject exists

ModGameObject.ToString

function ModGameObject.ToString() → string
Always returns `PFB_ModGameObject [Server] (ModGameObject_Server)`

ModGameObject.toString

function ModGameObject.toString() → string
Always returns `PFB_ModGameObject [Server] (ModGameObject_Server)`

ModGameObject.SetTexture

function ModGameObject.SetTexture( textureName )
Sets the texture on the GameObject (Custom meshes only)
Parameter Type Description
textureName TextureName See `TextureName` type alias

ModGameObject.AddForceImpulse

function ModGameObject.AddForceImpulse( x , y , z )
Add a force to the GameObject as an impulse
Parameter Type Description
x number
y number
z number

ModGameObject.AddForce

function ModGameObject.AddForce( x , y , z )
Add a force to the GameObject as a force
Parameter Type Description
x number
y number
z number

ModGameObject.AddForceAcceleration

function ModGameObject.AddForceAcceleration( x , y , z )
Add a force to the GameObject as an Acceleration
Parameter Type Description
x number
y number
z number

ModGameObject.AddForceVelocityChange

function ModGameObject.AddForceVelocityChange( x , y , z )
Add a force to the GameObject as a VelocityChange
Parameter Type Description
x number
y number
z number

ModGameObject.AddTorqueImpulse

function ModGameObject.AddTorqueImpulse( x , y , z )
Add a torque to the GameObject as an impulse
Parameter Type Description
x number
y number
z number

ModGameObject.AddTorqueForce

function ModGameObject.AddTorqueForce( x , y , z )
Add a torque to the GameObject as a force
Parameter Type Description
x number
y number
z number

ModGameObject.AddTorqueAcceleration

function ModGameObject.AddTorqueAcceleration( x , y , z )
Add a torque to the GameObject as an Acceleration
Parameter Type Description
x number
y number
z number

ModGameObject.AddTorqueVelocityChange

function ModGameObject.AddTorqueVelocityChange( x , y , z )
Add a torque to the GameObject as a VelocityChange
Parameter Type Description
x number
y number
z number

ModQuaternion

21 functions

ModQuaternion.Create

function ModQuaternion.Create( x , y , z , w ) → ModQuaternion
Creates a quaternion by manually defining its components
Parameter Type Description
x number
y number
z number
w number

ModQuaternion.Create

function ModQuaternion.Create( x , y , z ) → ModQuaternion
Creates a quaternion using euler angle components
Parameter Type Description
x number
y number
z number

ModQuaternion.Create

function ModQuaternion.Create( eulerAngle ) → ModQuaternion
Creates a quaternion using a euler angle vector3
Parameter Type Description
eulerAngle ModVector3

ModQuaternion.Create

function ModQuaternion.Create( angle , axis ) → ModQuaternion
Creates a quaternion using an angle and an axis to rotate around
Parameter Type Description
angle number
axis ModVector3

ModQuaternion.GetEuler

function ModQuaternion.GetEuler() → ModVector3
Returns a vector3 representing the euler angles of the quaternion

ModQuaternion.Multiply

function ModQuaternion.Multiply( otherQuaternion ) → ModQuaternion
Multiplies this quaternion with another quaternion and returns the resulting rotation
Parameter Type Description
otherQuaternion ModQuaternion

ModQuaternion.Lerp

function ModQuaternion.Lerp( firstQuaternion , secondQuaternion , t ) → ModQuaternion
Returns the resulting quaternion from a lerp between two quaternions
Parameter Type Description
firstQuaternion ModQuaternion
secondQuaternion ModQuaternion
t number Position in the interpolation (0=firstQuaternion, 1=secondQuaternion)

ModQuaternion.Slerp

function ModQuaternion.Slerp( firstQuaternion , secondQuaternion , t ) → ModQuaternion
Returns the resulting quaternion from a slerp between two quaternions
Parameter Type Description
firstQuaternion ModQuaternion
secondQuaternion ModQuaternion
t number Position in the interpolation (0=firstQuaternion, 1=secondQuaternion)

ModQuaternion.Negate

function ModQuaternion.Negate() → ModQuaternion
Returns a quaternion with all components negated

ModQuaternion.Add

function ModQuaternion.Add( other ) → ModQuaternion
Adds together two quaternions component-wise
Parameter Type Description
other ModQuaternion

ModQuaternion.Subtract

function ModQuaternion.Subtract( other ) → ModQuaternion
Subtracts two quaternions from each other component-wise
Parameter Type Description
other ModQuaternion

ModQuaternion.Multiply

function ModQuaternion.Multiply( scalar ) → ModQuaternion
Multiplies all quaternion components by a scalar
Parameter Type Description
scalar number

ModQuaternion.Divide

function ModQuaternion.Divide( scalar ) → ModQuaternion
Divides all quaternion components by a scalar
Parameter Type Description
scalar number

ModQuaternion.Inverse

function ModQuaternion.Inverse() → ModQuaternion
Returns the inverse rotation of this quaternion

ModQuaternion.Normalize

function ModQuaternion.Normalize() → ModQuaternion
Converts this quaternion to a quaternion with the same orientation but with a magnitude of 1.0.

ModQuaternion.op_Equality

function ModQuaternion.op_Equality( a , b ) → boolean
Returns true if both quaternions are the same, false if not (can be done with the normal `==` operator)
Parameter Type Description
a ModQuaternion
b ModQuaternion

ModQuaternion.op_Inequality

function ModQuaternion.op_Inequality( a , b ) → boolean
Returns true if both quaternions are not the same, false if not (can be done with the normal `~=` operator)
Parameter Type Description
a ModQuaternion
b ModQuaternion

ModQuaternion.Equals

function ModQuaternion.Equals( otherQuaternion ) → boolean
Returns true if both quaternions are the same, false if not (can be done with the normal `==` operator)
Parameter Type Description
otherQuaternion ModQuaternion

ModQuaternion.GetHashCode

function ModQuaternion.GetHashCode() → number
Returns the hash code of the quaternion

ModQuaternion.ToString

function ModQuaternion.ToString() → string
Returns a formatted string of a quaternion in the form `x:X y:Y z:Z w:W`

ModQuaternion.toString

function ModQuaternion.toString() → string
Returns a formatted string of a quaternion in the form `x:X y:Y z:Z w:W`

ModRaycastHit

6 functions

ModRaycastHit.DidHit

function ModRaycastHit.DidHit() → boolean
Returns if the raycast hit something

ModRaycastHit.GetHitNormal

function ModRaycastHit.GetHitNormal() → ModVector3
Returns the hit normal

ModRaycastHit.GetHitPosition

function ModRaycastHit.GetHitPosition() → ModVector3
Returns the hit position

ModRaycastHit.GetHitDistance

function ModRaycastHit.GetHitDistance() → number
Returns the distance to the hit

ModRaycastHit.ToString

function ModRaycastHit.ToString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModRaycastHit`

ModRaycastHit.toString

function ModRaycastHit.toString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModRaycastHit`

ModStructure

23 functions

ModStructure.GetPosition

function ModStructure.GetPosition() → ModVector3
Gets the position of the Transform (world space)

ModStructure.GetRotation

function ModStructure.GetRotation() → ModVector3
Gets the rotation of the Transform (local space)

ModStructure.GetScale

function ModStructure.GetScale() → ModVector3
Gets the scale of the Transform (local space)

ModStructure.TransformPoint

function ModStructure.TransformPoint( point ) → ModVector3
Returns the point's position in world space (Adds the current pos with input vector)
Parameter Type Description
point ModVector3

ModStructure.TransformDirection

function ModStructure.TransformDirection( direction ) → ModVector3
Returns the direction's world space direction
Parameter Type Description
direction ModVector3

ModStructure.Forward

function ModStructure.Forward() → ModVector3
Returns a normalized vector Forward in world space

ModStructure.Back

function ModStructure.Back() → ModVector3
Returns a normalized vector Back in world space

ModStructure.Left

function ModStructure.Left() → ModVector3
Returns a normalized vector Left in world space

ModStructure.Right

function ModStructure.Right() → ModVector3
Returns a normalized vector Right in world space

ModStructure.Up

function ModStructure.Up() → ModVector3
Returns a normalized vector Up in world space

ModStructure.Down

function ModStructure.Down() → ModVector3
Returns a normalized vector Down in world space

ModStructure.Destroy

function ModStructure.Destroy()
Destroy the structure

ModStructure.GetBlocks

function ModStructure.GetBlocks() → ModBlock[]
Gets all blocks in structure

ModStructure.AddForce

function ModStructure.AddForce( x , y , z )
Add a force to the given structure as an impulse. Units are `5kg * m/s²`
Parameter Type Description
x number
y number
z number

ModStructure.ToString

function ModStructure.ToString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModStructure`

ModStructure.toString

function ModStructure.toString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModStructure`

ModStructure.GetSeatedPlayerVelocity

function ModStructure.GetSeatedPlayerVelocity() → ModVector3
Gets the velocity of the player inside of the structure in world space

ModStructure.GetVelocity

function ModStructure.GetVelocity() → ModVector3
Gets the velocity of the structure's center of mass in world space

ModStructure.GetSpeed

function ModStructure.GetSpeed() → number
Gets the speed of the player inside of the structure. Units are `m/s`

ModStructure.GetOwnedByPlayerId

function ModStructure.GetOwnedByPlayerId() → PlayerID
Get player index who owns this structure. Returns `-1` if player is gone

ModStructure.GetPowerCores

function ModStructure.GetPowerCores() → number
Returns the number of power cores of the structure

ModStructure.GetWorldCenterOfMass

function ModStructure.GetWorldCenterOfMass() → ModVector3
Returns the Center of Mass of the structure in world space

ModStructure.Dispose

function ModStructure.Dispose()
Despawn the structure. Similar to `ModStructure.Destroy()` but the creation is removed instantly without playing the destruction animation

ModTransform

43 functions

ModTransform.SetPosition

function ModTransform.SetPosition( position )
Sets the position of the Transform (world space)
Parameter Type Description
position ModVector3

ModTransform.SetPosition

function ModTransform.SetPosition( x , y , z )
Sets the position of the Transform (world space)
Parameter Type Description
x number
y number
z number

ModTransform.GetPosition

Deprecated
function ModTransform.GetPosition() → ModVector3
Gets the position of the Transform (world space) [DEPRECATED USE `.GetPositionWorld()` INSTEAD]

ModTransform.SetRotation

function ModTransform.SetRotation( rotation )
Sets the rotation of the Transform (world space)
Parameter Type Description
rotation ModVector3

ModTransform.SetRotation

function ModTransform.SetRotation( x , y , z )
Sets the rotation of the Transform (world space)
Parameter Type Description
x number
y number
z number

ModTransform.GetRotation

function ModTransform.GetRotation() → ModVector3
Gets the rotation of the Transform (local space)

ModTransform.SetRotation

function ModTransform.SetRotation( rotation )
Sets the rotation of the Transform using a quaternion (world space)
Parameter Type Description
rotation ModQuaternion

ModTransform.GetRotationQuaternion

function ModTransform.GetRotationQuaternion() → ModQuaternion
Gets the rotation quaternions of the Transform (world space)

ModTransform.SetScale

function ModTransform.SetScale( scale )
Sets the scale of the Transform (local space). Setting a non-uniform scale may, among other things, break the objects' physics
Parameter Type Description
scale ModVector3

ModTransform.SetScale

function ModTransform.SetScale( x , y , z )
Sets the scale of the Transform (local space). Setting a non-uniform scale may, among other things, break the objects' physics
Parameter Type Description
x number
y number
z number

ModTransform.SetScale

function ModTransform.SetScale( scale )
Sets the scale of the Transform (local space)
Parameter Type Description
scale number

ModTransform.GetScale

function ModTransform.GetScale() → ModVector3
Gets the scale of the Transform (local space)

ModTransform.TransformPoint

function ModTransform.TransformPoint( point ) → ModVector3
Returns the point's local position (world space). Adds the current pos with input vector
Parameter Type Description
point ModVector3

ModTransform.TransformDirection

function ModTransform.TransformDirection( direction ) → ModVector3
Returns the direction's world space direction
Parameter Type Description
direction ModVector3

ModTransform.ToString

function ModTransform.ToString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModTransform`

ModTransform.toString

function ModTransform.toString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModTransform`

ModTransform.Forward

function ModTransform.Forward() → ModVector3
Returns a normalized vector Forward (world space)

ModTransform.Back

function ModTransform.Back() → ModVector3
Returns a normalized vector Back (world space)

ModTransform.Left

function ModTransform.Left() → ModVector3
Returns a normalized vector Left (world space)

ModTransform.Right

function ModTransform.Right() → ModVector3
Returns a normalized vector Right (world space)

ModTransform.Up

function ModTransform.Up() → ModVector3
Returns a normalized vector Up (world space)

ModTransform.Down

function ModTransform.Down() → ModVector3
Returns a normalized vector Down (world space)

ModTransform.GetPositionWorld

function ModTransform.GetPositionWorld() → ModVector3
Gets the position of the Transform (world space)

ModTransform.GetEulerAnglesWorld

function ModTransform.GetEulerAnglesWorld() → ModVector3
Gets the euler angles rotation of the Transform (world space)

ModTransform.GetRotationWorld

function ModTransform.GetRotationWorld() → ModQuaternion
Gets the quaternion rotation of the Transform (world space)

ModTransform.SetPositionWorld

function ModTransform.SetPositionWorld( position )
Sets the position of the Transform (world space)
Parameter Type Description
position ModVector3

ModTransform.SetPositionWorld

function ModTransform.SetPositionWorld( x , y , z )
Sets the position of the Transform (world space)
Parameter Type Description
x number
y number
z number

ModTransform.SetEulerAnglesWorld

function ModTransform.SetEulerAnglesWorld( eulerAngles )
Sets the euler angles rotation of the Transform (world space)
Parameter Type Description
eulerAngles ModVector3

ModTransform.SetEulerAnglesWorld

function ModTransform.SetEulerAnglesWorld( x , y , z )
Sets the euler angles rotation of the Transform (world space)
Parameter Type Description
x number
y number
z number

ModTransform.SetRotationWorld

function ModTransform.SetRotationWorld( rotation )
Sets the quaternion rotation of the Transform (world space)
Parameter Type Description
rotation ModQuaternion

ModTransform.SetRotationWorld

function ModTransform.SetRotationWorld( x , y , z , w )
Sets the quaternion rotation of the Transform (world space)
Parameter Type Description
x number
y number
z number
w number

ModTransform.GetPositionLocal

function ModTransform.GetPositionLocal() → ModVector3
Gets the position of the Transform (local space)

ModTransform.GetEulerAnglesLocal

function ModTransform.GetEulerAnglesLocal() → ModVector3
Gets the euler angles rotation of the Transform (local space)

ModTransform.GetRotationLocal

function ModTransform.GetRotationLocal() → ModQuaternion
Gets the quaternion rotation of the Transform (local space)

ModTransform.GetScaleLocal

function ModTransform.GetScaleLocal() → ModVector3
Gets the scale of the Transform (local space)

ModTransform.SetPositionLocal

function ModTransform.SetPositionLocal( position )
Sets the position of the Transform (local space)
Parameter Type Description
position ModVector3

ModTransform.SetPositionLocal

function ModTransform.SetPositionLocal( x , y , z )
Sets the position of the Transform (local space)
Parameter Type Description
x number
y number
z number

ModTransform.SetEulerAnglesLocal

function ModTransform.SetEulerAnglesLocal( eulerAngles )
Sets the euler angles rotation of the Transform (local space)
Parameter Type Description
eulerAngles ModVector3

ModTransform.SetEulerAnglesLocal

function ModTransform.SetEulerAnglesLocal( x , y , z )
Sets the euler angles rotation of the Transform (local space)
Parameter Type Description
x number
y number
z number

ModTransform.SetRotationLocal

function ModTransform.SetRotationLocal( rotation )
Sets the quaternion rotation of the Transform (local space)
Parameter Type Description
rotation ModQuaternion

ModTransform.SetRotationLocal

function ModTransform.SetRotationLocal( x , y , z , w )
Sets the quaternion rotation of the Transform (local space)
Parameter Type Description
x number
y number
z number
w number

ModTransform.SetScaleLocal

function ModTransform.SetScaleLocal( scale )
Sets the scale of the Transform (local space)
Parameter Type Description
scale ModVector3

ModTransform.SetScaleLocal

function ModTransform.SetScaleLocal( x , y , z )
Sets the scale of the Transform (local space)
Parameter Type Description
x number
y number
z number

ModVector3

27 functions

ModVector3.Create

function ModVector3.Create( input ) → ModVector3
Creates a vector3 from a string. String should be formatted as "(x, y, z)". Example input: "(4.5, 6, 10.8)"
Parameter Type Description
input string

ModVector3.Create

function ModVector3.Create( x , y , z ) → ModVector3
Creates a vector3 with specified values
Parameter Type Description
x number
y number
z number

ModVector3.Create

function ModVector3.Create() → ModVector3
Creates a vector3 with values defaulted to zero

ModVector3.Right

function ModVector3.Right() → ModVector3
Creates a vector3 pointing right (1, 0, 0)

ModVector3.Left

function ModVector3.Left() → ModVector3
Creates a vector3 pointing left (-1, 0, 0)

ModVector3.Up

function ModVector3.Up() → ModVector3
Creates a vector3 pointing up (0, 1, 0)

ModVector3.Down

function ModVector3.Down() → ModVector3
Creates a vector3 pointing down (0, -1, 0)

ModVector3.Forward

function ModVector3.Forward() → ModVector3
Creates a vector3 pointing forward (0, 0, 1)

ModVector3.Back

function ModVector3.Back() → ModVector3
Creates a vector3 pointing back (0, 0, -1)

ModVector3.op_UnaryNegation

function ModVector3.op_UnaryNegation( vector3 ) → ModVector3
Flips all the signs (can be done with the normal `-` operator)
Parameter Type Description
vector3 ModVector3

ModVector3.op_Addition

function ModVector3.op_Addition( first , second ) → ModVector3
Adds first and second together (can be done with the normal `+` operator)
Parameter Type Description
first ModVector3
second ModVector3

ModVector3.op_Subtraction

function ModVector3.op_Subtraction( first , second ) → ModVector3
Subtracts first and second together (can be done with the normal `-` operator)
Parameter Type Description
first ModVector3
second ModVector3

ModVector3.op_Multiply

function ModVector3.op_Multiply( vector3 , scalar ) → ModVector3
Multiplies the vector by the scalar (can be done with the normal `*` operator)
Parameter Type Description
vector3 ModVector3
scalar number

ModVector3.op_Division

function ModVector3.op_Division( vector3 , divisor ) → ModVector3
Divides the vector by the divisor (can be done with the normal `/` operator)
Parameter Type Description
vector3 ModVector3
divisor number

ModVector3.op_Equality

function ModVector3.op_Equality( first , second ) → boolean
Returns true if both vectors are the same, false if not (can be done with the normal `==` operator)
Parameter Type Description
first ModVector3
second ModVector3

ModVector3.Equals

function ModVector3.Equals( otherVector ) → boolean
Returns true if both vectors are the same, false if not (can be done with the normal `==` operator)
Parameter Type Description
otherVector ModVector3

ModVector3.op_Inequality

function ModVector3.op_Inequality( first , second ) → boolean
Returns true if both vectors are not the same, false if not (can be done with the normal `~=` operator)
Parameter Type Description
first ModVector3
second ModVector3

ModVector3.GetHashCode

function ModVector3.GetHashCode() → integer
Returns the hash code of the vector

ModVector3.ToString

function ModVector3.ToString() → string
Returns a formatted string of a vector in the form `(x, y, z)`

ModVector3.toString

function ModVector3.toString() → string
Returns a formatted string of a vector in the form `(x, y, z)`

ModVector3.Dot

function ModVector3.Dot( otherVector ) → number
Returns the dot product of two vector3
Parameter Type Description
otherVector ModVector3

ModVector3.Cross

function ModVector3.Cross( otherVector ) → ModVector3
Returns the cross product of two vector3
Parameter Type Description
otherVector ModVector3

ModVector3.Magnitude

function ModVector3.Magnitude() → number
Returns the magnitude/length

ModVector3.MoveTowards

function ModVector3.MoveTowards( vector , otherVector , maxDistanceDelta ) → ModVector3
Calculate a position between the points specified by current and target, moving no farther than the distance specified by maxDistanceDelta
Parameter Type Description
vector ModVector3
otherVector ModVector3
maxDistanceDelta number

ModVector3.Angle

function ModVector3.Angle( vector , otherVector ) → number
Calculates the angle in degrees between the vector from and another vector
Parameter Type Description
vector ModVector3
otherVector ModVector3

ModVector3.Distance

function ModVector3.Distance( vector , otherVector ) → number
Returns the distance between the ModVector and another vector
Parameter Type Description
vector ModVector3
otherVector ModVector3

ModVector3.Lerp

function ModVector3.Lerp( vector , otherVector , t ) → ModVector3
Linearly interpolates between two vectors
Parameter Type Description
vector ModVector3
otherVector ModVector3
t number Position in the interpolation (0=vector, 1=otherVector)

OS

11 functions

tm.os.DoFile

function tm.os.DoFile( filename ) → any
Higher-level function to load and run chunk of code from specified filename. Equivalent to the native 'dofile' function in Lua. The file must be within the `data_static` folder (subfolders are allowed)
Parameter Type Description
filename string Name of the file without the `.lua` extension

tm.os.ReadAllText_Static

function tm.os.ReadAllText_Static( path ) → string
Read all text of a file in the mods static data directory. Files in the static data directory can only be read and NOT written to
Parameter Type Description
path string Relative file path

tm.os.ReadAllText_Dynamic

function tm.os.ReadAllText_Dynamic( path ) → string
Read all text of a file in the mods dynamic data directory. Files in the dynamic data directory can be both read and written to. The dynamic data directory will NOT be uploaded to the steam workshop when you upload your mod. When a mod is run through the steam workshop, the dynamic data, unlike static data, is not located in the steam workshop directory but is located in the steam user data directory instead
Parameter Type Description
path string Relative file path

tm.os.WriteAllText_Dynamic

function tm.os.WriteAllText_Dynamic( path , stringToWrite )
Create or overwrite a file in the mods dynamic data directory. Files in the dynamic data directory can be both read and written to. The dynamic data directory will NOT be uploaded to the steam workshop when you upload your mod. When a mod is run through the steam workshop, the dynamic data, unlike static data, is not located in the steam workshop directory, but is located in the steam user data directory instead
Parameter Type Description
path string Relative file path
stringToWrite string Data to write in the file

tm.os.Log

function tm.os.Log( message )
Emit a log message The value is converted to a string following the same rules of tostring. The function print is not intended for formatted output, but only as a quick way to show a value, for instance for debugging. For complete control over the output, use string.format.
Parameter Type Description
message PrintableValue Message to log. See `PrintableValue` type alias

tm.os.GetTime

function tm.os.GetTime() → number
Get time game has been playing in seconds. Equivalent to `UnityEngine.Time.time`. Doesn't update within a single mod update cycle

tm.os.GetRealtimeSinceStartup

function tm.os.GetRealtimeSinceStartup() → number
Get the time since the game was started in seconds. Equivalent to `UnityEngine.Time.realtimeSinceStartup`. Updates within a single mod update cycle

tm.os.GetModDeltaTime

function tm.os.GetModDeltaTime() → number
Get the time since last update

tm.os.SetModTargetDeltaTime

function tm.os.SetModTargetDeltaTime( targetDeltaTime )
Determines how often the mod gets updated. `1/60` means 60 times per second. Can't update faster than the game (maximum is 60 times per second)
Parameter Type Description
targetDeltaTime number

tm.os.GetModTargetDeltaTime

function tm.os.GetModTargetDeltaTime() → number
Returns the target delta time for the mod

tm.os.IsSingleplayer

function tm.os.IsSingleplayer() → boolean
Returns true if session is in singleplayer

Other

8 functions

update

function update()
Global function executed on each mod update cycle. Should be redefined to use it

ModBlockMetaData.GetName

function ModBlockMetaData.GetName() → string
Gets the user-facing name of the block

ModBlockMetaData.GetGuid

function ModBlockMetaData.GetGuid() → BlockGuid
Gets the internal block ID

ModBlockMetaData.GetDescription

function ModBlockMetaData.GetDescription() → string
Gets the description of the block

ModPlayer.ToString

function ModPlayer.ToString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModPlayer`

ModPlayer.toString

function ModPlayer.toString() → string
Always returns `Trailmakers.Mods.Api.Proxies.ModPlayer`

UICallbackData.ToString

function UICallbackData.ToString() → string
Always returns `Trailmakers.Mods.Api.ModApiPlayerUI+UICallbackData`

UICallbackData.toString

function UICallbackData.toString() → string
Always returns `Trailmakers.Mods.Api.ModApiPlayerUI+UICallbackData`

Physics

26 functions

tm.physics.SetTimeScale

function tm.physics.SetTimeScale( speed )
Set the physics timescale relative to the default speed (acts as a multiplier of the normal time speed)
Parameter Type Description
speed number

tm.physics.GetTimeScale

function tm.physics.GetTimeScale() → number
Get the physics timescale relative to the default speed (acts as a multiplier of the normal time speed)

tm.physics.SetGravity

Deprecated
function tm.physics.SetGravity( strength )
Set the physics gravity in the down direction. Units are `m/s²`, default is `14 m/s²` [DEPRECATED USE `.SetGravityMultiplier()` INSTEAD]
Parameter Type Description
strength number

tm.physics.SetGravityMultiplier

function tm.physics.SetGravityMultiplier( multiplier )
Set the gravity multiplier. Has no effect in zero G locations. For example, setting the multiplier to 2 doubles gravity
Parameter Type Description
multiplier number

tm.physics.SetGravity

Deprecated
function tm.physics.SetGravity( gravity )
Set the physics gravity as per the provided vector. Units are `m/s²`, default is `(0, -14, 0) m/s²` [DEPRECATED FUNCTIONALITY MIGHT NOT WORK AS INTENDED]
Parameter Type Description
gravity ModVector3

tm.physics.GetGravity

Deprecated
function tm.physics.GetGravity() → ModVector3
Get the physics gravity. Units are `m/s²`, default is `(0, -14, 0) m/s²` [DEPRECATED FUNCTIONALITY MIGHT NOT WORK AS INTENDED]

tm.physics.GetGravityMultiplier

function tm.physics.GetGravityMultiplier() → number
Get the gravity multiplier

tm.physics.SpawnObject

function tm.physics.SpawnObject( position , name ) → ModGameObject
Spawn a spawnable at the position, e.g. PFB_Barrel
Parameter Type Description
position ModVector3 Position of the object
name Spawnable Name of the object. Can only be a default asset name (from the list returned by `tm.physics.SpawnableNames()`). See `Spawnable` type alias

tm.physics.ClearAllSpawns

function tm.physics.ClearAllSpawns()
Despawn all spawned objects from this mod

tm.physics.DespawnObject

function tm.physics.DespawnObject( gameObject )
Despawn a spawnable e.g. PFB_Barrel. Same as `gameObject.Despawn()`
Parameter Type Description
gameObject ModGameObject

tm.physics.SpawnableNames

function tm.physics.SpawnableNames() → string[]
Get a list of all possible spawnable names

tm.physics.GetAllBlockMetaData

function tm.physics.GetAllBlockMetaData() → ModBlockMetaData[]
Returns all block metadata

tm.physics.RemoveTimeScale

function tm.physics.RemoveTimeScale()
Removes the physics timescale

tm.physics.AddMesh

function tm.physics.AddMesh( filename , resourceName )
Add a mesh to all clients, note this will have to be sent to the client when they join (handled automatically)
Parameter Type Description
filename string The name of the mesh in the mod files (Must use the `.obj` format)
resourceName MeshName The name that the mesh will use. See `MeshName` type alias

tm.physics.AddTexture

function tm.physics.AddTexture( filename , resourceName )
Add a texture to all clients, note this will have to be sent to the client when they join (handled automatically)
Parameter Type Description
filename string The name of the texture in the mod files (Must use the `.png` or `.jpg` format)
resourceName TextureName The name that the texture will use. See `TextureName` type alias

tm.physics.SpawnCustomObjectRigidbody

function tm.physics.SpawnCustomObjectRigidbody( position , meshName , textureName , isKinematic , mass ) → ModGameObject
Spawn a custom physics object where mesh and texture have to be set by AddMesh and AddTexture
Parameter Type Description
position ModVector3 The position to spawn the object at
meshName MeshName The name of the mesh that the object will use. See `MeshName` type alias
textureName TextureName The name of the texture that the object will use. See `TextureName` type alias
isKinematic boolean Whether the object will be affected by physics or not
mass number The mass of the object. Units are `5kg`

tm.physics.SpawnCustomObject

function tm.physics.SpawnCustomObject( position , meshName , textureName ) → ModGameObject
Spawn a custom object where mesh and texture have to be set by AddMesh and AddTexture
Parameter Type Description
position ModVector3 The position to spawn the object at
meshName MeshName The name of the mesh that the object will use. See `MeshName` type alias
textureName TextureName The name of the texture that the object will use. See `TextureName` type alias

tm.physics.SpawnCustomObjectConcave

function tm.physics.SpawnCustomObjectConcave( position , meshName , textureName ) → ModGameObject
Same as `tm.physics.SpawnCustomObject` BUT adds concave collision support.
Parameter Type Description
position ModVector3 The position to spawn the object at
meshName MeshName The name of the mesh that the object will use. See `MeshName` type alias
textureName TextureName The name of the texture that the object will use. See `TextureName` type alias

tm.physics.SpawnBoxTrigger

function tm.physics.SpawnBoxTrigger( position , size ) → ModGameObject
Spawn a box trigger that will detect overlap but will not interact with physics
Parameter Type Description
position ModVector3 The position to spawn the Box Trigger at
size ModVector3 The Box Trigger' size

tm.physics.SetBuildComplexity

function tm.physics.SetBuildComplexity( value )
Sets the build complexity value. Default value is `700` and values above it can make the game unstable
Parameter Type Description
value integer

tm.physics.RegisterFunctionToCollisionEnterCallback

function tm.physics.RegisterFunctionToCollisionEnterCallback( targetObject , functionName )
Registers a function to the collision enter callback of a game object
Parameter Type Description
targetObject ModGameObject Object for which the callback will be registered
functionName string Name of the function to register. Must be in the global scope. This function will be executed with the `PlayerID` of the player who triggered it as its only parameter

tm.physics.RegisterFunctionToCollisionExitCallback

function tm.physics.RegisterFunctionToCollisionExitCallback( targetObject , functionName )
Registers a function to the collision exit callback of a game object
Parameter Type Description
targetObject ModGameObject Object for which the callback will be registered
functionName string Name of the function to register. Must be in the global scope. This function will be executed with the `PlayerID` of the player who triggered it as its only parameter

tm.physics.Raycast

function tm.physics.Raycast( origin , direction , hitPositionOut , maxDistance , ignoreTriggers ) → boolean
Returns a bool if raycast hit something. Hit argument gets overwritten with raycast data
Parameter Type Description
origin ModVector3 Origin of the raycast
direction ModVector3 Direction of the raycast in euler angles
hitPositionOut ModVector3 Reference to the vector in which the hit position will be stored (only modified if the raycast hit an object)
maxDistance number (Optional) Max distance from the origin to check for hits. If nil, the distance is infinite
ignoreTriggers boolean (Optional) Whether to ignore trigger objects

tm.physics.RaycastData

function tm.physics.RaycastData( origin , direction , maxDistance , ignoreTriggers ) → ModRaycastHit
Casts a ray with the specific settings and returns a `ModRaycastHit`
Parameter Type Description
origin ModVector3 Origin of the raycast
direction ModVector3 Direction of the raycast in euler angles
maxDistance number Max distance from the origin to check for hits
ignoreTriggers boolean (Optional) Whether to ignore trigger objects

tm.physics.GetMapName

function tm.physics.GetMapName() → string
Returns the internal name for the current map

tm.physics.GetWindVelocityAtPosition

Deprecated
function tm.physics.GetWindVelocityAtPosition( position ) → ModVector3
Deprecated: Returns the wind velocity at a position [DEPRECATED USE `tm.world.GetWindVelocityAtPosition()` INSTEAD]
Parameter Type Description
position ModVector3

Player

43 functions

tm.players.CurrentPlayers

function tm.players.CurrentPlayers() → ModPlayer[]
Get all players currently connected to the server

tm.players.Kick

function tm.players.Kick( playerId )
Forcefully disconnect a given player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.IsPlayerAdministrator

function tm.players.IsPlayerAdministrator( playerId ) → boolean
Whether the player is an admin
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetPlayerProfileId

function tm.players.GetPlayerProfileId( playerId ) → string
Get players' unique profile id
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetPlayerTransform

function tm.players.GetPlayerTransform( playerId ) → ModTransform
Get the transform of a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetPlayerGameObject

function tm.players.GetPlayerGameObject( playerId ) → ModGameObject
Get the GameObject of a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.IsPlayerInSeat

function tm.players.IsPlayerInSeat( playerId ) → boolean
Returns true if the player is in a seat
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.ForceExitSeat

function tm.players.ForceExitSeat( playerId )
Forces a player to exit their seat
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.OccupiedStructure

function tm.players.OccupiedStructure( playerId ) → ModStructure (Optional)
Returns `ModStructure` of the seat the player is in, or `nil` if not in a seat
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.KillPlayer

function tm.players.KillPlayer( playerId )
Kills a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.CanKillPlayer

function tm.players.CanKillPlayer( playerId ) → boolean
Checks if player can be killed
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.SetPlayerIsInvincible

function tm.players.SetPlayerIsInvincible( playerId , enabled )
Sets the invincibility status of a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
enabled boolean

tm.players.SetJetpackEnabled

function tm.players.SetJetpackEnabled( playerId , enabled )
Enables and disables the jetpack
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
enabled boolean

tm.players.GetPlayerStructures

function tm.players.GetPlayerStructures( playerId ) → ModStructure[]
Get all structure(s) owned by that player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetSpawnedStructureById

function tm.players.GetSpawnedStructureById( structureId ) → ModStructure[]
Get structure by ID. Can only get structures spawned through `tm.players.SpawnStructure()`
Parameter Type Description
structureId StructureID See `StructureID` type alias

tm.players.GetPlayerStructuresInBuild

function tm.players.GetPlayerStructuresInBuild( playerId ) → ModStructure[]
Get the structure(s) currently in build mode for a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetPlayerSelectBlockInBuild

function tm.players.GetPlayerSelectBlockInBuild( playerId ) → ModBlock (Optional)
Get the last selected block in the builder for that player. Returns `nil` if the player hasn't selected a block in the current session. Dragging blocks doesn't count as selecting them. When multiple blocks are selected, only the first selected block is returned
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetPlayerName

function tm.players.GetPlayerName( playerId ) → string
Get the player's name
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetPlayerTeam

function tm.players.GetPlayerTeam( playerId ) → TeamID
Get the player's team index
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.SetPlayerTeam

function tm.players.SetPlayerTeam( playerId , teamID )
Set the player's team index
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
teamID TeamID See `TeamID` type alias

tm.players.GetMaxTeamIndex

function tm.players.GetMaxTeamIndex() → TeamID
Returns the highest team index allowed (always returns `7`)

tm.players.GetPlayerIsInBuildMode

function tm.players.GetPlayerIsInBuildMode( playerId ) → boolean
Returns true if the player is in build mode
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.SetBlockLimit

function tm.players.SetBlockLimit( blockTypeGuid , limit )
Set block limit for a specific block type, 0 means the block will be banned
Parameter Type Description
blockTypeGuid BlockGuid Internal ID of the block. See `BlockGuid` type alias
limit number

tm.players.AddCamera

function tm.players.AddCamera( playerId , position , rotation , priority )
Add a camera. THERE CAN ONLY BE 1 CAMERA PER PLAYER!
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
position ModVector3
rotation ModVector3
priority number (Optional) priority of the camera. Cameras with higher values are used over those with lower values. If `nil`, uses 100

tm.players.RemoveCamera

function tm.players.RemoveCamera( playerId )
Remove a camera. THERE CAN ONLY BE 1 CAMERA PER PLAYER!
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.SetCameraPosition

function tm.players.SetCameraPosition( playerId , position )
Set camera position
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
position ModVector3

tm.players.SetCameraRotation

function tm.players.SetCameraRotation( playerId , rotation )
Set camera rotation
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
rotation ModVector3 Direction vector the camera will point in

tm.players.ActivateCamera

function tm.players.ActivateCamera( playerId , fadeInDuration )
Activate a camera with fade-in
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
fadeInDuration number

tm.players.DeactivateCamera

function tm.players.DeactivateCamera( playerId , fadeOutDuration )
Deactivate a camera with fade-out
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
fadeOutDuration number

tm.players.SpawnStructure

function tm.players.SpawnStructure( playerId , blueprint , structureId , position , rotation )
Spawn a structure for a player with given blueprint, position and rotation
Parameter Type Description
playerId PlayerID Player to which the blueprint will belong. See `PlayerID` type alias
blueprint TextureName Name of the blueprint to spawn. See `TextureName` type alias
structureId StructureID ID that will be used to reference the structure. See `StructureID` type alias
position ModVector3 Position of the spawned structure
rotation ModVector3 Rotation of the spawned structure

tm.players.DespawnStructure

function tm.players.DespawnStructure( structureId )
Despawn a structure
Parameter Type Description
structureId StructureID See `StructureID` type alias

tm.players.PlacePlayerInSeat

function tm.players.PlacePlayerInSeat( playerId , structureId )
Places the player in the seat of a structure
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
structureId StructureID See `StructureID` type alias

tm.players.SetBuilderEnabled

function tm.players.SetBuilderEnabled( playerId , isEnabled )
Set if the builder for a player should be enabled
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
isEnabled boolean

tm.players.SetRepairEnabled

function tm.players.SetRepairEnabled( playerId , isEnabled )
Set if repairing for a player should be enabled. Also enables/disables transform
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
isEnabled boolean

tm.players.GetBuilderEnabled

function tm.players.GetBuilderEnabled( playerId ) → boolean
Checks if building is enabled for a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetRepairEnabled

function tm.players.GetRepairEnabled( playerId ) → boolean
Checks if repairing is enabled for a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetPlayerSeatBlock

function tm.players.GetPlayerSeatBlock( playerId ) → ModBlock (Optional)
Returns the block the player is seated in, or `nil` if they aren't in a seat (in which case a message will be logged)
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.SetPlayerSpawnLocation

function tm.players.SetPlayerSpawnLocation( playerId , spawnLocationId )
Sets the spawn location the player should use when respawning. Will be overwritten if another spawn location is set, eg checkpoints on the map
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
spawnLocationId SpawnLocationID See `SpawnLocationID` type alias

tm.players.SetSpawnPoint

function tm.players.SetSpawnPoint( playerIndex , spawnLocationId , position , rotation )
Sets the position and rotation of the spawn point for a player ID at a given spawn location. Each spawn location is a group of spawn points, one for each player ID. spawnLocationId = id of the spawn location. playerId = player ID for which the spawn point will be used when respawning at the location
Parameter Type Description
playerIndex PlayerID See `PlayerID` type alias
spawnLocationId SpawnLocationID See `SpawnLocationID` type alias
position ModVector3
rotation ModVector3

tm.players.TeleportPlayerToSpawnPoint

function tm.players.TeleportPlayerToSpawnPoint( playerId , spawnLocationId , keepStructure )
Teleports a player to the selected spawn point location. To teleport all players use `tm.players.TeleportAllPlayersToSpawnPoint()`. Set `keepStructure` to true and it will try to keep their structure after teleporting (will be repaired)
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
spawnLocationId SpawnLocationID See `SpawnLocationID` type alias
keepStructure boolean Whether it should try to keep the players' structure after teleporting (will be repaired)

tm.players.TeleportAllPlayersToSpawnPoint

function tm.players.TeleportAllPlayersToSpawnPoint( spawnLocationId , keepStructure )
Teleports ALL players to the selected spawn point location. Use this to move up to 8 players to their spawn position. Set `keepStructure` to true and it will try to their structure after teleporting (will be repaired)
Parameter Type Description
spawnLocationId SpawnLocationID See `SpawnLocationID` type alias
keepStructure boolean Whether it should try to keep the players' structure after teleporting (will be repaired)

tm.players.GetPrimaryBlockColor

function tm.players.GetPrimaryBlockColor( playerId ) → ModColor
Gets the primary block color of a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

tm.players.GetSecondaryBlockColor

function tm.players.GetSecondaryBlockColor( playerId ) → ModColor
Gets the secondary block color of a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias

UI

21 functions

tm.playerUI.SendChatMessage

function tm.playerUI.SendChatMessage( senderName , message , color )
Send a message to chat. The message will be sent to all players in the game. Ignored in singleplayer
Parameter Type Description
senderName PrintableValue
message PrintableValue
color ModColor (Optional) Color of the sender name and message contents. If `nil`, white is used

tm.playerUI.AddUIButton

function tm.playerUI.AddUIButton( playerId , id , defaultValue , callback , data )
Add a button to the client's mod UI
Parameter Type Description
playerId PlayerID Player for which the UI element will be created. See `PlayerID` type alias
id UIElementID See `UIElementID` type alias
defaultValue PrintableValue Text of the button. See `PrintableValue` type alias
callback fun(data: UICallbackData) Function to execute when the button is pressed
data any Arbitrary data passed to the callback function

tm.playerUI.AddUIText

function tm.playerUI.AddUIText( playerId , id , defaultValue , callback , data )
Add a text field to the client's mod UI
Parameter Type Description
playerId PlayerID Player for which the UI element will be created. See `PlayerID` type alias
id UIElementID See `UIElementID` type alias
defaultValue PrintableValue Default text of the field. See `PrintableValue` type alias
callback fun(data: UICallbackData) Function to execute when the text is changed
data any Arbitrary data passed to the callback function

tm.playerUI.AddUILabel

function tm.playerUI.AddUILabel( playerId , id , defaultValue )
Add a label to the client's mod UI
Parameter Type Description
playerId PlayerID Player for which the UI element will be created. See `PlayerID` type alias
id UIElementID See `UIElementID` type alias
defaultValue PrintableValue Text of the label. See `PrintableValue` type alias

tm.playerUI.RemoveUI

function tm.playerUI.RemoveUI( playerId , id )
Remove an UI element
Parameter Type Description
playerId PlayerID ID of the player for which the UI element will be removed. See `PlayerID` type alias
id UIElementID See `UIElementID` type alias

tm.playerUI.SetUIValue

function tm.playerUI.SetUIValue( playerId , id , value )
Set the value of a client's UI element
Parameter Type Description
playerId PlayerID Player for which the UI element will be created. See `PlayerID` type alias
id UIElementID See `UIElementID` type alias. If `nil`, the element will become the same as creating the element from scratch with a `nil` default value
value PrintableValue New value of the UI element (text shown on the UI element). See `PrintableValue` type alias

tm.playerUI.ClearUI

function tm.playerUI.ClearUI( playerId )
Remove all UI elements for a player
Parameter Type Description
playerId PlayerID Player for which the UI element will be cleared. See `PlayerID` type alias

tm.playerUI.AddSubtleMessageForPlayer

function tm.playerUI.AddSubtleMessageForPlayer( playerId , header , message , duration , spriteAssetName ) → SubtleMessageID
Adds a subtle message for a specific player. Optional duration of the message and custom sprite icon can be added. String limits 32 characters.
Parameter Type Description
playerId PlayerID ID of the player for which the message will be displayed. See `PlayerID` type alias
header PrintableValue Title of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias
message PrintableValue Content of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias
duration number (Optional) Duration of the message in seconds. If `nil`, uses a default duration
spriteAssetName TextureName (Optional) Icon of the message. See `TextureName` type alias

tm.playerUI.AddSubtleMessageForAllPlayers

function tm.playerUI.AddSubtleMessageForAllPlayers( header , message , duration , spriteAssetName ) → SubtleMessageID
Adds a subtle message for ALL players. Optional duration of the message and custom sprite icon can be added. String limits 32 characters.
Parameter Type Description
header PrintableValue Title of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias
message PrintableValue Content of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias
duration number (Optional) Duration of the message in seconds. If `nil`, uses a default duration
spriteAssetName TextureName (Optional) Icon of the message. See `TextureName` type alias

tm.playerUI.ShowIntrusiveMessageForPlayer

function tm.playerUI.ShowIntrusiveMessageForPlayer( playerId , header , message , duration )
Shows an intrusive message for a specific player. Optional duration of the message can be added, default is 3 seconds.
Parameter Type Description
playerId PlayerID
header PrintableValue Title of the message
message PrintableValue Subtitle of the message
duration number (Optional) Duration of the message in seconds. If `nil`, uses 3s

tm.playerUI.ShowIntrusiveMessageForAllPlayers

function tm.playerUI.ShowIntrusiveMessageForAllPlayers( header , message , duration )
Shows an intrusive message for ALL players. Optional duration of the message can be added, default is 3 seconds.
Parameter Type Description
header PrintableValue Title of the message
message PrintableValue Subtitle of the message
duration number (Optional) Duration of the message in seconds. If `nil`, uses 3s

tm.playerUI.RemoveSubtleMessageForPlayer

function tm.playerUI.RemoveSubtleMessageForPlayer( playerId , id )
Removes a subtle message for a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
id SubtleMessageID

tm.playerUI.RemoveSubtleMessageForAll

function tm.playerUI.RemoveSubtleMessageForAll( id )
Removes a subtle message for ALL players
Parameter Type Description
id SubtleMessageID

tm.playerUI.SubtleMessageUpdateHeaderForPlayer

function tm.playerUI.SubtleMessageUpdateHeaderForPlayer( playerId , id , newHeader )
Update the header of a subtle message for a player
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
id SubtleMessageID
newHeader PrintableValue New title of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias

tm.playerUI.SubtleMessageUpdateHeaderForAll

function tm.playerUI.SubtleMessageUpdateHeaderForAll( id , newHeader )
Update the header of a subtle message for all players
Parameter Type Description
id SubtleMessageID
newHeader PrintableValue New title of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias

tm.playerUI.SubtleMessageUpdateMessageForPlayer

function tm.playerUI.SubtleMessageUpdateMessageForPlayer( playerId , id , newMessage )
Update the message of a subtle message
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
id SubtleMessageID
newMessage PrintableValue New content of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias

tm.playerUI.SubtleMessageUpdateMessageForAll

function tm.playerUI.SubtleMessageUpdateMessageForAll( id , newMessage )
Update the message of a subtle message for ALL players
Parameter Type Description
id SubtleMessageID
newMessage PrintableValue New content of the message. Only the first 32 characters will be displayed. See `PrintableValue` type alias

tm.playerUI.RegisterMouseDownPositionCallback

function tm.playerUI.RegisterMouseDownPositionCallback( playerId , callback )
Registers a function callback to get the world position of the cursor when left mouse button is clicked
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
callback fun(data: UICallbackData) Function to execute when the button is pressed. Data is inside `UICallbackData.value` as a `string` with the form `"(x, y, z)"`

tm.playerUI.DeregisterMouseDownPositionCallback

function tm.playerUI.DeregisterMouseDownPositionCallback( playerId , callback )
Deregisters a function callback to get the world position of the cursor when left mouse button is clicked
Parameter Type Description
playerId PlayerID See `PlayerID` type alias
callback fun(data: UICallbackData) Function to remove. The same function object must have been registered with `tm.playerUI.RegisterMouseDownPositionCallback()` first

tm.playerUI.ShowCursorWorldPosition

function tm.playerUI.ShowCursorWorldPosition()
Show cursor world position in the UI. The value updates automatically

tm.playerUI.HideCursorWorldPosition

function tm.playerUI.HideCursorWorldPosition()
Hide cursor world position in the UI

World

7 functions

tm.world.SetGlobalWind

function tm.world.SetGlobalWind( windVelocity )
Set a global wind velocity. The wind velocity is a vector in world space, where the x, y and z components represent the wind direction and speed
Parameter Type Description
windVelocity ModVector3

tm.world.GetWindVelocityAtPosition

function tm.world.GetWindVelocityAtPosition( position ) → ModVector3
Returns the wind velocity at a position
Parameter Type Description
position ModVector3

tm.world.SetTimeOfDay

function tm.world.SetTimeOfDay( percentage )
Set time of day (0-100). No effect if time is paused
Parameter Type Description
percentage number

tm.world.GetTimeOfDay

function tm.world.GetTimeOfDay() → number
Get time of day (0-100)

tm.world.SetPausedTimeOfDay

function tm.world.SetPausedTimeOfDay( isPaused )
Set if time of day should be paused or not
Parameter Type Description
isPaused boolean

tm.world.SetCycleDurationTimeOfDay

function tm.world.SetCycleDurationTimeOfDay( duration )
Set the cycle duration (seconds how fast a day goes by) for time of day
Parameter Type Description
duration number

tm.world.IsTimeOfDayPaused

function tm.world.IsTimeOfDayPaused() → boolean
Returns if the time of day is currently paused

Types & Classes

48 definitions

ModApiEnums

class
Table of Enum types

PrintableValue

alias alias for (string | number | boolean | ModVector3 | ModQuaternion | ModGameObject | ModTransform | ModStructure | ModBlock | ModRaycastHit | ModColor | UICallbackData)?
Types which can be implicitly converted to a string for logging/displaying on the UI. API types are converted using their `.ToString()` method. If `nil`, the empty string is used

ModApi

class
Trailmakers Modding API

ModApiTmOs

class
OS-level functionality. Everything to do with files and general mod systems

MeshName

alias alias for string
Name referencing a mesh loaded with `tm.physics.AddMesh()`

TextureName

alias alias for string
Name referencing a texture loaded with `tm.physics.AddTexture()`

ModApiPhysics

class
Everything that can effect physics, like gravity, spawning objects, and importing meshes. Environment, Physics, Time, Assets and Objects

ModBlockMetaData

class
Metadata information about a block

BlockGuid

alias alias for string Internal block ID

PlayerID

alias alias for integer
ID of a player. Goes from 0 to 7, and the ID 0 is guaranteed to be the host

TeamID

alias alias for integer
ID of a team. Goes from 0 to 7, with the value selected through the session settings UI being `TeamID + 1`

StructureID

alias alias for string
ID referencing a structure spawned with `tm.players.SpawnStructure()`

SpawnLocationID

alias alias for string
ID referencing a spawn point location created with `tm.players.SetSpawnPoint()`

ModPlayer

class
Class representing a player

Fields

Name Type Description
connectionId string ID of the connection of the player
playerId PlayerID See `PlayerID` type alias
playerProfileId string Player's unique profile id
playerName string Name of the player
teamId TeamID See `TeamID` type alias

ModApiPlayers

class
Everything to do with players actions and info

OnPlayerJoinedEvent

class
Event triggered when a player joins the server

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer)): nil Add function to event
remove fun(callback: fun(player: ModPlayer)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerLeftEvent

class
Event triggered when a player leaves the server

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer)): nil Add function to event
remove fun(callback: fun(player: ModPlayer)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerDiedEvent

class
Event triggered when a player dies

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, damage: ModDamage)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, damage: ModDamage)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerExitSeatEvent

class
Event triggered when a player exits a structure

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer)): nil Add function to event
remove fun(callback: fun(player: ModPlayer)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerEnterSeatEvent

class
Event triggered when a player enters a structure

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer)): nil Add function to event
remove fun(callback: fun(player: ModPlayer)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerSpawnedEvent

class
Event triggered when a player spawns

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, respawnReason: ModRespawnReason)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, respawnReason: ModRespawnReason)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerFlipStructureEvent

class
Event triggered when a player flips a structure

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, structure: ModStructure)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, structure: ModStructure)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerRepairStructureEvent

class
Event triggered when a player repairs a structure

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, structure: ModStructure)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, structure: ModStructure)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerKilledPlayerEvent

class
Event triggered when a player kills another player

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, damage: ModDamage, killedPlayer: ModPlayer)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, damage: ModDamage, killedPlayer: ModPlayer)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerTeamChangedEvent

class
Event triggered when a player changes to another team

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, newTeamId: number)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, newTeamId: number)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerEnterBuilder

class
Event triggered when a player enters the builder

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer)): nil Add function to event
remove fun(callback: fun(player: ModPlayer)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerExitBuilder

class
Event triggered when a player exits the builder

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer)): nil Add function to event
remove fun(callback: fun(player: ModPlayer)): nil Remove function from event. The same function object must have been registered with `.add()` first

ModApiPlayerUI

class
For adding UI to your mod

OnChatMessageEvent

class
Event triggered when a player sends a chat message

Fields

Name Type Description
add fun(callback: fun(senderName: string, message: string, color: ModColor)): nil Add function to event
remove fun(callback: fun(senderName: string, message: string, color: ModColor)): nil Remove function from event. The same function object must have been registered with `.add()` first

UIElementID

alias alias for string | number | boolean
ID of an UI element

SubtleMessageID

alias alias for string
ID of a subtle message, only exists for the players for which the subtle message was created and is different for each one

ModApiAudio

class
Lets you play audio and effect audio

InputKey

alias alias for "`" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0" | "-" | "=" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "[" | "]" | ";" | "'" | "\\" | "," | "." | "/" | "backspace" | "tab" | "enter" | "left shift" | "right shift" | "left control" | "left alt" | "space" | "right alt" | "right control" | "insert" | "home" | "page up" | "delete" | "end" | "page down" | "up" | "down" | "left" | "right" | "numlock" | "[/]" | "[*]" | "[-]" | "[+]" | "[enter]" | "[,]" | "[1]" | "[2]" | "[3]" | "[4]" | "[5]" | "[6]" | "[7]" | "[8]" | "[9]" | "[0]"
Keys that can have callbacks registered Note: letters are case insensitive

ModApiInput

class
Lets you trigger functions on key press/release by players

OnPlayerKeyDownEvent

class
Event triggered when a player presses a key

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, keyName: string)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, keyName: string)): nil Remove function from event. The same function object must have been registered with `.add()` first

OnPlayerKeyUpEvent

class
Event triggered when a player releases a key

Fields

Name Type Description
add fun(callback: fun(player: ModPlayer, keyName: string)): nil Add function to event
remove fun(callback: fun(player: ModPlayer, keyName: string)): nil Remove function from event. The same function object must have been registered with `.add()` first

ModVector3

class
A 3-axis vector (position, rotation, scale, etc.), can store 3 numbers

Fields

Name Type Description
x number X value of the vector
y number Y value of the vector
z number Z value of the vector

ModQuaternion

class
Quaternion object. Quaternions are for rotations, they get rid of gimbal lock that a vector3 rotation runs into. Quaternions can store 4 numbers

Fields

Name Type Description
x number X value of the quaternion (i coefficient)
y number Y value of the quaternion (j coefficient)
z number Z value of the quaternion (k coefficient)
w number W value of the quaternion (real part)

UICallbackData

class
Callback data for when user is interacting with UI elements

Fields

Name Type Description
playerId PlayerID Gives you the player that interacted with the element. See `PlayerID` type alias
id UIElementID Gives you the ID of the interacted element. See `UIElementID` type alias
type string Gives you the type of the interacted element
value string Gives you the value of the interacted element (text shown for text fields, and a string representation of a vector that can be parsed with `tm.vector3.Create()` for mouse position callbacks)
data any Gives you the data of the interacted element. You pass in this data when registering the UI element's callback

ModApiWorld

class
Represents the current world

ModGameObject

class
GameObjects in the game environment

ModTransform

class
Represents a Transform (position, rotation, scale) of a GameObject

ModBlock

class
Represents a block in a structure

AerodynamicBox

class
Aerodynamic drag box

Fields

Name Type Description
forward number
back number
up number
down number
left number
right number

ModStructure

class
Object representing a creation in the game

ModRaycastHit

class
Object containing the information of a raycast hit

ModColor

class
Represents a color

ModDamage

class
Some type and amount of damage that has been dealt by a player at given position and direction

Fields

Name Type Description
damageType ModDamageType
damageAmount number
damagePosition ModVector3
damageDirection ModVector3
damageDealerPlayer ModPlayer

Documentation sourced from Alvaroping's LuaLS Library.