Lua Documentation

Events

•  eventChatCommand ( playerName, command )
This event is triggered when a player uses a chat command (a message beginning with « ! »).
Arguments:
– playerName (String) : the player who sent the command
– command (String) : the message (without the initial « ! »)

•  eventChatMessage ( playerName, message )
This event is triggered when a player talks in the room chat.
Arguments:
– playerName (String) : the player who sent the message
– message (String) : the message

•  eventEmotePlayed ( playerName, emoteType, emoteParam )
This event is triggered when the player does an emote.
Arguments:
– playerName (String) : the player who did the emote
– emoteType (Int) : the type of emote played
– emoteParam (String) : the parameter used with the emote (only applies to the flag one)

•  eventFileLoaded ( fileNumber, fileData )
This event is triggered when a file gets fully loaded.
Arguments:
– fileNumber (String) : the file identifier
– fileData (String) : the file data

•  eventFileSaved ( fileNumber )
This event is triggered when a file gets saved.
Arguments:
– fileNumber (String) : the name of the file

•  eventKeyboard ( playerName, keyCode, down, xPlayerPosition, yPlayerPosition )
This event is triggered when a player presses a key.
Arguments:
– playerName (String) : the player who typed the key
– keyCode (Int) : the code of the typed key
– down (Boolean) : whether it was the press event, or the release one
– xPlayerPosition (Int) : the horizontal coordinate of the player when he or she typed the key
– yPlayerPosition (Int) : the vertical coordinate of the player when he or she typed the key

•  eventMouse ( playerName, xMousePosition, yMousePosition )
This event is triggered when a player perfoms a mouse click.
Arguments:
– playerName (String) : the player who made the click
– xMousePosition (Int) : the horizontal coordinate of the mouse click
– yMousePosition (Int) : the vertical coordinate of the mouse click

•  eventLoop ( elapsedTime, remainingTime )
This event occurs every 500 milliseconds.
Arguments:
– elapsedTime (Int) : the time in milliseconds elapsed since the beginning of the round
– remainingTime (Int) : the time in milliseconds remaining before the next round

•  eventNewGame ()
This event is triggered when a new round begins.

•  eventNewPlayer ( playerName )
This event is triggered when a new player joins the room.
Arguments:
– playerName (String) : the player who joined the room

•  eventPlayerDataLoaded ( playerName, playerData )
This event is triggered when player data gets loaded.
Arguments:
– playerName (String) : the player whose data got loaded
– playerData (String) : the data about the player

•  eventPlayerDied ( playerName )
This event is triggered when a player dies.
Arguments:
– playerName (String) : the player who died

•  eventPlayerGetCheese ( playerName )
This event is triggered when a player gets the cheese.
Arguments:
– playerName (String) : the player who got the cheese

•  eventPlayerLeft ( playerName )
This event is triggered when a player leaves the room.
Arguments:
– playerName (String) : the player who left the room

•  eventPlayerVampire ( playerName )
This event is triggered when a player turns into a vampire.
Arguments:
– playerName (String) : the player who turned into a vampire

•  eventPlayerWon ( playerName, timeElapsed, timeElapsedSinceRespawn )
This event triggers when a player enters the hole.
Arguments:
– playerName (String) : the player who entered the hole
– timeElapsed (Int) : the time in milliseconds elapsed since the beginning of the round
– timeElapsedSinceRespawn (Int) : the time in milliseconds elapsed since the last respawn

•  eventPlayerRespawn ( playerName )
This event is triggered when a player respawns.
Arguments:
– playerName (String) : the player who respawned

•  eventPopupAnswer ( popupId, playerName, answer )
This event is triggered when a player answers a popup (only type 1 and 2 popups).
Arguments:
– popupId (Int) : the popup identifier
– playerName (String) : the player who answered the popup
– answer (String) : the player’s answer
– yes or no for a type 1 popup
– any string for a type 2 poup

•  eventSummoningStart ( playerName, objectType, xPosition, yPosition, angle )
This event is triggered when a player starts summoning a shaman object.
Arguments:
– playerName (String) : the player who started summoning
– objectType (Int) : the kind of shaman object being summoned
– xPosition (Int) : the horizontal coordinate of the summoning point
– yPosition (Int) : the vertical coordinate of the summoning point
– angle (Int) : the rotation angle of the object being summoned

•  eventSummoningCancel ( playerName )
This event is triggered when a player cancels an object invocation.
Arguments:
– playerName (String) : the player who stopped summoning

•  eventSummoningEnd ( playerName, objectType, xPosition, yPosition, angle, objectDescription )
This event triggers when a player has finished an invocation.
Arguments:
– playerName (String) : the player who summoned the object
– objectType (Int) : the kind of the object
– xPosition (Int) : the horizontal position of the summoned object
– yPosition (Int) : the vertical position of the summoned object
– angle (Int) : the rotation angle of the summoned object
– objectDescription (Table) : the object table description as it would appear in the room’s objectList

•  eventTextAreaCallback ( textAreaId, playerName, eventName )
This event is triggered when a player clicks a text event.
Text event links are anchors tags links beginning with the “event:” string (e.g. : <a href=”event:callbackString”>Click here</a>).
If the link eventName begins with ‘#clear,’ the text area will be cleared, and the received eventName will be the text following the coma.
Arguments:
– textAreaId (Int) : the text area identifier
– playerName (String) : the player who clicked
– eventName (String) : the name of the clicked text event

•  eventColorPicked ( colorPickerId, playerName, color )
This event is triggered when a player chooses a color with a color picker.
Arguments:
– colorPickerId (Int) : the color picker identifier
– playerName (String) : the player who picked a color
– color (Int) : the color picked (-1 if the player didn’t picked one))

Functions

•  system.bindKeyboard ( playerName, keyCode, down, activate )
Listens to the player’s keyboard events.
Parameters:
– playerName (String) : the player you want to listen keyboard events from
– keyCode (Int) : the code of the key you want to listen
– to accurately listen for player movement (both arrows and wasd/zqsd keys), you can use 0 (left), 1 (up), 2 (right) or 3 (down)
– regular AS3 keycodes can be found on Adobe website
– down (Boolean) : whether it should listen for the press event, or the release one
– activate (Boolean) : whether it should be active (default value = true)

•  system.bindMouse ( playerName, active )
Listens to a player’s mouse events.
Parameters:
– playerName (String) : the player you want to listen mouse events from
– active (Boolean) : whether it should be active (default value = true)

•  system.disableChatCommandDisplay ( command, hide )
Prevents a module command (commands starting with « ! ») to be displayed in the room.
Parameters:
– command (String) : the command (without the initial « ! ») to hide
– hide (Boolean) : whether the command should be hided (default value = true)

•  system.exit ()
Deactivates the lua script running.

•  system.giveEventGift ( playerName, giftCode )
Gives an event reward to the targeted player.
Parameters:
– playerName (String) : the player to give the gift to
– giftCode (String) : the gift identifier (given by an admin)

•  system.loadFile ( fileNumber )
Requests the loading of a data file. The event eventFileLoaded is triggered when the file gets loaded.
Parameters:
– fileNumber (Int) : the identifier of the file to load (default value = 0)
Returns: (Boolean) whether the loading got started

•  system.loadPlayerData ( playerName )
Requests the loading of the player’s data for this module. The event eventPlayerDataLoaded is triggered when the player data gets loaded.
Parameters:
– playerName (String) : the player about whom you want to get the data
Returns: (Boolean) whether the loading got started

•  system.newTimer ( callback, time, loop, arg1, arg2, arg3, arg4 )
Creates a new timer to call a function after a delay, once or continuously.
Parameters:
– callback (Function) : The function to call
– time (Int) : the number of milliseconds that the function call should be delayed by
– loop (Boolean) : whether the function call should loop or happen only once (default value = false)
– arg1 (Object) : 1st argument of the callback function (default value = nil)
– arg2 (Object) : 2nd argument of the callback function (default value = nil)
– arg3 (Object) : 3rd argument of the callback function (default value = nil)
– arg4 (Object) : 4th argument of the callback function (default value = nil)
Returns: (Int) the new timer id

•  system.removeTimer ( timerId )
Destroys a timer.
Parameters:
– timerId (Int) : the identifier of the timer to stop

•  system.saveFile ( data, fileNumber )
Requests the saving of a data file (throttled to one per minute). The event eventFileSaved is triggered when the file get saved.
Parameters:
– data (String) : the data to store in the file
– fileNumber (Int) : the identifier (from 0 to 99) of the file to write the data in (default value = 0)
Returns: (Boolean) whether the saving got started

•  system.savePlayerData ( playerName, data )
Saves module data about a player.
Parameters:
– playerName (String) : the player about whom you want to save data
– data (String) : the player data to save

•  tfm.exec.addConjuration ( xPosition, yPosition, duration )
Adds conjuration to the map. Note: Grid coordinate are regular coordinate divided by 10 (as conjuration is a 10×10 pixel square).
Parameters:
– xPosition (Int) : the horizontal grid coordinate of the conjuration
– yPosition (Int) : the vertical grid coordinate of the conjuration
– duration (Int) : the duration of the conjuration in milliseconds (default value = 10000)

•  tfm.exec.addImage ( imageId, target, xPosition, yPosition, targetPlayer )
Displays an image on the map.
Parameters:
– imageId (String) : the image identifier
– target (String) : the game element to attach the image to
– #mobileId
– $playerName (on the mouse sprite)
– %playerName (with the mouse sprite removed)
– ?backgroundLayerDepth
– _groundLayerDepth
– !foregroundLayerDepth
– &fixedLayerDepth
– xPosition (Int) : the horizontal offset of the top-left corner of the image (0 being the middle of the game element) (default value = 0)
– yPosition (Int) : the vertical offset of the top-left corner of the image (0 being the middle of the game element) (default value = 0)
– targetPlayer (String) : the player who will see the image (if nil, applies to all players) (default value = nil)
Returns: (Int) the image identifier

•  tfm.exec.addJoint ( id, ground1, ground2, jointDef )
Adds a joint between two physic objects. . Note: In map XML codes, you can also add a « lua=”id” » property in a joint definition to be able to interact with it with LUA code.
Parameters:
– id (Int) : the identifier of the joint
– ground1 (Int) : the first ground the joint will affect
– ground2 (Int) : the second ground the joint will affect
– jointDef (Table) : the ground description
– type (Int): 0 -> distance joint, 1 -> prismatic joint, 2 -> pulley joint, 3 -> revolute joint
– point1 (String “x,y”): location of the ground1 anchor (default: the ground1’s center)
– point2 (String “x,y”): location of the ground2 anchor (default: the ground2’s center), only used with distance and pulley joints
– point3 (String “x,y”), point4 (String “x,y”): locations of the pulley’s anchors, only used with pulley joints
– frequency (Float), damping (Float): distance joints’ frequency and damping ratio
– axis (String “x,y”), angle (Int): prismatic joints’ axis and angle
– limit1 (Float), limit2 (Float), forceMotor (Float), speedMotor (Float): prismatic and revolute joints’ translation/rotation limits and motors
– ratio (Float): revolute joints’ ratio
– line (Int), color (Int), alpha (Float), foreground (Boolean): if none of these properties is defined, the joint won’t be drawn

•  tfm.exec.addPhysicObject ( id, xPosition, yPosition, bodyDef )
Spawns a ground.
Parameters:
– id (Int) : the identifier of the physic object
– xPosition (Int) : the horizontal coordinate of the center of the ground
– yPosition (Int) : the vertical coordinate of the center of the ground
– bodyDef (Table) : the ground description
– type (Int), width (Int), height (Int), foreground (Boolean), friction (Float), restitution (Float), angle (Int), color (Int), miceCollision (Boolean), groundCollision (Boolean)
– dynamic (Boolean), fixedRotation (Boolean), mass (Int), linearDamping (Float), angularDamping (Float) for dynamic grounds

•  tfm.exec.addShamanObject ( objectType, xPosition, yPosition, angle, xSpeed, ySpeed, ghost )
Spawns a shaman object.
Parameters:
– objectType (Int) : the type of the shaman object to spawn
– xPosition (Int) : the horizontal position of the spawn
– yPosition (Int) : the vertical position of the spawn
– angle (Int) : the rotation angle of the object, in degrees (default value = 0)
– xSpeed (Int) : the horizontal speed of the object (default value = 0)
– ySpeed (Int) : the vertical speed of the object (default value = 0)
– ghost (Boolean) : whether the spawned object should be transparent (default value = false)
Returns: (Int) the shaman object identifier

•  tfm.exec.chatMessage ( message, playerName )
Displays a chat message.
Parameters:
– message (String) : the chat message to display
– playerName (String) : the player who will get the message (if nil, applies to all players) (default value = nil)

•  tfm.exec.disableAfkDeath ( activate )
Deactivates the automatic afk death.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableAllShamanSkills ( active )
Deactivates all shaman skills.
Parameters:
– active (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableAutoNewGame ( activate )
Deactivates the automatic renewal of rounds.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableAutoScore ( activate )
Deactivates the automatic scoring management.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableAutoShaman ( activate )
Deactivates the automatic selection of shaman.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableAutoTimeLeft ( activate )
Deactivates the automatic remaining time change to 20s (when the shaman dies for example).
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableDebugCommand ( activate )
Disables the effects of the /debug command.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableMinimalistMode ( activate )
Disables the minimalist mode.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableMortCommand ( activate )
Disables the /mort command.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.disableWatchCommand ( activate )
Disables the effects of the /watch command.
Parameters:
– activate (Boolean) : whether the deactivation should be active (default value = true)

•  tfm.exec.displayParticle ( particleType, xPosition, yPosition, xSpeed, ySpeed, xAcceleration, yAcceleration, targetPlayer )
Displays a particle.
Parameters:
– particleType (Int) : the kind of particle you want to display
– xPosition (Int) : the horizontal coordinate of the particle
– yPosition (Int) : the vertical coordinate of the particle
– xSpeed (Number) : the horizontal speed of the particle (default value = 0)
– ySpeed (Number) : the vertical speed of the particle (default value = 0)
– xAcceleration (Number) : the horizontal acceleration of the particle (default value = 0)
– yAcceleration (Number) : the vertical acceleration of the particle (default value = 0)
– targetPlayer (String) : the player who should see the particle (if nil, applies to all players) (default value = nil)

•  tfm.exec.explosion ( xPosition, yPosition, power, radius, miceOnly )
Throws an explosion.
Parameters:
– xPosition (Int) : the horizontal coordinate of the center of the explosion
– yPosition (Int) : the vertical coordinate of the center of the explosion
– power (Int) : the maximum power of the explosion
– radius (Int) : the explosion radius (players further away won’t be affected)
– miceOnly (Boolean) : whether the explosion should affect only mice, or objects too (default value = false)

•  tfm.exec.giveCheese ( playerName )
Gives the cheese to a player.
Parameters:
– playerName (String) : the player who should get the cheese

•  tfm.exec.giveConsumables ( playerName, consumableId, amount )
Gives consumables to the targeted player.
Parameters:
– playerName (String) : the player to give the gift to
– consumableId (String) : the consumable identifier
– amount (String) : the amount of consumables to give (default value = “1”)

•  tfm.exec.giveMeep ( playerName )
Gives the meep competence to a player.
Parameters:
– playerName (String) : the player who should be able to meep

•  tfm.exec.killPlayer ( playerName )
Kills the selected player.
Parameters:
– playerName (String) : the player to kill

•  tfm.exec.lowerSyncDelay ( playerName )
Lowers the synchronization delay of a player to 400ms max
Parameters:
– playerName (String) : the player who should have a lower sync delay

•  tfm.exec.moveObject ( objectId, xPosition, yPosition, positionOffset, xSpeed, ySpeed, speedOffset, angle, angleOffset )
Defines the speed and position of a shaman object.
Parameters:
– objectId (Int) : the shaman object identifier
– xPosition (Int) : the horizontal coordinate of the point where the object will be moved
– yPosition (Int) : the vertical coordinate of the point where the object will be moved
– positionOffset (Boolean) : whether the specified position is an offset to apply to the current one, or the absolute one (default value = false)
– xSpeed (Int) : the horizontal coordinate of the speed to give to the object (default value = 0)
– ySpeed (Int) : the vertical coordinate of the speed to give to the object (default value = 0)
– speedOffset (Boolean) : whether the specified speed is an offset to apply to the current one, or the absolute one (default value = false)
– angle (Int) : the angle of the the object (default value = 0)
– angleOffset (Boolean) : whether the specified angle is an offset to apply to the current one, or the absolute one (default value = false)

•  tfm.exec.movePlayer ( playerName, xPosition, yPosition, positionOffset, xSpeed, ySpeed, speedOffset )
Defines the speed and position of a player.
Parameters:
– playerName (String) : the player to move
– xPosition (Int) : the horizontal coordinate of the point where the player will be moved
– yPosition (Int) : the vertical coordinate of the point where the player will be moved
– positionOffset (Boolean) : whether the specified position an offset to apply to the current one, or the absolute one (default value = false)
– xSpeed (Int) : the horizontal coordinate of the speed to give to the player (default value = 0)
– ySpeed (Int) : the vertical coordinate of the speed to give to the player (default value = 0)
– speedOffset (Boolean) : whether the specified speed an offset to apply to the current one, or the absolute one (default value = false)

•  tfm.exec.newGame ( mapCode, flipped )
Starts a new game
Parameters:
– mapCode (String) : the map code (default value = nil)
– nil (a random map)
– 6 (vanilla map)
– @42583 (editor map)
– #4 (perm category map)
– anything beginning with ‘&lt;’ (xml map)
– flipped (Boolean) : whether the map should be flipped (default value = nil (randomly mirrored in racing and bootcamp rooms, unless))

•  tfm.exec.playEmote ( playerName, emoteId, emoteArg )
Makes a player do an emote.
Parameters:
– playerName (String) : the player who should do the emote
– emoteId (Int) : the emote to do
– emoteArg (String) : the emote attribute (for the flag emote for example) (default value = nil)

•  tfm.exec.playerVictory ( playerName )
Makes a player enter the hole.
Parameters:
– playerName (String) : the player who should win

•  tfm.exec.removeImage ( imageId )
Removes an image.
Parameters:
– imageId (Int) : the image identifier

•  tfm.exec.removeJoint ( id )
Removes a joint from the game.
Parameters:
– id (Int) : the identifier of the joint to remove

•  tfm.exec.removeObject ( objectId )
Removes a shaman object.
Parameters:
– objectId (Int) : the shaman object identifier

•  tfm.exec.removePhysicObject ( id )
Removes a ground from the game.
Parameters:
– id (Int) : the identifier of the ground to remove

•  tfm.exec.respawnPlayer ( playerName )
Respawns a player.
Parameters:
– playerName (String) : the player to respawn

•  tfm.exec.setAutoMapFlipMode ( flipped )
Sets whether the following maps should be flipped (always, never, or TFM’s default behaviour).
Parameters:
– flipped (Boolean) : whether the maps should be flipped (default value = nil (the default TFM behaviour))

•  tfm.exec.setGameTime ( time, init )
Sets the game remaining time.
Parameters:
– time (Int) : the remaining time in seconds
– init (Boolean) : whether the remaining time should change even if the specified remaining time is higher than the current one (default value = true)

•  tfm.exec.setNameColor ( playerName, color )
Changes a player’s nickname’s color.
Parameters:
– playerName (String) : the player whose nickname should be colored
– color (Int) : the color of the nickname

•  tfm.exec.setPlayerScore ( playerName, score, add )
Sets the player’s score.
Parameters:
– playerName (String) : the player who should get his or her score changed
– score (Int) : the score
– add (Boolean) : whether the current score should be added to the specified one (default value = false)

•  tfm.exec.setRoomMaxPlayers ( maxPlayers )
Sets the max number of players in a room.
Parameters:
– maxPlayers (Int) : the maximum number of players the room can hold

•  tfm.exec.setRoomPassword ( password )
Password-protects a room.
Parameters:
– password (String) : the string to set as the password (an empty string removes the protection)

•  tfm.exec.setShaman ( playerName )
Makes a player a shaman.
Parameters:
– playerName (String) : the player who should become a shaman

•  tfm.exec.setVampirePlayer ( playerName )
Makes a player a vampire.
Parameters:
– playerName (String) : the player to make a vampire

•  tfm.exec.snow ( duration, snowballPower )
Makes the snow fall.
Parameters:
– duration (Int) : the snowfall duration in seconds (default value = 60)
– snowballPower (Int) : (default value = 10)

•  ui.addPopup ( id, type, text, targetPlayer, x, y, width, fixedPos )
Displays a popup.
Parameters:
– id (Int) : the identifier of the popup
– type (Int) : the popup type (0 for simple, 1 for yes or no, 2 for player input)
– text (String) : the text to display
– targetPlayer (String) : the player who will see the popup (if nil, applies to all players)
– x (Int) : the horizontal coordinate of the top-left corner (default value = 50)
– y (Int) : the vertical coordinate of the top-left corner (default value = 50)
– width (Int) : the width in pixels of the popup (if 0, it will be ajusted to the text width) (default value = 0)
– fixedPos (Boolean) : whether the position is fixed or if it should follow the player’s camera on long maps (default value = false)

•  ui.addTextArea ( id, text, targetPlayer, x, y, width, height, backgroundColor, borderColor, backgroundAlpha, fixedPos )
Displays a text area.
Parameters:
– id (Int) : the identifier of the text area
– text (String) : the text to display
– targetPlayer (String) : the player who will see the text area (if nil, applies to all players) (default value = nil)
– x (Int) : the horizontal coordinate of the top-left corner (default value = 50)
– y (Int) : the vertical coordinate of the top-left corner (default value = 50)
– width (Int) : the width in pixels of the text area (if 0, it will be ajusted to the text width) (default value = 0)
– height (Int) : the height in pixels of the text area (if 0, it will be ajusted to the text height) (default value = 0)
– backgroundColor (Int) : the background color of the text area (default value = 0x324650)
– borderColor (Int) : the border color of the text area (default value = 0)
– backgroundAlpha (Number) : the background’s opacity, from 0 (transparent) to 1 (opaque) (default value = 1)
– fixedPos (Boolean) : whether the position is fixed or if it should follow the player’s camera on long maps (default value = false)

•  ui.removeTextArea ( id, targetPlayer )
Removes a text area.
Parameters:
– id (Int) : the identifier of the text area
– targetPlayer (String) : the player whom the text area will disappear (if nil, applies to all players) (default value = nil)

•  ui.setMapName ( text )
Sets the map name.
Parameters:
– text (String) : the text to display as the map name

•  ui.setShamanName ( text )
Sets the shaman name.
Parameters:
– text (String) : the text to display as the shaman name

•  ui.showColorPicker ( id, targetPlayer, defaultColor, title )
Displays a color picker.
Parameters:
– id (Int) : the identifier of the color picker
– targetPlayer (String) : the player who will see the color picker (if nil, applies to all players) (default value = nil)
– defaultColor (Int) : the default color on the color picker (default value = 0)
– title (String) : the title of the color picker (default value = nil)

•  ui.updateTextArea ( id, text, targetPlayer )
Updates the content of a text area.
Parameters:
– id (Int) : the identifier of the text area
– text (String) : the new text to display
– targetPlayer (String) : the player who will get displayed the new text (if nil, applies to all players) (default value = nil)