DISCLAIMER: I will not provide support for any versions of SMBX2 prior to Beta 4.
The library can be loaded by adding stats = require("Stats")
to the top of your episode-wide luna.lua file. Alternatively, Here's a starter script with a simple Textplus-based HUD to get you going:
stats = require("Stats") local textplus = require("textplus") local fontB = textplus.loadFont("textplus/font/6.ini") function onHUDDraw() textplus.print{ x = 30, y = 550, xscale = 2, yscale = 2, font = fontB, text = "LEVEL: " .. stat.level } textplus.print{ x = 200, y = 550, xscale = 2, yscale = 2, font = fontB, text = "EXPERIENCE: " .. stat.xp } --textplus.print{ -- x = 0, --y = 20, -- xscale = 2, -- yscale = 2, --font = fontB, -- text = "FP: " .. stat.fp --} if stat.hp >= stats.criticalHP then textplus.print{ x = 0, y = 0, xscale = 2, yscale = 2, font = fontB, text = "HP: " .. stat.hp .. "/" .. stat.maxhp } else textplus.print{ x = 0, y = 0, xscale =2, yscale = 2, font = fontB, text = "HP: " .. stat.hp .."!/" .. stat.maxhp } end end stats.registerNPC(127, 3, 0, 4) -- Bit stats.xpDrop(127, 4)
stats.registerNPC(NPCID, pow, def, xpdrop)
- Registers an NPC and defines its stats. For reference:
NPCID
- The ID of the NPC you are registering.pow
- The base amount of damage that an NPC will do to the player. Note that if an NPC does not have a defined POW stat then it will throw an error if the player comes into contact with them.def
- Currently not used, so you may as well leave it as 0. Meant to interace with LightHitPoint somehow.xpdrop
- The amount of XP the player is given by defeating that enemy. You do not have to.
Example usage:
stats.registerNPC(1,>stats.registerNPC(1, 1, 0, 1) -- Registers the SMB3 Goomba, gives it 1 HP and POW, 0 DEF and awards one EXP for defeating it
[========]
stats.LevelUp(x)
- Increases the player's level by the specified ammount as well as their max HP by (5 * X) and POW by (1 * X). This script includes a new LunaLua event in the form of OnLevelUp()
, which is run whenever stats.LevelUp()
is called.
Example usage:
function onJump() stats.LevelUp(1) -- Grants a single level every time the player does a big jump. end function onLevelUp() Misc.dialog("Celebrate good times, come on!") -- Opens a dialog box whenever the player levels up. end
[========]
stats.GainXP()
- Grants the player experience points. If their EXP total reaches, stat.level * 5 + stat.level
it will call stats.LevelUp(1)
. stat.xp will then be subtracted by stat.level * 5 + stat.level
. This is applied multiple times until the player does not have enough experience to level up again.
Example usage:
function onDraw() stats.GainXP(1) - Grants 1 experience point every frame end
[========]
stats.heal(x)
- Restores the player's HP by X. Will not restore more HP than the player has. If X is zero, fully restores their HP.
Example usage:
function onJump() stats.heal(1) -- Restores 1 HP whenever you do a big jump end function onNPCKill() stats.heal(0) -- Fully restores HP every time an NPC is killed end
All stat variables are stored as save data. Note that stats
is used for functions while stat
is used for variables.
stat.pow
- The player's POW stat. POW does not do anything by itself. Instead meant to be used in tandem with other scripts.
stat.def
- The player's DEF stat. Enemy damage is subtracted by this. However, it does not naturally increment upon leveling up.
stat.maxhp
- The player's max HP. Automatically increments upon leveling up.
stat.alwaysBig
- A configuration option that defaults to true. Prevents you from entering a small state after taking damage. Is a functional component of the damage system, and is recommended to be left as true.
The following variables are public but should not be altered directly. Instead, they are meant to be displayed via textplus.
stat.level
- The player's level. Please do not attempt to manipulate this directly, as LevelUp()
increases the player's POW and max HP along with triggering onLevelUp()
.
stat.xp
- The player's experience. Please use GainXP()
instead of manipulating it directly, as doing so will not trigger level ups.
stat.hp
- The player's current HP. Manipulating it directly does not respect stats.maxhp
, so you should use stats.heal()
instead.
There are a few more variables meant as configuration options:
stats.criticalHP
- Point from where your HP is considered critically low. Meant to be used with other scripts.
stats.HPgrowth
- The HP increase for each levelup. Defaults to 5.
stats.POWgrowth
- The POW increase for each levelup. Defaults to 1.
stats.DEFgrowth
- The DEF increase for each levelup. Defaults to 0.
stats.baseHP
- Base HP. Added onto by HP growth. Defaults to 5.
stats.alwaysBig
- Prevents the player from entering a small state after taking damage. Defaults to true. It is a functional component of the damage system, and is recommended to be left as true.