Go Back   The PokéCommunity Forums > Create & Discover > Game Development > Scripts & Tutorials
Reload this Page Essentials Script Retrieve thrown pokeballs after battle

Notices
For all updates, view the main page.

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.



Reply
 
Thread Tools
  #1    
Old August 6th, 2014 (1:11 PM).
aramant16 aramant16 is offline
 
Join Date: Feb 2012
Posts: 8

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 highlighted 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
  attr_accessor :ballsused

And at line 209 I initialize it empty:

Code:
    @phoneTime            = 0
    @eventvars            = {}
    @safesave             = false
    @ballsused            = []

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

Code:
    pbDisplayBrief(_INTL("{1} threw one {2}!",self.pbPlayer.name,itemname))
    $PokemonGlobal.ballsused.push(ball) #balls used are recorded in the array
    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
      #### 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 && [email protected] && !$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
        }
    end
    $PokemonGlobal.ballsused=[] #to reset the array after the battle
    # Pass on Pokérus within the party
    infected=[]

Reply With Quote

Relevant Advertising!

  #2    
Old October 8th, 2014 (4:30 AM).
Sinconchi Sinconchi is offline
 
Join Date: Aug 2013
Posts: 1

Thank you very much for this script, i have been looking for something like this!

Reply With Quote
  #3    
Old April 11th, 2016 (4:41 PM).
richtofen richtofen is offline
 
Join Date: May 2015
Posts: 6

sorry for the bump. Can anyone tell me how to get this working in 16.1?

Reply With Quote
  #4    
Old April 23rd, 2016 (7:16 AM).
shiney570 shiney570 is offline
 
Join Date: Aug 2014
Location: Germany
Gender: Male
Posts: 95

why don't you just edit the part where the pokeball gets "deleted" ?

Reply With Quote
  #5    
Old April 23rd, 2016 (8:41 AM).
Rot8er_ConeX's Avatar
Rot8er_ConeX Rot8er_ConeX is offline
 
Join Date: May 2015
Location: The Dissa Region
Gender: Male
Posts: 605

Quote originally posted by shiney570:
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!

__________________
Features of Pokemon Entropy

The black circular "doodles" in my avatar are actually my username written in Gallifreyan. Yes I'm a Whovian.
Reply With Quote
  #6    
Old April 23rd, 2016 (10:54 AM).
shiney570 shiney570 is offline
 
Join Date: Aug 2014
Location: Germany
Gender: Male
Posts: 95

why are you talking about potions? why should i get infinite potions if i edit the so called subroutine to not take the pokeballs.

Reply With Quote
  #7    
Old April 23rd, 2016 (1:53 PM).
Rot8er_ConeX's Avatar
Rot8er_ConeX Rot8er_ConeX is offline
 
Join Date: May 2015
Location: The Dissa Region
Gender: Male
Posts: 605

Quote originally posted by shiney570:
why are you talking about potions? why should i get infinite potions if i edit the so called subroutine to not take the pokeballs.

Because it's the same subroutine, different items.

__________________
Features of Pokemon Entropy

The black circular "doodles" in my avatar are actually my username written in Gallifreyan. Yes I'm a Whovian.
Reply With Quote
  #8    
Old April 24th, 2016 (3:11 AM).
shiney570 shiney570 is offline
 
Join Date: Aug 2014
Location: Germany
Gender: Male
Posts: 95

so why not check for different item types? LOL

Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 6:03 PM.