Want to make a mod for Speedrush?
Well, you've come to the right place!
Here, I'll be documenting the Speedrush Lua API, as well as the mod system itself.
Prequisites:
- Knowledge of the Lua programming language (
Read the Docs Here)
- Knowledge of your operating systems file browser
- A text or code editor of any sorts (Though, I do recommend
Visual Studio Code)
Scripting API
Variables
playerCount - This variable indicates how many players are online on the said server.
playersDead - This variable how many players are on the "Game Over" screen on the said server.
gameVersion - This variable indicates the version of the game.
serverPing - This variable indicates the ping of the said server.
serverPort - This variable indicates the port number of the said server
isClient - This variable indicates if the script is acting as a client or server.
scriptPath - This variable indicates the location to the current script, minus the script file name.
speedrush - This variable is important; it contains utility functions shared by Speedrush, you can
learn more about it below.
Functions
speedrush.resetGlobals() - This function will reset all Speedrush provided variables to their default
values.
speedrush.system.getCWD() - This function will return the current working directory of Speedrush's
Unity Player.
speedrush.system.getAssembly(name) - This function will return the name of the C# assembly
containing the type specified in 'name'
speedrush.system.getDeltaTime() - This function will return the Unity 'deltaTime'.
speedrush.system.getDeltaTime() - This function will return the Unity 'time'.
speedrush.system.serverPrint(message) - This function will log the message specified in 'message'
to all of the platers connected to the said server.
speedrush.discord.setPresence(presence) - (This function will only work if the user has the Discord
chat app installed and running!) This function will set
the user's Discord chat app presence to the string
specified in 'presence'.
speedrush.util.getCSharpProperty(type, property) - This function will return the value of the 'Type's
property specified in 'property', if it exists. If
not, this function will return 'nil'.
speedrush.util.callCSharpMethod(method) - Immediately calls the method with the name specified
in 'method', if it exists.
speedrush.graphics.newSprite(tag, fileLocation, x, y, width, height) - Creates a new sprite on the
screen if 'fileLocation' exists
in
the mod folder path. The
sprite will only be created if
the file specified in
'fileLocation' contains valid
image data. 'x' and 'y' specify
the location of the sprite, and
width and height do exactly
what their names imply they
do. 'tag' is used for tracking
modifying the sprite.
speedrush.graphics.setSpritePosition(tag, x, y) - Changes the sprite specified in 'tag's position to
'x' and 'y'. If you have not called
speedrush.graphics.newSprite or the tag does not
exist, this function will not do anything.
speedrush.graphics.setSpriteSize(tag, width, height) - Changes the sprite specified in 'tag's width
and height to 'width' and 'height'. If you have
not called speedrush.graphics.newSprite or the
tag does not exist, this function will not do
anything.
speedrush.graphics.destroySprite(tag) - Destroys the sprite specified in 'tag'.
If you have not called speedrush.graphics.newSprite or the
tag does not exist, this function will not do anything.
Callbacks
Callbacks are functions that you need to define in your scripts, however they will be called automatically by Speedrush when the described event is triggered.
onEnable(firstTimeEnabled) - Called when the said mod is enabled, 'firstTimeEnabled' will be 'true'
if the said mod was just added.
onDisable() - Called when the said mod is disabled.
onPlayerJoin() - Called when a player joins the said server.
onUpdate() - Called every frame of the game.
onMove(direction) - Called when a player moves in any direction, possible values of 'direction' are
"LEFT" or "RIGHT".
onDash(flipped) - Called when a player dashes, if the player is facing left, then 'flipped' will be
'true', otherwise it will be false.
onExit() - Called when a player exits the said server.
onAnimationPlay(index) - Called when a player's sprite animation changes states. The parameter
'index' (Number) indicates the animation that will be played
(0 = Run, 1 = Jump, 2 = Dash, 3 = Idle)
onFlip(flip) - Called when a player's sprite flips. if the will be flipped left, then 'flip' will be
'true', otherwise it will be false.
Packaging your Mod
Speedrush mods are very easy to package, all you have to do is put all of your script files, images, etc into a folder with a data file. This data file should simply be named 'mod' and have the file extension '.json'.
Here is an example of a good mod folder structure:
.
script.lua
ignore/
script.lua
image.png
mod.json
Keep in mind:
- Speedrush will only run scripts with the file extension: '.lua' (Notice how Speedrush doesn't attempt
to run the 'image.png' file)
- Speedrush will only run scripts in the root mod directory folder (Notice how I titled the nested folder
in the file structure example: 'ignore')
- Although Speedrush cannot run scripts in nested folders directly, they can still be
required by other Lua
scripts.
- Speedrush will report script errors to you (If there is any) in the control panel window (Accessed by
pressing the 'Up' Arrow Key)
- Speedrush will block you from installing two mods with the same name.
Here is a template 'mod.json' file:
{
"name": "Template",
"description": "Template\nMod",
"version": 1.0
}
These are the only JSON fields needed for a full mod data file, so edit them to your liking.
Distributing your Mod
You are free to distribute, sell, or share your Speedrush mod in any way.
However, I do have some tips:
- Compress your folder to a .zip, .rar, .7z, etc., as most mod sharing sites do not allow a raw folder to be
uploaded.
- Add a readme file to introduce your mod in detail or provide an installation/usage tutorial.
- Follow the
Semantic Versioning rules when updating your mod and/or
data file's version field.
If you've followed all of these steps correctly, you should be able to start modding Speedrush like no tomorrow!
Happy Modding!
[ 2023-03-19 14:16:18 CET ] [ Original post ]