Thread: [Essentials Script] Pokémon TCG mod
View Single Post
Old September 25th, 2012 (9:23 AM).
Umbra's Avatar
Umbra Umbra is offline
Join Date: Aug 2009
Location: Nearby my feet.
Age: 20
Gender: Female
Nature: Calm
Posts: 1,742
Alright, I did understand what you said there.

I prefer a signle class (PokeBattle_Effects) with different variables that will in the outcome suit every needed situation
and to make it more flexible add a custom_code segment which allows you to evaluate a custom code just for incase there are
some un-defined methods required within the effect


We can do something simmilar to Essentials where we must create a code for every move (which is time more time consuming in
my opinion)

the PokeBattle_Effects class can store any type of effect: Move/Ability/Card and can be activated at selected points:
Turn Started/Turn Ended/Coin Flipped/Coin Heads/Coin Tales/Your Turn/Enemy Turn/ect. using an array you can select multiple
points to activate this at. I also did create a sample of what I mean (I only spent about 5 minutes or so on this so it's
not perfect and may seem a little confusing) but this is what I made:


  This is an example of what I would do for Effects, I can make any changes you wish
  You can add to this as you wish and or modify it. If you don't like this system,
  I can completely reconstruct this to Essential's style.
class PokeBattle_Effects

  attr_accessor :type            # Integer -- 0 = card, 1 = move, 2 = ability
  attr_accessor :activation_type # Integer -- when to activate the effect (0= your turn, 1= enemy's turn, 2= coin flip, 3= before attack, 4= during attack, ect.)
  attr_accessor :hold_effect     # Integer -- how many turns to hold the effect
  attr_accessor :effect          # Integer -- 0 = damage, 1 = status, and so forth
  attr_accessor :effect_attribute# Integer -- how much damage?, which status?, ect.
  attr_accessor :chance          # Integer -- Percentage chance of the succes of the effect
  attr_accessor :custom_function # String  -- A string containing ruby code on what to execute (executes every time called)
  attr_accessor :activated       # Boolean -- Is this effect active?
  attr_accessor :turns           # Integer -- Maximum turns to hold the effect (auto selected by hold_effect)
  # startup of the class
  def initialize(type, activation_type, effect, hold_effect = 1, custom_function = "")
    @type = type
    @activation_type = activation_type
    @effect = effect
    @hold_effect = hold_effect
    @custom_function = custom_function
    @turns = hold_effect
  # returns wether the ability is avaible to activate
  # if it is activatable it reset the activation turns (unless already active)
  def activatable?(a_type)
    @hold_effect = @turns if @activation_type == a_type && !@activated
    @activated = true if @activation_type == a_type && !@activated
    return @activation_type == a_type
  # returns if the effect is currently active
  def updatable?
    return @activated
  # updates and returns an array (the length will be 1 if it did not do anything)
  def update
    @hold_effect -= 1
    destroy = @hold_effect > 0
    ret = [destroy]
    if rand(100-@chance) == 0
      ret.push(eval(@custom_function)) if @custom_function != ""
    return ret

also, if you are going to read data ini-style like essentials does I made a small tool for this too:


  Just a handy tool for reading ini files
  Reads ini files and stores them in data.
  You can get values like so:
  ini.read_value(section(string or int), variable(string or int), default(anything))
  returns the value of the ini you set, but returns default if it does not exist

class IniReader
  attr_accessor :data
  def initialize(ini)
    array = IO.readlines(ini)
    @data = {}
    startoff_section = "["
    section_name = ""
    section_hash = {}
    for i in 0..array.length-1
      if array[i][0] == startoff_section[0]
        if i != 0
          @data[section_name] = section_hash
        section_name = array[i].split("[")[1].split("]")[0]
      elsif array[i].count("=") != 0
        tary = array[i].split("=")
        value = ""
        for i in 0..tary.length-2
    @data[section_name] = section_hash
  def read_value(section, variable, default=-1)
    section = "#{section}"
    variable = "#{variable}"
    if @data[section][variable] == nil
      ret = default
      ret = @data[section][variable]
    return ret

n ="Game.ini")
print n.read_value("Game", "Title")

so if you have a different idea or have improvements for the PokeBattle_Effects class, let me know.