Modding API Functions
A searchable list of all functions available in the Trailmakers Modding API.
Audio
4 functionstm.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 functionstm.GetDocs
function
tm.GetDocs()
→ string
Generates official Trailmakers Mods API Lua Docs
Input
2 functionstm.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
54 functionsModBlock.GetPosition
Gets the position of the transform (world space)
ModBlock.GetRotation
Gets the rotation of the transform (local space)
ModBlock.GetScale
Gets the scale of the transform (local space)
ModBlock.TransformPoint
Returns the point's position in world space (Adds the current pos with input vector)
| Parameter | Type | Description |
|---|---|---|
| point | ModVector3 |
ModBlock.TransformDirection
Returns the direction's world space direction
| Parameter | Type | Description |
|---|---|---|
| direction | ModVector3 |
ModBlock.Forward
Returns a normalized vector Forward in world space
ModBlock.Back
Returns a normalized vector Back in world space
ModBlock.Left
Returns a normalized vector Left in world space
ModBlock.Right
Returns a normalized vector Right in world space
ModBlock.Up
Returns a normalized vector Up in world space
ModBlock.Down
Returns a normalized vector Down in world space
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
Get the block's primary color
ModBlock.GetSecondaryColor
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
function
ModBlock.SetHealth(
hp
)
Set the block's health
| Parameter | Type | Description |
|---|---|---|
| hp | number |
ModBlock.GetStartHealth
function
ModBlock.GetStartHealth()
→ number
Get the block's start health
ModBlock.GetCurrentHealth
function
ModBlock.GetCurrentHealth()
→ number
Get the block's current health
ModBlock.GetName
function
ModBlock.GetName()
→ string
Get the name of the block's type
ModBlock.GetDrag
Get the drag values of an aerodynamic box
| Parameter | Type | Description |
|---|---|---|
| aerodynamicBoxIndex | integer |
ModBlock.GetDragAll
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
Get the default drag values of a aerodynamic box
| Parameter | Type | Description |
|---|---|---|
| aerodynamicBoxIndex | integer |
ModBlock.GetDefaultDragAll
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
Returns the structure a block belongs to
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
25 functionsModColor.Create
Creates a new color initialized to `RGBA(0, 0, 0, 0)`
ModColor.Create
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 value of the color
ModColor.G
function
ModColor.G()
→ number
Returns the green channel value of the color
ModColor.B
function
ModColor.B()
→ number
Returns the blue channel value of the color
ModColor.A
function
ModColor.A()
→ number
Returns the alpha channel value of the color
ModColor.White
Returns the color `RGBA(1.000, 1.000, 1.000, 1.000)`
ModColor.Black
Returns the color `RGBA(0.000, 0.000, 0.000, 1.000)`
ModColor.Red
Returns the color `RGBA(1.000, 0.000, 0.000, 1.000)`
ModColor.Green
Returns the color `RGBA(0.000, 1.000, 0.000, 1.000)`
ModColor.Blue
Returns the color `RGBA(0.000, 0.000, 1.000, 1.000)`
ModColor.Yellow
Returns the color `RGBA(1.000, 0.922, 0.016, 1.000)`
ModColor.Cyan
Returns the color `RGBA(0.000, 1.000, 1.000, 1.000)`
ModColor.Magenta
Returns the color `RGBA(1.000, 0.000, 1.000, 1.000)`
ModColor.Gray
Returns the color `RGBA(0.500, 0.500, 0.500, 1.000)`
ModColor.Clear
Returns the color ` RGBA(0.000, 0.000, 0.000, 0.000)`
ModColor.HSVToRGB
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.RGBToHSV
Converts a color in RGB to HSV. NOTE: this is currently broken
| Parameter | Type | Description |
|---|---|---|
| r | number | |
| g | number | |
| b | number |
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.GetHashCode
function
ModColor.GetHashCode()
→ number
Returns the hash code of the color
ModGameObject
20 functionsModGameObject.Despawn
function
ModGameObject.Despawn()
Despawns the object. This can not be done on players
ModGameObject.GetTransform
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
14 functionsModQuaternion.Create
Creates a quaternion by manually defining its components
| Parameter | Type | Description |
|---|---|---|
| x | number | |
| y | number | |
| z | number | |
| w | number |
ModQuaternion.Create
Creates a quaternion using euler angle components
| Parameter | Type | Description |
|---|---|---|
| x | number | |
| y | number | |
| z | number |
ModQuaternion.Create
Creates a quaternion using a euler angle vector3
| Parameter | Type | Description |
|---|---|---|
| eulerAngle | ModVector3 |
ModQuaternion.Create
Creates a quaternion using an angle and an axis to rotate around
| Parameter | Type | Description |
|---|---|---|
| angle | number | |
| axis | ModVector3 |
ModQuaternion.GetEuler
Returns a vector3 representing the euler angles of the quaternion
ModQuaternion.Multiply
Multiplies two quaternions and returns the result
| Parameter | Type | Description |
|---|---|---|
| otherQuaternion | ModQuaternion |
ModQuaternion.Lerp
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
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.op_Equality
function
ModQuaternion.op_Equality(
first
,
second
)
→ boolean
Returns true if both quaternions are the same, false if not (can be done with the normal `==` operator)
| Parameter | Type | Description |
|---|---|---|
| first | ModQuaternion | |
| second | 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.op_Inequality
function
ModQuaternion.op_Inequality(
first
,
second
)
→ boolean
Returns true if both quaternions are not the same, false if not (can be done with the normal `~=` operator)
| Parameter | Type | Description |
|---|---|---|
| first | ModQuaternion | |
| second | 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 functionsModRaycastHit.DidHit
function
ModRaycastHit.DidHit()
→ boolean
Returns if the raycast hit something
ModRaycastHit.GetHitNormal
Returns the hit normal
ModRaycastHit.GetHitPosition
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 functionsModStructure.GetPosition
Gets the position of the Transform (world space)
ModStructure.GetRotation
Gets the rotation of the Transform (local space)
ModStructure.GetScale
Gets the scale of the Transform (local space)
ModStructure.TransformPoint
Returns the point's position in world space (Adds the current pos with input vector)
| Parameter | Type | Description |
|---|---|---|
| point | ModVector3 |
ModStructure.TransformDirection
Returns the direction's world space direction
| Parameter | Type | Description |
|---|---|---|
| direction | ModVector3 |
ModStructure.Forward
Returns a normalized vector Forward in world space
ModStructure.Back
Returns a normalized vector Back in world space
ModStructure.Left
Returns a normalized vector Left in world space
ModStructure.Right
Returns a normalized vector Right in world space
ModStructure.Up
Returns a normalized vector Up in world space
ModStructure.Down
Returns a normalized vector Down in world space
ModStructure.Destroy
function
ModStructure.Destroy()
Destroy the structure
ModStructure.GetBlocks
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
Gets the velocity of the player inside of the structure in world space
ModStructure.GetVelocity
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
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
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 functionsModTransform.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
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
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
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
Gets the scale of the Transform (local space)
ModTransform.TransformPoint
Returns the point's local position (world space). Adds the current pos with input vector
| Parameter | Type | Description |
|---|---|---|
| point | ModVector3 |
ModTransform.TransformDirection
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
Returns a normalized vector Forward (world space)
ModTransform.Back
Returns a normalized vector Back (world space)
ModTransform.Left
Returns a normalized vector Left (world space)
ModTransform.Right
Returns a normalized vector Right (world space)
ModTransform.Up
Returns a normalized vector Up (world space)
ModTransform.Down
Returns a normalized vector Down (world space)
ModTransform.GetPositionWorld
Gets the position of the Transform (world space)
ModTransform.GetEulerAnglesWorld
Gets the euler angles rotation of the Transform (world space)
ModTransform.GetRotationWorld
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
Gets the position of the Transform (local space)
ModTransform.GetEulerAnglesLocal
Gets the euler angles rotation of the Transform (local space)
ModTransform.GetRotationLocal
Gets the quaternion rotation of the Transform (local space)
ModTransform.GetScaleLocal
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 functionsModVector3.Create
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
Creates a vector3 with specified values
| Parameter | Type | Description |
|---|---|---|
| x | number | |
| y | number | |
| z | number |
ModVector3.Create
Creates a vector3 with values defaulted to zero
ModVector3.Right
Creates a vector3 pointing right (1, 0, 0)
ModVector3.Left
Creates a vector3 pointing left (-1, 0, 0)
ModVector3.Up
Creates a vector3 pointing up (0, 1, 0)
ModVector3.Down
Creates a vector3 pointing down (0, -1, 0)
ModVector3.Forward
Creates a vector3 pointing forward (0, 0, 1)
ModVector3.Back
Creates a vector3 pointing back (0, 0, -1)
ModVector3.op_UnaryNegation
Flips all the signs (can be done with the normal `-` operator)
| Parameter | Type | Description |
|---|---|---|
| vector3 | ModVector3 |
ModVector3.op_Addition
Adds first and second together (can be done with the normal `+` operator)
| Parameter | Type | Description |
|---|---|---|
| first | ModVector3 | |
| second | ModVector3 |
ModVector3.op_Subtraction
Subtracts first and second together (can be done with the normal `-` operator)
| Parameter | Type | Description |
|---|---|---|
| first | ModVector3 | |
| second | ModVector3 |
ModVector3.op_Multiply
Multiplies the vector by the scalar (can be done with the normal `*` operator)
| Parameter | Type | Description |
|---|---|---|
| vector3 | ModVector3 | |
| scalar | number |
ModVector3.op_Division
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
Returns the cross product of two vector3
| Parameter | Type | Description |
|---|---|---|
| otherVector | ModVector3 |
ModVector3.Magnitude
function
ModVector3.Magnitude()
→ number
Returns the magnitude/length
ModVector3.MoveTowards
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
Linearly interpolates between two vectors
| Parameter | Type | Description |
|---|---|---|
| vector | ModVector3 | |
| otherVector | ModVector3 | |
| t | number | Position in the interpolation (0=vector, 1=otherVector) |
OS
11 functionstm.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 directly inside the `data_static folder`, subfolders aren't supported
| 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 time game has been playing in seconds. 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
9 functionsupdate
function
update()
Global function executed on each mod update cycle. Should be redefined to use it
Player.ToString
function
Player.ToString()
→ string
Always returns `Trailmakers.Mods.Api.ModApiPlayers+Player`
Player.toString
function
Player.toString()
→ string
Always returns `Trailmakers.Mods.Api.ModApiPlayers+Player`
OnPlayerEvent.add
function
OnPlayerEvent.add(
Function
)
Add function to event
| Parameter | Type | Description |
|---|---|---|
| Function | fun(player: Player): any |
OnPlayerEvent.remove
function
OnPlayerEvent.remove(
Function
)
Remove function from event. The same function object must have been registered with `OnPlayerEvent.add()` first
| Parameter | Type | Description |
|---|---|---|
| Function | fun(player: Player): any |
OnChatMessageEvent.add
function
OnChatMessageEvent.add(
Function
)
Add function to event
| Parameter | Type | Description |
|---|---|---|
| Function | fun(senderName: string, message: string, color: ModColor): any |
OnChatMessageEvent.remove
function
OnChatMessageEvent.remove(
Function
)
Remove function from event. The same function object must have been registered with `OnPlayerEvent.add()` first
| Parameter | Type | Description |
|---|---|---|
| Function | fun(senderName: string, message: string, color: ModColor): any |
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
25 functionstm.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
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
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.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 mesh will have to be sent to the client when they join (handled automatically)
tm.physics.AddTexture
function
tm.physics.AddTexture(
filename
,
resourceName
)
Add a texture to all clients, note this texture 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
| 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
Spawn a custom object
| 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
Spawn a custom object with 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
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
Deprecated: Returns the wind velocity at a position [DEPRECATED USE `tm.world.GetWindVelocityAtPosition()` INSTEAD]
| Parameter | Type | Description |
|---|---|---|
| position | ModVector3 |
Player
40 functionstm.players.CurrentPlayers
Get all players currently connected to the server
tm.players.GetPlayerTransform
Get the Transform of a player
tm.players.GetPlayerGameObject
Get the GameObject of a player
tm.players.OccupiedStructure
Returns `ModStructure` of the seat the player is in, or `nil` if not in a seat
tm.players.GetPlayerStructures
Get all structure(s) owned by that player
tm.players.GetSpawnedStructureById
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
Get the structure(s) currently in build mode for a player
tm.players.GetPlayerSelectBlockInBuild
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
tm.players.GetMaxTeamIndex
Returns the highest team index allowed (always returns `7`)
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.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.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.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) |
UI
21 functionstm.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.AddSubtleMessageForPlayer
function
tm.playerUI.AddSubtleMessageForPlayer(
playerId
,
header
,
message
,
duration
,
spriteAssetName
)
→ SubtleMessageID
Adds a subtle message for a specific player
| 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
| 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 functionstm.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
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
31 definitionsPrintableValue
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
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()`
ModApiPlayers
class
Everything to do with players actions and info
OnPlayerEvent
classModApiPlayerUI
class
For adding UI to your mod
OnChatMessageEvent
classUIElementID
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
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
Documentation sourced from Alvaroping's LuaLS Library.