• 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?".
  • 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.

Retrieve thrown pokeballs after battle

8
Posts
12
Years
    • Seen Dec 28, 2016
    Tired of throwing pokeballs that misteriously disappear after battle? This script allows you to retrieve some of the balls you used.
    With my settings, you can retrieve 1/3 of the balls with 40% chances, 1/2 with 9% and all but one with 1%. This is valid for each kind of ball you use during the battle, as long as you use at least two ball (for each type). E.g. : I throw 3 pokeballs, 2 megaball and 1 ultraball; I can retrieve the pokeballs and the megaballs, but not the ultraball.

    I know this isn't an incredible code, or very usefull, but that's what I can do for now. I hope to produce something better in the future, but for now that's all what I got:

    (I [S-HIGHLIGHT]highlighted [/S-HIGHLIGHT]the part of the code I added)

    To insert this function, I firstly created an array variable under the PokemonGlobalMetadata class, in the PokemonMap section, around line 149:

    Code:
      attr_accessor :phoneNumbers
      attr_accessor :phoneTime
      attr_accessor :eventvars
      attr_accessor :safesave
      [S-HIGHLIGHT]attr_accessor :ballsused[/S-HIGHLIGHT]

    And at line 209 I initialize it empty:

    Code:
        @phoneTime            = 0
        @eventvars            = {}
        @safesave             = false
        [S-HIGHLIGHT]@ballsused            = [][/S-HIGHLIGHT]

    Then I added this line in the function pbThrowPokeBall, at line 136:

    Code:
        pbDisplayBrief(_INTL("{1} threw one {2}!",self.pbPlayer.name,itemname))
        [S-HIGHLIGHT]$PokemonGlobal.ballsused.push(ball) #balls used are recorded in the array[/S-HIGHLIGHT]
        if battler.hp<=0

    In the end, I added the function in the PokeBattle_Battle section, around line 3561. I created a when in pbEndOfBattle, in case the battle is won (1) or the pokemon caught (4)
    (anyway when I defeat a wild pokemon, the code doesn't work, and I don't know why).

    Code:
            elsif @decision==5
              PBDebug.log("[Draw game]") if $INTERNAL
            end
         [S-HIGHLIGHT] #### 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)
                pbDisplayPaused(_INTL("{1} picked up {2} {3} he has thrown during the fight", $Trainer.name, retrieved, PBItems.getName(ball)))
              end
            }[/S-HIGHLIGHT]
        end
        [S-HIGHLIGHT]$PokemonGlobal.ballsused=[] #to reset the array after the battle[/S-HIGHLIGHT]
        # Pass on Pokérus within the party
        infected=[]
     
    1
    Posts
    10
    Years
    • Seen Oct 8, 2014
    Thank you very much for this script, i have been looking for something like this!
     
    824
    Posts
    8
    Years
  • why don't you just edit the part where the pokeball gets "deleted" ? :)

    because that's not how any of this works. You USE the item. This calls a subroutine that deletes the item being used. If you change that part of the subroutine, then Potions don't get "deleted" either. INFINITE HEALTH FOR EVERYONE!
     
    95
    Posts
    9
    Years
  • why are you talking about potions? why should i get infinite potions if i edit the so called subroutine to not take the pokeballs.
     

    Zeak6464

    Zeak #3205 - Discord
    1,101
    Posts
    11
    Years
  • (I [S-HIGHLIGHT]highlighted [/S-HIGHLIGHT]the part of the code I added)

    To insert this function, created an array variable under the PokemonGlobalMetadata class, in the PokemonMap section, around line 149:

    Code:
      attr_accessor :phoneNumbers
      attr_accessor :phoneTime
      attr_accessor :eventvars
      attr_accessor :safesave
      [S-HIGHLIGHT]attr_accessor :ballsused[/S-HIGHLIGHT]

    And at line 209 or an Empty space:

    Code:
        @phoneTime            = 0
        @eventvars            = {}
        @safesave             = false
        [S-HIGHLIGHT]@ballsused            = [][/S-HIGHLIGHT]

    add this line in the function pbThrowPokeBall:

    Code:
    when 0
            pbDisplay(_INTL("Oh no! The Pokémon broke free!"))
            [S-HIGHLIGHT] $PokemonGlobal.ballsused.push(ball) [/S-HIGHLIGHT]
            BallHandlers.onFailCatch(ball,self,battler)
          when 1
            pbDisplay(_INTL("Aww... It appeared to be caught!"))
            [S-HIGHLIGHT] $PokemonGlobal.ballsused.push(ball) [/S-HIGHLIGHT]
            BallHandlers.onFailCatch(ball,self,battler)
          when 2
            pbDisplay(_INTL("Aargh! Almost had it!"))
            [S-HIGHLIGHT] $PokemonGlobal.ballsused.push(ball) [/S-HIGHLIGHT]
            BallHandlers.onFailCatch(ball,self,battler)
          when 3
            pbDisplay(_INTL("Gah! It was so close, too!"))
            [S-HIGHLIGHT] $PokemonGlobal.ballsused.push(ball) [/S-HIGHLIGHT]
            BallHandlers.onFailCatch(ball,self,battler)

    add the function in the PokeBattle_Battle section, around line 3561. created a when in pbEndOfBattle, in case the battle is won (1) or the pokemon caught (4)

    This is for v16.2
    and 99% Chance at getting the balls back , you could also change that us as well by editing the
    chances=[99]
    Code:
    [S-HIGHLIGHT]
    
    #### 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|
                chances=[99]
                rnd=rand(100)
                if rnd<chances[0]
                  retrieved=(thrown)
                end
            $PokemonBag.pbStoreItem(ball,retrieved)
            pbDisplayPaused(_INTL("{1} picked up {2} {3} he has thrown during the fight", $Trainer.name, retrieved, PBItems.getName(ball)))}
        end
        $PokemonGlobal.ballsused=[] #to reset the array after the battle
    
    [/S-HIGHLIGHT]

    Thanks to :
    aramant16

    Edited by:
    Zeak
    Yoshi
     
    Back
    Top