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.

[Resolved] Level Up Class bonuses

Engine: RMXP
Script:

When a character levels up, he/she gets a increase in stats based on what class she is.
This can be configured in the script editor: for example, in class 1, the fighter, you can choose to have +3 str and +2 agl or something like that.
This script does not have to overwrite the normal level up thing in the character editor; they can gain stats like normal, except with the bonuses from the class added in.

Any questions?
 
What I think about this is that in order to make sure these bonuses don't get lost at the next level up, they'd be contained in a separate array (or even a Struct if possible) and be added to every single stat whenever they are calculated.

Then we create a Struct child class like this...

[rgss]class PlayerStats < Struct.new:)hp, :mp, :atk, :def, :mdef, :agi, :int)
end
 
# Then in Game_Actor we do something like this...
 
class Game_Actor
  alias kyon_gm_actor_init initialize
  def initialize(index)
     @bonus_stats = PlayerStats.new
     kyon_gm_actor_init(index)
  end
end
[/rgss]

What's left would be to include the @bonus_stats variable in every single method that needs to add any of its bonuses. Here's an example:

@mp += @bonus_stats[:mp]

or

return @mp + @bonus_stats[:mp]

If you need to add or substract any amount, just write something like...

@bonus_stats[:hp] += 15

@bonus_stats[:mdef] -= 4
 
@kyonides
No need to go that far man. There is a much easier way to do it. :D

Just put it above main or anywhere, as long as it is BELOW Game_Actor

Here. :)



Took me a few minutes, but it's really a simple script. :)

Code:
 

#==============================================================================

# ** Class Bonus per Level-Up

#  * Author: Drago del Fato

#  * Version: 1.1

#  * Engine: RMXP

#------------------------------------------------------------------------------

#  Different level up stats increase per class.

#==============================================================================

 

module ClassOptions

  # Class Types to gain bonuses

  # Type here ID's of the classes (you can find them in the database)

  # I wrote ID's for Fighter, Lancer and Mage

  CLASS_TYPES = [1, 2, 8]

  

  # Which stats to increase?

  # You need to have exact amount of status increase arrays

  # as the number of classes.

  # For example...

  # if you have class types: ["Fighter", "Mage", "Lancer"]

  # In this you need to have the array below like this:

  # [[stat1, stat2, stat3,...], [stat1, stat2, stat3,...],[stat1, stat2, stat3,..., statN]]

  

  # Increase numbers:

  # 1 - Max HP

  # 2 - Max SP

  # 3 - STR

  # 4 - AGI

  # 5 - DEX

  # 6 - INT

  

  CLASS_INCREASE = [[1, 3], [5, 3], [6, 2]]

  

  # Amount of Increase?

  # Same rules as above except for increase amount you type it in.

  # Keep in mind though... you need to have same index of what to increase

  # and amount of increase

  # For example: CLASS_INCREASE has [1, 3] for class Fighter and those

  # status are Max HP and STR

  # Below are [10, 3] which means Max HP will be increased by 10 each level

  # and STR will be increased by 3 each level.

  

  CLASS_AMOUNT = [[10, 3], [4, 2], [5, 20]]

  

end

 

class Game_Actor < Game_Battler

 

  

  def initialize(actor_id)

    super()

    setup(actor_id)

    if ClassOptions::CLASS_TYPES.include?(@class_id)

      index = ClassOptions::CLASS_TYPES.index(@class_id)

      @class_increase = ClassOptions::CLASS_INCREASE[index]

    else

      @class_increase = nil

    end

 

  end

  

  def increase(type)

    return 0 if @class_increase == nil

    if @class_increase.include?(type)

      index = ClassOptions::CLASS_TYPES.index(@class_id)

      # Level - 1 is because first level won't get any bonus.

      return ClassOptions::CLASS_AMOUNT[index][@class_increase.index(type)] * (@level - 1)

    else

      return 0

    end

  end

    

  def base_maxhp

    return $data_actors[@actor_id].parameters[0, @level] + increase(1)

  end

 

  def base_maxsp

    return $data_actors[@actor_id].parameters[1, @level] + increase(2)

  end

 

  def base_str

    n = $data_actors[@actor_id].parameters[2, @level] + increase(3)

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    n += weapon != nil ? weapon.str_plus : 0

    n += armor1 != nil ? armor1.str_plus : 0

    n += armor2 != nil ? armor2.str_plus : 0

    n += armor3 != nil ? armor3.str_plus : 0

    n += armor4 != nil ? armor4.str_plus : 0

    return [[n, 1].max, 999].min

  end

 

  def base_dex

    n = $data_actors[@actor_id].parameters[3, @level] + increase(4)

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    n += weapon != nil ? weapon.dex_plus : 0

    n += armor1 != nil ? armor1.dex_plus : 0

    n += armor2 != nil ? armor2.dex_plus : 0

    n += armor3 != nil ? armor3.dex_plus : 0

    n += armor4 != nil ? armor4.dex_plus : 0

    return [[n, 1].max, 999].min

  end

 

  def base_agi

    n = $data_actors[@actor_id].parameters[4, @level] + increase(5)

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    n += weapon != nil ? weapon.agi_plus : 0

    n += armor1 != nil ? armor1.agi_plus : 0

    n += armor2 != nil ? armor2.agi_plus : 0

    n += armor3 != nil ? armor3.agi_plus : 0

    n += armor4 != nil ? armor4.agi_plus : 0

    return [[n, 1].max, 999].min

  end

 

  def base_int

    n = $data_actors[@actor_id].parameters[5, @level] + increase(6)

    weapon = $data_weapons[@weapon_id]

    armor1 = $data_armors[@armor1_id]

    armor2 = $data_armors[@armor2_id]

    armor3 = $data_armors[@armor3_id]

    armor4 = $data_armors[@armor4_id]

    n += weapon != nil ? weapon.int_plus : 0

    n += armor1 != nil ? armor1.int_plus : 0

    n += armor2 != nil ? armor2.int_plus : 0

    n += armor3 != nil ? armor3.int_plus : 0

    n += armor4 != nil ? armor4.int_plus : 0

    return [[n, 1].max, 999].min

  end

 

end

 

# END OF SCRIPT

Keep in mind though that with this script, status bonuses are given per EACH level for specific classes. So it might seem as it is giving a lot but actually it is just adding the increase to normal status per level.
For example: Max HP of the Fighter Class (in this current configuration) is increased by 10 per level.

Just put me in the credits, either commercial or non-commercial game. And that's it. :)
 
Well, I know, since yesterday after reading his post, there was a list of instance variables called @maxhp_plus, @str_plus, @int_plus and so on. I guess you also overlooked that, Drago...

That means you only need to add those amounts to such variables in order to get the extra stats points. That means you may not even need to modify so many methods and thus include so many lines of code.

BTW, Daxis, remember that what he offered to you doesn't seem to let you customize every single one of your extra stats points (in a very graphical, visual way) according to their class since all classes included in the first array will get exactly the same extra points at level up. If you want to customize it, converted the second and third arrays he created into Hashes so every single class gets different extra stats points.

Example:

CLASS_INCREASE = {
1 => [[1,3],[4,3],[6,5]],
5 => [[1,3],[2,3],[6,5]],
8 => [[2,3],[3,3],[5,5]]
}

That might change the way the increase method work, so Drago might help you with that method modification.

Believe me, Drago, that might help people more than using an array.
 
wait, I thought you could aready give different class different stat bonuses (as it's the whole point of the script), at the class_types array part.
I mean, the easiest for non-script friendly people (>.>) to edit it would prolly be something like

class_1 = [
[1, 33]
[2, 21]
]

where class_1 (or something like that) is the class number, and the 1st array number 1 would be the stat (hp), and the 2nd (33) would be stat increase by.

I mean, I'm seriously not complaining, I'm getting a free script. It's only how I imagined it in my mind, as I had a similar script request before and someone answered it like that.
 
@maxhp_plus?
@str_plus?
@int_plus?

Look if he ONLY modifies that, ALL of the actors will get the SAME increase. Sure it's something which can be used easily and btw... seen Game_Battler? It modifies those variables (Enterbrain aint stupid to leave it just for show i guess).

Second... Lemme explain again how that works.

For example let's say you have these classes:

001 - Fighter
002 - Mage
003 - Hunter
004 - Wizard
005 - Monster
006 - Sage

And you want these classes to get bonuses, Fighter, Wizard, Monster, Sage so you do this

CLASS_TYPES = [1, 4, 5, 6]

Ok now... let's say:
- for Fighter - increases will be Strength and Agility
- for Wizard - Max SP and Intelligence
- for Monster - Strength, Max HP, Dexterity
- for Sage - Intelligence, Max SP, Max HP, Agility

Increase numbers are
1 - Max HP
2 - Max SP
3 - STR
4 - AGI
5 - DEX
6 - INT

and now you do this in variable CLASS_INCREASE


CLASS_INCREASE = [
[3, 4], # For Fighter class what to increase is 3 - Strength and 4 - Agility
[2, 6], # For Wizard class what to increase is 2 - Max SP and 6 - Intelligence
[3, 1, 5], # For Monster class what to increase is 3 - Strength, 1 - Max HP, 5 - Dexterity
[6, 2, 1, 4]] # For Sage class what to increase is 6 - Intelligence, 2 - Max SP, 1 - Max HP, 4 - Agility

Now you customize amount of bonus increase per each stat of the each class, and in this example it looks like this:

CLASS_AMOUNT = [
[3, 1], # Fighter: Strength will get bonus by 3 per each level, Agility will get bonus by 1 per each level
[4, 2], # Wizard: Max SP will get bonus by 4 per each level, Intelligence will get bonus by 2 per each level
[5, 10, 3], # Monster: Strength will get bonus by 5 per each level, Max HP by 10 each level and Dexterity by 3 each level
[4, 10, 3, 2]] # Sage: Intelligence will get bonus by 4 per each level, Max SP by 10 each level, Max HP by 3 each level and Agility by 2 each level

So you just read the array and see what to do. Now tell me how did I not allow to configure EACH of stat points?
 
That's why I suggested using a hash instead of an array, so they can easily deploy your version of the script. They wouldn't need to check the first Constant to remind them of what class they inserted in which position nor include a second or third value in a nested array to declare which is the correspondent hero class. They'd just need to check which key corresponds to a specific hero class and that's all, Drago. Remember that I said above "(in a very graphical, visual way) "... Believe me it's easier to read a hash due to its keys than an array with looks more abstract due to the need of recalling what was their exact index in such a nested array scheme.

Oh, BTW, I never tried to say it wouldn't work, I took a look at Drago's code and I think it's fine, but he could still modify it to make it look better.

I'm also going to post my own version as a new script in the Scripts subforum.
 

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