Relic Castle

Quite new to this so I'm not entirely sure how to work it out.

Under Pokébattle_Battler I have
if USENEWBATTLEMECHANICS
p+=1 if user.hasWorkingAbility(:PRANKSTER) && thismove.pbIsStatus?
p+=1 if user.hasWorkingAbility(:GALEWINGS) && isConst?(thismove.type,PBTypes,:FLYING)
p+=1 if user.hasWorkingAbility(:OPPORTUNIST) && thismove.opponent.damagestate.typemod>8
end

But the problem is here with PokéBattle_Battle I believe.
# Calculate each Pokémon's priority bracket, and get the min/max priorities
for i in 0...4
# Assume that doing something other than using a move is priority 0
pri=0
if @choices[0]==1 # Chose to use a move
pri=@choices[2].priority
pri+=1 if @battlers.hasWorkingAbility(:PRANKSTER) &&
@choices[2].pbIsStatus?
pri+=1 if @battlers.hasWorkingAbility(:GALEWINGS) &&
isConst?(@choices[2].type,PBTypes,:FLYING)
pri+=1 if @battlers.hasWorkingAbility(:OPPORTUNIST) &&
@choices[2].target.damagestate.typemod>8

And I can launch just fine, but when going into battle and choosing any move with the ability, I receive an error log of the spoiler below, while the turn restarts and I get to try to make a move again after the log boxes.

[Pokémon Essentials version 17]
Exception: NoMethodError
Message: undefined method `damagestate' for 0:Fixnum
PokeBattle_Battle:1032:in `pbPriority'
PokeBattle_Battle:1022:in `each'
PokeBattle_Battle:1022:in `pbPriority'
PokeBattle_Battle:2706:in `pbAttackPhase'
PokeBattle_Battle:2534:in `pbStartBattleCore'
PokeBattle_Battle:2533:in `logonerr'
PokeBattle_Battle:2533:in `pbStartBattleCore'
PokeBattle_Battle:2519:in `loop'
PokeBattle_Battle:2542:in `pbStartBattleCore'
PokeBattle_Battle:2342:in `pbStartBattle'
[Pokémon Essentials version 17]
Exception: NoMethodError
Message: undefined method `damagestate' for 0:Fixnum
PokeBattle_Battle:1032:in `pbPriority'
PokeBattle_Battle:1022:in `each'
PokeBattle_Battle:1022:in `pbPriority'
PokeBattle_Battle:2882:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Clauses:42:in `pbEndOfRoundPhase'
PokeBattle_Battle:2538:in `pbStartBattleCore'
PokeBattle_Battle:2537:in `logonerr'
PokeBattle_Battle:2537:in `pbStartBattleCore'
PokeBattle_Battle:2519:in `loop'
PokeBattle_Battle:2542:in `pbStartBattleCore'

I understand that damagestate is not a proper way to define it, but I don't know what other ways to.
I've tried looking at other Moves like Sucker Punch. and Abilities like Filter, Tinted Lens, and Ludicious89 on Pokecommunity's custom ability Pounce.

This is with Mej71's Gen 6 Assets, Aswell as Marin's Gen 7 assets.

Thanks in advance
Top