• 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.
  • Dawn, Gloria, Juliana, or Summer - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • 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] Disable item and exp gain during battle

  • 34
    Posts
    9
    Years
    • Seen May 22, 2021
    Hi, I am trying to disable items like potion and revive and exp gain during wild or trainer battle using a switch. But I am not sure how to code it. Does anybody know?
     
    Find the code that runs to give exp (try searching for "exp", "gain", or some of the other words in the message). Then you can stick it inside an if.

    For disabling items find the code that runs that lets the player choose "fight", "pokemon", "items", "run", and then adapt the code that disables "run" in a trainer battle to check for a switch instead of checking for an AI trainer.
     
    I am still lost as there is so many areas to change and i not sure where to edit, is it in PBExperience section for exp issue??

    And for the item, i tried this method under pokebattle_scene but it does not work.... the red words is the one that I have edited


    Code:
    def pbItemMenu(index)
        [COLOR="Red"]if $game_switches[86]==true[/COLOR]
        ret=0
        emptyspot=-1
        pkmnid=-1
        endscene=true
        oldsprites=pbFadeOutAndHide(@sprites)
        itemscene=PokemonBag_Scene.new
        itemscene.pbStartScene($PokemonBag)
        loop do
          item=itemscene.pbChooseItem
          break if item==0
          usetype=$ItemData[item][ITEMBATTLEUSE]
          cmdUse=-1
          commands=[]
          if usetype==0
            commands[commands.length]=_INTL("Cancel")
          else
            commands[cmdUse=commands.length]=_INTL("Use")
            commands[commands.length]=_INTL("Cancel")
          end
          itemname=PBItems.getName(item)
          command=itemscene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
          if cmdUse>=0 && command==cmdUse
            if usetype==1 || usetype==3
              pkmnlist=PokemonScreen_Scene.new
              pkmnscreen=PokemonScreen.new(pkmnlist,@battle.party1)
              itemscene.pbEndScene
              pkmnscreen.pbStartScene(_INTL("Use on which Pokémon?"),@battle.doublebattle)
              pkmnid=pkmnscreen.pbChoosePokemon
              emptyspot=0 if @battle.doublebattle && @battle.battlers[0].hp<=0
              emptyspot=2 if @battle.doublebattle && @battle.battlers[2].hp<=0
              if pkmnid>=0 && @battle.pbUseItemOnPokemon(item,pkmnid,pkmnscreen)
                pkmnscreen.pbRefresh
                pkmnlist.pbEndScene
                ret=item
                endscene=false
                break
              end
              pkmnlist.pbEndScene
              itemscene.pbStartScene($PokemonBag)
            elsif usetype==2 || usetype==4
              if @battle.pbUseItemOnBattler(item,index,itemscene)
                ret=item
                break
                [COLOR="red"]end[/COLOR]
              end
            end
          end
        end
     
    Last edited:
    I am still lost as there is so many areas to change and i not sure where to edit, is it in PBExperience section for exp issue??
    You might be able to make the change in there. Which function do you think you'd have to change?

    And for the item, i tried this method under pokebattle_scene but it does not work.... the red words is the one that I have edited

    Spoiler:
    This seems like a good start. What do you mean it doesn't work? Do you get an error message, or does it do nothing? If it does nothing, is your switch set to true?

    The only other thing I can think of is that you need to return 0 if the switch is false, because of what this comment says:
    Code:
    # Use this method to display the inventory
    # The return value is the item chosen, or 0 if the choice was canceled.
    Returning a 0 ought to behave exactly like if the player cancelled out of the menu.
     
    For the item yea, it does nothing, and yup it sets to true.
    meaning if i set to false, it will be disabled?

    let me try about it first
     
    For the item yea, it does nothing, and yup it sets to true.
    meaning if i set to false, it will be disabled?

    let me try about it first

    Yes. The way you wrote your code is "item menu only works if switch is true".

    You should get into the habit of testing your changes more fully. It would have only taken a minute to see what happens if you had it set to false, and then see what happens if it's true.
     
    Hmm, well i kinda works, I got this error message but the game can still continue:

    Exception: NoMethodError
    Message: undefined method `>' for nil:NilClass
    PokeBattle_Scene:2469:in `pbItemMenu'
    PokeBattle_Battle:2626:in `pbItemMenu'
    PokeBattle_Battle:2709:in `pbCommandPhase'
    PokeBattle_Battle:2666:in `loop'
    PokeBattle_Battle:2756:in `pbCommandPhase'
    PokeBattle_Battle:2655:in `each'
    PokeBattle_Battle:2655:in `pbCommandPhase'
    PokeBattle_Battle:2602:in `pbStartBattleCore'
    PokeBattle_Battle:2601:in `logonerr'
    PokeBattle_Battle:2601:in `pbStartBattleCore'
     
    Hmm, well i kinda works, I got this error message but the game can still continue:

    Exception: NoMethodError
    Message: undefined method `>' for nil:NilClass
    PokeBattle_Scene:2469:in `pbItemMenu'
    PokeBattle_Battle:2626:in `pbItemMenu'
    PokeBattle_Battle:2709:in `pbCommandPhase'
    PokeBattle_Battle:2666:in `loop'
    PokeBattle_Battle:2756:in `pbCommandPhase'
    PokeBattle_Battle:2655:in `each'
    PokeBattle_Battle:2655:in `pbCommandPhase'
    PokeBattle_Battle:2602:in `pbStartBattleCore'
    PokeBattle_Battle:2601:in `logonerr'
    PokeBattle_Battle:2601:in `pbStartBattleCore'

    This would be fixed by returning 0 instead of doing nothing if the switch is false. You can tell if you read the first line of code mentioned near the top of that error message (i.e. PokeBattle_Scene:2469).
    EDIT: And by knowing that a function returns nil by default.
     
    Last edited:
    sorry I dont understand what it means by returning to 0.
    = to 0 ?
     
    Code:
    def pbItemMenu(index)
        [color=red]return 0 if $game_switches[86]==false[/color]
        ret=0
        emptyspot=-1
        pkmnid=-1
        endscene=true
        oldsprites=pbFadeOutAndHide(@sprites)
        itemscene=PokemonBag_Scene.new
        itemscene.pbStartScene($PokemonBag)
        loop do
          item=itemscene.pbChooseItem
          break if item==0
          usetype=$ItemData[item][ITEMBATTLEUSE]
          cmdUse=-1
          commands=[]
          if usetype==0
            commands[commands.length]=_INTL("Cancel")
          else
            commands[cmdUse=commands.length]=_INTL("Use")
            commands[commands.length]=_INTL("Cancel")
          end
          itemname=PBItems.getName(item)
          command=itemscene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
          if cmdUse>=0 && command==cmdUse
            if usetype==1 || usetype==3
              pkmnlist=PokemonScreen_Scene.new
              pkmnscreen=PokemonScreen.new(pkmnlist,@battle.party1)
              itemscene.pbEndScene
              pkmnscreen.pbStartScene(_INTL("Use on which Pokémon?"),@battle.doublebattle)
              pkmnid=pkmnscreen.pbChoosePokemon
              emptyspot=0 if @battle.doublebattle && @battle.battlers[0].hp<=0
              emptyspot=2 if @battle.doublebattle && @battle.battlers[2].hp<=0
              if pkmnid>=0 && @battle.pbUseItemOnPokemon(item,pkmnid,pkmnscreen)
                pkmnscreen.pbRefresh
                pkmnlist.pbEndScene
                ret=item
                endscene=false
                break
              end
              pkmnlist.pbEndScene
              itemscene.pbStartScene($PokemonBag)
            elsif usetype==2 || usetype==4
              if @battle.pbUseItemOnBattler(item,index,itemscene)
                ret=item
                break
              end
            end
          end
        end

    That sort of thing.

    (Note, it's more idiomatic to write "!foo" rather than "foo==false")
     
    Last edited:
    Now there is a syntax error at line 3301 which is at the end of the page.
     
    Unfortutantely, it still does not work as there are still errors. What I have found out is that if delete the "return 0 if " without adding any "end" the game can continue but still can use item.
    But if i keep the "return 0 if " and I add the " end" with the rest of them, there is still syntax errors.
    If I keep the "return 0 if " but delete the "end" that I inserted below the break. The game can continue but i can still use the items.
     
    If I keep the "return 0 if " but delete the "end" that I inserted below the break. The game can continue but i can still use the items.

    That is the configuration of code I intended. I am surprised that it doesn't work, have you tried toggling the switch? Anyway, good luck.
     
    Last edited:
    yes I think I figured it out alrdy thx alot I feel I like a noob. Gonna try Adding words indicating cant use item to update those who want to use this script. I still experimentin about the exp gain. Once again thx.
     
    So for those who want to use temporary disable exp during battle using a switch. Control shift F "# Now calculate EXP for the participants ". It will bring the page to def pbGainEXP at secontion PokeBattle_battle. Find this code and add the script in red. This will disable the comment for expshare and expall if you have include in the script. You can choose what switch number you want.

    Code:
    # Now calculate EXP for the participants
            if partic>0 || expshare>0 || haveexpall 
              if !@opponent && successbegin && pbAllFainted?(@party2)
                @scene.pbWildBattleSuccess
                successbegin=false
              end
              for j in [email protected]
                next if !@party1[j] || !pbIsOwner?(0,j)
                next if @party1[j].hp<=0 || @party1[j].isEgg?
                haveexpshare=(isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
                              isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE))
                next if !haveexpshare && !@battlers[i].participants.include?(j)
                pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall)
              end
              if haveexpall
                showmessage=true
                 [COLOR="red"]if $game_switches[179]==true
                  showmessage=false
                 end[/COLOR] 
                for j in [email protected]
                  next if !@party1[j] || !pbIsOwner?(0,j)
                  next if @party1[j].hp<=0 || @party1[j].isEgg?
                  next if isConst?(@party1[j].item,PBItems,:EXPSHARE) ||
                          isConst?(@party1[j].itemInitial,PBItems,:EXPSHARE)
                  next if @battlers[i].participants.include?(j)
                  pbDisplayPaused(_INTL("The rest of your team gained Exp. Points thanks to the {1}!",
                     PBItems.getName(getConst(PBItems,:EXPALL)))) if showmessage  
                  showmessage=false
                  pbGainExpOne(j,@battlers[i],partic,expshare,haveexpall,false)
                end
              end
            end

    In the same section ( pokebattle_battle) , control F "growthrate=thispoke.growthrate" Then add the words in red in this code. Use the same switch number as before. This code allows your switch to disable exp gain.

    Code:
    growthrate=thispoke.growthrate
        newexp=PBExperience.pbAddExperience(thispoke.exp,exp,growthrate)
        exp=newexp-thispoke.exp
        
        [COLOR="red"]if $game_switches[179]==true 
            exp=0
        end[/COLOR]
       
        if exp>0
          if showmessages
            if isOutsider
              pbDisplayPaused(_INTL("{1} gained a boosted {2} Exp. Points!",thispoke.name,exp))
            else
              pbDisplayPaused(_INTL("{1} gained {2} Exp. Points!",thispoke.name,exp))
            end
          end

    To temporary disable bag during using a switch, Control shift F "Use this method to display the inventory" choose the option with pokebattle_scene. Add the script in red. You can choose what switch number you want. Unfortunately, I still not sure how to add the comment" item not allowed" so please enlighten me if anybody knows.

    Code:
    def pbItemMenu(index)
        [COLOR="red"]return 0 if $game_switches[178]==true[/COLOR]
        ret=0
        emptyspot=-1
        pkmnid=-1
        endscene=true
        oldsprites=pbFadeOutAndHide(@sprites)
        itemscene=PokemonBag_Scene.new
        itemscene.pbStartScene($PokemonBag)
        loop do
          item=itemscene.pbChooseItem
          break if item==0
          usetype=$ItemData[item][ITEMBATTLEUSE]
          cmdUse=-1
          commands=[]
          if usetype==0
            commands[commands.length]=_INTL("Cancel")
          else
            commands[cmdUse=commands.length]=_INTL("Use")
            commands[commands.length]=_INTL("Cancel")
          end
          itemname=PBItems.getName(item)
          command=itemscene.pbShowCommands(_INTL("{1} is selected.",itemname),commands)
          if cmdUse>=0 && command==cmdUse
            if usetype==1 || usetype==3
              pkmnlist=PokemonScreen_Scene.new
              pkmnscreen=PokemonScreen.new(pkmnlist,@battle.party1)
              itemscene.pbEndScene
              pkmnscreen.pbStartScene(_INTL("Use on which Pokémon?"),@battle.doublebattle)
              pkmnid=pkmnscreen.pbChoosePokemon
              emptyspot=0 if @battle.doublebattle && @battle.battlers[0].hp<=0
              emptyspot=2 if @battle.doublebattle && @battle.battlers[2].hp<=0
              if pkmnid>=0 && @battle.pbUseItemOnPokemon(item,pkmnid,pkmnscreen)
                pkmnscreen.pbRefresh
                pkmnlist.pbEndScene
                ret=item
                endscene=false
                break
              end
              pkmnlist.pbEndScene
              itemscene.pbStartScene($PokemonBag)
            elsif usetype==2 || usetype==4
              if @battle.pbUseItemOnBattler(item,index,itemscene)
                ret=item
                break
              end
            end
          end
        end
     
    Last edited:
    Back
    Top