Skip to content

Lua Library: `tanks`

F6 edited this page Jun 22, 2025 · 4 revisions

tanks library

The tanks library is globally available across all script contexts. Its primary purpose is convenience, and secondarily the ability to have your scripts run across different versions of Tanks with relative ease.


notify (message: string, duration: number?)

Send a notification to the player using TanksLua's Notification API

Arguments

  1. message: The message to send in the notification.
  2. duration: The amount of time units that the notification should be visible for. Will default to 200 if left blank.

playSound (sound: string, pitch: number?)

Send a notification to the player using TanksLua's Notification API

Arguments

  1. sound: The name of the sound to play.
  2. pitch: The pitch the sound should be played at. Will default to 1 if left blank.

Sub-libraries

tanks.game


Fields

Name Type Description
version string A string that is equal to the field version in the class tanks.Game. Exists for convenience.
isModApi boolean A boolean that will be true if the game is running Lancelot's ModAPI
tileSize number A number that is equal to the field tile_size in the class tanks.Game. Exists for convenience.

distance (a: Movable, b: Movable): number

Get the Euclidean distance between two Movables

Arguments

  1. a: The first movable
  2. b: The second movable

Returns

  1. The distance.

sqDistance (a: Movable, b: Movable): number

Get the squared Euclidean distance between two Movables. More performant than distance as it does not perform a sqrt.

Arguments

  1. a: The first Movable
  2. b: The second Movable

Returns

  1. The squared distance.

getMovables (): {Movable}

Get a table of all Movables in movables in the class tanks.Game.

Returns

  1. Table containing the Movables.

getPlayerTank (): Tank

Get the current value of the field playerTank in the class tanks.Game.

Returns

  1. The current player tank.

playing (): boolean

Convenience function primarily for use in update functions. Checks if the game is considered to be currently "playing". The criteria is as follows:

  • The screen is currently an instance of ScreenGame
  • The screen's paused field is false
  • The screen's playing field is true
  • The player tank's destroy field is false

Returns

  1. Whether the current state meets the criteria.

allied (a: Movable, b: Movable): boolean

Check if the two Movables are considered to be allied. The criteria is as follows:

  • Their teams both are non-null
  • Their teams are both equal to each other

Arguments

  1. a: The first Movable
  2. b: The second Movable

Returns

  1. Whether they are considered allied.

tanks.input

Fields

Name Type Description
codes {[string]:number} A dictionary of input code names to the input codes. Exists for convenience.

keyHeld (keyToCheck: number): boolean

Check if the key keyToCheck is currently held.

Arguments

  1. keyToCheck: The key to check.

Returns

  1. Whether the key is held.

mouseButtonHeld (buttonToCheck: number): boolean

Check if the mouse button buttonToCheck is currently held.

Arguments

  1. buttonToCheck: The button to check.

Returns

  1. Whether the button is held.

tanks.drawing


Fields

Name Type Description
objWidth number A number that is equal to the field objWidth of the object in the field drawing of tanks.Drawing
objHeight number A number that is equal to the field objHeight of the object in the field drawing of tanks.Drawing
objXSpace number A number that is equal to the field objXSpace of the object in the field drawing of tanks.Drawing
objYSpace number A number that is equal to the field objYSpace of the object in the field drawing of tanks.Drawing

color (r: number, g: number, b: number, a: number?)

Set the current draw color.

Arguments

  1. r: The red value of the color. Should between 0 and 1.
  2. g: The green value of the color. Should between 0 and 1.
  3. b: The blue value of the color. Should between 0 and 1.
  4. a: The alpha value of the color. Should between 0 and 1. Will default to 1 if left blank.

oval (x: number, y: number, width: number, height: number, drawMode: string, coordinateMode: string)

Draw an oval to the screen.

Arguments

  1. x: The X position of the oval.
  2. y: The Y position of the oval.
  3. width: The width of the oval.
  4. height: The height of the oval.
  5. drawMode: A string that should be either "fill" or "line" to pick whether the oval should be filled in.
  6. coordinateMode: A string that should be either "interface" or "game" to pick what kind of coordinate system the oval should be drawn in.

rect (x: number, y: number, width: number, height: number, drawMode: string, coordinateMode: string)

Draw a rectangle to the screen.

Arguments

  1. x: The X position of the rectangle.
  2. y: The Y position of the rectangle.
  3. width: The width of the rectangle.
  4. height: The height of the rectangle.
  5. drawMode: A string that should be either "fill" or "line" to pick whether the rectangleshould be filled in.
  6. coordinateMode: A string that should be either "interface" or "game" to pick what kind of coordinate system the rectangle should be drawn in.

fontSize (newSize: number?, coordinateMode: string): number?

Either get or set the font size for text drawing.

Arguments

  1. newSize: The number to set the font size to. Should be nil if you want to get the font size.
  2. coordinateMode: A string that should be either "interface" or "game" to pick what kind of coordinate system the font operation should be performed on.

Returns

  1. The current font size, if newSize is nil.

text (x: number, y: number, text: string, coordinateMode: string)

Draw text to the screen.

Arguments

  1. x: The X position of the text.
  2. y: The Y position of the text.
  3. text: The text to draw.
  4. coordinateMode: A string that should be either "interface" or "game" to pick what kind of coordinate system the text should be drawn in.

size (coordinateMode: string): number, number

Get the screen size of a given coordinate system.

Arguments

  1. coordinateMode: A string that should be either "interface" or "game" to pick what kind of coordinate system to get the size of.

Returns

  1. The width
  2. The height

tanks.multiplayer


isServer (): boolean

Check if the game is currently hosting a multiplayer party.

Returns

  1. Whether the game is currently hosting a multiplayer party.

isClient (): boolean

Check if the game is currently playing on a multiplayer party hosted by someone else.

Returns

  1. Whether the game is currently playing on a multiplayer party hosted by someone else.