• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Staff applications for our PokéCommunity Daily and Social Media team are now open! Interested in joining staff? Then click here for more info!
  • 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.

Disabling items in battle, and preventing AI from switching out

  • 67
    Posts
    12
    Years
    • Seen Aug 22, 2024
    1. How can I disable using Items in a trainer-battle?

    2. How can I avoid (permanently) that the oppenent switches out pokemon in a battle? (Somewhere in the Script i guess)
     
    1. How can I disable using Items in a trainer-battle?

    2. How can I avoid (permanently) that the oppenent switches out pokemon in a battle? (Somewhere in the Script i guess)

    1.) In the scripts, in PokeBattle_Battle (the one without the R), around line 3065, you should find the following code. Add the red part in. You already can't use your bag if it's an external battle (a battle over the internet with another player), the red part adds in that you can't use it when in an internal (in-game) battle with a trainer.
    Code:
                elsif cmd==1 # Bag
                  if !@internalbattle[COLOR="Red"] || @opponent[/COLOR]
                    if pbOwnedByPlayer?(i)
                      pbDisplay(_INTL("Items can't be used here."))
                    end
                  else
                    item=pbItemMenu(i)
                    if item[0]>0
                      if pbRegisterItem(i,item[0],item[1])
                        commandDone=true
                      end
                    end
                  end

    ...and thank you for helping me realize that I need to rewrite the AI to account for the drastic changes I've made to the type effectiveness code.
     
    uh okay and is there a command, so I can activade and deactivade this effect?
     
    uh okay and is there a command, so I can activade and deactivade this effect?

    Oh, I thought you wanted it for all trainer battles. Give me a minute to get everything ready - a trigger is possible but a lot more in-depth.
     
    1.) In the scripts, in PokeBattle_Battle (the one without the R), around line 3065, you should find the following code. Add the red part in. You already can't use your bag if it's an external battle (a battle over the internet with another player), the red part adds in that you can't use it if a certain flag is activated
    Code:
                elsif cmd==1 # Bag
                  if !@internalbattle[COLOR="Red"] || @noItems[/COLOR]
                    if pbOwnedByPlayer?(i)
                      pbDisplay(_INTL("Items can't be used here."))
                    end
                  else
                    item=pbItemMenu(i)
                    if item[0]>0
                      if pbRegisterItem(i,item[0],item[1])
                        commandDone=true
                      end
                    end
                  end

    2.) PokeBattle_Battle, around line 311, add this line
    Code:
      attr_accessor(:noItems)

    3.) PokeBattle_Battle, around line 336, make the following changes:
    Code:
    ################################################################################
    # Initialise battle class.
    ################################################################################
      def initialize(scene,p1,p2,player,opponent,skybattle=false,inverse=false[COLOR="Red"],noItems=false[/COLOR])
        if p1.length==0
          raise ArgumentError.new(_INTL("Party 1 has no Pokémon."))
          return
        end
        if p2.length==0
          raise ArgumentError.new(_INTL("Party 2 has no Pokémon."))
          return
        end
        if p2.length>2 && !opponent
          raise ArgumentError.new(_INTL("Wild battles with more than two Pokémon are not allowed."))
          return
        end
        @scene           = scene
        @decision        = 0
        @internalbattle  = true
        @doublebattle    = false
        @cantescape      = false
        @shiftStyle      = true
        @battlescene     = true
        @debug           = false
        @debugupdate     = 0
        if opponent && player.is_a?(Array) && player.length==0
          player = player[0]
        end
        if opponent && opponent.is_a?(Array) && opponent.length==0
          opponent = opponent[0]
        end
        @player          = player                # PokeBattle_Trainer object
        @opponent        = opponent              # PokeBattle_Trainer object
        @party1          = p1
        @party2          = p2
        @partyorder      = []
        for i in 0...6; @partyorder.push(i); end
        @fullparty1      = false
        @fullparty2      = false
        @battlers        = []
        @items           = nil
        @sides           = [PokeBattle_ActiveSide.new,   # Player's side
                            PokeBattle_ActiveSide.new]   # Foe's side
        @field           = PokeBattle_ActiveField.new    # Whole field (gravity/rooms)
        @environment     = PBEnvironment::None   # e.g. Tall grass, cave, still water
        @weather         = 0
        @weatherduration = 0
        @switching       = false
        @choices         = [ [0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1],[0,0,nil,-1] ]
        @successStates   = []
        for i in 0...4
          @successStates.push(PokeBattle_SuccessState.new)
        end
        @lastMoveUsed    = -1
        @lastMoveUser    = -1
        @synchronize     = [-1,-1,0]
        @megaEvolution   = []
        if @player.is_a?(Array)
          @megaEvolution[0]=[-1]*@player.length
        else
          @megaEvolution[0]=[-1]
        end
        if @opponent.is_a?(Array)
          @megaEvolution[1]=[-1]*@opponent.length
        else
          @megaEvolution[1]=[-1]
        end
        @amuletcoin      = false
        @extramoney      = 0
        @endspeech       = ""
        @endspeech2      = ""
        @endspeechwin    = ""
        @endspeechwin2   = ""
        @rules           = {}
        @turncount       = 0
        @peer            = PokeBattle_BattlePeer.create()
        @priority        = []
        @usepriority     = false
        @snaggedpokemon  = []
        @runCommand      = 0
        if hasConst?(PBMoves,:STRUGGLE)
          @struggle = PokeBattle_Move.pbFromPBMove(self,PBMove.new(getConst(PBMoves,:STRUGGLE)))
        else
          @struggle = PokeBattle_Struggle.new(self,nil)
        end
        @struggle.pp     = -1
        for i in 0...4
          battlers[i] = PokeBattle_Battler.new(self,i)
        end
        for i in @party1
          next if !i
          i.itemRecycle = 0
          i.itemInitial = i.item
        end
        for i in @party2
          next if !i
          i.itemRecycle = 0
          i.itemInitial = i.item
        end
        @happyhour=[false,false,false,false]
        @skybattle=skybattle
        @inverse=inverse
        [COLOR="red"]@noItems=noItems[/COLOR]
        @currentpriority=nil
      end

    4.) PTrainer_NPCTrainers, around line 259, make the following changes:
    Code:
    def pbDoubleTrainerBattle(trainerid1, trainername1, trainerparty1, endspeech1,
                              trainerid2, trainername2, trainerparty2, endspeech2, 
                              canlose=false,variable=nil,skybattle=false,inverse=false[COLOR="red"],noItems=false[/COLOR])
       # Sky battle eligibility for player
      if skybattle
        count=0
        for poke in $Trainer.party
          count+=1 if pbCanSkyBattle?(poke)
        end
        if count==0
          Kernel.pbMessage(_INTL("You don't have any eligible pokemon for a sky battle"))
          return false
        end
      end
      trainer1=pbLoadTrainer(trainerid1,trainername1,trainerparty1)
      Events.onTrainerPartyLoad.trigger(nil,trainer1)
      if !trainer1
        pbMissingTrainer(trainerid1,trainername1,trainerparty1)
      end
      trainer2=pbLoadTrainer(trainerid2,trainername2,trainerparty2)
      Events.onTrainerPartyLoad.trigger(nil,trainer2)
      if !trainer2
        pbMissingTrainer(trainerid2,trainername2,trainerparty2)
      end
      if !trainer1 || !trainer2
        return false
      end
      if $PokemonGlobal.partner
        othertrainer=PokeBattle_Trainer.new($PokemonGlobal.partner[1],
                                            $PokemonGlobal.partner[0])
        othertrainer.id=$PokemonGlobal.partner[2]
        othertrainer.party=$PokemonGlobal.partner[3]
        playerparty=[]
        for i in 0...$Trainer.party.length
          playerparty[i]=$Trainer.party[i]
        end
        for i in 0...othertrainer.party.length
          playerparty[6+i]=othertrainer.party[i]
        end
        fullparty1=true
        playertrainer=[$Trainer,othertrainer]
      else
        playerparty=$Trainer.party
        playertrainer=$Trainer
        fullparty1=false
      end
      combinedParty=[]
      for i in 0...trainer1[2].length
        combinedParty[i]=trainer1[2][i]
      end
      for i in 0...trainer2[2].length
        combinedParty[6+i]=trainer2[2][i]
      end
      #Sky battle eligibility for opponent
      if skybattle
        count=0
        for poke in combinedParty
          count+=1 if pbCanSkyBattle?(poke)
        end
        if count==0
          Kernel.pbMessage(_INTL("The opponents don't have any eligible pokemon for a sky battle"))
          return false
        end
      end
      scene=pbNewBattleScene
      battle=PokeBattle_Battle.new(scene,
         playerparty,combinedParty,playertrainer,[trainer1[0],trainer2[0]],skybattle,inverse[COLOR="red"],noItems[/COLOR])
      trainerbgm=pbGetTrainerBattleBGM([trainer1[0],trainer2[0]])
      battle.fullparty1=fullparty1
      battle.fullparty2=true
      battle.doublebattle=battle.pbDoubleBattleAllowed?()
      battle.endspeech=endspeech1
      battle.endspeech2=endspeech2
      battle.items=[trainer1[1],trainer2[1]]
      if Input.press?(Input::CTRL) && $DEBUG
        Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
        Kernel.pbMessage(_INTL("AFTER LOSING..."))
        Kernel.pbMessage(battle.endspeech)
        Kernel.pbMessage(battle.endspeech2) if battle.endspeech2 && battle.endspeech2!=""
        return true
      end
      Events.onStartBattle.trigger(nil,nil)
      battle.internalbattle=true
      pbPrepareBattle(battle)
      restorebgm=true
      decision=0
      pbBattleAnimation(trainerbgm) { 
         pbSceneStandby {
            decision=battle.pbStartBattle(canlose)
         }
         for i in $Trainer.party; (i.makeUnmega rescue nil); end
         if $PokemonGlobal.partner
           pbHealAll
           for i in $PokemonGlobal.partner[3]
             i.heal
             i.makeUnmega rescue nil
           end
         end
         if decision==2 || decision==5
           if canlose
             for i in $Trainer.party; i.heal; end
             for i in 0...10
               Graphics.update
             end
           else
             $game_system.bgm_unpause
             $game_system.bgs_unpause
             Kernel.pbStartOver
           end
         end
         Events.onEndBattle.trigger(nil,decision)
      }
      Input.update
      pbSet(variable,decision)
      return (decision==1)
    end
    
    
    def pbTrainerBattle(trainerid,trainername,endspeech,
                        doublebattle=false,trainerparty=0,canlose=false,variable=nil,
                        skybattle=false,inverse=false[COLOR="red"],noItems=false[/COLOR])
      if $Trainer.pokemonCount==0
        Kernel.pbMessage(_INTL("SKIPPING BATTLE...")) if $DEBUG
        return false
      end
      # Sky battle eligibility for player
      if skybattle
        count=0
        for poke in $Trainer.party
          count+=1 if pbCanSkyBattle?(poke)
        end
        if count==0
          Kernel.pbMessage(_INTL("You don't have any eligible pokemon for a sky battle"))
          return false
        end
      end
      if !$PokemonTemp.waitingTrainer && $Trainer.ablePokemonCount>1 &&
         pbMapInterpreterRunning?
        thisEvent=pbMapInterpreter.get_character(0)
        triggeredEvents=$game_player.pbTriggeredTrainerEvents([2],false)
        otherEvent=[]
        for i in triggeredEvents
          if i.id!=thisEvent.id && !$game_self_switches[[$game_map.map_id,i.id,"A"]]
            otherEvent.push(i)
          end
        end
        if otherEvent.length==1
          trainer=pbLoadTrainer(trainerid,trainername,trainerparty)
          Events.onTrainerPartyLoad.trigger(nil,trainer)
          if !trainer
            pbMissingTrainer(trainerid,trainername,trainerparty)
            return false
          end
          if trainer[2].length<=6 # 3
            $PokemonTemp.waitingTrainer=[trainer,thisEvent.id,endspeech]
            return false
          end
        end
      end
      trainer=pbLoadTrainer(trainerid,trainername,trainerparty)
      Events.onTrainerPartyLoad.trigger(nil,trainer)
      if !trainer
        pbMissingTrainer(trainerid,trainername,trainerparty)
        return false
      end
      if $PokemonGlobal.partner && ($PokemonTemp.waitingTrainer || doublebattle)
        othertrainer=PokeBattle_Trainer.new(
           $PokemonGlobal.partner[1],$PokemonGlobal.partner[0])
        othertrainer.id=$PokemonGlobal.partner[2]
        othertrainer.party=$PokemonGlobal.partner[3]
        playerparty=[]
        for i in 0...$Trainer.party.length
          playerparty[i]=$Trainer.party[i]
        end
        for i in 0...othertrainer.party.length
          playerparty[6+i]=othertrainer.party[i]
        end
        fullparty1=true
        playertrainer=[$Trainer,othertrainer]
        doublebattle=true
      else
        playerparty=$Trainer.party
        playertrainer=$Trainer
        fullparty1=false
      end
      #Sky battle eligibility for opponent
      if skybattle
        if $PokemonTemp.waitingTrainer
          count=0
          for poke in $PokemonTemp.waitingTrainer[0][2]
            count+=1 if pbCanSkyBattle?(poke)
          end
        end
        if count==0
          Kernel.pbMessage(_INTL("Opponent 1 doesn't have any eligible pokemon for a sky battle"))
          return false
        end
        count=0
        for poke in trainer[2]
          count+=1 if pbCanSkyBattle?(poke)
        end
        if count==0
          Kernel.pbMessage(_INTL("Opponent 2 doesn't have any eligible pokemon for a sky battle"))
          return false
        end
      end
      if $PokemonTemp.waitingTrainer
        combinedParty=[]
        fullparty2=false
        if false
          if $PokemonTemp.waitingTrainer[0][2].length>3
            raise _INTL("Opponent 1's party has more than three Pokémon, which is not allowed")
          end
          if trainer[2].length>3
            raise _INTL("Opponent 2's party has more than three Pokémon, which is not allowed")
          end
        elsif $PokemonTemp.waitingTrainer[0][2].length>3 || trainer[2].length>3
          for i in 0...$PokemonTemp.waitingTrainer[0][2].length
            combinedParty[i]=$PokemonTemp.waitingTrainer[0][2][i]
          end
          for i in 0...trainer[2].length
            combinedParty[6+i]=trainer[2][i]
          end
          fullparty2=true
        else
          for i in 0...$PokemonTemp.waitingTrainer[0][2].length
            combinedParty[i]=$PokemonTemp.waitingTrainer[0][2][i]
          end
          for i in 0...trainer[2].length
            combinedParty[3+i]=trainer[2][i]
          end
          fullparty2=false
        end
        scene=pbNewBattleScene
        battle=PokeBattle_Battle.new(scene,playerparty,combinedParty,playertrainer,
           [$PokemonTemp.waitingTrainer[0][0],trainer[0]],skybattle,inverse[COLOR="red"],noItems[/COLOR])
        trainerbgm=pbGetTrainerBattleBGM(
           [$PokemonTemp.waitingTrainer[0][0],trainer[0]])
        battle.fullparty1=fullparty1
        battle.fullparty2=fullparty2
        battle.doublebattle=battle.pbDoubleBattleAllowed?()
        battle.endspeech=$PokemonTemp.waitingTrainer[2]
        battle.endspeech2=endspeech
        battle.items=[$PokemonTemp.waitingTrainer[0][1],trainer[1]]
      else
        scene=pbNewBattleScene
        battle=PokeBattle_Battle.new(scene,playerparty,trainer[2],playertrainer,trainer[0],skybattle,inverse[COLOR="red"],noItems[/COLOR])
        battle.fullparty1=fullparty1
        battle.doublebattle=doublebattle ? battle.pbDoubleBattleAllowed?() : false
        battle.endspeech=endspeech
        battle.items=trainer[1]
        trainerbgm=pbGetTrainerBattleBGM(trainer[0])
      end
      if Input.press?(Input::CTRL) && $DEBUG
        Kernel.pbMessage(_INTL("SKIPPING BATTLE..."))
        Kernel.pbMessage(_INTL("AFTER LOSING..."))
        Kernel.pbMessage(battle.endspeech)
        Kernel.pbMessage(battle.endspeech2) if battle.endspeech2
        if $PokemonTemp.waitingTrainer
          pbMapInterpreter.pbSetSelfSwitch($PokemonTemp.waitingTrainer[1],"A",true)
          $PokemonTemp.waitingTrainer=nil
        end
        return true
      end
      Events.onStartBattle.trigger(nil,nil)
      battle.internalbattle=true
      pbPrepareBattle(battle)
      restorebgm=true
      decision=0
      Audio.me_stop
      pbBattleAnimation(trainerbgm,trainer[0].trainertype,trainer[0].name) { 
         pbSceneStandby {
            decision=battle.pbStartBattle(canlose)
         }
         for i in $Trainer.party; (i.makeUnmega rescue nil); end
         if $PokemonGlobal.partner
           pbHealAll
           for i in $PokemonGlobal.partner[3]
             i.heal
             i.makeUnmega rescue nil
             i.makeUnprimal rescue nil
           end
         end
         if decision==2 || decision==5
           if canlose
             for i in $Trainer.party; i.heal; end
             for i in 0...10
               Graphics.update
             end
           else
             $game_system.bgm_unpause
             $game_system.bgs_unpause
             Kernel.pbStartOver
           end
         else
           Events.onEndBattle.trigger(nil,decision)
           if decision==1 || decision==6
             $game_variables[26]=decision
             if $PokemonTemp.waitingTrainer
               pbMapInterpreter.pbSetSelfSwitch($PokemonTemp.waitingTrainer[1],"A",true)
             end
           end
         end
      }
      Input.update
      pbSet(variable,decision)
      $PokemonTemp.waitingTrainer=nil
      return decision==1
    end

    5.) when making trainer characters, make sure the green word is "true" if you want the bag to be inaccessable and "false" if you want the player to be able to use the Bag.
    Code:
    pbTrainerBattle(PBTrainers::YOUNGSTER,"Ben",_I("You're too good for me!"),false,0,false,0,false,false,[COLOR="SeaGreen"]false[/COLOR])
     
    Lol, instead of @opponent, just use $game_switches[x], where x is your switch number, then turn it on and off when you please.
     
    Thanks you, that worked fine.
    Leaves the problem with oppenent not switching out pokemon.
     
    Simply adding $game_switches[x] like suggested above did it for me, while being much more convenient than a new string in battles, as you could also disable it for certain pokemon encounters or w/e.
     
    Back
    Top