Hit point Changing attribute?

Started by shintashi, November 01, 2011, 01:14:42 pm

Previous topic - Next topic

shintashi

November 01, 2011, 01:14:42 pm Last Edit: November 01, 2011, 11:20:20 pm by shintashi
I'm looking for a way to have an attribute, even an existing attribute, to change hit points, including after the game is loaded, and the attribute is changed during play.

For example,

if I loaded base hit points at 500 and my agility was 50,
base hit points + agility = 550...

this is something I can already do, but where it stops working is if I increase agility to say, 100, during play.
instead of spitting out 500 + 100 = 600,
it spits out 550, no matter what.

The base values are locked in during initialization, even if one of the variables changes. So far I've only been able to get around this using a global,


 def maxhp
   n = [[base_maxhp + @maxhp_plus, 1].max, 9999].min
   for i in @states
     n *= $data_states[i].maxhp_rate / 100.0
   end
   n = [[Integer(n) + $life, 1].max, 9999].min
   return n
 end


but not using anything else internal to the Battler or Actor class.

winkio


shintashi

November 01, 2011, 04:27:02 pm #2 Last Edit: November 01, 2011, 04:30:21 pm by shintashi
Quote from: winkio on November 01, 2011, 03:44:47 pm
it already exists: maxhp_plus


how can I clone the functionality of maxhp_plus so battler attributes like self.str or self.agi can be integrated into my hit point calculation?

because stuff like this:


  def maxhp
      n = [[base_maxhp + @maxhp_plus, 1].max, 999999].min
    for i in @states
      n *= $data_states[i].maxhp_rate / 100.0
    end
    n = [[Integer(n) + self.agi, 1].max, 999999].min
    return n
  end


isn't working.


winkio

The code you have works perfectly fine, assuming it's in the right place.  Make sure you change the methods from both Game_Actor and Game_Battler, and that there are no scripts below that overwrite the changes.

shintashi

November 01, 2011, 04:51:46 pm #4 Last Edit: November 01, 2011, 05:03:44 pm by shintashi
Quote from: winkio on November 01, 2011, 04:42:03 pm
The code you have works perfectly fine, assuming it's in the right place.  Make sure you change the methods from both Game_Actor and Game_Battler, and that there are no scripts below that overwrite the changes.


ok, that' seems to work at the most basic level when it's in both game_actor and battler 1, I need to still check to see if it's compatible with my custom stats, if so, I can consider this a success. *fingers crossed*

edit: yes it works with stamina,
but it does not work with my endurance skill:

basically, when I try this:

  def maxhp
      n = [[base_maxhp + @maxhp_plus, 1].max, 999999].min
    for i in @states
      n *= $data_states[i].maxhp_rate / 100.0
    end
    n = [[Integer(n) + endurance_check, 1].max, 999999].min
    return n
  end




in conjunction with this:

#--------------------------------------------------------------------------
  # * Get Base Endurance
  #--------------------------------------------------------------------------
  def endurance_check
       if self.is_a?(Game_Actor)
       endurance_skills = []
         if @techniques.size == 0
           endurance_skills << 0
         else
          for i in 0...@techniques.size
             if @techniques[i] == nil
               next
             else
              a = @techniques[i].skills
                if a.include?(0)   
                  endurance_skills << @techniques[i].level
                else
                  endurance_skills << 0
                  next
                end
            end
          end
        end # if tech size
     n = 0 + endurance_skills.max

   else #is not an actor
    monster_size = self.element_ranks(19)
    monster_bonus = monster_size * 16
      n = Integer(self.str / 3) + monster_size
    end # if is actor
    return Integer(n)
  end


changing the endurance_check value, i.e., when


@techniques[i].level


is set to something other than zero, it doesn't add anything. Which is odd because I think it works else where, I'm going to test it before and after leveling as a damage bonus and see if the numbers appear.

winkio

having it in game_actor affects part members, having it in game_battler affects enemies.

shintashi

November 01, 2011, 08:09:45 pm #6 Last Edit: November 03, 2011, 07:29:22 am by game_guy
i finally figured out what i was doing wrong:

i was checking for a skill #0 in technique #0...x when I should have been checking for a skill #1 in technique #0.

EDIT:

spoke too soon:


 def maxhp
   vitality = x99(self.sta, endurance_check)
    n = [[vitality + @maxhp_plus, 1].max, 999999].min
   for i in @states
     n *= $data_states[i].maxhp_rate / 100.0
   end
   n = [[Integer(n), 1].max, 999999].min
   return n
 end


Can't get the part that says "@maxhp_plus" to work. I have copies in both game actor and battler 1.

EDIT
Spoiler: ShowHide
ok i fiddled with it some more and discovered the @maxhp_plus setting is working at initialization (i.e. when I set it to 100 my base hit points were all +100), but after initialization, the bonus does not change. this means at some point, the ability of maxhp_plus to be changed during play somehow disappeared in my rewrite.

edit:

so I've been tinkering some, and concluded I have no clue why it won't work. I tried @maxhp_plus as an attr_accessor and it still crashed.

I think this section:


 def maxhp=(maxhp)
   @maxhp_plus += maxhp - self.maxhp
   @maxhp_plus = [[@maxhp_plus, -9999].max, 9999].min
   @hp = [@hp, self.maxhp].min
 end


is probably what's preventing it from working. It's like when I switch from

this:

 def maxhp
   n = [[base_maxhp + @maxhp_plus, 1].max, 9999].min
   for i in @states
     n *= $data_states[i].maxhp_rate / 100.0
   end
   n = [[Integer(n), 1].max, 9999].min
   return n
 end


to this:


 def maxhp
   vitality = x99(self.sta, endurance_check)
    n = [[vitality + @maxhp_plus, 1].max, 999999].min
   for i in @states
     n *= $data_states[i].maxhp_rate / 100.0
   end
   n = [[Integer(n), 1].max, 999999].min
   return n
 end


only the changes to self.sta and endurance update. Put another way, when the program turns on, ALL THREE attributes:
1. self.sta [stamina]
2. endurance_check [endurance]
3. maxhp_plus

work fine. After the game starts, using things like events to change these attributes only works for:
1. self.sta [stamina]
2. endurance_check [endurance]

while
3. maxhp_plus

which is useful for things like spell buffs, remains whatever it is set to during initialization. I have no idea why these other attributes are able to change after initialization while maxhp_plus fails, since they are part of the same definition.




P.S.
 vitality = x99(self.sta, endurance_check)


just means :
 self.sta * (endurance_check + 2) 


EDIT:
Ok, I got it working. I think what I was doing was trying to use change HP instead of change Parameters> MaxHP. Which also threw me off because I hadn't done much eventing since last year. :facepalm:

"Modify" button, please.  - Zer0

Please don't double post within 24 hours - game_guy