• 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!
  • It's time to vote for your favorite Pokémon Battle Revolution protagonist in our new weekly protagonist poll! Click here to cast your vote and let us know which PBR protagonist you like most.
  • 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.

[Error] Using items in battle not working

A30502355

Newbie
  • 6
    Posts
    7
    Years
    • Seen Mar 20, 2024
    I don't know how. But whenever I use a healing item or just about any item on ANY pokémon that's not the one in the lead, it will not work. No error messages, it just goes straight to the opponent's turn. Even when I switch the lead pokémon out, only the one that was ORIGINALLY in the lead at the start of the battle can items be used on. Oddly enough, the X-items work fine, just items you can use on a pokémon in the back, so just about every other item.
    I don't know if an external thing I might have edited caused this, but this is what I believe to be the culprit, problem is, I can't find a solution (In PokeBattle_Battle):


    Code:
    ################################################################################
    # Using an item.
    ################################################################################
    # Uses an item on a Pokémon in the player's party.
      def pbUseItemOnPokemon(item,pkmnIndex,userPkmn,scene)
        pokemon=@party1[pkmnIndex]
        battler=nil
        name=pbGetOwner(userPkmn.index).fullname
        name=pbGetOwner(userPkmn.index).name if pbBelongsToPlayer?(userPkmn.index)
        pbDisplayBrief(_INTL("{1} used the\r\n{2}.",name,PBItems.getName(item)))
        PBDebug.log("[Use item] Player used #{PBItems.getName(item)} on #{pokemon.name}")
        ret=false
        if pokemon.isEgg?
          pbDisplay(_INTL("But it had no effect!"))
        else
          for i in 0...4
            if !pbIsOpposing?(i) && @battlers[i].pokemonIndex==pkmnIndex
              battler=@battlers[i]
            end
          end
          ret=ItemHandlers.triggerBattleUseOnPokemon(item,pokemon,battler,scene)
        end
        if !ret && pbBelongsToPlayer?(userPkmn.index)
          if $PokemonBag.pbCanStore?(item)
            $PokemonBag.pbStoreItem(item)
          else
            raise _INTL("Couldn't return unused item to Bag somehow.")
          end
        end
        return ret
      end
    
    # Uses an item on an active Pokémon.
      def pbUseItemOnBattler(item,index,userPkmn,scene)
        PBDebug.log("[Use item] Player used #{PBItems.getName(item)} on #{@battlers[index].pbThis(true)}")
        ret=ItemHandlers.triggerBattleUseOnBattler(item,@battlers[index],scene)
        if !ret && pbBelongsToPlayer?(userPkmn.index)
          if $PokemonBag.pbCanStore?(item)
            $PokemonBag.pbStoreItem(item)
          else
            raise _INTL("Couldn't return unused item to Bag somehow.")
          end
        end
        return ret
      end
    
      def pbRegisterItem(idxPokemon,idxItem,idxTarget=nil)
        if idxTarget==0 && @battlers[idxTarget].effects[PBEffects::Embargo]>0
          pbDisplay(_INTL("Embargo's effect prevents the item's use on {1}!",@battlers[idxTarget].pbThis(true)))
          return false
        end
        if ItemHandlers.hasUseInBattle(idxItem)
          if idxPokemon==0 # Player's first Pokémon
            if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
              ItemHandlers.triggerUseInBattle(idxItem,@battlers[idxPokemon],self)
              if @doublebattle
                @choices[idxPokemon+2][0]=3         # "Use an item"
                @choices[idxPokemon+2][1]=idxItem   # ID of item to be used
                @choices[idxPokemon+2][2]=idxTarget # Index of Pokémon to use item on
              end
            else
              if $PokemonBag.pbCanStore?(idxItem)
                $PokemonBag.pbStoreItem(idxItem)
              else
                raise _INTL("Couldn't return unusable item to Bag somehow.")
              end
              return false
            end
          else
            if ItemHandlers.triggerBattleUseOnBattler(idxItem,@battlers[idxPokemon],self)
              pbDisplay(_INTL("It's impossible to aim without being focused!"))
            end
            return false
          end
        end
        @choices[idxPokemon][0]=3         # "Use an item"
        @choices[idxPokemon][1]=idxItem   # ID of item to be used
        @choices[idxPokemon][2]=idxTarget # Index of Pokémon to use item on
        side=(pbIsOpposing?(idxPokemon)) ? 1 : 0
        owner=pbGetOwnerIndex(idxPokemon)
        if @megaEvolution[side][owner]==idxPokemon
          @megaEvolution[side][owner]=-1
        end
        return true
      end
    
      def pbEnemyUseItem(item,battler)
        return 0 if !@internalbattle
        items=pbGetOwnerItems(battler.index)
        return if !items
        opponent=pbGetOwner(battler.index)
        for i in 0...items.length
          if items[i]==item
            items.delete_at(i)
            break
          end
        end
        itemname=PBItems.getName(item)
        pbDisplayBrief(_INTL("{1} used the\r\n{2}!",opponent.fullname,itemname))
        PBDebug.log("[Use item] Opponent used #{itemname} on #{battler.pbThis(true)}")
        if isConst?(item,PBItems,:POTION)
          battler.pbRecoverHP(20,true)
          pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
        elsif isConst?(item,PBItems,:SUPERPOTION)
          battler.pbRecoverHP(50,true)
          pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
        elsif isConst?(item,PBItems,:HYPERPOTION)
          battler.pbRecoverHP(200,true)
          pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
        elsif isConst?(item,PBItems,:MAXPOTION)
          battler.pbRecoverHP(battler.totalhp-battler.hp,true)
          pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
        elsif isConst?(item,PBItems,:FULLRESTORE)
          fullhp=(battler.hp==battler.totalhp)
          battler.pbRecoverHP(battler.totalhp-battler.hp,true)
          battler.status=0; battler.statusCount=0
          battler.effects[PBEffects::Confusion]=0
          if fullhp
            pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
          else
            pbDisplay(_INTL("{1}'s HP was restored.",battler.pbThis))
          end
        elsif isConst?(item,PBItems,:FULLHEAL)
          battler.status=0; battler.statusCount=0
          battler.effects[PBEffects::Confusion]=0
          pbDisplay(_INTL("{1} became healthy!",battler.pbThis))
        elsif isConst?(item,PBItems,:XATTACK)
          if battler.pbCanIncreaseStatStage?(PBStats::ATTACK,battler)
            battler.pbIncreaseStat(PBStats::ATTACK,1,battler,true)
          end
        elsif isConst?(item,PBItems,:XDEFEND)
          if battler.pbCanIncreaseStatStage?(PBStats::DEFENSE,battler)
            battler.pbIncreaseStat(PBStats::DEFENSE,1,battler,true)
          end
        elsif isConst?(item,PBItems,:XSPEED)
          if battler.pbCanIncreaseStatStage?(PBStats::SPEED,battler)
            battler.pbIncreaseStat(PBStats::SPEED,1,battler,true)
          end
        elsif isConst?(item,PBItems,:XSPECIAL)
          if battler.pbCanIncreaseStatStage?(PBStats::SPATK,battler)
            battler.pbIncreaseStat(PBStats::SPATK,1,battler,true)
          end
        elsif isConst?(item,PBItems,:XSPDEF)
          if battler.pbCanIncreaseStatStage?(PBStats::SPDEF,battler)
            battler.pbIncreaseStat(PBStats::SPDEF,1,battler,true)
          end
        elsif isConst?(item,PBItems,:XACCURACY)
          if battler.pbCanIncreaseStatStage?(PBStats::ACCURACY,battler)
            battler.pbIncreaseStat(PBStats::ACCURACY,1,battler,true)
          end
        end
      end
     
    Last edited by a moderator:
    Well to try to give more details I really REALLY want this fixed, please help me:
    -I can still select the item to use on the pokemon originally in the 2nd - 6th slot. And it still consumes the item. But it just goes straight to the opponent's turn, no text, no error messages.
    -Probably the reason why X items still work is because it didn't have to bring up the party menu to use it on perhaps?
    -In double battles the same thing happens, only the mon in the first slot originally in the match does it work.
     
    Never mind, I figured it out on my own, just needed to change index == 0 to index >= 0
     
    Back
    Top