Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Help with HP/SP stuff

I couldn't think of a better title, but I can explain really well.  :lol: I am working on an auto-recover on map, and I can't figure out how to check HP, SP, and MaxHP/SP within the script. I've tried @hp and @maxhp, but that's no good because it doesn't define an actor. Right now my if command to check if the HP is lower than MaxHP looks like this:
Code:
    if UPDATE_HP
      if @hp < @maxhp then

Which is no good because the if statement gives me errors. So I need help trying to get the the if fixed as well. it tells me '<' isn't right...

I am running the script in Scene_Map, but I don't know how to make it run in the background. Is it something to do with the definition or what? Help please... This is my first script from scratch so I'm a little confused.

Thanks in advance for the help.

EDIT: I know its in the wrong section...reported for a move.
 
I'm not 100% sure of this, so I'll update when I am, but I believe it should look like

UPDATE: got it working proper now
Code:
if UPDATE_HP
  if $game_party.actors[1].hp < $game_party.actors[1].maxhp
    do something
  end
end
that would do it

and just for fun, if you want to do it for all the actors separately, you could change it to this:
Code:
if UPDATE_HP
  for i in 1..$game_party.actors.size
    if $game_party.actors[i].hp < $game_party.actors[i].maxhp
      do something
    end
  end
end
 
Make sure that you don't run that regenerate scipt before the map is completely initialized. If you run it straight away, there's gonna be a problem because $game_party only initializes later

EDIT: A way to get around that would be
Code:
if UPDATE_HP
  unless $game_party == nil
    for i in 1..$game_party.actors.size
      if $game_party.actors[i].hp < $game_party.actors[i].maxhp
        do stuff
      end
    end
  end
end
 
Where exactly do you run the method? Because if you run it in scene_map, it won't continue running in Scene_Menu unless you put special circumstances in place. If it's used in an event, the same thing goes.
To test it, instead of going to menu change the script so that, under the stuff that's meant to be done it says p "something"
so it'd be
Code:
if $game_party.actors[i].hp < $game_party.actors[i].maxhp
  do stuff
  p "something"
end

It'll be annoying as hell, but it will tell you whether or not the code gets executed properly, and once you find out whether it does, it'll be easier to find out any problems you may have
 
In VX, they changed $game_party.actors to $game_party.members.  In XP, Game_Party actually held the actor data in the @actors variable, but VX changed it to just store the actor ids in @actors.  Then they made the method members to return an array of Game_Actors.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top