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.

More variety in elements.

I have looked for a script that does this, but I haven't been able to find it...
I want to make a status effect that instead of only lowering your damage to a certain element by half, it gives you the option of completely change it to a new letter (like you have C resistance to something, with the status, it can be set to A or F or whatever)
that way you could receive 0 damage from skills from that element, or absorb it, or to the contrary, be a lot weaker against it...
I hope it's not something TOO complicated, I'm guessing it could be done checking the state ID in the script where attacks and skills calculate their damage, and if the state ID equals the status I want, it could change the damage algorithm...
I would really like to do this, I think it could add a lot of veriety to my game.
thanx in advance.
 

poccil

Sponsor

To do this, modify the element_rate method of Game_Actor and Game_Enemy:

Game_Actor:

Code:
  def element_rate(element_id)
    # Get values corresponding to element effectiveness
    table = [0,200,150,100,50,0,-100]
    elementRank=modifyElementRank(
       $data_classes[@class_id].element_ranks[element_id])
    result = table[elementRank]
    # If this element is protected by armor, then it's reduced by half
    for i in [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
      armor = $data_armors[i]
      if armor != nil and armor.guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # If this element is protected by states, then it's reduced by half
    for i in @states
      if $data_states[i].guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # End Method
    return result
  end

Game_Enemy:

Code:
  def element_rate(element_id)
    # Get a numerical value corresponding to element effectiveness
    table = [0,200,150,100,50,0,-100]
    elementRank=modifyElementRank(
        $data_enemies[@enemy_id].element_ranks[element_id])
    result = table[elementRank]
    # If protected by state, this element is reduced by half
    for i in @states
      if $data_states[i].guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # End Method
    return result
  end

Both changes above use the modifyElementRank function to change the element rank.  It is to be placed in a new script section.

Code:
class Game_Battler
  def modifyElementRank(elementRank) # 1=A, 2=B, ..., 6=F
    # If battler has state with ID 20
    if self.state?(20)
       elementRank=6 # F resistance
    end
    return elementRank
  end
end
 
So I just have to paste those in game_actor and game_enemy instead of the default ones, and the new one in a new script?
I would have to make a new
Code:
 # If battler has state with ID 20
    if self.state?(20)
       elementRank=6 # F resistance
    end
    return elementRank
  end
for each state right?
Still one more doubt, taking the example that state with ID 20 makes you absorb thunder (that's resistance F)
I know how to put the resistance, but where can I choose resistance from which element?
or it automatically detects that by ticking the "element defense" case in the states tab?

EDIT: It works, but has some problems, I made a state that gives invulnerability to thunder element, but then I just learned that It makes me invulnerable to ALL elements!
what do I have to edit in order to make it just invulnerable to 1 element?
 

poccil

Sponsor

Use this code.  Place it in a new script section.  Look at the ELEMENTRANKMODIFIER at the top of the script to learn
how to customize it.

Code:
class Game_Battler
##############
  # Element Ranks can be 1=A, 2=B, ..., 6=F
  ELEMENTRANKMODIFIER={
   13=>6, # Syntax: StateID=>ChangedElementRank
   21=>5
  }
##############
  def modifyElementRank(element, elementRank) 
    # If battler has state with ID 20
    for i in @states
     if ELEMENTRANKMODIFIER.include?(i) &&
         $data_states[i].guard_element_set.include?(element)
       elementRank=ELEMENTRANKMODIFIER[i] # F resistance
     end
    end
    return elementRank
  end
end

class Game_Actor
  def element_rate(element_id)
    # Get values corresponding to element effectiveness
    table = [0,200,150,100,50,0,-100]
    elementRank=modifyElementRank(element_id,
        $data_classes[@class_id].element_ranks[element_id])
    result = table[elementRank]
    # If this element is protected by armor, then it's reduced by half
    for i in [@armor1_id, @armor2_id, @armor3_id, @armor4_id]
      armor = $data_armors[i]
      if armor != nil and armor.guard_element_set.include?(element_id)
        result /= 2
      end
    end
    # If this element is protected by states, then it's reduced by half
    for i in @states
      if $data_states[i].guard_element_set.include?(element_id)
        result /= 2 unless Game_Battler::ELEMENTRANKMODIFIER.include?(i)
      end
    end
    # End Method
    return result
  end
end


class Game_Enemy
  def element_rate(element_id)
    # Get a numerical value corresponding to element effectiveness
    table = [0,200,150,100,50,0,-100]
    elementRank=modifyElementRank(element_id,
        $data_enemies[@enemy_id].element_ranks[element_id])
    result = table[elementRank]
    # If protected by state, this element is reduced by half
    for i in @states
      if $data_states[i].guard_element_set.include?(element_id)
        result /= 2 unless Game_Battler::ELEMENTRANKMODIFIER.include?(i)
      end
    end
    # End Method
    return result
  end
end
 

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