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.

regena state problem

hey

i dont know whats wrong with it..

Code:
class Game_Battler

HP_STATE = 18 # state id
MP_STATE = 19  # state id
HP_RATE = 50   # in percent
MP_RATE = 40   # in percent
  
def hp_mp_recovery
  for state_id in HP_STATE
      if state?(state_id) and @hp > 0
      @hp_regen = (self.maxhp / 100) * HP_RATE
      self.hp += @hp_regen
    end
  for state_id in MP_STATE  
      if state?(state_id) and @sp > 0
      @mp_regen = (self.maxsp / 100) * MP_RATE
      self.sp += @mp_regen
      end
    end
  end
end
end

it dont work.. no errors but no regenration when the state is applied.
anyone can tell me why?
its my first script...
 
Well, the regeneration method is there, but that's all. There nothing that calls the method. Are you sure the script is complete?

By the way, I've made a Regeneration script for VX a couple of weeks ago if you are interrested.
 
It depends where you want the battler to regenerate.
If you want an actor to regen on the map, it eould be something like $game_actors[actor_id].hp_mp_recovery

It will work with any battler object; @my_battler.hp_mp_recovery
 
Right now, it won't. Because the state check occures in the hp_mp_recovery method and this method is not used anywhere.

If you want it to work, you will have to modify a part of Scene_Battle. For example, if you want the party members to recover at every turns (party turns), you'll have to add a bit of code in the start_party_command_selection method in Scene_Battle.

I'd do something like
Code:
def start_party_command_selection
  for member in $game_party.members
    member.hp_mp_recovery
  end
# rest of the code here
end
This will cycle through all party actor and call the hp_mp_recovery method for all of them.


EDIT:
Also, there's an error in your code. There is no END for your if state?(state_id) and @hp > 0
You should also add a dead? check in either the recovery method or the member loop.
Adding HP to a dead battler will remove it's death state.
 
i tried it with aliasing but every time i get an error (scene_battle line 188) ..

HP_STATE = 18 # state id
MP_STATE = 19  # state id
HP_RATE = 50  # in percent
MP_RATE = 40  # in percent
#-------------------------------------------------------------------------------
class Scene_Battle
alias hp_mp_recovery start_party_command_selection
def start_party_command_selection
    for member in $game_party.members
    member.hp_mp_recovery
  end
#-------------------------------------------------------------------------------
#
#-------------------------------------------------------------------------------
class Game_Battler
  def hp_mp_recovery
  for state_id in HP_STATE
      if state?(state_id) and @hp > 0
      @hp_regen = (self.maxhp / 100) * HP_RATE
      self.hp += @hp_regen
    end
  for state_id in MP_STATE 
      if state?(state_id) and @sp > 0
      @mp_regen = (self.maxsp / 100) * MP_RATE
      self.sp += @mp_regen
      end
    end
  end
end
end

sorry for wasting your time :X
 
You're not wasting my time ;)

Ok, first of all, you did half of the aliasing.
You should do it like that:
Code:
class My_Class
  alias new_method_name original_method_name
  def original_method_name
    new_method_name
    # your new code here
  end
end
Second mistake, in Scene_Battle you forgot to add an end at the end of the method and the class.
Code:
# Begining of the class
class My_Class

  # Begining of the method
  def my_method

    # Begining of the loop
    for member in $game_party.members
 
    end # End of the loop

  end # End of the method

end # End of the class

And finally, you haven't fixed the misplaced end in Game_Battler.
Besides that, everything else seems fine.
 

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