Submit Your Article Guild Wars 2 Forum RPG Maker VX.com
 
RPG Maker
 

 Username:
 Password:
   Not a member? Register!



Home > Tutorials > Ruby Game Scripting System > Element Tagging for Complex Effects

Element Tagging for Complex Effects


This tutorial will teach you how to streamline the process of creating weapons with complex effects so that the effect doesn't need to be coded in indivually for each weapon. Note that all the code samples are from class Game_Battler.

Do you want to create a complex weapon effect that will be used by several weapons, but don't want to code in the effect for every single weapon? If so, this tutorial is for you. First, create an element with a descriptive name. For instance, in the picture at right, I've set up the elements for this tutorial. I want to make weapons that I can give the "Critical+10%" and/or "Critical+20%" properties at will. Now, we need to create some code to return the weapon's critical bonus to the attack resolution method. Code sample 1 illustrates this code.

In this case, I check to see if the attacker passed to the method is a Game_Actor object, since monsters can't use weapons. If it is a Game_Actor object, then I check to see whether the element IDs of the "special" elements are in the weapon's element set, and add the appropriate critical bonus.

picture
Create an element associated with the effect you want to create



Code Sample 1

Code:
def critical_bonus(attacker)
bonus = 0
unless attacker.is_a?(Game_Actor)
return 0
end
if attacker.element_set.include?(2)
bonus += 10
end
if attacker.element_set.include?(3)
bonus += 20
end
return bonus
end


That's not all we need to do, though. If the code change in Code Sample 2 isn't performed, the engine will count these elements when determining the elemental damage modifier for an attack. Therefore, we must delete the "special" element IDs from the element set array. The relevant lines are highlighted in red.

Code Sample 2

Code:
def elements_correct(element_set)
elements = element_set.clone
elements.delete(2)
elements.delete(3)

if elements == []
return 100
end
weakest = -100
for i in elements
weakest = [weakest, self.element_rate(i)].max
end
return weakest
end


Now, for this particular effect, I need to make it so that when someone attacks, their critical hit chance will rise if they have an appropriate weapon equipped. I go to the section of code shown in Code Sample 3, where critical hits are determined, and add the snippet of code shown in red. What you do in this step depends on what effect you're coding. You will need to have enough competence to figure out what needs to be done on your own, since I can't cover every situation.

Code Sample 3

Code:
def attack_effect(attacker)
[...]
self.damage *= elements_correct(attacker.element_set)
self.damage /= 100
if self.damage > 0
if rand(100) < 4 * attacker.dex / self.agi
+ critical_bonus(attacker)
self.damage *= 2
self.critical = true
end
if self.guarding?
self.damage /= 2
end
[...]
end


Details
Tutorial: Element Tagging for Complex Effects
Date Listed: 2008-06-05
Author: RPG Advocate
Total Hits: 2372


Embed
Short URL:

HTML:

BB Code:



RPG RPG Revolution
RPG RPG Revolution is your #1 stop for game development and console RPG games, as well as those created by people like you. Link to us to support us, so we may grow to be better website community for you.

RPG RPG Revolution is an Privacy Policy and Legal