v18 Adding new abilities and battle effects in essentials 18.1

This thread pertains to v18 of Pokémon Essentials.

MegaTorterra

Novice
Member
Joined
Nov 7, 2020
Posts
24
Age
18
So, i started using essentials 18.1 and i immediately noticed that the scripts involving abilities were modified and tutorials and abilities from 17.2 are different, since they involve writing in places that don't exist anymore. So i was wondering: if i want to add an ability where do i need to edit the code? I noticed that there are various "pages" of scripts that are related to abilities. If that can help you, the abilities i'm working on are: A type boosting ability (like Transistor), a stat boost on type hit (like Justified), a terrain summoner ability (like Psychic Surge) and an immunity ability (like Levitate).

Aside from this, to add the terrain ability it's obvious that i also need to add the terrain it summons. I added it in PBBattleTerrains, but i don't know what else i need to edit to add its effects. The effect i'd like to add is something like a reverse version of grassy terrain, that damages any pokemon affected by the terrain except pokemon of a certain type.
I guess that weathers work in a similar manner, so i'll take the chance to ask where do i need to add weather effects as well.

Last but not least i have another question about terrains... Where do i need to put the terrain's graphics? I couldn't find the place to put them.
 
Last edited:

TechSkylander1518

Wiki Dweeb
Member
Joined
Mar 24, 2017
Posts
382
So i was wondering: if i want to add an ability where do i need to edit the code?
Abilities don't really have any designated place. They affect all sorts of elements of battle (status conditions, type effectiveness, move power, etc.), and so they're scattered across the various scripts for battling.

You're on the right track by comparing yours to existing abilities, though! Finding an ability with a similar function is exactly how you go about figuring out where to put in the new code!

In your script editor, press Ctrl+Shift+F. This opens up the search feature, but across all script sections! Type in the name of an ability that works similarly to yours, and you'll see all the sections it's called in, and you can copy and modify that code for your own!

Same principle goes for the terrains and weathers, too! Look in the code that defines their effects, and use that to make your own!

(Also, not trying to shame you, but since you're asking here, I get the impression that you don't know about the Essentials wiki? Just going to link it to you because it's a really helpful resource!)
 

MegaTorterra

Novice
Member
Joined
Nov 7, 2020
Posts
24
Age
18
Abilities don't really have any designated place. They affect all sorts of elements of battle (status conditions, type effectiveness, move power, etc.), and so they're scattered across the various scripts for battling.

You're on the right track by comparing yours to existing abilities, though! Finding an ability with a similar function is exactly how you go about figuring out where to put in the new code!

In your script editor, press Ctrl+Shift+F. This opens up the search feature, but across all script sections! Type in the name of an ability that works similarly to yours, and you'll see all the sections it's called in, and you can copy and modify that code for your own!

Same principle goes for the terrains and weathers, too! Look in the code that defines their effects, and use that to make your own!

(Also, not trying to shame you, but since you're asking here, I get the impression that you don't know about the Essentials wiki? Just going to link it to you because it's a really helpful resource!)
Yes, the wiki saved me in a lot of occasions! Thank you for the ctrl+shift+f suggestion, i didn't know there was such function in rpg maker!
 

MegaTorterra

Novice
Member
Joined
Nov 7, 2020
Posts
24
Age
18
So, i successfully added a new terrain and the ability that summons it, but i found a problem in its effect:

Terrain effect:
      if @field.terrain==PBBattleTerrains::Glitched && b.affectedByTerrain? && b.canHeal? && pbHasType?(:GLITCH)
        PBDebug.log("[Lingering effect] Glitched Terrain heals #{b.pbThis(true)}")
        b.pbRecoverHP(b.totalhp/16)
        pbDisplay(_INTL("{1}'s HP was restored.",b.pbThis))
      else if b.takesIndirectDamage?
        PBDebug.log("[Lingering effect] Glitched Terrain heals #{b.pbThis (true)}")
        b.pbReduceHP(b.totalhp/16)
        pbDisplay(_INTL("{1} was hurt by Glitched Terrain!",b.pbThis))
       end
      end

When the turn ends, i receive an error message saing that in line 284 (the first line of code i just posted), saying this:
Ruby:
---------------------------
Pokemon Essentials
---------------------------
[Pokémon Essentials version 18.1]
Exception: NameError
Message: undefined local variable or method `b' for #<PokeBattle_Battle:0xdb01570>



Backtrace:
Battle_Phase_EndOfRound:284:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Clauses:40:in `pbEndOfRoundPhase'
Battle_StartAndEnd:326:in `pbBattleLoop'
Battle_StartAndEnd:326:in `logonerr'
Battle_StartAndEnd:326:in `pbBattleLoop'
Battle_StartAndEnd:308:in `loop'
Battle_StartAndEnd:329:in `pbBattleLoop'
Battle_StartAndEnd:300:in `pbStartBattleCore'
Battle_StartAndEnd:258:in `pbStartBattle'
PField_Battles:421:in `pbTrainerBattleCore'

This exception was logged in
C:\Users\USERNAME\Saved Games\Pokemon Essentials\errorlog.txt.
Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK   
---------------------------

Can anybody explain me where is the problem?
P.S. (Glitch type is successfully added and the other functions of the terrain work fine)
 

NettoHikari

Trainer
Member
Joined
Jan 4, 2019
Posts
99
The error says the variable "b" is undefined, which means you placed your code in slightly the wrong place or you need to rename "b" to whatever the name of the battler is. I know you pasted the code you tried, but can you also show some of the code before and after your own? I believe that would be roughly lines 280 - 300 in script section Battle_Phase_EndOfRound.
 

MegaTorterra

Novice
Member
Joined
Nov 7, 2020
Posts
24
Age
18
I'll post from the grass+fire pledge effect to grassy terrain.
lines 264-305:
    # Sea of Fire damage (Fire Pledge + Grass Pledge combination)
    curWeather = pbWeather
    for side in 0...2
      next if sides[side].effects[PBEffects::SeaOfFire]==0
      next if curWeather==PBWeather::Rain || curWeather==PBWeather::HeavyRain
      @battle.pbCommonAnimation("SeaOfFire") if side==0
      @battle.pbCommonAnimation("SeaOfFireOpp") if side==1
      priority.each do |b|
        next if b.opposes?(side)
        next if !b.takesIndirectDamage? || b.pbHasType?(:FIRE)
        oldHP = b.hp
        @scene.pbDamageAnimation(b)
        b.pbReduceHP(b.totalhp/8,false)
        pbDisplay(_INTL("{1} is hurt by the sea of fire!",b.pbThis))
        b.pbItemHPHealCheck
        b.pbAbilitiesOnDamageTaken(oldHP)
        b.pbFaint if b.fainted?
      end
    end
    # Glitched Terrain (damaging)
      if @field.terrain==PBBattleTerrains::Glitched && b.affectedByTerrain? && b.canHeal? && pbHasType?(:GLITCH) #the problem is in this line
        PBDebug.log("[Lingering effect] Glitched Terrain heals #{b.pbThis(true)}")
        b.pbRecoverHP(b.totalhp/16)
        pbDisplay(_INTL("{1}'s HP was restored.",b.pbThis))
      else if b.affectedByTerrain? && b.takesIndirectDamage? && !pbHasType(:GLITCH)
        PBDebug.log("[Lingering effect] Glitched Terrain heals #{b.pbThis (true)}")
        @scene.pbDamageAnimation(b)
        b.pbReduceHP(b.totalhp/16,false)
        pbDisplay(_INTL("{1} was hurt by Glitched Terrain!",b.pbThis))
         b.pbItemHPHealCheck
        b.pbFaint if b.fainted?
       end
      end
    # Status-curing effects/abilities and HP-healing items
    priority.each do |b|
      next if b.fainted?
      # Grassy Terrain (healing)
      if @field.terrain==PBBattleTerrains::Grassy && b.affectedByTerrain? && b.canHeal?
        PBDebug.log("[Lingering effect] Grassy Terrain heals #{b.pbThis(true)}")
        b.pbRecoverHP(b.totalhp/16)
        pbDisplay(_INTL("{1}'s HP was restored.",b.pbThis))
      end

I slightly modified the ability's code, because there was a little error.
By the way, to negate something i have to put the "!" before the thing i want to negate, right?
 
Last edited:

MegaTorterra

Novice
Member
Joined
Nov 7, 2020
Posts
24
Age
18
I have some news. After some modifications in the code of the Terrain (i removed all the "b"s one by one until something different happened), I managed to understand where the problem is. The problem is that "b.affectedByTerrain?" is undefined in RPGXP's opinion. This is not because of the new terrain, but it's a problem that seems to affect also Grassy Terrain. As a matter of fact, when i tried using Grassy Surge instead of Glitch Realm (the ability that sets up the Glitched Terrain), at the end of the turn it gave me the same error, but saying that "affectedByTerrain?" is undefined instead of "b". I probably inherited the problem, since i copied and modified Grassy Terrain's code for Glitched Terrain.
 
Last edited:

MegaTorterra

Novice
Member
Joined
Nov 7, 2020
Posts
24
Age
18
So, i tried removing the buggy code and now grassy terrain works fine. I tried adding it again below grassy terrain this time and something weird happened:
In Grassy terrain my pokemon (the faster one, altough idk if that matters) gets healed, but when the foe's pokemon should be healed, an error is displayed
Grassy terrain error:
---------------------------
Pokemon Essentials
---------------------------
[Pokémon Essentials version 18.1]
Exception: NoMethodError
Message: undefined method `affectedByTerrain?' for #<PokeBattle_Battle:0xdbec2c0>



Backtrace:
Battle_Phase_EndOfRound:297:in `__clauses__pbEndOfRoundPhase'
Battle_Phase_EndOfRound:284:in `each'
Battle_Phase_EndOfRound:284:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Clauses:40:in `pbEndOfRoundPhase'
Battle_StartAndEnd:326:in `pbBattleLoop'
Battle_StartAndEnd:326:in `logonerr'
Battle_StartAndEnd:326:in `pbBattleLoop'
Battle_StartAndEnd:308:in `loop'
Battle_StartAndEnd:329:in `pbBattleLoop'
Battle_StartAndEnd:300:in `pbStartBattleCore'



This exception was logged in
C:\Users\USERNAME\Saved Games\Pokemon Essentials\errorlog.txt.
Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK 
---------------------------

This time the code is written this way:

Grassy and Glitched Terrain code:
    # Status-curing effects/abilities and HP-healing items
    priority.each do |b|
      next if b.fainted?
      # Grassy Terrain (healing)
      if @field.terrain==PBBattleTerrains::Grassy && b.affectedByTerrain? && b.canHeal?
        PBDebug.log("[Lingering effect] Grassy Terrain heals #{b.pbThis(true)}")
        b.pbRecoverHP(b.totalhp/16)
        pbDisplay(_INTL("{1}'s HP was restored.",b.pbThis))
      end
      # Glitched Terrain (damaging)
      if @field.terrain==PBBattleTerrains::Glitched && b.affectedByTerrain? && b.canHeal? && pbHasType?(:GLITCH)
        PBDebug.log("[Lingering effect] Glitched Terrain heals #{b.pbThis(true)}")
        b.pbRecoverHP(b.totalhp/16)
        pbDisplay(_INTL("{1}'s HP was restored.",b.pbThis))
      elsif affectedByTerrain? && b.takesIndirectDamage? && !pbHasType(:GLITCH)
        PBDebug.log("[Lingering effect] Glitched Terrain heals #{b.pbThis (true)}")
        @scene.pbDamageAnimation(b)
        b.pbReduceHP(b.totalhp/16,false)
        pbDisplay(_INTL("{1} was hurt by Glitched Terrain!",b.pbThis))
         b.pbItemHPHealCheck
        b.pbFaint if b.fainted?
      end
      # Healer, Hydration, Shed Skin
      BattleHandlers.triggerEORHealingAbility(b.ability,b,self) if b.abilityActive?
      # Black Sludge, Leftovers
      BattleHandlers.triggerEORHealingItem(b.item,b,self) if b.itemActive?
    end
At this point i'm wondering wheter the fact that the pokemon i'm using is Glitch/SecondType is affecting somehow both codes during the check (?)
 

NettoHikari

Trainer
Member
Joined
Jan 4, 2019
Posts
99
Your assessment of the error was slightly incorrect - "b.affectedByTerrain?" was only causing a problem in your original code because you had not put it inside the "priority.each do |b|" loop. In fact, Grassy Terrain actually works fine in base Essentials, but since your code was placed before Grassy Terrain, it ended up breaking that too.

That said, your newest code seems to be almost correct. You just need to change this line:
Ruby:
if @field.terrain==PBBattleTerrains::Glitched && b.affectedByTerrain? && b.canHeal? && pbHasType?(:GLITCH)
to:
Ruby:
if @field.terrain==PBBattleTerrains::Glitched && b.affectedByTerrain? && b.canHeal? && b.pbHasType?(:GLITCH)

As well as this line:
Ruby:
elsif affectedByTerrain? && b.takesIndirectDamage? && !pbHasType(:GLITCH)
to:
Ruby:
elsif b.affectedByTerrain? && b.takesIndirectDamage? && !b.pbHasType?(:GLITCH)

If you still get a syntax error, please post it here again because I may have missed a typo somewhere or something. Your code looks really close now, if not correct.
 

MegaTorterra

Novice
Member
Joined
Nov 7, 2020
Posts
24
Age
18
I edited the code like you said and now i get this error:
Glitch Realm error:
---------------------------
Pokemon Essentials
---------------------------
[Pokémon Essentials version 18.1]
Exception: NoMethodError
Message: undefined method `affectedByTerrain?' for #<PokeBattle_Battle:0xe06b0a8>


Backtrace:
Battle_Phase_EndOfRound:297:in `__clauses__pbEndOfRoundPhase'
Battle_Phase_EndOfRound:284:in `each'
Battle_Phase_EndOfRound:284:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Clauses:40:in `pbEndOfRoundPhase'
Battle_StartAndEnd:326:in `pbBattleLoop'
Battle_StartAndEnd:326:in `logonerr'
Battle_StartAndEnd:326:in `pbBattleLoop'
Battle_StartAndEnd:308:in `loop'
Battle_StartAndEnd:329:in `pbBattleLoop'
Battle_StartAndEnd:300:in `pbStartBattleCore'


This exception was logged in
C:\Users\USERNAME\Saved Games\Pokemon Essentials\errorlog.txt.
Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK   
---------------------------

When I use Grassy Terrain i get a similar error.
 
Top