Jump to content
  • entries
    4
  • comments
    27
  • views
    2,122

Weapon Powers

oichidan

990 views

Alright, so... I know there are many scripts about weapon powers out there, but I wrote something for use within my project. Please feel free to use it the way you'd like to.

 

Features:

  • A new parameter: Weapon Power (WP). Define each weapon and armor's 'weapon power' by note-tagging in the database.
  • Rewrite performance considerations by factoring the weapon power into the equation, meaning that when we select 'optimize', weapon power will also be considered.

Here's the code. As always, insert it below the materials section above Main. Place it on top of scripts that will depend on 'wp'.

 

 

# WEAPON POWERS# ------------------------ oichidan | 2017# Originally intended for use within #TMoJ RPG# Description# This script adds a new property 'wp' in the RPG::Weapon class. Each weapon and armor will now# have weapon power parameter specified by note-tagging in the database. The weapon power will also# be factored when optimizing equipment and can be used in damage equations as well.# This script is meant to be used in RPG Maker VX Ace.# Notetags (Place it in weapon and armors)# 1. <WEAPON POWER: xx>#    Sets the weapon/armor 'weapon power' to xx.#    We can also use weapon_power, WP, wp, WEP, wep, and weapon power, #    case insensitive, instead of WEAPON POWER in the notetag format above.# Usage# 1. Obtain the equipment by using (Game_Actor).equips[0] for the weapon, [1] for the second slot#    (if dual-wield), and other numbers you're using as to place your equipment slots.#    For example, in a damage equation: a.equips[0] refers to the topmost weapon equipped#    (in case you're using 'vanilla' RPG Maker VX Ace, that is, the equipment slots have yet to#     be modified).# 2. Reference the weapon power with the 'wp' or 'power' property.#    a.equips[0].wp refers to the weapon power equipped in the topmost equipment slot of the actor.#    REMINDER: the 'wp' parameter will be invalid if:#    - The weapon power has not been set#    - The actor is not equipping any weapons#    At such cases, exceptions will raise.# Note: The 'wp' property is read-write, meaning that you -can- change its value mid-game.# Here's the script. Feel free to use it the way you'd love to.# There are still errors here and there, but if this eventually comes of use, I'm glad.# You are not required to credit me at anyway, and you're free to use it in commercial games.# But if you do, I'd really appreciate it. Credit me as 'oichidan' or 'Aldian Hudaya',# and the copy of the game would be much appreciated, too.# Cheers! -oichidan | Aldian Hudaya# -------------------------------------------------------------------------------------module DataManager    class <<self; alias load_database_wp load_database; end    def self.load_database      load_database_wp      load_notetags_wp    end        def self.load_notetags_wp      for weapon in $data_weapons        next if weapon.nil?        weapon.load_notetag_wp      end      for armor in $data_armors        next if armor.nil?        armor.load_notetag_wp      end    end      endclass RPG::Weapon < RPG::EquipItem  attr_accessor :wp  alias :power :wp    def load_notetag_wp    wep = 0    self.note.split(/[\r\n]+/).each { |line|      case line        when /<(:WEAPON_POWER|weapon_power|WP|wp|WEP|wep|WEAPON POWER|weapon power):[ ](\d+)>/i          wep = $2.to_i          @wp = wep      end    }  end    # Overwrite: Performance  def performance    self.wp + params[2] + params[4] + params.inject(0) {|r, v| r += v}  end  endclass RPG::Armor < RPG::EquipItem  attr_accessor :wp  alias :power :wp  def load_notetag_wp    wep = 0    self.note.split(/[\r\n]+/).each { |line|      case line        when /<(:WEAPON_POWER|weapon_power|WP|wp|WEP|wep|WEAPON POWER|weapon power):[ ](\d+)>/i          wep = $2.to_i          @wp = wep      end    }  end    # Overwrite: Performance  def performance    self.wp + params[0] + params[1] + params[3] + params.inject(0) {|r, v| r += v}  endend

 

 

 

Some damage formulas created by using weapon power (though creativity -is- limitless):

 

# Some damage formulas using the 'wp' property and the weapon power script. # Inspired heavily by Final Fantasy Tactics: War of The Lions (Square Enix).# Place the damage formula below in the damage formula textbox in the database.# Reminder: - Set the weapon power for each weapon accordingly.# There are many a thousand ways or more to implement different skills for different weapons,# or at least different formula for different kinds of weapon attacks. The formulas presented# below are merely things that might inspire you in creating damage formulas that differs for each# weapon.# For the other hand in a dual-wield weapon, a.equips[0] becomes a.equips[1].# KNIFE, LONGBOW(a.atk + a.agi) / 2 * a.equips[0].wp# SWORD, CROSSBOWa.atk * a.equips[0].wp# FLAIL, AXErand(a.atk) * a.equips[0].wp # rand(x) means to generate a random number from 0 to x.# NINJATOa.agi * a.equips[0].wp# STAFFa.mat * a.equips[0].wp# PISTOLa.equips[0].wp**2 # The same as a.equips[0].wp * a.equips[0].wp# BOOK(a.mat + a.atk) / 2 * a.equips[0].wp# The possibilities are limitless! 

 

 

 

The comments box below are open for further discussions. Ideas, suggestions, critiques and feedback are always welcome! <3

  • Like 1


3 Comments


Recommended Comments

Interesting... I kinda wanted to do something like this myself at some point but I am still not sure how to handle dual wielding. Well, really I want to do something like the SaGa series where you can hold a bunch of weapons and select what one you wanna use each round but eh. Personally I would have had each weapon have it's own attach formula rather then just a value though.

Share this comment


Link to comment

Interesting... I kinda wanted to do something like this myself at some point but I am still not sure how to handle dual wielding. Well, really I want to do something like the SaGa series where you can hold a bunch of weapons and select what one you wanna use each round but eh. Personally I would have had each weapon have it's own attach formula rather then just a value though.

 

In my project, I defined a 'regular attack' method that checks the equipped weapon and crafts the damage value based on a given formula, and it also works with dual wield too. Well, I can also use a custom formula by note-tagging, but nah, I'll go with this one for now.

 

So I put this code on the damage formula for the default attack skill:

a.formulae(a, 

Then define this method in the Game_Battler class:

 

 

class Game_Battler < Game_BattlerBase
  def formulae(a, 
    w0  = a.equips[0]
    w1  = a.equips[1] if a.dual_wield?
    wp0 = w0.wp rescue 0
    wp1 = w1.wp if w1 rescue 0
    result = 0
    # In case of projectiles.
    # Note that all projectiles in my project is two-handed,
    # so dual wield will not be in the case.
    # Reminder: Put a projectile check on the weapon class
    # I've set my project so that equip slot #5 (Ammunition)
    # can only be enabled if the actor equips a projectile weapon
    wp0 += a.equips[5].wp if a.equips[5] rescue 0

=begin
 Note: I've also written another script in my project that implements Bravery and Faith
       similar to Final Fantasy Tactics. Each character (Actor of Enemy) has their own
       bravery and faith level, and this determines damage outcomes and is used in various
       damage formulas.
       
       So a.bra refers to the Bravery level (0-100) of 'a' and a.fa refers to the Faith
       level of 'a'.
       
       If you're interested, I can also share the script here.
=end
    if a.enemy? # The enemy is attacking
      result = ((a.atk*a.bra)/100)*a.atk # Yeah I know the parentheses can be ditched out.
                                         # But I'll do with this, just in case.
      result += ((a.atk*a.bra)/100)*a.atk if w1 # It could've been result *= 2 if a.dual_wield?
                                                # but I plan to differ each enemy attack
                                                # but still had no idea how it'd be, so I'll go
                                                # with this just in case.
    else
      if w0.nil? # Barehanded
        result = ((a.atk*a.bra)/100)*a.atk
        result *= a.dual_wield? ? 2 : 1
        # I've made it so that if you equip at least one weapon, barehanded dual-wield
        # will be invalid, and that weapon alone will be used in attacks.
      else
        result = weapon_damage(w0)  
        result += weapon_damage(w1) if a.dual_wield?
        # The weapon_damage method is defined in another file. It basically calculates
        # the damage based on the weapon passed to the method as parameter.
      end
    end
    
    result
  end
end

Notes

Yeah, I know, the 'b' parameter that references to the target is indeed unused, but if at a time later I want to use the target of the action, I don't have to recode everything.

 

 

 

Hmm... The ability of being able to choose weapons for each turn is interesting.

Share this comment


Link to comment

Custom formulas are neat at least because you can make all sorts of weapons that use different stats and styles. You can replace 'atk' with 'str' for example, and have some weapon damage be based on your agi or mag or whatever. You can have some that take mixes of stats or fixed power, some that do other things. It could be possible to go one step further and let you choose the default attack skill per weapon.

 

Yeah the SaGa series has lots of interesting and unusual combat mechanics like that. It wasn't based on the same kind of attack/defend/magic/item menu system that Final Fantasy was. Instead most of the older ones (also known as the Final Fantasy Legend 1 and 2, 3 used a Final Fantasy attack/defend/magic/item system for some reason) just gave you a menu of equipped items or 'talents' you could use to attack with while the newer ones (Romancing SaGa series and beyond, with maybe one or two exceptions) had the left and right buttons choose your weapon and up and down choose different moves you could use with them (spells got their own 'weapon' selection, and items usually had to be equipped in weapon slots for you to be able to use them in battle anyway). This means that you could, and often would, equip a few weapons with different abilities and choose between them depending on the situation. Maybe you wanna give someone a powerful sword for most attacks, but there is this staff with a built in healing spell or a mace with a nice AOE attack. In the SaGa series, you can usually equip all three and be able to use any of them in any given round (though there are reasons not to do this, you usually want to focus on the skills for one weapon type for any one character, shields and most usable items often take weapons slots, and most of the time you wanna stick with using your most powerful weapon anyway).

Share this comment


Link to comment
×
Top ArrowTop Arrow Highlighted