Page 1 of 1

customHealth.lua [v1.2] - New CHS with less features

Posted: Wed Apr 12, 2023 12:24 am
by Marioman2007
Title says it all, this is for those who just need a custom health system.
It has better code than CHS but less features. I felt like CHS was bulky so I did a little recode.

GIF:
Spoiler: show
Image

Credits:
- Me
- LxXzit
- FieryExplosion
- Mageker

Loading
Loading is done like any other library.

Code: Select all

local health = require("customHealth")

Changelog:
v1.0 - First release
v1.1 - Now you can store mushrooms in the reserve box and specify a default powerup.
v1.2 - Added health.onPostPlayerHurt, health bar now hides with the vanilla hud, setting hudoverride.visible.itemBox now works, and some fixes related to powerup and hp setting.

Download:
https://drive.google.com/file/d/1-r5__2 ... sp=sharing

Give credits if used! Enjoy!

Re: customHealth.lua [v1] - New CHS with less features

Posted: Wed May 24, 2023 11:42 pm
by Mal8rk
Is there a way to have custom hurt sheets for other characters aside from Mario, Luigi, Peach, or Toad?

Re: customHealth.lua [v1] - New CHS with less features

Posted: Thu May 25, 2023 2:44 am
by Marioman2007
Mal8rk wrote:
Wed May 24, 2023 11:42 pm
Is there a way to have custom hurt sheets for other characters aside from Mario, Luigi, Peach, or Toad?

Code: Select all

health.VFX.hurt[CHARACTER_#] = Graphics.loadImageResolved(path)

CHARACTER_# must be a character constant: https://docs.codehaus.moe/#/constants/characters
path must be a string, for example - "customHealth/hurtWario.png"

Re: customHealth.lua [v1] - New CHS with less features

Posted: Fri Jun 02, 2023 2:57 am
by Thundaga_T2
Is it possible to have either this one, or the original be compatible with MDA's Sonic Monitors? Specifically having the bubble shield give infinite air while its active?

Re: customHealth.lua [v1.1] - New CHS with less features

Posted: Wed Feb 07, 2024 2:22 am
by Marioman2007
Version 1.1 released!
Changelog in the main post

Thundaga_T2 wrote:
Fri Jun 02, 2023 2:57 am
Is it possible to have either this one, or the original be compatible with MDA's Sonic Monitors? Specifically having the bubble shield give infinite air while its active?

You can use this code (after loading customhealth):

Code: Select all

local monitor = require("monitor_ai")

function health.onPlayerHurt(event, p)
    if monitor.getPlayerData(p).currentShield then
        event.cancelled = true
    end
end

Re: customHealth.lua [v1.1] - New CHS with less features

Posted: Sun Feb 11, 2024 7:42 pm
by RotisserieSalad
would it be possible to only have this code active in one section? i want to use it for a boss at the end of a castle but i don't want to use the health system for the entire castle
if it's not possible that's ok!

Re: customHealth.lua [v1.1] - New CHS with less features

Posted: Mon Feb 19, 2024 2:59 am
by Jumper
Is it at all possible to set a custom main and max health outside the default 3 main, 6 max?

Like if someone wanted to change it to be 5 for main, and 10 for max?

Re: customHealth.lua [v1.1] - New CHS with less features

Posted: Mon Feb 19, 2024 6:22 am
by Marioman2007
Jumper wrote:
Mon Feb 19, 2024 2:59 am
Is it at all possible to set a custom main and max health outside the default 3 main, 6 max?

Like if someone wanted to change it to be 5 for main, and 10 for max?

you can use this code to do that:

Code: Select all

local health = require("customHealth")
health.settings.mainHealth = 5
health.settings.maxHealth = 10
health.curHealth = health.settings.mainHealth
Note that you will need to change the health bar sprites too.
Here's the layout to do that.

Code: Select all

Frame 1  - 0 health
Frame 2  - 1 health
Frame 3  - 2 health
Frame 4  - 3 health
Frame 5  - 4 health
Frame 6  - 5 health
Frame 7  - No health (used in the counting up animation)
Frame 8  - 6 health
Frame 9  - 7 health
Frame 10 - 8 health
Frame 11 - 9 health
Frame 12 - 10 health
Frame 13 - Daredevil health

Re: customHealth.lua [v1.1] - New CHS with less features

Posted: Mon Feb 19, 2024 7:38 am
by Jumper
Marioman2007 wrote:
Mon Feb 19, 2024 6:22 am
Jumper wrote:
Mon Feb 19, 2024 2:59 am
Is it at all possible to set a custom main and max health outside the default 3 main, 6 max?

Like if someone wanted to change it to be 5 for main, and 10 for max?

you can use this code to do that:

Code: Select all

local health = require("customHealth")
health.settings.mainHealth = 5
health.settings.maxHealth = 10
health.curHealth = health.settings.mainHealth
Note that you will need to change the health bar sprites too.
Here's the layout to do that.

Code: Select all

Frame 1  - 0 health
Frame 2  - 1 health
Frame 3  - 2 health
Frame 4  - 3 health
Frame 5  - 4 health
Frame 6  - 5 health
Frame 7  - No health (used in the counting up animation)
Frame 8  - 6 health
Frame 9  - 7 health
Frame 10 - 8 health
Frame 11 - 9 health
Frame 12 - 10 health
Frame 13 - Daredevil health
TYVM, man.

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Sat Apr 13, 2024 3:47 am
by Marioman2007
Version 1.2 is here

More bug fixes, changelog in the main post.

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Thu May 16, 2024 12:48 am
by Jaximus_The_Great
I was testing this out, it worked great, but I'm not proficient in lua code, so I can't figure out how to make the life mushroom work.

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Sat May 18, 2024 10:47 am
by Just_Thomas
Hello,
first of all: Thanks for your work.

But let's get straight down to business (joke):
I think (!!) this might be bug with the fire flower here.
Collecting the item gives health but does not increase the health bar.
So either I guess the health increase is not supposed to happen or the display does bug around. I guess it is the first one.
Image

I hope I haven't overlooked anything here...

Edit: But that has nothing to do with the mushroom in the reserve box (after collecting the flower), does it? After all, it is not “activated”. Would be strange, if it does count as "extra health".
Image
Image

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Wed May 29, 2024 8:46 pm
by PizzaNoob
Is there any way to "hide" the bar when cutscenePal is active?

Edit: I actually found out my self LOL

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Wed Sep 18, 2024 7:18 pm
by FutureNyanCat
I reported that this script causes issues with the Defines.levelFreeze define, which will make it not pause the entire level anymore, because its value was always set via the onTick function in the script.

Consequentially it also prevents the basegame green P-Switch and SMB2 clocks from working properly.

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Sun Jan 26, 2025 5:49 pm
by PizzaNoob
Hey I found a bug with respawnRooms and customHealth.
Basically, when the player dies, they keep dying on and on.
From my understanding, whenever the bar is at 0, it kills the player no matter what. Is there a way in which I can reset the player's bar after a quick death?

Image

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Sat Feb 01, 2025 10:58 am
by Marioman2007
PizzaNoob wrote:
Sun Jan 26, 2025 5:49 pm
Hey I found a bug with respawnRooms and customHealth.
Basically, when the player dies, they keep dying on and on.
From my understanding, whenever the bar is at 0, it kills the player no matter what. Is there a way in which I can reset the player's bar after a quick death?

Image

Do you have v1.2? Because it works fine for me.

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Sat Feb 01, 2025 1:14 pm
by PizzaNoob
Marioman2007 wrote:
Sat Feb 01, 2025 10:58 am
PizzaNoob wrote:
Sun Jan 26, 2025 5:49 pm
Hey I found a bug with respawnRooms and customHealth.
Basically, when the player dies, they keep dying on and on.
From my understanding, whenever the bar is at 0, it kills the player no matter what. Is there a way in which I can reset the player's bar after a quick death?

Image

Do you have v1.2? Because it works fine for me.
Yeah. Turns out I just had to change "local respawnRooms
pcall(function() respawnRooms = require("respawnRooms") end)"
to "local respawnRooms
pcall(function() respawnRooms = require("Scripts/respawnRooms") end)".
I have all scripts in a seperate file.

Re: customHealth.lua [v1.2] - New CHS with less features

Posted: Tue Feb 18, 2025 7:33 pm
by AlphaBlue1011
Came up with a way to make the health never go up past 2 without changing the main and max health values:
function onStart()
health.curHealth = 2
end

function onTick()
if health.curHealth >= 3 then
health.curHealth = 2
end
end
this could be useful in two-hit challenges. Also, just setting the main or max health to 2 or anything else seems to mess up how the health is rendered without making changes to the sprites. this is just a lazy way to make it display properly in a situation like this.