PixelPest wrote:
Right. Sorry. So Mudkip, do:
Code: Select all
if player.character == 5 and player.powerup == 6 then
--health bar script
end
What no
How is
how is what you're doing even remotely helpful.
He's asking how he should tackle a healthbar script and how to force the character to state 6 at all times.
While I won't write the code for you (mudkip), because it's important that you work this out for yourself, I'm gonna (unlike other people *nudge*) provide some sources and tips on what to do and how to tackle this.
-Setting the player to link and initially setting him to state 6 is no issue. Use function onStart() and player.powerup, as well as player.character, which you can find here:
http://wohlsoft.ru/pgewiki/Player_%28class%29
You might want to build in a check though for the latter.
-Setting the player powerup to 6 might be a bit tricky. If the player powerup was 1 before, link will start clipping through the ground. There are a few workarounds, but the safest is probably breifly setting the powerup state to 2 before setting it to 6.
-To impliment your own health bar you want to create a variable in the data class:
http://wohlsoft.ru/pgewiki/Data_%28class%29
The data class is a class which you can use to save variables between levels. Pyro made a tutorial on it, too:
https://www.youtube.com/watch?v=dnTH_cBYZhs
By using it you can make a variable which will store the player's current HP. Once it reaches 0 you kill the player (once).
-The normal way how smbx handles health might sound to be obsolete, however you can still use it to detect changes to the player's hp.
http://wohlsoft.ru/pgewiki/SMBX_Player_Offsets
Offset 0x16 stores the number of hearts. Ideally you want this to be 2 at all times, breifly falling back to 1 when hit and going to 3 when getting a powerup for a frame or two. During that time you catch the difference and adjust your data class variable (and the player powerup if needed).
For a first-hand look on a health bar script like this, take a look at hudOfTime.lua. It does what I described here. Make sure to not copy the code though without having understood what it does, since else you might end up puzzled in a few weeks when something breaks somehow.