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

About this blog

Some opinions and writings regarding RGSS3

Entries in this blog

 

Weapon Powers

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'.         Some damage formulas created by using weapon power (though creativity -is- limitless):       The comments box below are open for further discussions. Ideas, suggestions, critiques and feedback are always welcome! <3

oichidan

oichidan

 

A Small Reminder about Array Iteration

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

oichidan

 

Documentation of in-game classes

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

oichidan

 

8.times versus for i in 1..8

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.

oichidan

oichidan

×
Top ArrowTop Arrow Highlighted