Advertiser Content

Alan Flygon

A new GUY!!!

Male
Kerala
Seen 1 Week Ago
Posted 1 Week Ago
76 posts
1.2 Years
Hi Guys
I used some move script that I found on the community but some of them are giving me an error
Please help me, I am new to scripting and Ruby language
The first one is Spotlight:
Spoiler:

This is the code I found
################################################################################
# This round, target becomes the target of attacks that have single targets. (Spotlight)
################################################################################
class PokeBattle_Move_1A6 < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    if !@battle.doublebattle
      @battle.pbDisplay(_INTL("But it failed!"))
      return -1
    end
    pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
    opponent.effects[PBEffects::FollowMe]=true
    if !opponent.pbPartner.isFainted?
      opponent.pbPartner.effects[PBEffects::FollowMe]=false
    end
    @battle.pbDisplay(_INTL("{1} shone a spotlight on {2}!",attacker.pbThis,opponent.pbThis))
    return 0
  end
end
This is the error that pops up
[Pokémon Essentials version 17.2]
Exception: NoMethodError
Message: undefined method `>' for false:FalseClass
PokeBattle_Battler:2142:in `pbChangeTarget'
PokeBattle_Battler:2139:in `each'
PokeBattle_Battler:2139:in `pbChangeTarget'
PokeBattle_Battler:3168:in `pbUseMove'
PokeBattle_Battler:3165:in `loop'
PokeBattle_Battler:3188:in `pbUseMove'
PokeBattle_Battler:3386:in `pbProcessTurn'
PokeBattle_Battler:3385:in `logonerr'
PokeBattle_Battler:3385:in `pbProcessTurn'
PokeBattle_Battle:2829:in `pbAttackPhase'

Next one is Throat Chop:
Spoiler:

This is the code I found
Spoiler:

But throat chop seems pretty straight forward, like a combination of imprison and healblock is how I did it (avoided looking into disable because it was referenced too many times lol)

First thing you need to do is add an effect to PBEffects
ThroatChop         = 109 # use whatever is the next lowest value for you
And obviously add a def to Move_effects:
class PokeBattle_Move_CF15 < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    ret=super(attacker,opponent,hitnum,alltargets,showanimation)
    if opponent.damagestate.calcdamage>0 && !opponent.damagestate.substitute &&
        !opponent.isFainted?
      opponent.effects[PBEffects::ThroatChop]=2
      @battle.pbDisplay(_INTL("{1} can't use sound based moves!",opponent.pbThis))
    end
    return ret
  end
end
Then you just have a few things left to

first find pbTryUseMove in PokeBattle_battler and add this (I added mine below the imprison code)
if @effects[PBEffects::ThroatChop]>0 && !pbOpposing1.fainted?
      if thismove.isSoundBased?
        @battle.pbDisplay(_INTL("{1} can't use {2} because they were Throat Chopped!",pbThis,thismove.name))
        PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because they were Throat chopped!")
        return false
      end
    end
The previous block prevents an already selected move from being used. This next block will prevent them from choosing it: put in PokeBattle_Battle in pbCanChooseMove (again I put it below imprison)
if thispkmn.effects[PBEffects::ThroatChop]>0 && thismove.isSoundBased?
      if showMessages
        pbDisplayPaused(_INTL("{1} can't use {2} because they are throat chopped!",thispkmn.pbThis,thismove.name))
      end
      return false
    end
And lastly decrement the value if it's more than 0 in PokeBattle_Battle in pbEndofRoundPhase (this time I put it below Heal bell because it works similar)
# Throat Chop
    for i in priority
      next if i.fainted?
      if i.effects[PBEffects::ThroatChop]>0
        i.effects[PBEffects::ThroatChop]-=1
        if i.effects[PBEffects::ThroatChop]==0
          pbDisplay(_INTL("{1}'s can use sound based moves again!",i.pbThis))
          PBDebug.log("[End of effect] #{i.pbThis} is no longer Throat chopped")
        end
      end
    end
I just tested on an Exploud that knows only sound moves and it prevented an already selected move and also prevented move selection causing it to struggle. If anyone happens to know the real lines pokemon displays when throat chop effects happen please let me know!


This is two errors that pops up one after the other
Spoiler:
[Pokémon Essentials version 17.2]
Exception: NoMethodError
Message: undefined method `>' for nil:NilClass
PokeBattle_Battle:820:in `pbCanChooseMove?'
PokeBattle_Battle:800:in `pbCanShowFightMenu?'
PokeBattle_Battle:2602:in `pbCommandPhase'
PokeBattle_Battle:2599:in `loop'
PokeBattle_Battle:2689:in `pbCommandPhase'
PokeBattle_Battle:2588:in `each'
PokeBattle_Battle:2588:in `pbCommandPhase'
PokeBattle_Battle:2535:in `pbStartBattleCore'
PokeBattle_Battle:2534:in `logonerr'
PokeBattle_Battle:2534:in `pbStartBattleCore'

Spoiler:
[Pokémon Essentials version 17.2]
Exception: NoMethodError
Message: undefined method `>' for nil:NilClass
PokeBattle_Battle:3487:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Battle:3485:in `each'
PokeBattle_Battle:3485:in `__clauses__pbEndOfRoundPhase'
PokeBattle_Clauses:42:in `pbEndOfRoundPhase'
PokeBattle_Battle:2543:in `pbStartBattleCore'
PokeBattle_Battle:2542:in `logonerr'
PokeBattle_Battle:2542:in `pbStartBattleCore'
PokeBattle_Battle:2524:in `loop'
PokeBattle_Battle:2547:in `pbStartBattleCore'
PokeBattle_Battle:2347:in `pbStartBattle'


Next one is Laser Focus:
Spoiler:

This is the script by Marin:
Spoiler:
################################################################################
# The user's next move will be a critical hit
################################################################################
class PokeBattle_Move_CF18 < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    if attacker.effects[PBEffects::LaserFocus]>0
      @battle.pbDisplay(_INTL("But it failed!"))
      return -1
    else
    attacker.effects[PBEffects::LaserFocus]=1
    @battle.pbDisplay(_INTL("{1} began focusing hard!",attacker.pbThis))
    return 0
    end
  end
end


# Next, paste this line in PBEffects (Change the number to the lowest number that's not used)

    LaserFocus         = 113


# In PokeBattle_Battler, paste this line directly under "def pbEffectsOnMoveEnd":

    user.effects[PBEffects::LaserFocus]-=1


# In PokeBattle_Move, paste this uner "def isCritical?":

    return true if attacker.effects[PBEffects::LaserFocus]>0


This is the two error I get:
Spoiler:
[Pokémon Essentials version 17.2]
Exception: NoMethodError
Message: undefined method `>' for nil:NilClass
PokeBattle_MoveEffects:1784:in `pbEffect'
PokeBattle_Battler:3154:in `pbUseMove'
PokeBattle_Battler:3153:in `logonerr'
PokeBattle_Battler:3153:in `pbUseMove'
PokeBattle_Battler:3386:in `pbProcessTurn'
PokeBattle_Battler:3385:in `logonerr'
PokeBattle_Battler:3385:in `pbProcessTurn'
PokeBattle_Battle:2829:in `pbAttackPhase'
PokeBattle_Battle:2826:in `each'
PokeBattle_Battle:2826:in `pbAttackPhase'
[Pokémon Essentials version 17.2]
Exception: NoMethodError
Message: undefined method `>' for nil:NilClass
PokeBattle_Move:532:in `pbIsCritical?'
PokeBattle_Move:589:in `pbCalcDamage'
PokeBattle_Move:1287:in `pbEffect'
PokeBattle_Battler:2752:in `pbProcessMoveAgainstTarget'
PokeBattle_Battler:2708:in `each'
PokeBattle_Battler:2708:in `pbProcessMoveAgainstTarget'
PokeBattle_Battler:3185:in `pbUseMove'
PokeBattle_Battler:3165:in `loop'
PokeBattle_Battler:3188:in `pbUseMove'
PokeBattle_Battler:3386:in `pbProcessTurn'
I also tried using the fix for "def pbEffectsOnMoveEnd" which I found on his thread but no luck
Female
Seen 3 Hours Ago
Posted 3 Weeks Ago
66 posts
1 Years
I'm not really good with errors but I'll try.

I think you probably have to initialize the effects value for your abilities. I keep noticing ">" and "=" in your errors. So I think that might be the problem. For example, for Laser Focus it would look like this:
@effects[PBEffects::LaserFocus] = 0
I think the place to put it is in PokeBattle_Battler, under @effects[PBEffects::Yawn]. I did so for Laser Focus and it works correctly. I have not tried Throat Chop or Spotlight, yet, but I think the same method should work.

WolfPP

Discord: Wolf#1235

Male
Brazil
Seen 1 Hour Ago
Posted 3 Hours Ago
626 posts
334 Days
I sent to you about Laser Focus:
Spoiler:

PBEffects add (113 will be your last number):
LaserFocus         = 113
PokeBattle_Battler add below '@effects[PBEffects::Yawn]= 0':
@effects[PBEffects::LaserFocus]       = 0
Then, add a new def after/below 'def pbProcessTurn(choice)' code:
Spoiler:

  def pbEffectsOnMoveEnd(move,user,target,damage)
    user.effects[PBEffects::LaserFocus]-=1
    damage=0 if damage==nil
    if damage>0
      if !target.damagestate.substitute
        if target.hasWorkingAbility(:WIMPOUT) &&
            target.hp<target.totalhp/2 && target.hp+damage>target.totalhp/2
          @battle.pbDisplayEffect(target)
          PBDebug.log("[#{target.pbThis}'s #{PBAbilities.getName(target.ability)} triggered]")
          choices=[]
          party=@battle.pbParty(target.index)
          for i in 0...party.length
            choices[choices.length]=i if @battle.pbCanSwitchLax?(target.index,i,false)
          end
          if choices.length>0
            newpoke=choices[@battle.pbRandom(choices.length)]
            target.pbResetForm
            @battle.pbReplace(target.index,newpoke,false)
            @battle.pbDisplay(_INTL("{1} was dragged out!",target.pbThis))
            @battle.pbOnActiveOne(target)
            target.pbAbilitiesOnSwitchIn(true)
          elsif !@battle.opponent
            @battle.decision=3
          end
        elsif target.hasWorkingAbility(:EMERGENCYEXIT) && target.hp<target.totalhp/2 && 
         target.hp+damage>target.totalhp/2
          @battle.pbDisplayEffect(target)
          PBDebug.log("[#{target.pbThis}'s #{PBAbilities.getName(target.ability)} triggered]")
          choices=[]
          party=@battle.pbParty(target.index)
          for i in 0...party.length
            choices[choices.length]=i if @battle.pbCanSwitchLax?(target.index,i,false)
          end
          if choices.length>0
            newpoke=choices[@battle.pbRandom(choices.length)]
            target.pbResetForm
            @battle.pbReplace(target.index,newpoke,false)
            @battle.pbDisplay(_INTL("{1} was dragged out!",target.pbThis))
            @battle.pbOnActiveOne(target)
            target.pbAbilitiesOnSwitchIn(true)
          elsif !@battle.opponent
            @battle.decision=3
          end
        end
      end
    end
  end


In 'PokeBattle_MoveEffect' script, add:
Spoiler:

################################################################################
# The user's next move will be a critical hit (Laser Focus)
################################################################################
class PokeBattle_Move_19A < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    if attacker.effects[PBEffects::LaserFocus]>0
      @battle.pbDisplay(_INTL("But it failed!"))
      return -1
    else
    attacker.effects[PBEffects::LaserFocus]=1
    @battle.pbDisplay(_INTL("{1} began focusing hard!",attacker.pbThis))
    return 0
    end
  end
end
19A will be your code here and into move.txt too.


Finally, 'PokeBattle_Move' script, add below 'return true if pbCritialOverride(attacker,opponent)'
return true if attacker.effects[PBEffects::LaserFocus]>0


Throat Chop:
Spoiler:

In PBEffects add (111 and 112 will be your last number. Edit if not):
ThroatChop = 111
LastMoveFailed = 112

Inside 'PokeBattle_Battler' script, add below '@effects[PBEffects::Yawn]= 0':
@effects[PBEffects::LastMoveFailed]   = false
@effects[PBEffects::ThroatChop]       = 0
Below 'if pbOpposing2.effects[PBEffects::Imprison] && !pbOpposing2.fainted?' code, add:
    if @effects[PBEffects::ThroatChop]>0 && !pbOpposing1.fainted?
      if thismove.isSoundBased?
        @battle.pbDisplay(_INTL("{1} can't use {2} because they were Throat Chopped!",pbThis,thismove.name))
        PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because they were Throat chopped!")
        return false
      end
    end
Now, in 'PokeBattle_MoveEffects' script, add a new code to the move:
Spoiler:

################################################################################
# Throat Chop
################################################################################
class PokeBattle_Move_CF15 < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    ret=super(attacker,opponent,hitnum,alltargets,showanimation)
    if opponent.damagestate.calcdamage>0 && !opponent.damagestate.substitute &&
        !opponent.isFainted?
      opponent.effects[PBEffects::ThroatChop]=2
      @battle.pbDisplay(_INTL("{1} can't use sound based moves!",opponent.pbThis))
    end
    return ret
  end
end
CF15 will be your code for that here and inside move.txt too


In 'PokeBattle_Battle' script, below 'if opp2.effects[PBEffects::Imprison]' code, paste (like that):
Spoiler:

    if opp2.effects[PBEffects::Imprison]
      if thismove.id==opp2.moves[0].id ||
         thismove.id==opp2.moves[1].id ||
         thismove.id==opp2.moves[2].id ||
         thismove.id==opp2.moves[3].id
        if showMessages
          pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
        end
        #PBDebug.log("[CanChoose][#{opp2.pbThis} has: #{opp2.moves[0].name}, #{opp2.moves[1].name},#{opp2.moves[2].name},#{opp2.moves[3].name}]")
        return false
      end
    end
    if thispkmn.effects[PBEffects::ThroatChop]>0 && thismove.isSoundBased?
      if showMessages
        pbDisplayPaused(_INTL("{1} can't use {2} because they are throat chopped!",thispkmn.pbThis,thismove.name))
      end
      return false
    end


Then, inside '# Ice Body' code, paste:
    # Throat Chop
    for i in priority
      next if i.fainted?
      if i.effects[PBEffects::ThroatChop]>0
        i.effects[PBEffects::ThroatChop]-=1
        if i.effects[PBEffects::ThroatChop]==0
          pbDisplay(_INTL("{1}'s can use sound based moves again!",i.pbThis))
          PBDebug.log("[End of effect] #{i.pbThis} is no longer Throat chopped")
        end
      end
    end
Now, to add about 'LastMoveFailed', inside 'PokeBattle_Battler', add below 'user.effects[PBEffects::Stockpile]=0 if thismove.function==0x113':
user.effects[PBEffects::LastMoveFailed]=true
Inside 'def pbProcessMoveAgainstTarget(thismove,user,target,numhits,turneffects,nocheck=false,alltargets=nil,showanimation=true,dancercheck=false)' add (use CTRL SHIFT F to find the code):
      user.pbFaint if user.fainted? # no return
      #return if numhits>1 && target.damagestate.calcdamage<=0
      if numhits>1 && target.damagestate.calcdamage<=0
        user.effects[PBEffects::LastMoveFailed]=true
        return
      end
      @battle.pbJudgeCheckpoint(user,thismove)
      # Additional effect
Finally, add (use CTRL SHIFT F to find the code):
    # Berry check
    for j in 0...4
      @battle.battlers[j].pbBerryCureCheck
    end
    target.pbUpdateTargetedMove(thismove,user)
    user.effects[PBEffects::LastMoveFailed]=false
  end

Alan Flygon

A new GUY!!!

Male
Kerala
Seen 1 Week Ago
Posted 1 Week Ago
76 posts
1.2 Years
I sent to you about Laser Focus:
Spoiler:

PBEffects add (113 will be your last number):
LaserFocus         = 113
PokeBattle_Battler add below '@effects[PBEffects::Yawn]= 0':
@effects[PBEffects::LaserFocus]       = 0
Then, add a new def after/below 'def pbProcessTurn(choice)' code:
Spoiler:

  def pbEffectsOnMoveEnd(move,user,target,damage)
    user.effects[PBEffects::LaserFocus]-=1
    damage=0 if damage==nil
    if damage>0
      if !target.damagestate.substitute
        if target.hasWorkingAbility(:WIMPOUT) &&
            target.hp<target.totalhp/2 && target.hp+damage>target.totalhp/2
          @battle.pbDisplayEffect(target)
          PBDebug.log("[#{target.pbThis}'s #{PBAbilities.getName(target.ability)} triggered]")
          choices=[]
          party=@battle.pbParty(target.index)
          for i in 0...party.length
            choices[choices.length]=i if @battle.pbCanSwitchLax?(target.index,i,false)
          end
          if choices.length>0
            newpoke=choices[@battle.pbRandom(choices.length)]
            target.pbResetForm
            @battle.pbReplace(target.index,newpoke,false)
            @battle.pbDisplay(_INTL("{1} was dragged out!",target.pbThis))
            @battle.pbOnActiveOne(target)
            target.pbAbilitiesOnSwitchIn(true)
          elsif !@battle.opponent
            @battle.decision=3
          end
        elsif target.hasWorkingAbility(:EMERGENCYEXIT) && target.hp<target.totalhp/2 && 
         target.hp+damage>target.totalhp/2
          @battle.pbDisplayEffect(target)
          PBDebug.log("[#{target.pbThis}'s #{PBAbilities.getName(target.ability)} triggered]")
          choices=[]
          party=@battle.pbParty(target.index)
          for i in 0...party.length
            choices[choices.length]=i if @battle.pbCanSwitchLax?(target.index,i,false)
          end
          if choices.length>0
            newpoke=choices[@battle.pbRandom(choices.length)]
            target.pbResetForm
            @battle.pbReplace(target.index,newpoke,false)
            @battle.pbDisplay(_INTL("{1} was dragged out!",target.pbThis))
            @battle.pbOnActiveOne(target)
            target.pbAbilitiesOnSwitchIn(true)
          elsif !@battle.opponent
            @battle.decision=3
          end
        end
      end
    end
  end


In 'PokeBattle_MoveEffect' script, add:
Spoiler:

################################################################################
# The user's next move will be a critical hit (Laser Focus)
################################################################################
class PokeBattle_Move_19A < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    if attacker.effects[PBEffects::LaserFocus]>0
      @battle.pbDisplay(_INTL("But it failed!"))
      return -1
    else
    attacker.effects[PBEffects::LaserFocus]=1
    @battle.pbDisplay(_INTL("{1} began focusing hard!",attacker.pbThis))
    return 0
    end
  end
end
19A will be your code here and into move.txt too.


Finally, 'PokeBattle_Move' script, add below 'return true if pbCritialOverride(attacker,opponent)'
return true if attacker.effects[PBEffects::LaserFocus]>0


Throat Chop:
Spoiler:

In PBEffects add (111 and 112 will be your last number. Edit if not):
ThroatChop = 111
LastMoveFailed = 112

Inside 'PokeBattle_Battler' script, add below '@effects[PBEffects::Yawn]= 0':
@effects[PBEffects::LastMoveFailed]   = false
@effects[PBEffects::ThroatChop]       = 0
Below 'if pbOpposing2.effects[PBEffects::Imprison] && !pbOpposing2.fainted?' code, add:
    if @effects[PBEffects::ThroatChop]>0 && !pbOpposing1.fainted?
      if thismove.isSoundBased?
        @battle.pbDisplay(_INTL("{1} can't use {2} because they were Throat Chopped!",pbThis,thismove.name))
        PBDebug.log("[Move failed] #{pbThis} can't use #{thismove.name} because they were Throat chopped!")
        return false
      end
    end
Now, in 'PokeBattle_MoveEffects' script, add a new code to the move:
Spoiler:

################################################################################
# Throat Chop
################################################################################
class PokeBattle_Move_CF15 < PokeBattle_Move
  def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
    ret=super(attacker,opponent,hitnum,alltargets,showanimation)
    if opponent.damagestate.calcdamage>0 && !opponent.damagestate.substitute &&
        !opponent.isFainted?
      opponent.effects[PBEffects::ThroatChop]=2
      @battle.pbDisplay(_INTL("{1} can't use sound based moves!",opponent.pbThis))
    end
    return ret
  end
end
CF15 will be your code for that here and inside move.txt too


In 'PokeBattle_Battle' script, below 'if opp2.effects[PBEffects::Imprison]' code, paste (like that):
Spoiler:

    if opp2.effects[PBEffects::Imprison]
      if thismove.id==opp2.moves[0].id ||
         thismove.id==opp2.moves[1].id ||
         thismove.id==opp2.moves[2].id ||
         thismove.id==opp2.moves[3].id
        if showMessages
          pbDisplayPaused(_INTL("{1} can't use the sealed {2}!",thispkmn.pbThis,thismove.name))
        end
        #PBDebug.log("[CanChoose][#{opp2.pbThis} has: #{opp2.moves[0].name}, #{opp2.moves[1].name},#{opp2.moves[2].name},#{opp2.moves[3].name}]")
        return false
      end
    end
    if thispkmn.effects[PBEffects::ThroatChop]>0 && thismove.isSoundBased?
      if showMessages
        pbDisplayPaused(_INTL("{1} can't use {2} because they are throat chopped!",thispkmn.pbThis,thismove.name))
      end
      return false
    end


Then, inside '# Ice Body' code, paste:
    # Throat Chop
    for i in priority
      next if i.fainted?
      if i.effects[PBEffects::ThroatChop]>0
        i.effects[PBEffects::ThroatChop]-=1
        if i.effects[PBEffects::ThroatChop]==0
          pbDisplay(_INTL("{1}'s can use sound based moves again!",i.pbThis))
          PBDebug.log("[End of effect] #{i.pbThis} is no longer Throat chopped")
        end
      end
    end
Now, to add about 'LastMoveFailed', inside 'PokeBattle_Battler', add below 'user.effects[PBEffects::Stockpile]=0 if thismove.function==0x113':
user.effects[PBEffects::LastMoveFailed]=true
Inside 'def pbProcessMoveAgainstTarget(thismove,user,target,numhits,turneffects,nocheck=false,alltargets=nil,showanimation=true,dancercheck=false)' add (use CTRL SHIFT F to find the code):
      user.pbFaint if user.fainted? # no return
      #return if numhits>1 && target.damagestate.calcdamage<=0
      if numhits>1 && target.damagestate.calcdamage<=0
        user.effects[PBEffects::LastMoveFailed]=true
        return
      end
      @battle.pbJudgeCheckpoint(user,thismove)
      # Additional effect
Finally, add (use CTRL SHIFT F to find the code):
    # Berry check
    for j in 0...4
      @battle.battlers[j].pbBerryCureCheck
    end
    target.pbUpdateTargetedMove(thismove,user)
    user.effects[PBEffects::LastMoveFailed]=false
  end
Thanks you so much Wolf bro
Now the only one remaining is the Spotlight
Advertiser Content