- 8
- Posts
- 13
- 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:
And at line 209 I initialize it empty:
Then I added this line in the function pbThrowPokeBall, at line 136:
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).
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=[]