• 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.
  • 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] Picking up thrown Pokeballs

  • 143
    Posts
    11
    Years
    • Seen Jun 11, 2021
    So I applied a really old script made for an older version of Essentials. This script was made by aramant16. I followed the installation scripts as close as I could since I'm using Version 16.2 rather than the old version the script was made for and I've had little to no problems with it until my game suddenly crashed with this error:

    Spoiler:

    I've determined the error has something to do with this line of code:
    Code:
    def self.pbStoreItem(items,maxsize,maxPerSlot,item,qty,sorting=false)
        raise "Invalid value for qty: #{qty}" if qty<0
    The only problem is I don't know how to fix it. Here's where I inserted the main parts of the code, by the way:

    Code:
    elsif @decision==2
            @scene.pbShowOpponent(0)
            pbDisplayPaused(@endspeechwin.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
            if @opponent.is_a?(Array)
              @scene.pbHideOpponent
              @scene.pbShowOpponent(1)
              pbDisplayPaused(@endspeechwin2.gsub(/\\[Pp][Nn]/,self.pbPlayer.name))
            end
          end
          [COLOR=Red][B]#### PICK UP POKEBALLS ####
          when 1, 4
            pokeballs=$PokemonGlobal.ballsused
            ball_count=Hash.new(0)
            pokeballs.each{|balltype| ball_count[balltype]+=1}
            ball_count.each{|ball, thrown|
    #Balls are not retrieved if they are thrown on or under water, or after a battle
              if ball_count[ball]>1 && !@opponent && !$PokemonGlobal.diving && !$PokemonGlobal.surfing
                chances=[40,9,1]
                rnd=rand(100)
                if rnd<chances[0]
                  retrieved=(thrown/3)
                elsif rnd<(chances[0]+chances[1])
                  retrieved=(thrown/2)
                elsif rnd<(chances[0]+chances[1]+chances[2])
                  retrieved=(thrown-1) #number of balls picked up shouldn't be superior to balls thrown (if pokemon is captured)
                end
                $PokemonBag.pbStoreItem(ball,retrieved)
                if retrieved>0
                  pbDisplayPaused(_INTL("{1} picked up {2} {3} thrown during the fight", $Trainer.name, retrieved, PBItems.getName(ball)))
                end
              end
            }
        end
        $PokemonGlobal.ballsused=[] #to reset the array after the battle[/B][/COLOR]
        # Pass on Pokérus within the party
        infected=[]
     
    Back
    Top