Modding Tutorial

All Modding reference in a single article

Information


Starblast Modding interface can be found here: https://starblast.io/modding.html (ECP required)

Starblast Modding interface allows you to create custom mods for Starblast. The interface is made of a code editor window, on the left, and a console window, on the right. The code editor is where you type the JavaScript code for your mod. The console is where you can type commands to start your mod, stop it or interact with it while it is running.

Main programming language uses in this interface is JavaScript (ECMAScript)

Important Notes
In newer version of browsers’ updates, you can’t use the Modding Client in incognito mode anymore as they restrict some incognito features which are used by the editor.

And make sure to read all of these from the start to the end so that you won’t miss any important info!

Creating your first mod
In the Mod Code window, type the code for your first mod:

Change region
Once your mod code is ready, in the console, start by selecting your preferred region for modding using the command. For example with Europe:

&gt; region Europe Region set to Europe &gt; █ (Currently modding is only available in these 3 zones: Europe, America, Asia)

Start mod
Then to start running your mod, type command :

&gt; start Mod started https://starblast.io#1234@12.34.56.78:2000 Use 'test' to open game frame for testing &gt; █

Test the mod
As instructed by the console, you may want to open a test window to join your modded game with a Starblast client. Type :

&gt; test &gt; █

ALWAYS keep the Mod Editor Tab being active while running the mod!
This is one of the most important things you need to keep in your mind!

Why? Because that’s nuances of how browsers work.

Browsers slow down all javascript in non-active tabs in order to decrease the CPU processes.

For some mods (e.g Battle Royale), it doesn’t matter like with ship tree and options only,

but for other mods where some logic in tick function or events - it will affect them A LOT!

Ticks start to work slower and slower…

Soon everything will be lagging in game, like any reactions on mod buttons, any mod logic like spawning something in tick, etc.

And… depending on mod complexity it can just CRASH THE ENTIRE MOD - locally, server will continue to work so game will work but without mod logic anymore.

So, always keep the mod editor tab online or you will have unpredictable results!

Also, you need to have a stable internet connection if you don’t want your mods becoming laggy.

Stop the currently running mod
You can stop your mod anytime by using command. Note that this will kill the game and disconnect all connected players:

&gt; stop Mod stopped &gt; █

Print any values to the terminal, can be used in both mod code (after mod started) and terminal

Syntax:

&gt; echo(&quot;Message from terminal!&quot;) Message from terminal! &gt; █

Clear the the terminal, only available in terminal

Syntax:

Display help message inside the terminal, terminal use only

Syntax:

Definition
Stored in  is a data structure where you can set options for your custom, modded game. These options are used for initializing the game when you start your mod. Changing them while the mod is running does not affect the game.

Custom ships and custom tree
You can import ships made with Starblast Ship Editor. In the Ship Editor, use "Mod Export” feature to export a JavaScript code snippet for the modding interface. Then paste this snipped in the coding window and add this:

Then run your mod. If your ship is set to level=1 model=1, your ship will replace the Fly. You can replace other ships in the tree in a similar way, using. Or you can remove the original ship tree completely and provide a whole new one using.

Customizing the emote-chat system
The vocabulary used for the emote-chat system can be customized by setting the field  in the game option as follows:

This allows using Starblast built-in emote icons, which are listed here for reference: https://starblast.io/glyphs.html

You can also use unicode icons, here is a good source for reference: https://unicode.org/emoji/charts/full-emoji-list.html

Note that wide unicode characters (using more than 2 bytes) require a specific Javascript syntax as shown in the example above (example: )

Custom asteroids maps
You can create a custom map of asteroids. This allows creating a maze for example. The custom map you provide is actually a JavaScript character string which is used to "paint” the map.

For example:

In the example above, 9 sets the biggest size of asteroid. You can use smaller values for adding smaller asteroids to the grid. Any value other than a digit will be interpreted as no asteroid. If your  is set to 30, make sure to create 30 lines and 30 columns, or you may get unpredictable results.

Note: Use  for blank custom map

You can use Online Map Editor (a community tool) to create, edit and export maps.

Other common options
Most of the options are inherited from the usual custom games. A few more options have been added, specifically for modding (top of the list):

Deatmatch mode specific options
Example:

Definition
Found in  is a JavaScript function which is called 60 times per second. In this function’s body, you will be able to code specific actions that your mod needs to take automatically while the game is running. This function can be modified while the modded game is running and the changes will apply automagically.

General
Your mod can receive events through the function :

Definition
Can be accessible through, is an integer presenting game’s duration

Unit
The unit of this value is tick, where 1 tick = 1/60 seconds

Which means that 60 ticks = 1 second, 120 ticks = 2 seconds and so on.

Uses
This code uses to set the first ship in the list to the center of the map in the first minute of the mod and reset its crystals every 5 seconds (assume that there is one ship staying from the start of the mod):

Ships
You can access to the list of ships (players) through the array

You can also find a ship with specific id using, which returns an object represent the matched ship or   (if there are no ships matching the provided id)

Accessible fields
You have read access to the ship’s main fields and options:

Configuration
You can set different options on the ships. For example:

&gt; game.ships[0].set({x:0,y:0}); &gt; █ Will move the first ship in the list to the center of the map

List of accepted options when using :

Intermission
You can send the ship to intermission (a screen with results, offering to respawn). This screen allows you to display custom results information:

&gt; game.ships[0].intermission({&quot;Best Achievement&quot;:&quot;Managed to run the mod&quot;,&quot;Score&quot;:1234}); &gt; █

Triggering and Customizing player’s GameOver screen
You can also trigger the gameover screen for any given ship. Here again, you can pass results information to pass on to the player:

&gt; game.ships[0].gameover({&quot;Rating&quot;:&quot;Can do better&quot;,&quot;Score&quot;:1234}); &gt; █

Calling instructor
You can have the flight instructor send instructions to the player. For this find the players’s ship and use:

&gt; ship.instructorSays(&quot;Hello!&quot;) &gt; █ You can hide the instructor window using:

&gt; ship.hideInstructor &gt; █ You can later show it again using:

&gt; ship.showInstructor &gt; █ A second, optional parameter allows you to choose which one of the instructor characters will talk to the player. Example:

&gt; ship.instructorSays(&quot;Here is your report, Commander&quot;,&quot;Maria&quot;) &gt; █

General
The mod can create custom UI components that will show up on the player’s screen. This is done by calling  on the ship, passing in a component descriptor.

For example:

&gt; ship.setUIComponent({   id:&quot;myid&quot;,    position:[0,0,25,25],    clickable: true,    shortcut: &quot;X&quot;,    visible: true,    components: [      { type:&quot;box&quot;,position:[0,0,100,100],fill:&quot;#456&quot;,stroke:&quot;#CDE&quot;,width:2},      { type: &quot;text&quot;,position: [0,0,100,50],color: &quot;#FFF&quot;,value: &quot;My Text&quot;},      { type: &quot;player&quot;,id: 1, position: [0,0,50,50],color: &quot;#FFF&quot;},    ]  }) &gt; █ Here is the list of UIComponent’s accepted options:

Combining with events
The example below creates a warp button for every player, which can be clicked and results in the ship warping to another random location, also adding 3 seconds invulnerability to it:

Full example: https://github.com/pmgl/starblast-modding/blob/master/examples/warp_button.js

Customizing the scoreboard or radar
The built-in scoreboard or radar can be replaced by your own custom scoreboard/radar component. As soon as an UI component with id  or   is created, you will be responsible for updating the scoreboard/radar. Your custom scoreboard/radar component does not have to include a  because it will automatically fill the area already reserved for the perspective UI Component.

Global UI
You can use  to set the UI to all current players in the game

Remove all ship’s secondary slots
Syntax:

Aliens
You can access to the list of aliens through the array

You can also find an alien with specific id using, which returns an object represent the matched alien or   (if there are no aliens matching the provided id)

Creation
To create an alien, use

List of accepted options:

(Note: Server will response with  when at least one input property value is improper)

Here is the list of supported codes:

A new  object is immediately added to  ; however it cannot be used before it has been assigned an id (positive integer) by the server.

Limits
You can only have 300 alive aliens (including aliens generated by the game mode) at any time in your game

Configuration
Once an alien is live and has an assigned id, you can set options to it. For example:

&gt; game.aliens[0].set({x:0,y:0}); &gt; █ Will move the first alien in the list to the center of the map

Accepted options when using :

Collectibles
You can spawn collectible weapons in the playfield

You can also find a collectible with specific id using, which returns an object represent the matched collectible or   (if there are no collectibles matching the provided id)

Creation
Here is an example:

&gt; game.addCollectible({code:10,x:0,y:0}); &gt; █ This will add a new collectible pack of rockets to coordinates (0;0)

Here is the list of supported codes:

(Note: Server will response with  when at least one input property value is improper)

Limits
You can only have 50 active collectibles (only counts collectibles added from your modding client) at any time in your game

Accessing
You can check the collectibles still available to collect in the playfield by using:

Asteroids
You can access to the list of moving asteroids through the array

You can also find an asteroid with specific id using, which returns an object represent the matched asteroid or   (if there are no asteroids matching the provided id)

Creation
To create an asteroid, use.

Here is the list of accepted options:

(Note: Server will response with  when at least one input property value is improper)

A new  object is immediately added to   ; however it cannot be used before it has been assigned an id (positive integer) by the server.

Limits
You can only have 300 alive asteroids (including moving asteroids generated by the game mode) at any time in your game

Configuration
Once an asteroid is live and has an assigned id, you can set options to it. For example:

&gt; game.asteroids[0].set({x:0,y:0}); &gt; █ Will move the first asteroid in the list to the center of the map

List of accepted options when using :

Add 3D objects to the scenery
The mod can create custom, textured 3D objects and add them to the scenery using  method.

Accessing
Game property  stores all active 3D Objects maintained by the mod

You shouldn’t modify this property in order to keep the mod run smoothly

Changing or moving an object
Use  again with the same object instance id.

Removing an object
removes the object with given id. You can omit the id parameter, which will remove all custom objects in the scene.

Example
Working example, adding cube objects to the scenery: https://github.com/pmgl/starblast-modding/blob/master/examples/adding_cube.js

Accessing
Once the mod starts running, all detailed options will be passed into the  object

Accessible fields
This includes all properties defined in, plus some extended fields listed below (except if they are not defined):

Assigning custom properties to some entities/objects
You can assign properties into some game entities or objects as side notes/indicators

Accessing and assigning
Simply just call out their  property (which is always an object) and assign properties to it.

Supported objects/entities

 * object
 * all ships
 * all aliens
 * all collectibles
 * all asteroids

Set custom maps in-game
You can use  to set custom map while the game is running

where  has the same format as the custom map in

Lock/unlock the mod from attracting new players
Use  to lock/unlock the mod to be visible to players (only for Modding Space mods)

There is also game boolean properties  is used to determine if the mod is open or not

Black screen issue
In most cases you’re getting a black screen after loading your mod cause of bad ship tree.

Follow these rules to avoid it:


 * 1) Your ship tree must have a ship with type/code 101.
 * 2) If your ship tree has level 2 ships, then it should have level 1 ships too.
 * 3) Either models should go in the right order without gaps: 1, 2, 3 etc (not 1, 6, 17) or control all ship tree routes by   parameter in ship codes (but keep correct order for unreachable ships).
 * 4) You can’t have possibly infinite ship tree routes, made by   parameters - all routes should end at some ship, there shouldn’t be able to come back to some ship again.

My mod closed accidentally but the game is not stopped
Sometimes, some unexpected problems can crash the mod, but it only disconnects from the modding side, or so-called "controller” side, the game itself will continue running without control from your modding client until it meets the closing requirements (or even in some serious occasions, game developers - like PMGL - need to close it by themselves).

Here is some reasons which can lead to mod crashing:


 * 1) Closing/Reloading the modding tab/window without stopping the mod first (Most common one)
 * 2) Very unstable internet connection
 * 3) Server resolve error (which will automatically disconnect the controller by itself)
 * 4) Browser tab hangs/crashes (careful of infinite while/for loops)

Also keep in mind that you can’t reconnect to your previously crashed server, even if it’s still running.

Tutorial and Documentation

 * GitHub version
 * How to add ship to the mod - by InterdictorSD
 * Modding Live #2 by PMGL
 * General modding tutorial by Wolfan

Tools

 * Map Editor

Code resources

 * Community Mods Archive
 * WIP Modding plus by Dpleshkov
 * Starblast code reference by Bhpsngum
 * Starblast code and objects reference by 45rfew
 * Starblast code reference by Wolfan

Update Status
This page was updated on Fri, 28 May 2021 17:02:18 GMT from the origin, requested by