Multipoints.lua

From Moondust Wiki
Revision as of 00:40, 16 February 2015 by Hoeloe (talk | contribs)
Jump to navigation Jump to search

Download Latest Version

Multipoints is a library that enhances SMBX midpoints. It allows for multiple midpoints to be placed in a level, and for the player to spawn at a different location to the midpoint itself. It can also expand midpoints in other ways, though these are more advanced.

THIS LIBRARY REQUIRES THE TRIGGERS LIBRARY


Installation

Place the file multipoints.lua in the LuaScriptsLib folder.

How to use

1. Place a single SMBX midpoint on the ground in a location separate from the rest of the level. This can be in its own section, or in any point unreachable from playing the level. It is recommended to re-sprite the midpoint so that it is invisible.

2. Create a Lua Trigger using the Trigger library (see the Trigger library "how to use" document). Make sure you know the ID of the NPC used to create the Trigger (an Axe is recommended). You do not need to do steps 6-9 in the "how to use" document, as these are done by the Multipoint library.

3. Re-sprite the Axe NPC as a midpoint. Alternatively, make the Axe NPC invisible, and use a background object re-sprited as a midpoint. Either way, make sure this object disappears when the player makes contact with the midpoint.

4. Make the midpoint Axe call the Trigger (step 2) on Death.

5. Make a layer that hides the Multipoint midpoint and its hitbox. This will be used when we spawn having already collected the midpoint. Here, it will be referred to as "HideMidpointLayer", but any name will work.

6. Jump into lunadll.lua, and import Multipoints as an API. If you used an NPC other than the Axe as your Trigger, you will need to tell Multipoints using the triggerID value.

7. Use the function addMidpoint to create a new functioning midpoint. You must specify the coordinates of the Trigger NPC, the section containing the Multipoint midpoint, the spawn location, and the name of the "HideMidpointLayer" event. You can optionally also specify a list of Lua functions to call when spawning to that midpoint.

8. You should now have a working midpoint! You can repeat steps 2-7 as many times as you like to create multiple midpoints!


Example

After first creating a layer with an axe NPC, placed at the location (-200000,-200000) (just outside the bottom left of the default SMBX section), and creating an event to show this layer. There is an Axe, re-sprited to look like a midpoint, that will spawn the player at (-150000,-150000), and an event called "HideMidpointLayer" that removed the midpoint and its hitbox:

multipoints = loadAPI("multipoints");

multipoints.addMidpoint(-200000, -200000, 0, -150000, -150000, "HideMidpointLayer");

Documentation

Values

These are variables you can access

midpointCount number The number of midpoints currently registered with Multipoint.
levelName string The name prefixed to all UserData variables to ensure they remain unique. By default, this is: "<level filename> - ".
triggerID number The ID of the NPC to use for midpoint triggers. By default, this is 178 (Axe).


External Use Functions

These are functions you will need to use the library

addMidpoint triggerX triggerY section spawnX spawnY hideEvent extraActions
Creates a new midpoint. nil number

The X coordinate of the trigger.

number

The Y coordinate of the trigger.

number

The section in which to spawn the player.

number

The X coordinate at which to spawn the player.

number

The Y coordinate at which to spawn the player.

string:optional

The SMBX event to trigger when respawning after having collected this midpoint. This typically hides the midpoint layer, so it cannot be collected again.

function:optional

Lua code to run when respawning on this midpoint.


Internal Use Functions

These are functions that the library uses to function, but are not necessary for the user

getCheckpointID
Returns the ID of the last collected checkpoint. Returns -1 if no checkpoint has yet been collected. number
getCheckpointStatus id
Returns true if the specified checkpoint has been collected, false otherwise. boolean number

The ID of the checkpoint.

resetMidpoints
Resets the midpoint values to their defaults. This effectively sets all midpoints to their uncollected state (but won't re-spawn collected midpoints). Caution: This function will not reset SMBX midpoint status, so calling this function may cause the player to spawn at the location of the SMBX midpoint (which is normally inaccessible) when they next spawn. nil