Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Elemental defense debuff code

Wolfus

Member

I'm trying to create an elemental debuff system in RPGMaker XP but it's proving to be difficult. Sorry for the wall of text.

Our example element will be fire. Using "states," you can create resistances to various elements. It is easy to create a spell that gives a player the "fire resistance" state, reducing all incoming fire damage by 50%. However, I can't figure out how to do the opposite.

I would like to create a spell that would increase fire damage taken by 50%. When creating enemies, you can set their "Elemental Efficiency" which adjusts how much damage they take from various elements. However, you can't adjust this in combat as there is no command for it.

--------------------

I have a theory how this could work: create a state called Fire Debuff, and create a spell that applies the Fire Debuff. Make every fire spell trigger a common event that does a condition branch and checks if the enemy has the fire debuff on. We could store the damage done in a variable, then multiply the variable times 2 and do a force damage command using that variable. Everything should work, the only problem is storing the damage in a variable.

The ultimate goal is to mix elements. A person with a fire debuff would take fire damage normally, but would be weaker against water elements. It would be the same for a lightning debuff and taking extra damage from earth spells (if they were opposites in your game). If each character mastered different elements, they would have to combo their spells and manipulate the debuffs and elemental strengths to maximize damage.

Does anyone have any ideas on how to make this happen? Thank you in advance for any help or even just taking the time to read this.
 

Atoa

Member

I have this add-on for my ACBS, that with an small edits, change how RMXP manages resistances.

Code:
#==============================================================================

# New Resistance Sustem

# By Atoa

#==============================================================================

# This script allows you to set an new style for elemental and status

# resistance.

# You can set resistances direct to actors (and not only to classes),

# and set increases/decreases of resistance to equipments and states.

# You can also set how the resistances will stack.

#==============================================================================

 

module Atoa

  # Do not remove or change these lines

  State_Resist = {}

  Element_Resist = {}

  # Do not remove or change these lines

 

  # Resistance values.

  #                  A  , B , C , D , E , F

  States_Table = [0, 100, 100, 80, 40, 0, 0]

  #                    A ,  B ,  C , D , E, F

  Element_Table = [0, 200, 150, 100, 50, 0, -100]

 

  # Style of the resistance acumulation

  Addition_Type = 0

  # 0 = The values are added, considering all values

  # 1 = The values are added, considering only the higher and the lower values

  # 2 = The value used are the average, considering all values

  # 3 = The value used are the average, considering only the higher and the lower values

 

  # Element_Resist[Type] = {Type_ID => {Element_ID => Resist_Value}

  #   Type = type of the object that gives the resistance

  #     'Actor' = actor's natural resistance

  #     'State' = resistance given by states

  #     'Armor' = resistance given by armors

  #     'Weapon' = resistance given by weapons

  #   Type_ID = id of the actor, state, armor or weapon

  #   Element_ID = ID of the element that will have the value change

  #   Resist_Value = Resistance change value, must be an Integer.

  #     positive values are increases in resistance, negative are reductions.

  #     E.g.: an actor imune to fire equips an armor that gives -1 fire resistance

  #       will have the fire resistance changed from imune to resistant.

  Element_Resist['Actor'] = {}

 

  Element_Resist['State'] = {}

 

  Element_Resist['Armor'] = {}

 

  Element_Resist['Weapon'] = {}

 

 

  # State_Resist[Type] = {Type_ID => {State_ID => Resist_Value}

  #   Type = type of the object that gives the resistance

  #     'Actor' = actor's natural resistance

  #     'State' = resistance given by states

  #     'Armor' = resistance given by armors

  #     'Weapon' = resistance given by weapons

  #   Type_ID = id of the actor, state, armor or weapon

  #   State_ID = ID of the state that will have the value change

  #   Resist_Value = Resistance change value, must be an Integer.

  #     positive values are increases in resistance, negative are reductions.

  State_Resist['Actor'] = {}

 

  State_Resist['State'] = {}

 

  State_Resist['Armor'] = {}

 

  State_Resist['Weapon'] = {}

  #=============================================================================

end

 

#==============================================================================

# ■ Atoa Module

#==============================================================================

$atoa_script = {} if $atoa_script.nil?

$atoa_script['Atoa New Resistances'] = true

 

#==============================================================================

# ■ RPG::Weapon

#------------------------------------------------------------------------------

# Classe que gerencia as armas

#==============================================================================

 

class RPG::Weapon

  #--------------------------------------------------------------------------

  # Incluir modulo de configuração

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  # Resistencias elementais

  #--------------------------------------------------------------------------

  def element_resist

    resist = Element_Resist.dup

    set_element_resist = []

    for i in 1...$data_system.elements.size

      if resist['Weapon'] != nil && resist['Weapon'][@id] != nil &&

         resist['Weapon'][@id][i] != nil

        set_element_resist[i] = resist['Weapon'][@id][i]

      else

        set_element_resist[i] = 0

      end

    end

    return set_element_resist

  end

  #--------------------------------------------------------------------------

  # Resistencias contra efeitos

  #--------------------------------------------------------------------------

  def state_resist

    resist = State_Resist.dup

    set_state_resist = []

    for i in 1...$data_states.size

      if resist['Weapon'] != nil && resist['Weapon'][@id] != nil &&

         resist['Weapon'][@id][i] != nil

        set_state_resist[i] = resist['Weapon'][@id][i]

      else

        set_state_resist[i] = 0

      end

    end

    return set_state_resist

  end

end

 

#==============================================================================

# ■ RPG::Armor

#------------------------------------------------------------------------------

# Classe que gerencia as armaduras

#==============================================================================

 

class RPG::Armor

  #--------------------------------------------------------------------------

  # Incluir modulo de configuração

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  # Resistencias elementais

  #--------------------------------------------------------------------------

  def element_resist

    resist = Element_Resist.dup

    set_element_resist = []

    for i in 1...$data_system.elements.size

      if resist['Armor'] != nil && resist['Armor'][@id] != nil &&

         resist['Armor'][@id][i] != nil

        set_element_resist[i] = resist['Armor'][@id][i]

      else

        set_element_resist[i] = 0

      end

    end

    return set_element_resist

  end

  #--------------------------------------------------------------------------

  # Resistencias contra efeitos

  #--------------------------------------------------------------------------

  def state_resist

    resist = State_Resist.dup

    set_state_resist = []

    for i in 1...$data_states.size

      if resist['Armor'] != nil && resist['Armor'][@id] != nil &&

         resist['Armor'][@id][i] != nil

        set_state_resist[i] = resist['Armor'][@id][i]

      else

        set_state_resist[i] = 0

      end

    end

    return set_state_resist

  end

end

 

#==============================================================================

# ■ RPG::State

#------------------------------------------------------------------------------

# Classe que gerencia os efeitos

#==============================================================================

 

class RPG::State

  #--------------------------------------------------------------------------

  # Incluir modulo de configuração

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  # Resistencias elementais

  #--------------------------------------------------------------------------

  def element_resist

    resist = Element_Resist.dup

    set_element_resist = []

    for i in 1...$data_system.elements.size

      if resist['State'] != nil && resist['State'][@id] != nil &&

         resist['State'][@id][i] != nil

        set_element_resist[i] = resist['State'][@id][i]

      else

        set_element_resist[i] = 0

      end

    end

    return set_element_resist

  end

  #--------------------------------------------------------------------------

  # Resistencias contra efeitos

  #--------------------------------------------------------------------------

  def state_resist

    resist = State_Resist.dup

    set_state_resist = []

    for i in 1...$data_states.size

      if resist['State'] != nil && resist['State'][@id] != nil &&

         resist['State'][@id][i] != nil

        set_state_resist[i] = resist['State'][@id][i]

      else

        set_state_resist[i] = 0

      end

    end

    return set_state_resist

  end

end

 

#==============================================================================

# ■ Game_Battler

#------------------------------------------------------------------------------

# Esta classe gerencia os jogadores da batalha.

# Esta classe identifica os Aliados ou Heróis como (Game_Actor) e

# os Inimigos como (Game_Enemy).

#==============================================================================

 

class Game_Battler

  #--------------------------------------------------------------------------

  # Incluir modulo de configuração

  #--------------------------------------------------------------------------

  include Atoa

  #--------------------------------------------------------------------------

  # Definir chances base e sucesso dos efeitos

  #     state_id : ID do efeito

  #--------------------------------------------------------------------------

  def state_rate(state_id)

    result = state_rate_ranks(state_id)

    return result

  end

  #--------------------------------------------------------------------------

  # Aplicar Troca de Status (+)

  #     plus_state_set  : Trocar Status (+)

  #--------------------------------------------------------------------------

  def states_plus(plus_state_set)

    effective = false

    for i in plus_state_set

      unless self.state_guard?(i)

        effective |= self.state_full?(i) == false

        if $data_states[i].nonresistance

          @state_changed = true

          add_state(i)

        elsif self.state_full?(i) == false

          state = state_rate(i)

          if rand(100) < state

            @state_changed = true

            add_state(i)

          end

        end

      end

    end

    return effective

  end  

  #--------------------------------------------------------------------------

  # Cálculo do Dano do Atributo

  #     element_set : atributo

  #--------------------------------------------------------------------------

  def elements_correct(element_set)

    value = 100

    absorb = false

    for i in element_set

      element = element_rate_rank(i)

      element *= -1 if element < 0 and absorb == true

      value *= element / 100.0

      absorb = true if element < 0 and absorb == false

    end

    return value.to_i

  end

end

 

#==============================================================================

# ■ Game_Actor

#------------------------------------------------------------------------------

# Esta é a classe que trata dos Heróis na Batalha.

#==============================================================================

 

class Game_Actor < Game_Battler

  #--------------------------------------------------------------------------

  # Configuração

  #     actor_id : ID do Herói

  #--------------------------------------------------------------------------

  alias setup_newresist setup

  def setup(actor_id)

    setup_newresist(actor_id)

    @element_resist = element_resist

    @state_resist = state_resist

  end

  #--------------------------------------------------------------------------

  # Definição de armas

  #--------------------------------------------------------------------------

  def weapons

    return [$data_weapons[@weapon_id]]

  end

  #--------------------------------------------------------------------------

  # Definição de armaduras

  #--------------------------------------------------------------------------

  def armors

    result = []

    result << $data_armors[@armor1_id]

    result << $data_armors[@armor2_id]

    result << $data_armors[@armor3_id]

    result << $data_armors[@armor4_id]

    return result.compact

  end

  #--------------------------------------------------------------------------

  # Definição de equipamentos

  #--------------------------------------------------------------------------

  def equips

    return weapons + armors

  end

  #--------------------------------------------------------------------------

  # Resistencias elementais

  #--------------------------------------------------------------------------

  def element_resist

    resist = Element_Resist.dup

    set_element_resist = []

    for i in 1...$data_system.elements.size

      if resist['Actor'] != nil && resist['Actor'][@actor_id] != nil &&

         resist['Actor'][@actor_id][i] != nil

        set_element_resist[i] = resist['Actor'][@actor_id][i]

      else

        set_element_resist[i] = 0

      end

    end

    return set_element_resist

  end

  #--------------------------------------------------------------------------

  # Mudar Resistencias elementais

  #     elements : novas resistencias

  #--------------------------------------------------------------------------

  def element_resist=(elements)

    return @element_resist unless elements.is_a?(Hash)

    resist = elements.dup

    @element_resist = []

    for i in 1...$data_system.elements.size

      if resist != nil && resist[i] != nil

        @element_resist[i] = resist[i]

      else

        @element_resist[i] = 0

      end

    end

    return @element_resist

  end

  #--------------------------------------------------------------------------

  # Resistencias contra efeitos

  #--------------------------------------------------------------------------

  def state_resist

    resist = State_Resist.dup

    set_state_resist = []

    for i in 1...$data_states.size

      if resist['Actor'] != nil && resist['Actor'][@actor_id] != nil &&

         resist['Actor'][@actor_id][i] != nil

        set_state_resist[i] = resist['Actor'][@actor_id][i]

      else

        set_state_resist[i] = 0

      end

    end

    return set_state_resist

  end

  #--------------------------------------------------------------------------

  # Resistencias contra efeitos

  #     elements : novas resistencias

  #--------------------------------------------------------------------------

  def state_resist=(states)

    return @state_resist unless states.is_a?(Hash)

    resist = states.dup

    @state_resist = []

    for i in 1...$data_states.size

      if resist != nil && resist[i] != nil

        @state_resist[i] = resist[i]

      else

        @state_resist[i] = 0

      end

    end

    return @state_resist

  end

  #--------------------------------------------------------------------------

  # Definir Resistencia elemental

  #--------------------------------------------------------------------------

  def elemental_resist(element_id)

    @element_resist[element_id] = 0 if @element_resist[element_id].nil?

    value = $data_classes[@class_id].element_ranks[element_id]

    case Addition_Type

    when 0,2

      value += @element_resist[element_id]

      element_size = 1

      for eqp in equips

        value += eqp.element_resist[element_id]

        element_size += 1 if eqp.element_resist[element_id] != 0

      end

      for state in @states

        value += $data_states[state].element_resist[element_id]

        element_size += 1 if $data_states[state].element_resist[element_id] != 0

      end

      if $atoa_script['Atoa Equip Set']

        for set in @set_elemental_resist

          value += set[element_id] if set[element_id] != nil

          element_size += 1 if set[element_id] != nil and set[element_id] != 0

        end

      end

      value /= element_size if Addition_Type == 2      

    when 1,3

      base_resist = set_base_elemental_resist(value, element_id)

      base_resist.sort! {|a,b| b <=> a}

      h = base_resist.first.nil? ? 0 : base_resist.first

      l = base_resist.last.nil? ? 0 : base_resist.last

      addition = h + l

      addition /= 2 if  h > 0 and l < 0 and Addition_Type == 3

      value = 3 + addition

    end

    return [[value.to_i, 6].min, 1].max

  end

  #--------------------------------------------------------------------------

  # Definir valores base de resistencia elemental

  #--------------------------------------------------------------------------

  def set_base_elemental_resist(value, element_id)

    base_resist = [value - 3, @element_resist[element_id]]

    for eqp in equips

      base_resist << eqp.element_resist[element_id]

    end

    for state in @states

      base_resist << $data_states[state].element_resist[element_id]

    end

    if $atoa_script['Atoa Equip Set']

      for set in @set_elemental_resist

        base_resist << set[element_id] if set[element_id] != nil

      end

    end

    return base_resist

  end

  #--------------------------------------------------------------------------

  # Definir Resistencia contra efeitos

  #--------------------------------------------------------------------------

  def states_resist(state_id)

    @state_resist[state_id] = 0 if @state_resist[state_id].nil?

    value = $data_classes[@class_id].state_ranks[state_id]

    case Addition_Type

    when 0,2

      value += @state_resist[state_id]

      state_size = 1

      for eqp in equips

        value += eqp.state_resist[state_id]

        state_size += 1 if eqp.state_resist[state_id] != 0

      end

      for state in @states

        value += $data_states[state].state_resist[state_id]

        state_size += 1 if $data_states[state].state_resist[state_id] != 0

      end

      if $atoa_script['Atoa Equip Set']

        for set in @set_state_resist

          value += set[state_id] if set[state_id] != nil

          element_size += 1 if set[state_id] != nil and set[state_id] != 0

        end

      end

      value /= state_size if Addition_Type == 2

    when 1,3

      base_resist = set_base_state_resist(value, state_id)

      base_resist.sort! {|a,b| b <=> a}

      h = base_resist.first.nil? ? 0 : base_resist.first

      l = base_resist.last.nil? ? 0 : base_resist.last

      addition = h + l

      addition /= 2 if  h > 0 and l < 0 and Addition_Type == 3

      value = 3 + addition

    end

    return [[value.to_i, 6].min, 1].max

  end

  #--------------------------------------------------------------------------

  # Definir valores base de resistencia elemental

  #--------------------------------------------------------------------------

  def set_base_state_resist(value, state_id)

    base_resist = [value - 3, @state_resist[state_id]]

    for eqp in equips

      base_resist << eqp.state_resist[state_id]

    end

    for state in @states

      base_resist << $data_states[state].state_resist[state_id]

    end

    if $atoa_script['Atoa Equip Set']

      for set in @set_state_resist

        base_resist << set[state_id] if set[state_id] != nil

      end

    end

    return base_resist

  end

  #--------------------------------------------------------------------------

  # Definir multiplicador base do dano

  #     element_id : ID do elemento

  #--------------------------------------------------------------------------

  def element_rate_rank(element_id)

    table = Element_Table

    result = table[elemental_resist(element_id)]

    return result

  end

  #--------------------------------------------------------------------------

  # Definir chances base e sucesso dos efeitos

  #     state_id : ID do efeito

  #--------------------------------------------------------------------------

  def state_rate_ranks(state_id)

    table = States_Table

    result = table[states_resist(state_id)]

    return result

  end

  #--------------------------------------------------------------------------

  # Definir Defesa contra Status

  #     state_id : ID do status

  #--------------------------------------------------------------------------

  def state_guard?(state_id)

    for eqp in equips

      next if eqp.is_a?(RPG::Weapon)

      return true if eqp.guard_state_set.include?(state_id)

    end

    return false

  end

end

 

#==============================================================================

# ■  Game_Enemy

#------------------------------------------------------------------------------

# Este é a classe que trata dos inimigos. Esta classe é usada juntamente com

# a classe Game_Troop ($game_troop)

#==============================================================================

 

class Game_Enemy < Game_Battler

  #--------------------------------------------------------------------------

  # Definir multiplicador base do dano

  #     element_id : ID do elemento

  #--------------------------------------------------------------------------

  def element_rate_rank(element_id)

    table = Element_Table

    result = table[$data_enemies[@enemy_id].element_ranks[element_id]]

    value = $data_enemies[@enemy_id].element_ranks[element_id]

    case Addition_Type

    when 0,2

      element_size = 1

      for i in @states

        value += $data_states[i].element_resist[element_id]

        element_size += 1 if $data_states[i].element_resist[element_id] != 0

      end

      value /= element_size if Addition_Type == 2

    when 1,3

      base_resist = [value - 3]

      for i in @states

        base_resist << $data_states[i].element_resist[element_id]        

      end

      base_resist.sort! {|a,b| b <=> a}

      h = base_resist.first.nil? ? 0 : base_resist.first

      l = base_resist.last.nil? ? 0 : base_resist.last

      addition = h + l

      addition /= 2 if  h > 0 and l < 0 and Addition_Type == 3

      value = 3 + addition

    end

    result = table[[[value.to_i, 6].min,1].max]

    return result

  end

  #--------------------------------------------------------------------------

  # Definir chances base e sucesso dos efeitos

  #     state_id : ID do efeito

  #--------------------------------------------------------------------------

  def state_rate_ranks(state_id)

    table = States_Table

    result = table[$data_enemies[@enemy_id].state_ranks[state_id]]

    value = $data_enemies[@enemy_id].state_ranks[state_id]

    case Addition_Type

    when 0,2

      state_size = 1

      for i in @states

        value += $data_states[i].state_resist[state_id]

        state_size += 1 if $data_states[i].state_resist[state_id] != 0

      end

      value /= state_size if Addition_Type == 2

    when 1,3

      base_resist = [value - 3]

      for i in @states

        base_resist << $data_states[i].state_resist[state_id]        

      end

      base_resist.sort! {|a,b| b <=> a}

      h = base_resist.first.nil? ? 0 : base_resist.first

      l = base_resist.last.nil? ? 0 : base_resist.last

      addition = h + l

      addition /= 2 if  h > 0 and l < 0 and Addition_Type == 3

      value = 3 + addition

    end

    result = table[[[value.to_i, 6].min,1].max]

    return result

  end

end
With it you can create states that changes the elemental resist, not only increasing.
 

Wolfus

Member

Your script looks pretty good. I've tried testing it out but immediately got an error on "line 273".

In the "read me" in your script, it says "All scripts bellow Main are optional Add-Ons for the ACBS, and aren't vital for the systems. If you want to use any of them, move the script to above main, leaving them just bellow the script "ACBS | Battle Main Code". However, there is no "ACBS |Battle Main Code" in the script at all.

Maybe I'm doing something wrong or maybe the name of a script has changed. The script looks really cool and I'd love to try it ... but for now I just can't figure it out.
 

Atoa

Member

@Wolfus
Are you using the ACBS? this script i posted here is a non-ACBS version.
If you're not using the ACBS, *ignore* all referecences to the ACBS on the script, just paste it above Main, bellow all other scripts.

If you are using the ACBS, you should know that the current english version has some problems, so you should wait for the next update.

Also the like 273 is a blank line, there's no way for it to return an error like this.
I just test this script on an new project and no error was returned.
 

Wolfus

Member

Hello again. Thank you for being patient with me. I found the source of the problem I was having.

I downloaded your ACBS demo and copied the script from that to my game. I changed the script to the one you posted here and now the line 273 error is gone.

Now I have a new problem. If I use the script with no adjustments made (only copy+paste), I get an error when an enemy uses any spell:

spellerror.jpg


I tried using the script in a fresh project and I wasn't getting any errors. The only other scripts I'm using is a Blackjack mini-game and Blizzard's Tons of Addons. Most of the addons in Blizzard's Tons of Addons is disabled, however. I tried turning off any scripts that affect battle but the client still crashes.

Is this a problem with conflicting scripts or is something in my database not compatible with the script?
 

Atoa

Member

You didn't undestood, DON'T use the ACBS scripts.
Use the one i posted on this topic, it's edited to work without the ACBS.

I double checked it on an new demo and everything is fine. So if it don't work it's most likely incompatibility.

BTW the tons of add-ons changes a LOT of things, so he may be the one causing the problems.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top