I'm trying to make HP increase with an xstat.

When using N.A.S.T.Y. Extra Stats https://forums.rpgmakerweb.com/index.php?threads/n-a-s-t-y-extra-stats.998/ and Theo Custom Parameter Formula https://www.rpgmakercentral.com/topic/20334-theo-custom-parameter-formula/, I am trying to create a custom parameter that determines how much HP is gained by an actor's Constitution xstat. I'll preclude this by saying that I have little to no understanding of how ruby scripting works, and I am struggling through the dark to try and get this to work. Forgive me for my lack of understanding if I make simple scripting errors.

I'll give a run down of what is supposed to happen: Let's say a character starts with 20 HP at level 1, and starts with 10 CON. Any amount of CON above 10 increases Max HP by 8, per point in CON. That's governed by this formula: 20 + (8 * (CON - 10)) For instance, if a character has 12 CON, he has 20 + (8 * (12-10)). This becomes 20 + 16 = 36.

The formula I made in the Theo Custom Parameter script looks like this (the relevant part between "def" and the second "end"):

Code:
  def custom_mhp(ori_param)
    if $game_actors[actor.id].xstat.con > 10
      20 + (8 * ($game_actor[actor.id].xstat.con - 10))
    else
      20
    end
  end

With this, I get an "Stack Level Too Deep" error. I have tried other variations like:

Code:
  def custom_mhp(ori_param)
    if $game_actors.xstat.con > 10
      20 + (8 * ($game_actors.xstat.con - 10))
    else
      20
    end
  end

This don't work either. I feel like the only way to move forward is blocked because I lack the knowledge to understand how this works.
I haven't tested anything, but does it work if you do something like:
Code:
def custom_mhp(ori_param)
   ori_param = @xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
 end

Since the method is in the Game_Actor class, you don't need to use $game_actors or anything like that.
I haven't tested anything, but does it work if you do something like:
Code:
def custom_mhp(ori_param)
   ori_param = @xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
 end

Since the method is in the Game_Actor class, you don't need to use $game_actors or anything like that.

I just tried it and I got an error that says "undefined method 'con' for nil:NilClass.

The reason I used $game_actors is because this is what it said for the extra stats script:

Code:
# *For Scripters
#
# -If you want to access the stats, just use:
# actor.xstat.STAT - Where STAT is the name of the new stat
#
# Ex. $game_actors[1].xstat.str , will return actor 1's str
I'd try changing the order of the scripts. You could also try:
Code:
def custom_mhp(ori_param)
   return ori_param = 20 unless @xstat.con
   ori_param = @xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
 end
I'd try changing the order of the scripts. You could also try:
Code:
def custom_mhp(ori_param)
   return ori_param = 20 unless @xstat.con
   ori_param = @xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
 end
I got the same error. I changed the order of the two scripts, and that didn't change the outcome.
$game_actors[actor.id].xstat.con

def custom_mhp(ori_param) ori_param = @xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20 end
Could you not combine these to give...
Code:
def custom_mhp(ori_param)
  ori_param = $game_actors[actor.id].xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
end
Could you not combine these to give...
Code:
def custom_mhp(ori_param)
  ori_param = $game_actors[actor.id].xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
end
I plugged it in, but I got the error "stack level too deep". Also, I get these errors when I start a new game. By the way, what does the "actor.id" part do in the brackets?
Where are you putting this?
I plugged it in, but I got the error "stack level too deep"
This code should go right in the script.
Code:
  # --------------------------------------------------------------------------
  # * ) Defense Point
  # --------------------------------------------------------------------------
  def custom_def(ori_param)
    ori_param   # <-- Define it here
  end
  # --------------------------------------------------------------------------
  # * ) Magic Attack
  # --------------------------------------------------------------------------
  def custom_mat(ori_param)
    ori_param   # <-- Define it here
  end
  # --------------------------------------------------------------------------
  # * ) Magic Defense
  # --------------------------------------------------------------------------
  def custom_mdf(ori_param)
    ori_param   # <-- Define it here
  end
  # --------------------------------------------------------------------------
  # * ) Agility Point
  # --------------------------------------------------------------------------
  def custom_agi(ori_param)
    ori_param   # <-- Define it here
  end
The issue is because of where things are being run. Theo's script is trying to pull parameters that don't exist yet. You could try two things:

Option 1:
Code:
  alias z26_s setup unless $@
  def setup(actor_id)
    @xstat = Z26::Xstats.new(*([0]*Z26::STATS.size))
    z26_s(actor_id)
    for item in equips.compact
      z26variate_equip(item)
    end
    for stat in Z26::STATS
      z26variate_stats(stat, @level)
    end
  end
Replace the aliased setup method in Game_Actor with this in NASTY's script.

Option 2:
Code:
  def custom_mhp(ori_param)
    return ori_param = 20 unless @xstat && @xstat.con
    ori_param = @xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
  end
Use that as your code in Theo's script.
The issue is because of where things are being run. Theo's script is trying to pull parameters that don't exist yet. You could try two things:

Option 1:
Code:
  alias z26_s setup unless $@
  def setup(actor_id)
    @xstat = Z26::Xstats.new(*([0]*Z26::STATS.size))
    z26_s(actor_id)
    for item in equips.compact
      z26variate_equip(item)
    end
    for stat in Z26::STATS
      z26variate_stats(stat, @level)
    end
  end
Replace the aliased setup method in Game_Actor with this in NASTY's script.

Option 2:
Code:
  def custom_mhp(ori_param)
    return ori_param = 20 unless @xstat && @xstat.con
    ori_param = @xstat.con > 10 ? 20 + (8 * (@xstat.con - 10)) : 20
  end
Use that as your code in Theo's script.

I tried option 2 first, and it works great! Can you explain how it's different?

Also, thank you so much!
Where are you putting this?

This code should go right in the script.
Code:
  # --------------------------------------------------------------------------
  # * ) Defense Point
  # --------------------------------------------------------------------------
  def custom_def(ori_param)
    ori_param   # <-- Define it here
  end
  # --------------------------------------------------------------------------
  # * ) Magic Attack
  # --------------------------------------------------------------------------
  def custom_mat(ori_param)
    ori_param   # <-- Define it here
  end
  # --------------------------------------------------------------------------
  # * ) Magic Defense
  # --------------------------------------------------------------------------
  def custom_mdf(ori_param)
    ori_param   # <-- Define it here
  end
  # --------------------------------------------------------------------------
  # * ) Agility Point
  # --------------------------------------------------------------------------
  def custom_agi(ori_param)
    ori_param   # <-- Define it here
  end
I was putting them where they were supposed to go in the script.
The reason is because the parameters are set up before the xstats, so it was throwing an error (because you're referring to something that doesn't exist yet). With the first option, I was basically moving the xstats (albeit blank ones) to be set up first. The second option basically says 'if the xstats aren't set up yet, don't continue with the rest of the code and set ori_param to 20'.

Hope that makes sense.

Original thread: https://forums.rpgmakerweb.com/threads/im-trying-to-make-hp-increase-with-an-xstat.103792/