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.

Quick Script Modify...? [Resolved]

Ok, I came across this script that I like, what it does is set an attack amount for the weapon. Meaning whatever is in the "attack" spot for weapons or monsters will always be the same. For example, I put in 100 as the monsters attack, all he'll hit is 100.

My request: Is it possible to instead of having a set attack, to have it use a range, for instance a range of 50-100, instead of just hitting 100. Or is their a script that could allow me to set a range, either is fine (edit or different script) The script is posted below:

Code:
class Game_Battler
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : 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
      # Calculate basic damage
      self.damage = attacker.atk
      # 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
end

Thanks for any help given!  :thumb:
 
You can do something along those lines by using a simple edit (a range 50% of total to 100%), so change this line:
Code:
self.damage = attacker.atk
Into:
Code:
min = attack.atk * 0.5
self.damage = rand(min, attacker.atk)
That should do the trick. So if you set 100 for a weapon, damage will range between 50 and 100. If you set 500, it will range between 250 and 500.
 
I replaced: "self.damage = attacker.atk" like you said...but I got this error...

"Script 'Attack' line 14:NameError occurred.
undefined local variable or method `attack' for #<Game_Enemy:0x3d81c00>"

Error line was line 14 (as stated above in the error)

Any ideas...?

here is the script after the edit:

Code:
class Game_Battler
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : 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
      # Calculate basic damage
      min = attack.atk * 0.5
      self.damage = rand(min, attacker.atk)
      # 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
end
 
Now I'm getting another error (I may just be stupid or missing something  :dead: , but...)

Script 'Attack' line 15: ArgumentError occurred.
wrong number of arguments(2 for 1)

so a ya...is something I did......

edited script:

Code:
class Game_Battler
  #--------------------------------------------------------------------------
  # * Applying Normal Attack Effects
  #     attacker : 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
      # Calculate basic damage
      min = attacker.atk * 0.5
      self.damage = rand(min, attacker.atk)
      # 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
end
 
Thanks to both of you! I got it working, had to make a slight edit to Freakboy's suggestion(don't get me wrong, it did work) but  I changed it to this:

Code:
min = attacker.atk * 0.5
max = attacker.atk
self.damage = rand(max - min + min)

It was changed to that on account that the numbers got messed up with the "+ min" outside the parenthesis, so thanks again to both of you! :thumb:
 
Note that with your change, Shadow32o, the damage CAN be 0 with any weapon. The rand function returns a random number between 0 and the supplied value. Freakboy's method returns the minimum value + a random number between 0 and the minimum value, which was in theory what you asked for.

Though, glad it worked it for you in the end.
 

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