Quote:
Originally Posted by chandie
Is there a practical way of putting a health bar and an automatic EOL event when his energy is 0?
|
Hi! Awesome that you're learning JJ2+ scripting. The scripting documentation describes several entities that should help you.
A boss health bar is drawn for players if their
bossActivated is true and
boss refers to an object by its
ID. There's also an accompanying
activateBoss method, or you could use the traditional Activate Boss event. See especially the documentation for
boss, as it describes how the health bar's size is determined.
Most JJ2 boss behaviors work the following way: the boss starts out inactive and its behavior has a loop over all players that checks if any
active player's
bossActivated is true. If it is, the boss changes its
state to something else, indicating that it's now active. Then, whenever the boss is active, it runs a loop that sets all players'
boss to itself. This results in the health bar being drawn.
When the boss is defeated and its
energy is 0, the game doesn't despawn it, and instead (much like you, it seems) uses its behavior as a countdown to end the level. First, when the
counter is 0, it might display some message much like
showText. Then it waits between 4 and 6.5 seconds before it proceeds to the next level, depending on whether the player is firing bullets, for some weird reason (maybe under the assumption that if they're firing, they're getting impatient? Either way it's currently a speedrun strat to keep shooting after defeating a boss). Your magic number of 2300 seems pretty big as, at 70 ticks per second, that corresponds to over half a minute. Your strategy of spawning an EOL event seems valid, but it's generally a better idea to call
jjNxt with default parameters.
To sum up the order of events in a typical boss fight:
- The boss is inactive.
- The player touches an Activate Boss event. This sets their bossActivated to true.
- The dormant boss detects that there's a player with an active boss fight so it wakes up.
- The boss sets all players' boss property to itself. This lets the health bar know what size it should have.
- Players defeat the boss. The boss behavior may display a text message.
- After a few seconds, the boss behavior ends the current level.