RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Help] Modding battle script to take position into account.

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 89
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):

Code: [Select]
 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:

Code: [Select]
 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!

*
Rep:
Level 98
2010 Best Veteran2014 Best Use of Avatar and Signature Space2014 Best IRC Chatterbox2014 Most Mature Member2014 Best Writer2014 Best Counsel2014 Favorite Staff Member2014 King of RMRK2013 Favorite Staff MemberSecret Santa 2013 ParticipantFor the great victory in the Breakfast War.Secret Santa 2012 Participant2011 Best Writer2011 Best Counsel2010 Funniest Member2010 Best Writer
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.
you awoke in a burning paperhouse
from the infinite fields of dreamless sleep

**
Rep: +0/-0Level 89
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:

Code: [Select]
 #--------------------------------------------------------------------------
  # * 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!