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

A Small Reminder about Array Iteration

oichidan

959 views

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.

  • Like 1


2 Comments


Recommended Comments

You can simplify this and make it faster I think:

class Window_EquipItem < Window_ItemList
 def projectile?(weapon)
   return false unless weapon.is_a?(RPG::Weapon)
   [5, 29, 6, 8, 30, 7, 9, 10, 11, 24].any? do |x|
     weapon.wtype_id == x
   end
 end
end

Though I suggest you: A. Put the check in a method that can be run on the weapon object, and B. Write some note tag instead of using raw ids. I just use my note field hash script for that kinda thing.

Share this comment


Link to comment

You can simplify this and make it faster I think:

field hash script for that kinda thing.

 

Oh, right. How could I've forgotten the any? method x'D thanks~

 

A. Put the check in a method that can be run on the weapon object

Hmm, you meant to define such method in the RPG::Weapon class?

 

B. Write some notetag instead of using raw ids

Good idea. Regular expressions will do.

Share this comment


Link to comment
×
Top ArrowTop Arrow Highlighted