Battle Algorithm (RESOLVED)

Started by G_G, March 22, 2009, 01:21:37 am

Previous topic - Next topic

G_G

March 22, 2009, 01:21:37 am Last Edit: March 22, 2009, 09:51:24 am by game_guy
This is a simple one and its for a certain part of this game I am making. First of all I only need the enemies do to the damage there Strength is set to, regardless of the actors other stats. So if an enemies strength is set to 1 it'll do one damage. I also need it the same for weapons. If a weapon's strength is set to 1 it'll do one damage.

And if it is possible could you make it only use the algorithms if Switch Number 1 is on. Please help thank you in advance.

shdwlink1993

Made very quickly. Lemme know if there's any bugs.
Battle Algorithm: ShowHide

class Game_Battler
 
  def attack_effect(attacker)
    # Clear critical flag
    self.critical = false
    # First hit detection
    hit_result = (rand(100) < attacker.hit)
    # If hit occurs
    if hit_result == true
      if !$game_switches[1]
        # Calculate basic damage
        atk = [attacker.atk - self.pdef / 2, 0].max
        self.damage = atk * (20 + attacker.str) / 20
        # 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
          self.damage /= 2 if self.guarding?
        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)
      else
        self.damage = attacker.str
      end
    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
 
end
Stuff I've made:




"Never think you're perfect or else you'll stop improving yourself."

"Some people say the glass is half full... some half empty... I just wanna know who's been drinking my beer."

G_G

Not sure if I wasnt descriptive enough or not sorry if I wasnt but the enemy still did over than the strength I set it to.
I want it like this
Enemy's Strength is 10 and I want it to do exactly 10 damage to me no matter what the other stats are. I also want it for weapons so if I set the bronze sword attack to 10 it'll do exactly 10 damage reguarding the enemies other stats.

shdwlink1993

You were descriptive enough. It's just that the script didn't work as intended.

This will do it. This works differently from the above one in that I actually aliased the code like a good person should and not just assume you used the defaults :shy:. I wasn't sure if you wanted the character's to be able to miss or not, so there are two versions. And I did actually test this. xD

Spoiler: ShowHide
Code: Can Miss
class Game_Battler
  alias ggattack attack_effect
  def attack_effect(attacker)
    if $game_switches[1]
      self.critical = false
      hit_result = (rand(100) < attacker.hit)
      if hit_result == true
        self.damage = attacker.str
        remove_states_shock
        self.hp -= self.damage
        @state_changed = false
        states_plus(attacker.plus_state_set)
        states_minus(attacker.minus_state_set)
      else
        self.damage = 'Miss'
      end
    else
      ggattack(attacker)
    end
    return true
  end
end


Code: Cannot Miss
class Game_Battler
  alias ggattack attack_effect
  def attack_effect(attacker)
    if $game_switches[1]
      self.critical = false
      self.damage = attacker.str
      remove_states_shock
      self.hp -= self.damage
      @state_changed = false
      states_plus(attacker.plus_state_set)
      states_minus(attacker.minus_state_set)
    else
      ggattack(attacker)
    end
    return true
  end
end
Stuff I've made:




"Never think you're perfect or else you'll stop improving yourself."

"Some people say the glass is half full... some half empty... I just wanna know who's been drinking my beer."

G_G

Works great shdwlink *powers up* thank you