[Library] Stats.lua - A basic RPG mechanics script

Share and discuss custom LunaLua code and content packs for SMBX2.
ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

[Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Mon Mar 14, 2022 4:23 am

Stats.lua is a freely-reusable EXP, leveling and HP implementation for SMBX2, intended for RPG-styled episodes. While I originally made it for a project I am working on, I thought I might as well publicize it.

Features:
  • Limited HP system replacing Small Mario, keeping the player big until they run out of HP
  • NPCs are registered manually on a per-script basis, allowing you to set different stats per level
  • Leveling and experience system - level up every time the player earns a specific amount of experience points
  • Functions to manipulate HP and EXP outside of standard enemy stuff
  • Contains a handful of configuration options
  • Excessively over-commented
GIFs: show
Note that the HUD is NOT part of the library. However, the code that makes it is on the Gist.
Image
Image
Download at https://gist.github.com/ShadowXeldron/5 ... bf1dd020c2. Documentation is also included.

ditditdit
Dolphin
Dolphin
Posts: 92
Joined: Sun Jan 02, 2022 4:25 pm
Flair: e
Pronouns: she/they
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ditditdit » Fri Mar 25, 2022 6:40 pm

what about power ups??

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Sat Mar 26, 2022 4:12 am

ditditdit wrote:
Fri Mar 25, 2022 6:40 pm
what about power ups??
Power-ups function as usual, it's just you can't become Small Mario so the only way for an enemy to kill you is if your HP runs out.

Cloud Devil
Cheep-Cheep
Cheep-Cheep
Posts: 13
Joined: Sun Nov 07, 2021 8:17 am
Pronouns: he/him

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby Cloud Devil » Sat Mar 26, 2022 5:50 am

Does this work on all characters or it only works on Mario?

Mal8rk
Snifit
Snifit
Posts: 200
Joined: Mon Oct 25, 2021 11:04 pm
Flair: English Speaking Spanish Speaker
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby Mal8rk » Sat Mar 26, 2022 11:19 am

this is very cool! but I think xp should get harder and harder to collect as your level progresses, just like in an actual rpg

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Sat Mar 26, 2022 3:47 pm

Cloud Devil wrote:
Sat Mar 26, 2022 5:50 am
Does this work on all characters or it only works on Mario?
The EXP system works for everyone, while the HP system works for all characters except Mega Man, Bowser, Ninja Bomberman and Samus.
POPME wrote:
Sat Mar 26, 2022 11:19 am
this is very cool! but I think xp should get harder and harder to collect as your level progresses, just like in an actual rpg
The amount of EXP needed to level up via GainXP() increases by the formula (stat.level * 5 + stat.level).

DrMekar
Eerie
Eerie
Posts: 779
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby DrMekar » Sat Mar 26, 2022 6:22 pm

This looks amazing, however I can't get it to work. Not sure if I'm just really rusty with Lua right now, but just loading Stats just throws an Error when touching an enemy and using the sample does nothing for me.

I'm also not sure how to fill it out, since the description has the line filled out:
function stats.registerNPC(NPCID, pow, def, xpdrop)

However in the Code, there are this things:
enemyPOW[NPCID] = pow
enemyDEF[NPCID] = def
xpDrops[NPCID] = xpdrop

Do I copy that for every NPC or can I put multiple IDs in there, if the Stat is the same. Here's an Example of what I was trying to do:
enemyPOW[1, 6] = 1
enemyPOW[261] = 3
enemyDEF[1, 6, 261 = 0
xpDrops[1, 6] = 1
xpDrops[261] = 3

I apperiate some help here, since I'd really like to use this for an Episode.

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Sun Mar 27, 2022 9:17 am

DrMekar wrote:
Sat Mar 26, 2022 6:22 pm
This looks amazing, however I can't get it to work. Not sure if I'm just really rusty with Lua right now, but just loading Stats just throws an Error when touching an enemy and using the sample does nothing for me.

I'm also not sure how to fill it out, since the description has the line filled out:
function stats.registerNPC(NPCID, pow, def, xpdrop)

However in the Code, there are this things:
enemyPOW[NPCID] = pow
enemyDEF[NPCID] = def
xpDrops[NPCID] = xpdrop

Do I copy that for every NPC or can I put multiple IDs in there, if the Stat is the same. Here's an Example of what I was trying to do:
enemyPOW[1, 6] = 1
enemyPOW[261] = 3
enemyDEF[1, 6, 261 = 0
xpDrops[1, 6] = 1
xpDrops[261] = 3

I apperiate some help here, since I'd really like to use this for an Episode.
The reason the stats are giving you an error for every NPC is because you haven't registered them.

You use stats.registerNPC(NPCID, pow, def, xpdrop) for every NPC you want to add. For example, if you wanted the SMB3 Goomba to have 1 HP, 1 POW, 0 DEF and award one experience point, you would use stats.registerNPC(1, 1, 0, 1) in your luna.lua file. So, for what you're trying to do, I'd use this code:

Code: Select all

stats.registerNPC(1, 1, 0, 1)
stats.registerNPC(6, 1, 0, 1)
stats.registerNPC(261, 3, 0, 3)
I also wouldn't recommend editing Stats.lua directly. It's designed in a way that requires using stats.registerNPC.

DrMekar
Eerie
Eerie
Posts: 779
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby DrMekar » Sun Mar 27, 2022 9:29 am

Dragon0307 wrote:
Sun Mar 27, 2022 9:17 am
DrMekar wrote:
Sat Mar 26, 2022 6:22 pm
This looks amazing, however I can't get it to work. Not sure if I'm just really rusty with Lua right now, but just loading Stats just throws an Error when touching an enemy and using the sample does nothing for me.

I'm also not sure how to fill it out, since the description has the line filled out:
function stats.registerNPC(NPCID, pow, def, xpdrop)

However in the Code, there are this things:
enemyPOW[NPCID] = pow
enemyDEF[NPCID] = def
xpDrops[NPCID] = xpdrop

Do I copy that for every NPC or can I put multiple IDs in there, if the Stat is the same. Here's an Example of what I was trying to do:
enemyPOW[1, 6] = 1
enemyPOW[261] = 3
enemyDEF[1, 6, 261 = 0
xpDrops[1, 6] = 1
xpDrops[261] = 3

I apperiate some help here, since I'd really like to use this for an Episode.
The reason the stats are giving you an error for every NPC is because you haven't registered them.

You use stats.registerNPC(NPCID, pow, def, xpdrop) for every NPC you want to add. For example, if you wanted the SMB3 Goomba to have 1 HP, 1 POW, 0 DEF and award one experience point, you would use stats.registerNPC(1, 1, 0, 1) in your luna.lua file. So, for what you're trying to do, I'd use this code:

Code: Select all

stats.registerNPC(1, 1, 0, 1)
stats.registerNPC(6, 1, 0, 1)
stats.registerNPC(261, 3, 0, 3)
I also wouldn't recommend editing Stats.lua directly. It's designed in a way that requires using stats.registerNPC.
About that Last Part, am I suppose to make multiple Lua Files? I thought that I just enter everything in Stats.Lua, since it's the only Lua File in the Download.

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Sun Mar 27, 2022 2:18 pm

DrMekar wrote:
Sun Mar 27, 2022 9:29 am
Dragon0307 wrote:
Sun Mar 27, 2022 9:17 am
DrMekar wrote:
Sat Mar 26, 2022 6:22 pm
This looks amazing, however I can't get it to work. Not sure if I'm just really rusty with Lua right now, but just loading Stats just throws an Error when touching an enemy and using the sample does nothing for me.

I'm also not sure how to fill it out, since the description has the line filled out:
function stats.registerNPC(NPCID, pow, def, xpdrop)

However in the Code, there are this things:
enemyPOW[NPCID] = pow
enemyDEF[NPCID] = def
xpDrops[NPCID] = xpdrop

Do I copy that for every NPC or can I put multiple IDs in there, if the Stat is the same. Here's an Example of what I was trying to do:
enemyPOW[1, 6] = 1
enemyPOW[261] = 3
enemyDEF[1, 6, 261 = 0
xpDrops[1, 6] = 1
xpDrops[261] = 3

I apperiate some help here, since I'd really like to use this for an Episode.
The reason the stats are giving you an error for every NPC is because you haven't registered them.

You use stats.registerNPC(NPCID, pow, def, xpdrop) for every NPC you want to add. For example, if you wanted the SMB3 Goomba to have 1 HP, 1 POW, 0 DEF and award one experience point, you would use stats.registerNPC(1, 1, 0, 1) in your luna.lua file. So, for what you're trying to do, I'd use this code:

Code: Select all

stats.registerNPC(1, 1, 0, 1)
stats.registerNPC(6, 1, 0, 1)
stats.registerNPC(261, 3, 0, 3)
I also wouldn't recommend editing Stats.lua directly. It's designed in a way that requires using stats.registerNPC.
About that Last Part, am I suppose to make multiple Lua Files? I thought that I just enter everything in Stats.Lua, since it's the only Lua File in the Download.
You don't need more than just Stats.lua and luna.lua. You just need to put the stats.require() stuff in your luna.lua.

DrMekar
Eerie
Eerie
Posts: 779
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby DrMekar » Sun Mar 27, 2022 3:31 pm

Dragon0307 wrote:
Sun Mar 27, 2022 2:18 pm
DrMekar wrote:
Sun Mar 27, 2022 9:29 am
Dragon0307 wrote:
Sun Mar 27, 2022 9:17 am

The reason the stats are giving you an error for every NPC is because you haven't registered them.

You use stats.registerNPC(NPCID, pow, def, xpdrop) for every NPC you want to add. For example, if you wanted the SMB3 Goomba to have 1 HP, 1 POW, 0 DEF and award one experience point, you would use stats.registerNPC(1, 1, 0, 1) in your luna.lua file. So, for what you're trying to do, I'd use this code:

Code: Select all

stats.registerNPC(1, 1, 0, 1)
stats.registerNPC(6, 1, 0, 1)
stats.registerNPC(261, 3, 0, 3)
I also wouldn't recommend editing Stats.lua directly. It's designed in a way that requires using stats.registerNPC.
About that Last Part, am I suppose to make multiple Lua Files? I thought that I just enter everything in Stats.Lua, since it's the only Lua File in the Download.
You don't need more than just Stats.lua and luna.lua. You just need to put the stats.require() stuff in your luna.lua.
Ah, now it's clear. Thanks alot. Just one more question, do I need to define XP Drop for everything, even things like a Hammer that can't be defeated?

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Sun Mar 27, 2022 5:22 pm

DrMekar wrote:
Sun Mar 27, 2022 3:31 pm
Dragon0307 wrote:
Sun Mar 27, 2022 2:18 pm
DrMekar wrote:
Sun Mar 27, 2022 9:29 am


About that Last Part, am I suppose to make multiple Lua Files? I thought that I just enter everything in Stats.Lua, since it's the only Lua File in the Download.
You don't need more than just Stats.lua and luna.lua. You just need to put the stats.require() stuff in your luna.lua.
Ah, now it's clear. Thanks alot. Just one more question, do I need to define XP Drop for everything, even things like a Hammer that can't be defeated?
I haven't personally tried it yet, but for things that can't be defeated you can simply define the EXP drop as zero.

DrMekar
Eerie
Eerie
Posts: 779
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby DrMekar » Mon Mar 28, 2022 2:11 pm

Alright. I did another Question though, which would be how I combine that with LightHitPoint.Lua. I always found that nice, but
didn't want to include, since it's kinda 'unfair' to only allow the Enemies to have HP Bars.

Also I would like the Player to heal, when consuming specific Powerups. I saw the Heal Function, but I'm unsure how to use it.

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Fri Apr 01, 2022 6:48 am

DrMekar wrote:
Mon Mar 28, 2022 2:11 pm
Alright. I did another Question though, which would be how I combine that with LightHitPoint.Lua. I always found that nice, but
didn't want to include, since it's kinda 'unfair' to only allow the Enemies to have HP Bars.

Also I would like the Player to heal, when consuming specific Powerups. I saw the Heal Function, but I'm unsure how to use it.
Sorry for the late reply (since I can't get SMBX2 working on any of my devices right now for some reason; probably a Wine update broke it), but I'm actually using LightHitPoint in my project as well. You can just assign the LightHitPoint values normally, and doing. However, I am changing the amount of damage the player can do every frame since it's the only way I could think of getting damage output to scale with the player's level before I implemented onLevelUp:
--HARM TYPES
local function onDraw()
lhp.setHarmtypeDamage(HARM_TYPE_JUMP, stat.level * 0.75) -- When Mario jumps on an enemy
lhp.setHarmtypeDamage(HARM_TYPE_FROMBELOW, stat.level * 3) -- When Mario hits a block, damaging enemies on it.
lhp.setHarmtypeDamage(HARM_TYPE_TAIL, stat.level * 1.5) -- When Mario uses a Tanooki spin.
lhp.setHarmtypeDamage(HARM_TYPE_SPINJUMP, stat.level * 1) -- When Mario spin jumps.
lhp.setHarmtypeDamage(HARM_TYPE_SWORD, stat.level * 0.75) -- When Link stabs someone.

--NPC HARM DAMAGE

lhp.setNPCDamage(13, stat.level * 1.25) --Fireballs
lhp.setNPCDamage(171, stat.level * 3) --Player Hammers
end


This is the exact code I'm using for the damage values in my episode. Feel free to change those values if you want.

A plan for later versions is to add integration with LightHitPoint so that you can assign everything in a single line, as well as finding some use for the currently unused defence stat.

I haven't been able to test it yet due to the aforementioned issues with accessing SMBX2, but this script should heal you by 5 HP whenever you grab an SMB3 Super Mushroom. Feel free to repurpose it for other items.

Code: Select all

function onNPCKill(t,k,h) -- t = Event Token, k = Killed NPC, h = Harm Type
    if h == HARM_TYPE_VANISH and k.id == 9
        stats.heal(5)
    end
end

DrMekar
Eerie
Eerie
Posts: 779
Joined: Sat Apr 08, 2017 7:16 am
Flair: CUSTOM CHARACTER CREATOR
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby DrMekar » Tue Apr 05, 2022 3:47 pm

Dragon0307 wrote:
Fri Apr 01, 2022 6:48 am
DrMekar wrote:
Mon Mar 28, 2022 2:11 pm
Alright. I did another Question though, which would be how I combine that with LightHitPoint.Lua. I always found that nice, but
didn't want to include, since it's kinda 'unfair' to only allow the Enemies to have HP Bars.

Also I would like the Player to heal, when consuming specific Powerups. I saw the Heal Function, but I'm unsure how to use it.
Sorry for the late reply (since I can't get SMBX2 working on any of my devices right now for some reason; probably a Wine update broke it), but I'm actually using LightHitPoint in my project as well. You can just assign the LightHitPoint values normally, and doing. However, I am changing the amount of damage the player can do every frame since it's the only way I could think of getting damage output to scale with the player's level before I implemented onLevelUp:
--HARM TYPES
local function onDraw()
lhp.setHarmtypeDamage(HARM_TYPE_JUMP, stat.level * 0.75) -- When Mario jumps on an enemy
lhp.setHarmtypeDamage(HARM_TYPE_FROMBELOW, stat.level * 3) -- When Mario hits a block, damaging enemies on it.
lhp.setHarmtypeDamage(HARM_TYPE_TAIL, stat.level * 1.5) -- When Mario uses a Tanooki spin.
lhp.setHarmtypeDamage(HARM_TYPE_SPINJUMP, stat.level * 1) -- When Mario spin jumps.
lhp.setHarmtypeDamage(HARM_TYPE_SWORD, stat.level * 0.75) -- When Link stabs someone.

--NPC HARM DAMAGE

lhp.setNPCDamage(13, stat.level * 1.25) --Fireballs
lhp.setNPCDamage(171, stat.level * 3) --Player Hammers
end


This is the exact code I'm using for the damage values in my episode. Feel free to change those values if you want.

A plan for later versions is to add integration with LightHitPoint so that you can assign everything in a single line, as well as finding some use for the currently unused defence stat.

I haven't been able to test it yet due to the aforementioned issues with accessing SMBX2, but this script should heal you by 5 HP whenever you grab an SMB3 Super Mushroom. Feel free to repurpose it for other items.

Code: Select all

function onNPCKill(t,k,h) -- t = Event Token, k = Killed NPC, h = Harm Type
    if h == HARM_TYPE_VANISH and k.id == 9
        stats.heal(5)
    end
end
Thanks for Insight and sorry for the also late reply. I see if I can get it to work, after finishing my Custom Boss NPC I'm working on.

Wrath666
Cheep-Cheep
Cheep-Cheep
Posts: 13
Joined: Thu Dec 23, 2021 3:06 pm
Flair: Anger & Hatred
Pronouns: he/him

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby Wrath666 » Sat Apr 09, 2022 2:18 am

Would it be possible to recreate Zelda 2's leveling system with this? And if not, could you add those features?

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Sat Apr 09, 2022 3:25 am

Wrath666 wrote:
Sat Apr 09, 2022 2:18 am
Would it be possible to recreate Zelda 2's leveling system with this? And if not, could you add those features?
Theoretically, although I have no intention of doing so. You are welcome to use the script as a base to make it however.

RadMetalMarioSMIX
Bit
Bit
Posts: 65
Joined: Sat Mar 14, 2015 6:42 pm
Flair: What kind of grave is this?
Pronouns: he/him

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby RadMetalMarioSMIX » Fri May 20, 2022 12:56 pm

Is there a way to apply an hp bar to this and make the experience the score?

P.S. This would be great for Paper Mario and Mario & Luigi Episodes.

ShadowXeldron
Snifit
Snifit
Posts: 232
Joined: Sun Dec 08, 2019 8:21 am
Flair: phpBB > ProBoards
Pronouns: He/Him
Contact:

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby ShadowXeldron » Fri May 20, 2022 6:31 pm

RadMetalMarioSMIX wrote:
Fri May 20, 2022 12:56 pm
Is there a way to apply an hp bar to this and make the experience the score?

P.S. This would be great for Paper Mario and Mario & Luigi Episodes.
Not sure how to implemet a HP bar but it's definitely possible. I'm not sure about making EXP score though, and SMBX has a pretty limited scoring system where you can only select preset values unlike this script where you can specify an EXP drop on a per-NPC basis. You're welcome to try and rework it to use score if you really want though.

RadMetalMarioSMIX
Bit
Bit
Posts: 65
Joined: Sat Mar 14, 2015 6:42 pm
Flair: What kind of grave is this?
Pronouns: he/him

Re: [Library] Stats.lua - A basic RPG mechanics script

Postby RadMetalMarioSMIX » Mon May 23, 2022 2:55 pm

For registering NPCs do I put it in the global and/or level Luna.lua file?
Would that also apply to healing Items?

P.S. Is there anything this isn’t compatible with?


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari