Help - Search - Members - Calendar
Full Version: HP/SP Recovery on Level Up
RPG RPG Revolution Forums > Scripting > Script Development and Support
kowbrainz
Hi,

I'm fairly new to scripting, so this was just a basic thing to start off with. I'd just like to alter the default game script so that every time an actor levels up, their SP and HP are recovered fully.

Here's the part of the Actor class which deals with a change in level - anyone able to help with what I need to add to this (or whether I need to do anything else different) in order to get this to work? Thanks

CODE
  #--------------------------------------------------------------------------
  # * Change Level
  #     level : new level
  #--------------------------------------------------------------------------
  def level=(level)
    # Check up and down limits
    level = [[level, $data_actors[@actor_id].final_level].min, 1].max
    # Change EXP
    self.exp = @exp_list[level]

   #insert HP and SP recovery code here

   end
Tsukihime
You will have to change two functions.

The one you copied is when you run the "change level" command in an event.

The second is just above it, where you "change exp".
You can add do something like

CODE
def exp=(exp)
    @exp = [[exp, 9999999].min, 0].max
    # Level up
    while @exp >= @exp_list[@level+1] and @exp_list[@level+1] > 0
        @level += 1
        # Learn skill
        for j in $data_classes[@class_id].learnings
            if j.level == @level
                learn_skill(j.skill_id)
            end
        end
        @hp = self.maxhp
        @sp = self.maxsp
    end
    # Level down
    while @exp < @exp_list[@level]
        @level -= 1
    end
    # Correction if exceeding current max HP and max SP
    @hp = [@hp, self.maxhp].min
    @sp = [@sp, self.maxsp].min
end


And similarly add those two new lines to the other function as well.

You may want to keep the "correction" cause it handles cases where hp/sp goes down upon exp change, such as negative HP/SP curve per level up.
kowbrainz
Ah right, I see. Thanks! biggrin.gif
lilcooldude69
cant u event this as well...?
Tsukihime
Probably.
But would it have to be done on every map?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.