• 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.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Which Pokémon Masters protagonist do you like most? Let us know by casting a vote in our Masters favorite protagonist poll here!
  • Red, Hilda, Paxton, or Kellyn - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] Simple Script Help

This Script causes your team's Pokémon to lose levels by passing out and going to the Pokémon Center. But when you have a level 1 Pokémon in the Team and you lose, there is a crash, would anyone know how to solve it?

Events.onEndBattle += proc { |_sender,e|
decision = e[0]
canLose = e[1]
if decision == 2 && !canLose
$Trainer.party.each{|pkmn|
if !pkmn.isEgg?
newLv = pkmn.level - (rand(1) + 1)
newLv.clamp(1,PBExperience.maxLevel)
pkmn.level = newLv
pkmn.calcStats
end
}
end
}
 
Just save it from going below 1 by adding a additional condition.
Should do the job.

Code:
Events.onEndBattle += proc { |_sender,e|
decision = e[0]
canLose = e[1]
if decision == 2 && !canLose
$Trainer.party.each{|pkmn|
if !pkmn.isEgg? && pkmn.level > 1
newLv = pkmn.level - (rand(1) + 1)
newLv.clamp(1,PBExperience.maxLevel)
pkmn.level = newLv
pkmn.calcStats
end
}
end
}
 
Back
Top