Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Element Tagging for Complex Effects by RPG Advocate
#1
Element Tagging for Complex Effects
by RPG Advocate
saved from Phylomortis.Com


Introduction
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.

Here we go
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.

----Elements----
001: Fire
002: Critical+10%
003: Critical+20%

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.

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.

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
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
Reply }
#2
I remember reading about this technique very long ago. I thought that it was very clever and I realized how much scripts could be used to go beyond the program's limits.
I would say that it was the beginning of me thinking like a scripter lol.
Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Creating a Custom Window by RPG Advocate DerVVulfman 0 3,681 03-11-2009, 06:49 PM
Last Post: DerVVulfman
   Selectable Window Fundamentals by RPG Advocate DerVVulfman 0 3,523 03-11-2009, 06:39 PM
Last Post: DerVVulfman



Users browsing this thread: