Engines

2D Fighter Maker 2002

Game Maker

Fury²

RPG Maker 2000

RPG Maker 2003

RPG Maker VX

RPG Maker XP

RPG Toolkit

Verge

Forums

Games

News

Resources

Scripts

Tutorials

Utilities

Sponsors

Affiliates

Home > Articles > Tutorials > Ruby Game Scripting System (RGSS) > Element Tagging for Complex Effects

Element Tagging for Complex Effects

Author: RPG Advocate
Updated: October 04, 2007

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.


Create an element associated with the effect you want to create

Code Sample 1

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

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

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

¨Ï Copyright 2007 RPG RPG Revolution.

Contact Us