Game Development Reference
In-Depth Information
Critically Coded
As robust as RMVXA is right out of the box, it has a few quirks that bug me. Thankfully, you can tweak and edit such
things within the Script Editor. This first exercise is very nearly a one-liner. All we need to do is find the code that
governs critical hit rates. Let's go to the Script Editor and run a search for “critical.” Quite a few results will pop up,
but we're interested in the entry that says “ Game_Battler (487): * Calculate Critical Rate of Skill/Item .”
Clicking it takes us to the following method:
#--------------------------------------------------------------------------
# * Calculate Critical Rate of Skill/Item
#--------------------------------------------------------------------------
def item_cri(user, item)
item.damage.critical ? user.cri * (1 - cev) : 0
end
What we see here is a method ( item_cri ) that accepts two parameters when run. For the curious, user is defined
in Scene_ItemBase , while item is defined in Game_BaseItem . As you may recall from earlier in the topic, what we're
looking at right now is a ternary expression. The preceding text is equivalent to the following code. The question mark
takes the place of the then , while the colon does the same for the else .
if item.damage.critical
then user.cri * (1-cev)
else 0
That's the extent of this particular method. Basically, if the skill or item is capable of landing criticals, then the
chance to land a critical is equal to the user's critical hit chance multiplied by 1, minus the enemy's critical evasion
rate (the result is a percentage). Let's create a new page in the Materials section of the Script Editor to hold the altered
version of our item_cri method. Here's the altered result:
class Game_Battler
def item_cri(user, item)
item.damage.critical ? (user.cri + (user.luk * 0.002)) - (luk * 0.002) \
* (1 - cev) : 0
end
end
In my version, I made it so that the luck of both the user and the target influence the ability to land a critical hit.
The backward slash after (luk * 0.002) is used to tell RMVXA to read the next line as part of the previous one.
recall that weird things happen when we split a single expression over multiple lines, if the game decides
to run at all. the backward slash tells rMVxa to run the next line as a direct continuation of the previous one, which, of
course, helps prevent such weirdness.
Note
 
 
Search WWH ::




Custom Search