From SRB2 Wiki
< Lua
Jump to: navigation, search

This page gathers all Lua functions that are specific to SRB2Kart, or differ from SRB2 v2.1's default functionality. For further reading on how these work, please see its respective functions page.


Function Return value(s) Description
K_PlayAttackTaunt(mobj_t source) void Plays the attack taunt of the source mobj. This is intended to be used for player mobjs.

This function respects the player's voice preferences (never, tasteful or meme), so it is fine to use this multiple times over a short timespan, and let the game handle the cooldown. In-game, players will perform their attack taunts as they throw offensive items, such as an Orbinauts, Jawz or Bananas thrown forwards.

K_PlayBoostTaunt(mobj_t source) void Plays the boost taunt of the source mobj. This is intended to be used for player mobjs.

This function respects the player's voice preferences (never, tasteful or meme), so it is fine to use this multiple times over a short timespan, and let the game handle the cooldown. In-game, players will perform their boost taunts as they use Sneakers or Pogo Springs.

K_PlayPowerGloatSound(mobj_t source) void Plays the power gloat sound of the source mobj. This is intended to be used for player mobjs.

In-game, player will perform power gloating when they use Shrink, Grow or Invincibility, and will always taunt by doing so.

K_PlayOvertakeSound(mobj_t source) void Plays the overtaking position sound of the source mobj. This is intended to be used for player mobjs.

This function respects the player's voice preferences (never, tasteful or meme), so it is fine to use this multiple times over a short timespan, and let the game handle the cooldown. In addition, players may not play their overtake sound up until 10 seconds have passed in a Race. They will never play their overtake sound in Battle. S_StartSound(mobj, sfx_kslow) may be used instead if this is desired.

K_PlayLossSound(mobj_t source) void Plays the loss sound of the source mobj. This is intended to be used for player mobjs.

This function does not perform voice preference handling, and as such it can be used repeatedly. Players will perform their loss sound if they finish a race in a bottom-half placement.

K_PlayHitEmSound(mobj_t source) void Plays the hit 'em sound of the source mobj. This is intended to be used for player mobjs.

There will always be a four second cooldown on how often this function can be used. Even if the player has voice preferences set to never, they will still hear a ping sound. Players will perform their hit 'em sound if they successfully hit another player with an item, or make them explode (using an Eggman Monitor, for example.)

K_GetKartColorByName(string name) UINT8 (SKINCOLOR_*) Returns a color by their common name, or SKINCOLOR_NONE if there is no name that matches the color.
K_IsPlayerLosing(player_t player) boolean Returns true if the player is in a bottom-half placing in Race, false otherwise.
K_IsPlayerWanted(player_t player) boolean Returns true if the player is one of the Wanted players in Battle, false otherwise.
K_KartBouncing(mobj_t mobj1, mobj_t mobj2, boolean bounce, boolean solid) void The function that performs the "bumpcode" of the game. mobj1 and mobj2 indicates who (or what) collided with who (or what).

When bounce is set to true, the momy of the mobj1 becomes reversed, effectively working as Goomba Stomp. When solid is set to true, the weight of mobj2 is set to be the same as mobj1, to handle cases where the mobj1 collides with a wall, or a solid, unmovable block like the ice blocks in Vanilla Lake.

K_MatchGenericExtraFlags(mobj_t mo, mobj_t master) void Handles flipping, transparency and split-screen rendering flags from the master mobj to the mo mobj. Very useful if you want another attached mobj to the player to also show flash-tics, flipping, etc..
K_DoInstashield(player_t player) void Performs the instashield animation on the player, which is the blue shield animation that appears when a player nullifies damage through flash-tics. Do note that this is visual only and does not handle invulnerability of the sort.

Instashield effects last for 15 tics. Calling the function during this duration will not play it again unless player.kartstuff[k_instashield] is set to zero.

K_SpawnBattlePoints(player_t source, [player_t victim], UINT8 amount) void Creates Battle's point gaining animation. Do note that it is visual only and does not add any points by itself.

source is to whom the animation will appear. victim is optional, but if inputted, the visuals will have the victim's palette, while setting it to nil will use the source's colors. The amount indicates how many points the animation will have. There's only animations for +1, +2 and +3 points gained - anything else than these will make the animation not appear.

K_SpinPlayer(player_t player, [mobj_t source, INT32 type, mobj_t inflictor, boolean trapitem]) void Spins a player out. source is where the spin-out comes from, and inflictor is the player who caused it.

Setting type to zero (spinout) will make sfx_slip play and make the player move if they were moving less than a fourth of their speed, which is banana-stepping behaviour. Setting it higher than zero does not cause these effects to happen (internally referred to as a wipeout instead). In Battle, setting trapitem to true will make this spinout not award extra points or reduce the player's or the source's wanted status. Does nothing in Race otherwise.

K_SquishPlayer(player_t player, [mobj_t source, mobj_t inflictor]) void Squishes a player. source is where the squishing comes from, and inflictor is the player who caused it. Normally, squishes caused by Grow or Shrink set source and inflictor to be the same.
K_ExplodePlayer(player_t player, [mobj_t source, mobj_t inflictor]) void Causes a player to blow up. source is what caused the explosion, and inflictor is who caused it.

This skips the area-of-effect damage and visual elements of the explosion - call K_SpawnKartExplosion and K_SpawnMineExplosion to perform the AoE damage effect and explosion visuals respectively.

K_StealBumper(player_t player, player_t victim, boolean force) void Handles bumper stealing in Battle. Does nothing if called on the Race gametype.

If called, player will steal a bumper from victim. This also handles Karma Comeback if player did not have any more bumpers left. If force is set to true, player will steal a bumper from victim regardless of if it was normally possible or not (if they had any more bumpers left, in flash-tics, etc..)

K_SpawnKartExplosion(fixed_t x, fixed_t y, fixed_t z, [fixed_t radius, INT32 number, mobjtype_t type,

angle_t rotangle, boolean spawncenter, boolean ghostit, mobj_t source])

void Spawns a mine explosion on the x, y and z coordinates. The optional parameters default to the Mine's parameters. Note that the visuals are handled by K_SpawnMineExplosion instead (see below).
  • radius is the explosion radius. Defaults to 32 * FRACUNIT.
  • number is the number of type spawned to determine the explosion radius. Defaults to 32.
  • type is the type of object spawned. Defaults to MT_MINEEXPLOSION.
  • rotangle is the angle of the spawned object. Defaults to 0.
  • spawncenter determines if the Objects spawned should be on the inputted x, y and z. Defaults to true.
  • ghostit determines if ghosts of the objects should spawn instead. This nullifies the explosion's effects. Defaults to false.
  • source determines who did the explosion. Defaults to nil.

Do note that the default values might not lead to an accurate explosion radius to the visuals. Here is a snippet that creates an accurate Mine explosion radius:

local explodedist = FixedMul( (3 * (192 * FRACUNIT) ) / 2, mapobjectscale)

-- can be any mobj you wish to use as a reference or an actual position.
-- the last nil is your source
for i = 0, 15 do
	explodedist + (32 * mapobjectscale), 32, MT_MINEEXPLOSION,
	i * (ANGLE_45 / 4), true, false, nil)
K_SpawnMineExplosion(mobj_t source, [UINT8 color]) void Spawns the purely visual Mine explosion effect to where the source is. If no color is set, SKINCOLOR_KETCHUP is used as the default color, otherwise it's possible to use any SKINCOLOR_* enumeration to color the explosion.
K_SpawnBoostTrail(player_t player) void Spawns the characteristic fire trail after using a Sneaker or getting a perfect Starboost behind the player's wheels. This function should be called once every tic to make a worthwhile boost trail.
K_SpawnSparkleTrail(mobj_t mo) void Spawns invincibility sparkles around mo. This should be called multiple times to make the sparkles more prominent.
K_SpawnWipeoutTrail(mobj_t mo, boolean translucent) void Spawns a white smoke effect on the mo's wheels - this is the same smoke effect used when players receive a hit.

If translucent is set to true, the smoke becomes transparent and does not move around as much, which is the same effect used when players drag an item or enter offroad. Likewise with the other trail functions, this should be called multiple times to make the smoke effect more prominent.

K_DriftDustHandling(mobj_t spawner) void Spawns the drift dust and plays the drift sound on the spawner mobj. These will not happen unless the spawner is on the ground, and on odd frames. Thus, this function should be ran over multiple tics to make a noticeable drift effect.
K_DoSneaker(player_t player, [INT32 type]) void Gives the player the sneaker effect, as if they were using a Sneaker item or stood on a boost pad.

type changes some cosmetic effects:

  • 0 will not make the player taunt.
  • 1 will make the player taunt. In addition, any non-zero type will make the player taunt.
  • 2 will make the boost trail effect appear on instead.
K_DoPogoSpring(mobj_t mo, [fixed_t vertispeed, UINT8 sound]) void Handles the vertical momentum given to mo when launched by a spring, handling gravity flipping and underwater physics. Note that this does not give the yellow/red spring's k_pogospring kartthing unless it is set to a non-zero value manually. In addition, the thrust factor will be increased by 1.25 or 1.115 if the player is under the effect of Sneakers or Invulnerability respectively, as long as the k_pogospring kartthing is not set to 2 (yellow springs). Do note that this thrust factor increase does not stack if both effects are present - Sneakers take priority.

vertispeed, if set to zero, will at least be between 48<<FRACBITS and 72<<FRACBITS, while sound:

  • If set to 0, it will not play any sound.
  • If set to 1, it will play the spring panel/object sound.
  • If set to 2, it will play the pogo spring item sound.
K_KillBananaChain(mobj_t banana, [mobj_t inflictor, mobj_t source]) void Destroys the banana chain that the player is currently dragging. Do note that the name is misleading, and it works with dragging Mines and Kitchen Sinks as well. inflictor and source can be set for MobjDeath hook handling purposes, but aside from directing the direction to where the dragging items move when destroyed, they serve no purpose.
K_RepairOrbitChain(mobj_t orbit) void "Repairs" a Jawz' and Orbinauts' orbital chain to make sure their hnext and hprev references are correct and to correct the player's item amount number.
K_FindJawzTarget(mobj_t actor, player_t source) player_t The Jawz' targetting system. The actor is the Jawz, and the source is the player who possesses it. Returns the player who is nearest to the source, which can be nil. The targetting will ignore dead players, invisible players and its source.
  • In the Race gametype, players who are in front of the source position-wise take precedence. The cone to detect players in front of the source is also ANGLE_67h (67.5º).
  • In the Battle gametype, the maximum range of a Jawz is 1028 fracunits, and the cone to detect players in front of the source is ANGLE_45 (45º) instead.

See also A_JawzChase.

K_GetKartDriftSparkValue(player_t player) INT32 Returns the Drift Spark Value of the player, based on their speed and weight. This is used to determine the thresholds for blue, red and rainbow miniturbos and their respective spark effects.
K_KartUpdatePosition(player_t player) void Updates the current position or standing of the player in Race or Battle, respectively.
K_DropItems(player_t player) void Drops the player's current item, alongside their amount, that they were holding in their item box. If their item was deployed, they will drop to the ground instead.
K_StripItems(player_t player) void Completely wipes the player's item-related states, except for an Eggman Monitor's roulette.
K_StripOther(player_t player) void Resets all item roulettes' status, Invincibility and Grow/Shrink timers, and Eggman Monitor-related timers.
K_MomentumToFacing(player_t player) void Transforms the player's momentum to where the player is looking. This function will not work if they're not on the ground, or if the difference between the player's direction and their momentum is higher than 90 degrees.
K_GetKartSpeed(player_t player, [boolean doboostpower]) fixed_t Returns the player's speed in fixed_t, accounting for the game's current kartspeed and if the player has any bumpers left in Battle (which sets their speed stat to 1).

If doboostpower is set to true, the player's k_boostpower and k_speedboost kartstuff variables will be accounted for the calculation.

K_GetKartAccel(player_t player) fixed_t Returns the player's acceleration in fixed_t, accounting if the player has any bumpers left in Battle (which sets their speed stat to 1).
K_GetKartFlashing(player_t player) UINT16 Returns the flashtics amount that the player should get after recovering from damage, depending on the mode being played and the player's speed stat.

By default, the flashtics amount is 3*TICRATE/2. This is multiplied by 2 if the Battle gametype is active. In addition, to account for the player's acceleration stat (or lack thereof), the flashtics amount is added by (flashingtics / 8) * (player.kartspeed).

K_GetItemPatch(UINT8 item, [boolean tiny]) string Returns a 64x64 patch name based on the KITEM_* or KRITEM_* type that is passed to the item variable. If tiny is set to true, it'll return a 32x32 patch instead.
K_SetRaceCountdown(tic_t racecountdown) void Sets the remaining time before all players blow up, in tics. This is used in the Race gametype to blow up players on bottom-half placements, after all top-halp placement players have finished. The default time used in races is 30 * TICRATE
K_SetExitCountdown(tic_t exitcountdown) void Sets the remaining time before the game finishes, after all players have finished the game (by crossing the finish line enough times in Race or by being the last one standing in Battle, for example), in tics. The default time used is 5 * TICRATE.
K_SetIndirectItemCooldown(tic_t indirectitemcooldown) void Sets the time before a Self-Propelled Bomb or a Shrink item can be rolled again, in tics. The default time set in-game is 20 * TICRATE.
K_SetHyudoroCooldown(tic_t hyubgone) void Sets the time before a Hyudoro item can be rolled again, in tics. The default time set in-game is 5 * TICRATE.

Iterator functions

Function Iterator type Description
displayplayers.iterate() displayplayers Iterates over all split-screen players.


Function Return value(s) Description
S_MusicType() musictype_t Returns the music's format:
  • 0 is MU_NONE - no music.
  • 1 is MU_CMD.
  • 2 is MU_WAV.
  • 3 is MU_MOD.
  • 4 is MU_MID.
  • 5 is MU_OGG.
  • 6 is MU_MP3.
  • 7 is MU_MP3_MAD_UNUSED.
  • 8 is MU_FLAC.
  • 10 is MU_GME.
S_MusicPlaying() boolean Returns true if music is loaded.
S_MusicPaused() boolean Returns true if music is paused.
S_MusicInfo(player_t player) string, integer, boolean Gets the music information that is being played on the player.

The function returns the following:

  • string - the music filename.
  • integer - sound flags.
  • boolean - returns true if the song has a looping point.
S_MusicName() string Returns the song's filename as a string.
S_MusicExists(string mname, [boolean checkMIDI, boolean checkDigi]) boolean Checks if the music whose filename is mname exists. checkMIDI and checkDigi helps check if there's MIDI and Digital versions of the music.
S_SetMusicLoopPoint(UINT32 looppoint) boolean Sets at which point should the music start again once it is finished playing, in miliseconds.
S_GetMusicLoopPoint() UINT32 Gets at which point should the music start again once it is finished playing, in miliseconds.
S_PauseMusic([player_t player]) boolean Pauses the music if it is playing.
S_ResumeMusic([player_t player]) boolean Resumes the music if it is playing.

Patch/string drawing functions

See also: HUD library functions.

Function Return value(s) Description
v.drawKartString(int x, int y, string text, [int flags]) nil Draws text on the screen at the screen coordinates given, using the same font as the one used by the "FREE PLAY" text, or the item counters when a player has multiple of the same item, among other uses.


  • flags determines the video flags given, which control extra effects such as color and translucency.
v.drawOnMinimap(fixed_t x, fixed_t y, fixed_t scale, patch_t patch, [colormap c, boolean centered]) nil Draws a patch on the minimap according to the x and y coordinates on the actual level, and its set scale.


  • c determines the colormap applied to the patch – use v.getColormap to obtain a value that can be used here.
  • centered misleadingly de-centers the patch, as it is assumed to be centered by default.

Additional togglable HUD items

Huditem name Description
"gametypeinfo" Bumpers, karma, or laps, depending on the game type.
"minimap" The minimap on the right side of the screen in 1P, middle in 2P and 4P, and bottom right in 3P.
"item" Item slot on the top left.
"position" The position indicator on the bottom right.
"check" The "CHECK" F-Zero indicator.
"minirankings" The gametype rankings on the left side of the screen.
"battlerankingsbumpers" The bumper drawer for battle. Useful if you wish a custom battle game type without involving bumpers.
"battlefullscreen" Battle's full-screen overlay, telling the player to "WAIT", or "ATTACK OR PROTECT", etc..
"battlecomebacktimer" The comeback timer in "battlefullscreen".
"wanted" The "WANTED" picture that appears on the bottom-right of the screen when a player is wanted in Battle.
"speedometer" The speedometer on the bottom-left of the screen.
"freeplay" "Free Play" text when playing solo.
"rankings" The player rankings that displays all players' position, name and time (or NO CONTEST if they did not finish in time), as well as the game speed.
  Lua [view]
Language features SyntaxMetatables
SRB2 data ActionsConstantsFunctionsGlobal variablesHooksUserdata structures
SRB2Kart data Kart Userdata structures
Tutorials Freeslots and Object resourcesCustom player ability