• entries
    4
  • comments
    27
  • views
    667

About this blog

Some opinions and writings regarding RGSS3

Entries in this blog

oichidan

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

oichidan

Alright, let this post remind me at times I forget this thing.

 

I've been developing an RPG project lately. At present I wanted to modify the equip screen. I've added a new equip slot (ammunition) using Yanfly's Ace Equip Engine. By the time the user selects a projectile weapon, I want them to select an ammunition from their inventory list.

 

The ammunition list shown will correspond to the equipped weapon (you won't get a list of handgun bullets if you're equipping a bowgun). The following method is to remind me to check weapon IDs whether they're a projectile weapon or not.

=beginThe projectile weapon IDs are 5, 29, 6, 8, 30, 7, 9, 10, 11, 24.We create a method to check the weapon ID and return true if the weapon is a projectile weapon.=endclass Window_EquipItem < Window_ItemList  def projectile?(weapon)    return false unless weapon.is_a?(RPG::Weapon)    result = false    [5, 29, 6, 8, 30, 7, 9, 10, 11, 24].each do |x|      result = true if (weapon.wtype_id == x)    end    return result  endend

 

At present, the capabilities are:

  • Able to equip projectile weapons that uses ammunition.
  • The ammunition is defined as armors in the database, but will later be ammunition in-game using Yanfly's Ace Equip Engine's note-tagging.
  • There's a corresponding item at the database. An example works best.
    • Suppose we're equipping a bowgun.
    • The ammunition equipped is a set of birch bolts.
    • There is a 'birch bolt' item in the database entry.
    • Each time the bowgun is fired, one 'birch bolt' will be lost.
    • The attack will fail if we're running out of ammunition, and a corresponding message will be shown.

    [*]Each weapon has a new 'weapon power' parameter written in the note box by note-tagging (I wrote the code for implementing weapon power). The damage formula will use the weapon power in conjunction with the actor's statistics.

 

I'll post something when this project is starting to make sense.

oichidan

I noticed recently that there hasn't been any documentation made on the in-game classes, such as Cache, DataManager, BattleManager... I had to move back and forth at the script editor, and print out their instance variables via Yanfly's debug script as well as printing them via a line of code for many purposes.

 

It might have been really, really convenient if one makes such documentation for ease of referencing. I guess I'll put a new blog category of RGSS3 Documentation and see what I can do there.

oichidan

I've recently came across a code excerpt that piqued my interest.

# Taken from Ace Equip Engine, Yanfly Engine Ace# All credits and copyrights where they due.8.times {|i| draw_item(0, line_height * i, i) }

The syntax above essentially repeats the instructions in the block given after the times method call as much as 8 times. If we define this code using a for loop, an equivalent would be:

for i in 0..8 do  draw_item(0, line_height * i, i)end

Then a question arose on my mind. Which would be better and why?

 

Let's consider the pros and cons of both code structures.

 

First one is the times function. This function actually calls for an iterator block, requiring evaluation, as it defines a yield clause in its definition. It basically repeats the instructions in the iterator block, yielding a local variable to signal how many times the iteration had performed, as much as n times, where n is the said number. 8.times would mean 8 times.

 

A consideration would be if the number is not a number literal, but is a variable that contains a numeric value. Fine, we can use to_i to convert non-integer to integer values, but what if the variable ends up being a negative number?

exa = 0exa -= rand <= 0.5 ? 1 : -1# ...# at this point, exa would contain either positive or negative number, and we want to perform a loop# of instruction for exa times.exa.to_i.times do |ex|  puts ex + "\n"end

The RPG Maker VX Ace help files mention that if the instance variable that calls the times function is a negative number, it does nothing. It doesn't matter if we mean to check for negative variables, since we can simply just exa.abs.to_i.times do |ex| things out, but if we meant to do a loop (say, if exa is 2, then we want a loop 2 times, as do if exa is -2, and using abs function is tedious in your opinion), in such cases, the for loop is handy.

exa = 0exa -= rand <= 0.5 ? 1 : -1# blablablafor ex in 0..exa do  puts ex + "\n"end 

This way, whether exa is positive or negative, the loop will still perform its job.

 

The downside of a for loop is that while iterator expressions introduces a new block scope for local variables (and thus, we can perform wider range of actions inside the block scope), for loops doesn't introduce such scopes, and so, for has no effects on local variables.

 

Basically, we would say that the following two loops will output the same.

8.times do { |x| puts x }for x in 0..8 do puts x end

So, we can conclude that both of them are equivalent in terms of performance. If we want to perform operations that modify the local variable passed to the loop, then the times and iterator block expression would come handy. Otherwise, the for loop might come in handy as well. The usage of both of them mutually is a choice of each own programmer.