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.

Change Actor Class During Battle Script?

Hey guys, I'm trying to figure out a way to change an actor's class during battle. Using the event command "change actor's class" won't work during battle. So does anyone know how I could change it with a script during battle? Thanks for any advice.
 
Thanks for the reply, I tried this but its not working...

EDIT: actually, it is changing the class but I don't know if its changing it during battle or after the battle ends because when the class changes you should have a different set of attacks but the set of attacks are not changing... It seems as if its not changing until after the battle ends. Is it possible to fix this?

Also, is it possible to specify what actor to change its class instead of specifying what party member? Thanks.
 
You can use:

$game_actors[n].class_id = m

n = actor_id from database

The only other thing this does than change the class, is remove any weapons that are equipped that the class can't use.
You wouldn't see a change in skills until the character leveled up. (and then I think he'd keep the old skills, just add new ones)
You'd need to add to the class=(class) method something like they use in the Game_Actor.setup method:

Code:
    # Learn skill

    for i in 1..@level

      for j in $data_classes[@class_id].learnings

        if j.level == i

          learn_skill(j.skill_id)

        end

      end

    end

but you'd also have to remove the old skills, so maybe:

Code:
    # Learn skill

    for i in 1..@level

      for j in $data_classes[old_class_id].learnings

        if j.level == i

          forget_skill(j.skill_id)

        end

      end

      for j in $data_classes[@class_id].learnings

        if j.level == i

          learn_skill(j.skill_id)

        end

      end

    end

That would remove the skills from the old class, add the skills for the new class, and leave any other skills learned in another way (scroll, taught)

Since the class=(class) method removes unequipable weapons, and you can't equip a weapon in battle, you could also get stuck without a weapon.

What, exactly are you trying to achieve by changing classes in the middle of battle? Just a change in skills?
 
I'm using the Tales of Battle system and I'm trying to make a skill similar to the Ex Gauge system in Final Fantasy Dissidia, so I have it to where when a certain skill is used, if a certain variable is 50 or higher, then the character gets a new skill, one you can press c to use instead of equipping it from the skill menu. If you have to equip it from the skill menu then you will keep the Ex Gauge skill and that's what I'm trying to avoid.

Here is how a battler is set up in the system:

Code:
when 22 #class ID

      @armor1_id = 1

      @walk_x_speed         =  4.0   # 「歩行X速度」

      @frict_x_break        =  1.0   # 「摩擦Xブレーキ力」

      @dash_x_speed         =  10.0   # 「走行X速度」

      @crouch_to_jump       =  1     # 「ジャンプ開始にかかるフレーム」

      @air_x_velocity       =  0.8   # 「空中X加速度」

      @air_x_maximum        =  6.0   # 「空中X最大速度」

      @air_x_resistance     =  0.2   # 「空中X空気抵抗」

      @air_y_velocity       =  0.8   # 「落下Y加速度」

      @air_y_maximum        =  18.0   # 「落下Y最大速度」

      @swoop_y_speed        = 17.25  # 「急降下Y最高速度」

      @max_jumps            =  2    # 「最高連続ジャンプ回数」

      @weight               =  0.10  # 「重さ」

      @guard_durability        = 35     # 「ガード耐久力」

      @jump_y_init_velocity    = 10  # 「地上ジャンプY初速度」

      @airjump_y_init_velocity = 9   # 「空中ジャンプY初速度」

      @stand_body_rect      = Rect.new( -20 , -54, 40, 45) #  直立時くらい判定(Rect)

      @sit_body_rect        = Rect.new( -20 , -24, 40, 20) # しゃがみ時くらい判定(Rect)

      @down_body_rect       = Rect.new( -20 , -10, 40, 20) # ダウン時くらい判定(Rect)

      # Attacks used by pressing C

      @forte_ids[ 1]        = 1125 # x Normal Attack

      @forte_ids[ 4]        = 1073 # =>=>+x

      @forte_ids[ 5]        = 1123 # =>+x

      @forte_ids[ 6]        = 1081 # arriba+x

      

      @forte_ids[11]        = 1091 # Shattering Pulse (x)

      @forte_ids[12]        = 1093 # Ataque 2 ( -> + x )

When Ex Gauge is activated, I tried changing the class so the battler would have this setup instead:

Code:
when 23 #Ex Gauged Class

      @armor1_id = 1

      @walk_x_speed         =  4.0   # 「歩行X速度」

      @frict_x_break        =  1.0   # 「摩擦Xブレーキ力」

      @dash_x_speed         =  10.0   # 「走行X速度」

      @crouch_to_jump       =  1     # 「ジャンプ開始にかかるフレーム」

      @air_x_velocity       =  0.8   # 「空中X加速度」

      @air_x_maximum        =  6.0   # 「空中X最大速度」

      @air_x_resistance     =  0.2   # 「空中X空気抵抗」

      @air_y_velocity       =  0.8   # 「落下Y加速度」

      @air_y_maximum        =  18.0   # 「落下Y最大速度」

      @swoop_y_speed        = 17.25  # 「急降下Y最高速度」

      @max_jumps            =  2    # 「最高連続ジャンプ回数」

      @weight               =  0.10  # 「重さ」

      @guard_durability        = 35     # 「ガード耐久力」

      @jump_y_init_velocity    = 10  # 「地上ジャンプY初速度」

      @airjump_y_init_velocity = 9   # 「空中ジャンプY初速度」

      @stand_body_rect      = Rect.new( -20 , -54, 40, 45) #  直立時くらい判定(Rect)

      @sit_body_rect        = Rect.new( -20 , -24, 40, 20) # しゃがみ時くらい判定(Rect)

      @down_body_rect       = Rect.new( -20 , -10, 40, 20) # ダウン時くらい判定(Rect)

      #Normal Attacks Used by pressing C

      @forte_ids[ 1]        = 1113 # x Ex Gauge Skill Renzokuken (Squall)

      @forte_ids[ 4]        = 1073 # =>=>+x

      @forte_ids[ 5]        = 1123 # =>+x

      @forte_ids[ 6]        = 1081 # arriba+x

      

      @forte_ids[11]        = 1091 # Shattering Pulse (x)

      @forte_ids[12]        = 1093 # Ataque 2 ( -> + x )

And after the Ex Gauged skill is used I wanted it to change the battler's class back to what it was before so it can't keep using its Ex Gauged Skill. By changing the actors class, it only changes it after battle instead of during battle and I'm trying to make it to where I can actively change its class during battle with events so I can have this dynamic shift between normal and Ex Gauge modes. This was also my plan for using different weapon sets, but if I can't have this dynamic shift between classes during battle, or something similar to it to where I can change the battler's set up on the go, then I'm going to have a hard time making the battlers able to switch weapon/fight styles and using "limit break" type skills.
 
I'm not familiar with the "Tales of" battle system or FF(anything)...

But it sounds like, simply put: You want a skill that adds another skill, and once you use that new skill you want it to go away. (which you can do easily with common events for both skills)

Skill A => executes common event to add Skill B
Skill B => executes common event to remove Skill B

OR....

You want to change the @forte_ids[1] property of the battler when either skill is used.
which would require adding some code to change that property when the skill is used.
 
Yes if I can change the Forte_Id code thing I think that would be exactly what I'm looking for but I don't know what code to put it. I tried just copying and pasting the battler setup but it does not work like that. (I found ruby to be the most confusing programming language I've used), so do you know what code I could use to change the @forte_ids[1] value? I really appreciate your help Brewmeister.

As for just adding skills, this almost works but if you just add it then you'll have to equip it and press X to use it (those are reserved for special skills including spells) but when you try to take it away, it still remains equipped but it disappears from the list of skills you can equip so that doesn't work.
 
You need methods to read & write @forte_ids. If these methods only need to return a value (read), and write the new value (write),
you can create them with the statement:

attr_accessor :forte_ids

then from outside the class, you use

<battler>.forte_ids[1] = 1113

where <battler> is your battler object ($game_actor[n], @active_battler, etc..)
 
I tried putting this in a script event

Code:
attr_accessor :forte_ids

$game_actor[18].forte_ids[1] = 1113

But I got an error when it tried to run:

"NoMethodError occurred while running script. Undefined method 'attr_accessor' for #<Interpreter:0x9484c90>"

What did I do wrong?

EDIT I also just tried to put $game_actor[18].forte_ids[1] = 1113 and I got this error:

"NoMethodError occurred while running script. Undefined method '[]' for nil:NilClass"

The real annoying thing about ruby is I don't even know what these errors mean. With C++ it at least tells you exactly whats wrong, why and where. I also tried putting a Game_Battler class at the beginning of the code and it said the same thing only the undefined method was "class".

I really appreciate the help Brewmeister.
 
Ok I tried putting attr_accessor :forte_ids at the top of both the Game_Battler script and the Game_Battler class section of the battle system script but I'm still getting the same error as before...
 

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