Checking HP Globally at all times

● ARCHIVED · READ-ONLY
Started by coldReactive 20 posts View original ↗
  1. Hi, I'm making a game that cannot have gameovers, so I have to have an event that is constantly checking if the player has 0 or less than 0 HP. If they do, it runs a common event to respawn the player without loss of any data, etc. Is it possible to do this without relying on third-party scripts? Because I currently have a Common Event that is checking if 0001:HP is less than or equal to 0 (This variable is set to actor 1's Current HP Pool) but because the trigger has to be none (Since adding a switch trigger to the event on the spawn area that is always active, causes the player not to be able to move) it can't keep checking forever.

    It has to be a global event because the map has to tell that global event what map you died in, etc.

    I have a loop set up on a map right now, and it still isn't working:

    Code:
    @> Loop    @>Conditional Branch: Variable [0001:HP] <= 0        @>Call Common Event: [DeathCheck]        @>    : Else        @>    : Branch End    @>: Repeat Above@>
  2. Sounds like you have a few issues.

    If adding a trigger means the player can't move, that means you've got the event set to Autorun. Autorun MEANS the player can't move. You should change it to Parallel Process. Even in a parallel process, if you've got a loop inside and you want it to be constantly running, you should add a Wait 10 Frames (or some number) because you don't need to check for this condition the default 60 times a second (that could also affect performance, though it is probably NOT why your character can't move).

    However, by the time your event even triggers, HP is already <= 0, and the death processing has happened. You don't get a chance, in events and common events, to tell it to do something else.

    Also, are you constantly updating variable 1 to contain the player's HP? You can't just say Control Variables [1] = Player's HP at the start of the game and expect it to ALWAYS stay up to date - if the player's HP is 10 when you run the Control Variables command, then variable 1 will always contain 10, even if the player has levelled up and gone up to 1000HP since. You would need to do Control Variables [1] = Player's HP immediately before the Conditional Branch. Or you could just do it as a Conditional Branch: Script: $game_actor[1].hp <= 0 and ditch the variable altogether.

    How many actors are in your party? Do you want them ALL to ALWAYS have 1 HP or more? Or are you only concerned with at least ONE of them still being "alive"? If you have several actors and you always want them ALL to have HP, you will need to repeat the test for each actor, which then means you have to do a test to see if the actor is in the party.

    Also, by putting it in a common event, unless you have an added script, it's not going to run in battles.

    How many ways can the player die? In battle? On the map as a result of slip damage (poison)? Any other ways?

    I would just add a little script snippet that overrides the hp= method to not allow it to go below 1 for a party member. That means it's going to do the check exactly at the time HP changes and no other time, which is exactly what you want, to avoid testing/processing when nothing has changed. It also handles a party of any size, without having to check to see who's IN the party or how many are in the party.

    In a new script slot below all others (above Main), put this:

    Code:
    class Game_Actor < Game_Battler  def hp=(hp)    super([hp,1].max)  endend
  3. The game has no battles at all save for scripted ones, so it won't matter with that. I kind of figured autorun was having problems.

    The game is now giving me the error saying that undefined method `[]' for nil:NilClass when the DeathCheck runs checking $game_actor[1].hp <= 0
  4. I edited my post while you were posting. I would still go with the script snippet.


    How do they lose HP if your battles are all scripted (by scripted, I assume they're like cutscenes and the player doesn't actually choose actions)?
  5. you missed an s, that's why it's giving errors. It should be $game_actors not $game_actor
  6. Wouldn't that snippet of code max it so that no one can die though? I thought what they wanted to happen was they could lose the battle, but just respawn, which does require the HP to drop below 0.
  7. When all actor's HP hits zero, the game would then proceed to GO screen... to stop that needs a bit longer script...

    Using Shaz, script, we could add another line that turns on a switch, which in turn the common event can use as a condition for it to run, then the CE would turn it off afterwards...

    That way, we can achieve what he wants with minimal scripting.

    something like

    class Game_Actor < Game_Battler  def hp=(hp)    $game_switches[id]=true if hp < 1    super([hp,1].max)  endendAlso, based on the OP's statements, there's seems to be no actual battles at all

    The game has no battles at all save for scripted ones, so it won't matter with that
  8. Even if he has only scripted battles, does he want it so that the players *never* drop below 1 HP in a battle? If so, that takes away all challenge too, as a player could just bum rush every fight, and not care about being at 1 HP to start a fight, as the enemy will now do 0 damage (based on that max command). That's why I say I doubt they mean to not allow an actor to hit 0 HP.
  9. You don't get the idea of the snippet, it's not really to keep players alive.

    Once the HP should be below zero, the snippet I posted will turn on a switch. Then that switch will be used by his common event that should run when a player "dies". But, since the HP is zero, the event still won't run. Why? Because the game will process the GO screen. and that is why we set the HP back to 1, so that the game won't process the GO screen. That way, we ensure that his common event for respawning the player will run.

    if it's inside a battle, he will simply add an End battle processing event command to the common event to stop the battle (though he will need Tsukihime's script to make common events run in battle)

    Do you get it now?
  10. I don't think your snippet does that though. I see it turns on the switch, but then it also still sets the HP to 1 for the battle, as that line would still process as far as I can tell, and the battle would continue normally. Now he might be able to add a line to check that switch every round in every battle and see if it got flipped, but can that be done? I thought if they used a parallel process to check if that switch had triggered it would only trigger outside of battle, not during battle.
  11. See the bolded lines :)

    But, since the HP is zero, the event still won't run. Why? Because the game will process the GO screen. and that is why we set the HP back to 1, so that the game won't process the GO screen. That way, we ensure that his common event for respawning the player will run.

    if it's inside a battle, he will simply add an End battle processing event command to the common event to stop the battle (though he will need Tsukihime's script to make common events run in battle)
  12. Ok, that works. I was thinking he was using parallel processes, so didn't see any way for that to work at all until *after* the battle was over.
  13. If it's inside a battle he could just get Hime's script for making CE run on other scenes... Or he could just use troop events since he probably won't have lots of troops anyway. 

    On a side note, I think Hime or somebody else also has a script that allows you to run events when an actor (or was it the party) dies...
  14. Engr. Adiktuzmiko said:
    you missed an s, that's why it's giving errors. It should be $game_actors not $game_actor
    Now the game turns blank for some reason and no errors occur when the script is continuously run.
  15. The snippets of code are so he doesn't HAVE to run a parallel process.
  16. So how do I call these scripts? Or do they always run? If so, do I just check if hp is set to 1? Because just throwing a scriptlet at me isn't going to help. I need to know what it does, how to use it, where to use it (including non-battles) and how I should re-do my conditional statement:

    GOIC1Un.png

    It's going to have multiple areas (Possibly more than 25 different combinations) where I need to check where the person has died, and if they were inside a sub-map (IE: A Dungeon) and reference this when they respawn. Right now, this deathcheck event is causing the game to go black screen when it tries to check. It's using a parallel process that I started as soon as the player gained control. Once the parallel process turns on, the game just immediately stops functioning.

    ReviveDeath1 is a control switch that tells another event what to do after the player wakes up. That event takes the data from the end of each combination and shows text based on that after the player has awoken.
  17. if you use my edit, you would simply make the common event an autorun that uses whatever switch you pass into my snippet as the condition to run, then at the last part of your common event, make sure to set the switch to OFF.


    The purpose of the snippet is so that you could avoid using a parallel process CE.
  18. Engr. Adiktuzmiko said:
    if you use my edit, you would simply make the common event an autorun that uses whatever switch you pass into my snippet as the condition to run, then at the last part of your common event, make sure to set the switch to OFF.

    The purpose of the snippet is so that you could avoid using a parallel process CE.
    So I just put your script below everything but main, then I set the Script to autorun trigger when the Switch it on? Okay, done. Now the game still doesn't function when it occurs.

    Edit: For some reason, a control switch was causing the problem (It didn't before.)
  19. could you post your new common event?
  20. I had to set the control switch of an event at the bottom of its conditional branch, it was causing the game to freeze immediately when that control switch was changed. It didn't do it before when I had no HP Checking system in place though. But it's fine. Everything is fine, nothing is ruined now.