Help with healing formula

Hello, I have a question, you'll see, I have been working in a certain formula


class Game_Battler < Game_BattlerBase
def hp_regen(a, b)
x0 = ([30000, b.mhp].min) / 16.0
dmg = x0 + b.luk
variance = Random.new
low = 0.87
high = 0.99
dmg *= variance.rand(low..high)
return dmg.round.to_i
end
end


You'll see, just before the variane part I want to add those multipliers


-If b's level is bigger than 10 but lower or equal than 20, then dmg is multiplied by 1.2


-If b's level is bigger than 20 but lower or equal than 30, then dmg is multiplied by 1.4


-If b's level is bigger than 30 but lower or equal than 40, then dmg is multplied by 1.6


-If b's level is bigger than 40, then dmg is multiplied by 1.8


Can someone help me to make this? Thank you 🙂
I think this works, though I can't test it myself at the moment.

Code:
class Game_Battler < Game_BattlerBase
  def hp_regen(a, b)
    x0 = ([30000, b.mhp].min) / 16.0
    dmg = x0 + b.luk
    case b.level
    when  1..10 then dmg *= 1.0
    when 11..20 then dmg *= 1.2
    when 21..30 then dmg *= 1.4
    when 31..40 then dmg *= 1.6
    else ; dmg *= 1.8 end
    variance = Random.new
    low = 0.87
    high = 0.99
    dmg *= variance.rand(low..high)
    return dmg.round.to_i
  end
end
dmg *= [1.2, 1.4, 1.6, 1.8][[1, [4, b.lvl / 10].min].max - 1]


copy/paste that so you don't do any typos.


That's saying to take b's level and divide by 10, restricting to a range of 1 to 4.  Then take away 1 to give you an array index.


This might not be quite what you want though ... what should happen if b's level is less than or equal to 10?  It might not quite be right around the exact levels of 10, 20, 30, 40 either.  So treat it as a starting point and tweak it as necessary.


You could just do a loop setting i to 1-99 and running that using i instead of b.lvl, outputting the result to the console, to see exactly what you'll get with each number, rather than trying to test it during battle - would take much less time to get the formula correct.
This might not be quite what you want though ... what should happen if b's level is less than or equal to 10?



It should be multiplied by 1, which is the same than not adding a multiplier, I'll check both solutions in a while, thanks a lot by the help


EDIT:


@Rinobi when the level is between 11 and 20, it works, but from level 20 and later, it just don't keep increasing


@Shaz Your idea doesn't display any healing, does that mean it's not working?
In that case, try this instead:


dmg *= [1, 1.2, 1.4, 1.6, 1.8][[4, b.lvl / 10].min]


[4, b.lvl / 10].min should give you 0, 1, 2, 3 or 4, and I've added the x1 multiplier to the array.
In that case, try this instead:


dmg *= [1, 1.2, 1.4, 1.6, 1.8][[4, b.lvl / 10].min]


[4, b.lvl / 10].min should give you 0, 1, 2, 3 or 4, and I've added the x1 multiplier to the array.



Still not showing any healing
You need to do some debugging (output to the console) to see what's happening each step of the way.  That may not be the line that's causing the problem.  Did you do the test I suggested in my first post, just to make sure you're getting the correct number for each value from 1 to 99?
You need to do some debugging (output to the console) to see what's happening each step of the way.  That may not be the line that's causing the problem.  Did you do the test I suggested in my first post, just to make sure you're getting the correct number for each value from 1 to 99?



How do I make this work in the console? I don't know how to make it
Put this into a script command on an event and run it once, with the console open:

Code:
for i in 1...99
  dmg = [1, 1.2, 1.4, 1.6, 1.8][[4, i/10].min]
  p sprintf('%d: %d', i, dmg)
end



That will tell you what the multiplier will be for each level.  If there's an error in the formula, you'll get an error when you try to run the event, probably something about Game_Interpreter line 1411 or something similar.  But if it gives you values, then that's not where the issue is - in that case, show us your whole method as it currently stands.
Finally back at my desk.
I tested this method and it worked fine on my end.


#==============================================================================
# ** Game_Battler
#------------------------------------------------------------------------------
# A battler class with methods for sprites and actions added. This class
# is used as a super class of the Game_Actor class and Game_Enemy class.
#==============================================================================
class Game_Battler < Game_BattlerBase
#--------------------------------------------------------------------------
# * New Method: Calculate Health Regeneration
#--------------------------------------------------------------------------
def hp_regen(a, b)
dmg = (([30000, b.mhp].min) / 16.0) + b.luk
case b.level
when 1..10 then dmg *= 1.0
when 11..20 then dmg *= 1.2
when 21..30 then dmg *= 1.4
when 31..40 then dmg *= 1.6
else ; dmg *= 1.8 end
variance = Random.new
low, high = 0.87, 0.99
dmg *= variance.rand(low..high)
return dmg.round.to_i
end # hp_regen
end # Game_Battler




Are you certain that the level was being advanced correctly in your experiments?


@Shaz @S.Court Just replace b.lvl with b.level as no lvl method exist within Ace.
Thank you - I did question whether it was lvl or level when I wrote it.  OP, try that replacement first and see if it makes a difference.



Otherwise, you're getting two different approaches here which is making the thread a bit confusing.  If you want to go with Rinobi's method then just stick with that and don't worry about mine at all.  As long as it works, it doesn't really matter which one you go with 🙂
Very well, it's solved, thanks a lot guys by the help ^_^

Original thread: https://forums.rpgmakerweb.com/threads/help-with-healing-formula.66448/