• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Errors When Scripting Tar Shot & Obstruct Moves

  • 9
    Posts
    8
    Years
    • Seen Sep 13, 2020
    Hello all,

    I posted in WolfPP's Gen8 scripting thread about some errors I'm having trouble fixing regarding some of the moves and was re-directed to also post in this forum.

    I have double-checked that I copied all of WolfPP's scripts correctly for both Tar Shot and Obstruct, yet I keep getting the same errors when I use the moves.

    Here is Tar Shot:
    [PokeCommunity.com] Errors When Scripting Tar Shot & Obstruct Moves


    My PokeBattle_MoveEffects Line 1800 looks like this:
    Code:
        return -1 if !opponent.pbCanReduceStatStage?(PBStats::SPEED,attacker,true,self)
    But I see pbCanReduceStatStage?" in other places too...and those other moves work fine. So how is it an undefined method?

    Here is Obstruct:
    [PokeCommunity.com] Errors When Scripting Tar Shot & Obstruct Moves


    My PokeBattle_Battler Line 3261 looks like this:
    Code:
          totaldamage+=damage if damage>0
    I guess I don't understand how the ">" symbol is undefined?

    If anyone knows where I'm going wrong or what I'm not looking at, I would greatly appreciate any help! I'm still learning how to read the error codes, but I'm scratching my head with these two...
     
    Regarding your first error, I don't know exactly what's going wrong but the simple error of "undefined method for Nil::nilclass" hints at a method being used on class without being defined for it.In this case this means that the method "pbCanReduceStatStage?" isn't defined for the class "PokeBattle_Battler" (opponent) which I can't really get behind?

    The second error is the same type and is usually related to the "<" and ">" operators not being defined for non Numeric classes. It boils down to this example which is impossible to solve:
    Code:
    "hello">0
    In your case you should double check if the "damage" variable is storing a number.
     
    Right, "pbCanReduceStatStage?" is used elsewhere in the script without error...so to me, that seems like it already is defined.

    As far as "damage" storing a number, I believe it is. I searched for "def damage" and found it in the script section RPG_Sprite:
    Code:
        def damage(value, critical)
          dispose_damage
          if value.is_a?(Numeric)
            damage_string = value.abs.to_s
          else
            damage_string = value.to_s
          end
          bitmap = Bitmap.new(160, 48)
          bitmap.font.name = "Arial Black"
          bitmap.font.size = 32
          bitmap.font.color.set(0, 0, 0)
          bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)
          bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)
          bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)
          bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)
          if value.is_a?(Numeric) and value < 0
            bitmap.font.color.set(176, 255, 144)
          else
            bitmap.font.color.set(255, 255, 255)
          end
          bitmap.draw_text(0, 12, 160, 36, damage_string, 1)
          if critical
            bitmap.font.size = 20
            bitmap.font.color.set(0, 0, 0)
            bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)
            bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)
            bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)
            bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)
            bitmap.font.color.set(255, 255, 255)
            bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)
          end
          @_damage_sprite = ::Sprite.new(self.viewport)
          @_damage_sprite.bitmap = bitmap
          @_damage_sprite.ox = 80
          @_damage_sprite.oy = 20
          @_damage_sprite.x = self.x
          @_damage_sprite.y = self.y - self.oy / 2
          @_damage_sprite.z = 3000
          @_damage_duration = 40
        end

    ...so I think that should be fine too. Hmmm.
     
    To make this easier, could you copy paste your whole version of "TarShot" and "Obstruct" from "PokeBattle_MoveEffects" and also your
    "def pbProcessMoveAgainstTarget" from "PokeBattle_Battler". I'd look through it if you'd like. :)
     
    For Obstruct, try adding the pbEffect for obsruct in def inditialize of PokeBattle_Battler.

    For tar shot, recheck what you copy pasted.
     
    @Golisopod User
    "For Obstruct, try adding the pbEffect for obsruct in def inditialize of PokeBattle_Battler."

    I have this line under "def pbInitEffects(batonpass)":
    Code:
          @effects[PBEffects::Obstruct]    = false
    Is that what you mean?

    "For tar shot, recheck what you copy pasted."
    I just double-checked my copying/pasting for Tar Shot. In fact, I re-copied and re-pasted the code for it, but I'm still getting the same error.

    @Turn20Negate
    In PokeBattle_Move Effects, here is what I have...

    Tar Shot:
    Code:
    ################################################################################
    # Decreases the target's Speed by 1 stage.
    ################################################################################
    class PokeBattle_Move_044 < PokeBattle_Move
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
        return super(attacker,opponent,hitnum,alltargets,showanimation) if pbIsDamaging?
        return -1 if !opponent.pbCanReduceStatStage?(PBStats::SPEED,attacker,true,self)
        pbShowAnimation(@id,attacker,opponent,hitnum,alltargets,showanimation)
        ret=opponent.pbReduceStat(PBStats::SPEED,1,attacker,false,self)
        return ret ? 0 : -1
      end
    
      def pbAdditionalEffect(attacker,opponent)
        return if opponent.damagestate.substitute
        if opponent.pbCanReduceStatStage?(PBStats::SPEED,attacker,false,self)
          opponent.pbReduceStat(PBStats::SPEED,1,attacker,false,self)
        end
      end
      
      def pbEffectAfterHit(attacker,opponent,turneffects)
        if isConst?(@id,PBMoves,:TARSHOT) && !opponent.effects[PBEffects::TarShot]
          opponent.effects[PBEffects::TarShot]=true
          @battle.pbDisplay(_INTL("{1} became weaker to fire!",opponent.pbThis))
        end
      end
    
    
      def pbModifyDamage(damagemult,attacker,opponent)
        if isConst?(@id,PBMoves,:BULLDOZE) &&
           @battle.field.effects[PBEffects::GrassyTerrain]>0
          return (damagemult/2.0).round
        end
        return damagemult
      end
    end

    Obstruct:
    Code:
    ################################################################################
    # Obstruct
    ################################################################################
    class PokeBattle_Move_174 < PokeBattle_Move
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
      end
    end
    ...for Obstruct, I also have the following under the code sections for Protect, Detect, Quick Guard, Wide Guard, Endure, King's Shield, and Spiky Shield:
    Code:
           0x174   # Obstruct

    Here is the whole script for "def pbProcessMoveAgainstTarget" from PokeBattle_Battler (hidden as spoiler since its long):
    Spoiler:

    I appreciate both of you for trying to help me out with this! Both errors are really stumping me!
     
    Do you have Obstruct in module PBEffects?

    Also for Tar Shot, try making it
    Code:
    return -1 if opponent && !opponent.pbCanReduceStatStage?(PBStats::SPEED,attacker,true,self)
     
    I do have Obstruct in module PBEffects, here is what it looks like...
    Spoiler:

    I think we are getting somewhere with Tar Shot...after I added what you suggested, now the move actually plays the animation, but it doesn't show any effect and now comes up with a new error:
    [PokeCommunity.com] Errors When Scripting Tar Shot & Obstruct Moves
     
    Is this how your PBS version of Tar Shot looks like? The red parts are especially important.
    Spoiler:

    Oh, and for Tar Shot try replacing
    Code:
     if pbIsDamaging?
    with
    Code:
    if @basedamage>0
     
    Last edited:
    Tar Shot is finally working!! Thank you so much for drawing my attention to the PBS file. I had been scouring the script when the problem was in the PBS file the whole time. For some reason I had the target set to "User" instead of "Single Opponent." No idea how that happened. But it's working perfectly now! Thanks @Turn20Negate!

    I checked out the PBS file for Obstruct too and found that it was incorrectly targeted to "Single Opponent." Once I switched that over to "User," the error message now doesn't appear, but the move doesn't do anything. It says "[Pokemon] used Obstruct!" and then nothing happens and the turn goes to the opponent, who is able to hit me still.

    If it helps, here is the PBS line for Obstruct that I have:
    Code:
    707,OBSTRUCT,Obstruct,174,0,DARK,Status,0,10,0,10,4,,"This move enables the user to protect itself from all attacks. Its chance of failing rises if it is used in succession. Direct contact harshly lowers the attacker's Defense stat."
     
    Last edited:
    Happy I could help. :)
    By the way, I noticed that your Obstruct code for "PokeBattle_MoveEffects" is empty, therefore it does nothing.You can just copy paste my version of the move, simply make sure that the function codes for "ratesharers" are the same for you.
    Spoiler:
     
    Okay so I copied your version of Obstruct for "PokeBattle_MoveEffects" and now I'm getting this error:
    [PokeCommunity.com] Errors When Scripting Tar Shot & Obstruct Moves


    Do I need to add something for "previousMove" in PokeBattle_Battler?
     
    Mb, previousmove isn't defined in the base version of essentials, this should work instead of it though:
    Code:
    PBMoveData.new(attacker.lastMoveUsed).function
     
    Awesome, that got Obstruct to work perfectly as well! I can't thank you enough for all your help, I really appreciate it! 😁 You too @GolisopodUser!
     
    Back
    Top