Main Menu

[Help] Modding battle script to take position into account.

Started by Saber, December 19, 2005, 09:44:22 AM

0 Members and 1 Guest are viewing this topic.

Saber

I'm working on a battle script that'll take the character's position, as determined by their class, into account in the battle. Now, while I have the variable pulling just fine, the script only works half right.

What works is the defender's position. If they're in the middle or rear position, they take the lowered damage (80% or 60%, respectively). However, they still deal normal damage, not the desired 80%/60%.

Here's what I've got for my damage calculation snippet (I marked where the position damage correction starts and ends):

 def attack_effect(attacker)
   # Clear critical flag
   self.critical = false
   # First hit detection
   hit_result = (rand(100) < (attacker.hit + (attacker.dex / self.agi) * 40))
   # If hit occurs
   if hit_result == true
     # Calculate basic damage
     atk = [attacker.atk - self.pdef / 2, 0].max
     self.damage = atk * (2 + attacker.str) / 2
     # Element correction
     self.damage *= elements_correct(attacker.element_set)
     self.damage /= 100
     # If damage value is strictly positive
     if self.damage > 0
       # Critical correction
       if rand(100) < 4 * attacker.dex / self.agi
         self.damage *= 2
         self.critical = true
       end
       # Guard correction
       if self.guarding?
         self.damage /= 2
       end
       # Attacker position correction          // This is the start of the position correction
       if attacker.position == 1               //
         self.damage *= 80                     //
         self.damage /= 100                    //
       elsif attacker.position == 2            //
         self.damage *= 60                     //
         self.damage /= 100                    //
       end                                     //
       # Defender position correction          //
       if self.position == 1                   //
         self.damage *= 80                     //
         self.damage /= 100                    //
       elsif self.position == 2                //
         self.damage *= 60                     //
         self.damage /= 100                    //
       end                                     // This is the end of the position correction
     end
     # Dispersion
     if self.damage.abs > 0
       amp = [self.damage.abs * 15 / 100, 1].max
       self.damage += rand(amp+1) + rand(amp+1) - amp
     end
     # Second hit detection
     eva = 8 * self.agi / attacker.dex + self.eva
     hit = self.damage < 0 ? 100 : 100 - eva
     hit = self.cant_evade? ? 100 : hit
     hit_result = (rand(100) < hit)
   end
   # If hit occurs
   if hit_result == true
     # State Removed by Shock
     remove_states_shock
     # Substract damage from HP
     self.hp -= self.damage
     # State change
     @state_changed = false
     states_plus(attacker.plus_state_set)
     states_minus(attacker.minus_state_set)
   # When missing
   else
     # Set damage to "Miss"
     self.damage = "Miss"
     # Clear critical flag
     self.critical = false
   end
   # End Method
   return true
 end


Any help as to why the damage portion of the snippet isn't working would be greatly appreciated. Oh, and in case it helps, here's how I pulled the position variable:

 def position
   n = @position
   return n
 end


Thanks in advance!
Project(s):
Dragonblade: First Awakening - Demo not yet available
Dragonblade: The Forum game - Join now!

Sophist

Nobody has came across rows for that script.They have rows in the Normal battle system,yet their might NOT be away to get that to happen.
And as for your other problem,ask Crankeye.
*UPDATE!*Well,actually,after I took a look at it,you have no way to get them from Position 1 to Position 2,as It seems.Fix that,it might work.
[fright]you awoke in a burning paperhouse
from the infinite fields of dreamless sleep
[/fright]

Saber

While I don't exactly understand what you meant in your update, I did eventually get this to work. What I did, is have the position make modifications in battle to a character's attack and physical defense stats.

In the Game_Battler 1 snippet, I edited the following:

 #--------------------------------------------------------------------------
 # * Get Attack Power
 #--------------------------------------------------------------------------
 def atk
   n = base_atk
   for i in @states
     n *= $data_states[i].atk_rate / 100.0
   end
   # Position correction
   if self.position == 1
     n *= 80
     n /= 100
   elsif attacker.position == 2
     n *= 60
     n /= 100
   end
   return Integer(n)
 end
 #--------------------------------------------------------------------------
 # * Get Physical Defense Power
 #--------------------------------------------------------------------------
 def pdef
   n = base_pdef
   for i in @states
     n *= $data_states[i].pdef_rate / 100.0
   end
   # Position correction
   if self.position == 1
     n *= 120
     n /= 100
   elsif attacker.position == 2
     n *= 140
     n /= 100
   end
   return Integer(n)
 end


It works beautifully. Thanks for the reply, though!
Project(s):
Dragonblade: First Awakening - Demo not yet available
Dragonblade: The Forum game - Join now!