Advertisement
Vendily

Overworld Rest

Jun 19th, 2019
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.69 KB | None | 0 0
  1. # Pokemon fall asleep after a battle if and only if they are not at full health and they do not already have a status, as well as a bit of a random chance. The trainer has to walk a bit before the pokemon might fall asleep. I have the rates set way too high. Pokemon have a chance to wake up when their hp is full. Credit to Riviera for the idea, and I'll probably edit this with the proper styled header once I have their approval for the implementation.
  2. OVERWORLDRESTSTEPTHRESHOLD    = 30 # 30 steps to have chance of sleeping
  3. OVERWORLDRESTSLEEPCHANCE      = 4  # 1/4 chance of falling asleep
  4. OVERWORLDRESTWAKECHANCE       = 4  # 1/4 chance of staying asleep at full health
  5. OVERWORLDRESTHEALFRACTION     = 16 # 1/16 of total hp healed
  6.  
  7. class PokeBattle_Pokemon
  8.   attr_accessor(:overworldreststeps)
  9.  
  10.   def overworldreststeps
  11.     @overworldreststeps=0 if !@overworldreststeps
  12.     return @overworldreststeps
  13.   end
  14. end
  15.  
  16. Events.onEndBattle+=proc {|sender,e|
  17.    decision = e[0]
  18.    canlose  = e[1]
  19.    for pkmn in $Trainer.party
  20.      pkmn.overworldreststeps=0
  21.    end
  22. }
  23.  
  24. Events.onStepTaken+=proc {|sender,e|
  25.    next if !$Trainer
  26.    for pkmn in $Trainer.party
  27.      pkmn.overworldreststeps+=1
  28.      if pkmn.status==0 && pkmn.hp!=pkmn.totalhp &&
  29.          pkmn.overworldreststeps>OVERWORLDRESTSTEPTHRESHOLD &&
  30.          rand(OVERWORLDRESTSLEEPCHANCE)==0
  31.        pkmn.status=PBStatuses::SLEEP
  32.        pkmn.statusCount=3
  33.      end
  34.      if pkmn.status==PBStatuses::SLEEP
  35.        pkmn.hp+=(pkmn.totalhp/OVERWORLDRESTHEALFRACTION).floor
  36.        pkmn.hp=pkmn.totalhp if pkmn.hp>pkmn.totalhp
  37.        if pkmn.hp==pkmn.totalhp
  38.          pkmn.healStatus if rand(OVERWORLDRESTWAKECHANCE)==0
  39.        end
  40.      end
  41.    end
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement