Advertisement
TechSkylander1518

Bonus HP Bars

Mar 29th, 2021 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.05 KB | None | 0 0
  1. #There's two changes in other scripts that need to be made to make this work right:
  2. # In Battle_StartAndEnd, find  def pbEndOfBattle and paste this right below it: (minus the #)
  3. #    $game_variables[BARS_VARIABLE]=0
  4. # This makes sure that the variable for bonus bars is reset after each battle.
  5. # In PItem_BattleItemEffects, find this section:
  6. #     if battler.semiInvulnerable?
  7. #      scene.pbDisplay(_INTL("It's no good! It's impossible to aim at a Pokémon that's not in sight!")) if showMessages
  8. #      next false
  9. #    end
  10. # Below "end", paste this: (minus the #s)
  11. #    if battler.pokemon.hpbars && battler.pokemon.hpbars>0
  12. #      scene.pbDisplay(_INTL("It's no good! There's no way the Pokémon can be caught with this much HP!")) if showMessages
  13. #      next false
  14. #    end
  15. # This makes sure that the player can't catch a Pokemon with bonus bars
  16.  
  17.  
  18. #The variable that stores how many bonus bars a Pokemon will get
  19. BARS_VARIABLE=2
  20. #The variable that stores which position in a trainer's party should be given bonus bars
  21. TRAINER_POSITION_VARIABLE=4
  22.  
  23.  
  24. module Multiple_HP
  25.    attr_reader   :hpbars
  26.  
  27.    @hpbars=0
  28.  
  29.   def hpbars=(value)
  30.     value = 0 if value<0
  31.     @hpbars = value
  32.     @pokemon.hpbars = value if @pokemon
  33.   end
  34.  
  35.  
  36.   def hp=(value)
  37.     value = 0 if value<0
  38.     @hp = value
  39.     if @hp==0
  40.      if @hpbars>0
  41.          @hpbars-=1
  42.          @hp=@totalhp
  43.      else
  44.         @status      = PBStatuses::NONE
  45.         @statusCount = 0
  46.       end
  47.     end
  48.   end
  49.  
  50.  
  51. end
  52.  
  53.  
  54. class PokeBattle_Pokemon
  55.  include Multiple_HP
  56. end
  57.  
  58.  
  59. class PokeBattle_Battler
  60.  include Multiple_HP
  61.  
  62.    def pbFaint(showMessage=true)
  63.     if @pokemon.hpbars
  64.       if @pokemon.hpbars>0
  65.         @pokemon.hpbars-=1
  66.         self.hp+=self.totalhp
  67.         @battle.scene.pbRefreshOne(@index)
  68.         @battle.pbDisplayBrief(_INTL("{1}'s health bar was depleted!",pbThis)) if showMessage
  69.         return
  70.       end
  71.     end
  72.     if !fainted?
  73.       PBDebug.log("!!!***Can't faint with HP greater than 0")
  74.       return
  75.     end
  76.     return if @fainted   # Has already fainted properly
  77.     @battle.pbDisplayBrief(_INTL("{1} fainted!",pbThis)) if showMessage
  78.     PBDebug.log("[Pokémon fainted] #{pbThis} (#{@index})") if !showMessage
  79.     @battle.scene.pbFaintBattler(self)
  80.     pbInitEffects(false)
  81.     # Reset status
  82.     self.status      = PBStatuses::NONE
  83.     self.statusCount = 0
  84.     # Lose happiness
  85.     if @pokemon && @battle.internalBattle
  86.       badLoss = false
  87.       @battle.eachOtherSideBattler(@index) do |b|
  88.         badLoss = true if b.level>=self.level+30
  89.       end
  90.       @pokemon.changeHappiness((badLoss) ? "faintbad" : "faint")
  91.     end
  92.     # Reset form
  93.     @battle.peer.pbOnLeavingBattle(@battle,@pokemon,@battle.usedInBattle[idxOwnSide][@index/2])
  94.     @pokemon.makeUnmega if mega?
  95.     @pokemon.makeUnprimal if primal?
  96.     # Do other things
  97.     @battle.pbClearChoice(@index)   # Reset choice
  98.     pbOwnSide.effects[PBEffects::LastRoundFainted] = @battle.turnCount
  99.     # Check other battlers' abilities that trigger upon a battler fainting
  100.     pbAbilitiesOnFainting
  101.     # Check for end of primordial weather
  102.     @battle.pbEndPrimordialWeather
  103.   end
  104.  
  105.  
  106. end
  107.  
  108.  
  109.  
  110. class PokemonDataBox
  111.     def initializeDataBoxGraphic(sideSize)
  112.     @sideSize=sideSize
  113.     onPlayerSide = ((@battler.index%2)==0)
  114.     if !@battler.pokemon.hpbars
  115.       @battler.pokemon.hpbars=0
  116.     end
  117.     # Get the data box graphic and set whether the HP numbers/Exp bar are shown
  118.     if sideSize==1   # One Pokémon on side, use the regular data box BG
  119.       bgFilename = ["Graphics/Pictures/Battle/databox_normal",
  120.                     "Graphics/Pictures/Battle/databox_normal_foe"][@battler.index%2]
  121.       if onPlayerSide
  122.         @showHP  = true
  123.         @showExp = true
  124.       end
  125.     else   # Multiple Pokémon on side, use the thin data box BG
  126.       bgFilename = ["Graphics/Pictures/Battle/databox_thin",
  127.                     "Graphics/Pictures/Battle/databox_thin_foe"][@battler.index%2]
  128.     end
  129.       #Set up multibar box BGs
  130.     if  @battler.pokemon.hpbars>0
  131.         @showHP  = false
  132.         @showExp = false
  133.         bgFilename = ["Graphics/Pictures/Battle/databox_multibars",
  134.               "Graphics/Pictures/Battle/databox_multibars_foe"][@battler.index%2]
  135.         if @battler.pokemon.hpbars>3
  136.           bgFilename = ["Graphics/Pictures/Battle/databox_multibars_mid",
  137.                     "Graphics/Pictures/Battle/databox_multibars_mid_foe"][@battler.index%2]          
  138.         end
  139.         if @battler.pokemon.hpbars>6
  140.           bgFilename = ["Graphics/Pictures/Battle/databox_multibars_big",
  141.                     "Graphics/Pictures/Battle/databox_multibars_big_foe"][@battler.index%2]
  142.         end
  143.     end
  144.      bgFilename = ["Graphics/Pictures/Battle/databox_multibars_big",
  145.                     "Graphics/Pictures/Battle/databox_multibars_big_foe"][@battler.index%2]
  146.     @databoxBitmap  = AnimatedBitmap.new(bgFilename)
  147.     # Determine the co-ordinates of the data box and the left edge padding width
  148.     if onPlayerSide
  149.       if @battler.pokemon.hpbars>0
  150.       @spriteX = Graphics.width - 260
  151.     else
  152.       @spriteX = Graphics.width - 244
  153.     end
  154.       @spriteY = Graphics.height - 192
  155.       if @battler.pokemon.hpbars>6
  156.           @spriteY = Graphics.height - 212
  157.       end
  158.       @spriteBaseX = 34
  159.     else
  160.       if @battler.pokemon.hpbars>0
  161.         @spriteX = 0
  162.       else
  163.         @spriteX = -16
  164.       end
  165.       @spriteY = 36
  166.       if @battler.pokemon.hpbars>6
  167.         @spriteY = 16
  168.       end
  169.       @spriteBaseX = 16
  170.     end
  171.     case sideSize
  172.     when 2
  173.       @spriteX += [-12,  12,  0,  0][@battler.index]
  174.       @spriteY += [-20, -34, 34, 20][@battler.index]
  175.     when 3
  176.       @spriteX += [-12,  12, -6,  6,  0,  0][@battler.index]
  177.       @spriteY += [-42, -46,  4,  0, 50, 46][@battler.index]
  178.     end
  179.   end
  180.  
  181.  
  182.   def initializeOtherGraphics(viewport)
  183.     # Create other bitmaps
  184.     @numbersBitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/icon_numbers"))
  185.     @hpBarBitmap   = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/overlay_hp"))
  186.     @expBarBitmap  = AnimatedBitmap.new(_INTL("Graphics/Pictures/Battle/overlay_exp"))
  187.     # Create sprite to draw HP numbers on
  188.     @hpNumbers = BitmapSprite.new(124,16,viewport)
  189.     pbSetSmallFont(@hpNumbers.bitmap)
  190.     @sprites["hpNumbers"] = @hpNumbers
  191.     # Create sprite wrapper that displays HP bar
  192.     @hpBar = SpriteWrapper.new(viewport)
  193.     @hpBar.bitmap = @hpBarBitmap.bitmap
  194.     @hpBar.src_rect.height = @hpBarBitmap.height/3
  195.     @sprites["hpBar"] = @hpBar
  196.     # Create sprite wrapper that displays Exp bar
  197.     @expBar = SpriteWrapper.new(viewport)
  198.     @expBar.bitmap = @expBarBitmap.bitmap
  199.     @sprites["expBar"] = @expBar
  200.     # Create sprite wrapper that displays everything except the above
  201.     @contents = BitmapWrapper.new(@databoxBitmap.width,@databoxBitmap.height)
  202.     self.bitmap  = @contents
  203.     self.visible = false
  204.     self.z       = 150+((@battler.index)/2)*5
  205.     pbSetSystemFont(self.bitmap)
  206.   end
  207.  
  208.   def dispose
  209.     pbDisposeSpriteHash(@sprites)
  210.     @databoxBitmap.dispose
  211.     @numbersBitmap.dispose
  212.     @hpBarBitmap.dispose
  213.     @expBarBitmap.dispose
  214.     @contents.dispose
  215.     super
  216.   end
  217.  
  218.  
  219.   def refresh
  220.     self.bitmap.clear
  221.     return if !@battler.pokemon
  222.     if !@battler.pokemon.hpbars
  223.       @battler.pokemon.hpbars=0
  224.     end
  225.     textPos = []
  226.     imagePos = []
  227.     # Draw background panel
  228.     #update the panel if number of bars has changed
  229.     onPlayerSide = ((@battler.index%2)==0)
  230.     # Get the data box graphic and set whether the HP numbers/Exp bar are shown
  231.     if @sideSize==1   # One Pokémon on side, use the regular data box BG
  232.       bgFilename = ["Graphics/Pictures/Battle/databox_normal",
  233.                     "Graphics/Pictures/Battle/databox_normal_foe"][@battler.index%2]
  234.       if onPlayerSide
  235.         @showHP  = true
  236.         @showExp = true
  237.       end
  238.     else   # Multiple Pokémon on side, use the thin data box BG
  239.       bgFilename = ["Graphics/Pictures/Battle/databox_thin",
  240.                     "Graphics/Pictures/Battle/databox_thin_foe"][@battler.index%2]
  241.     end
  242.     if @battler.pokemon.hpbars>0
  243.         @showHP  = false
  244.         @showExp = false
  245.           bgFilename = ["Graphics/Pictures/Battle/databox_multibars_big",
  246.                     "Graphics/Pictures/Battle/databox_multibars_big_foe"][@battler.index%2]
  247.         if @battler.pokemon.hpbars<=6
  248.           bgFilename = ["Graphics/Pictures/Battle/databox_multibars_mid",
  249.                     "Graphics/Pictures/Battle/databox_multibars_mid_foe"][@battler.index%2]          
  250.         end
  251.         if @battler.pokemon.hpbars<=3
  252.               bgFilename = ["Graphics/Pictures/Battle/databox_multibars",
  253.               "Graphics/Pictures/Battle/databox_multibars_foe"][@battler.index%2]
  254.         end
  255.     end      
  256.     @databoxBitmap  = AnimatedBitmap.new(bgFilename)
  257.     if onPlayerSide
  258.           @spriteX = Graphics.width - 260
  259.           @spriteY = Graphics.height - 192
  260.         if @battler.pokemon.hpbars>6
  261.             @spriteY = Graphics.height - 212
  262.           end
  263.     else
  264.         @spriteX = 0
  265.         @spriteY = 36
  266.         if  @battler.pokemon.hpbars>6
  267.           @spriteY = 16
  268.         end
  269.     end
  270.     self.bitmap.blt(0,0,@databoxBitmap.bitmap,Rect.new(0,0,@databoxBitmap.width,@databoxBitmap.height))
  271.     # Draw Pokémon's name
  272.     nameWidth = self.bitmap.text_size(@battler.name).width
  273.     nameOffset = 0
  274.     nameOffset = nameWidth-116 if nameWidth>116
  275.     textPos.push([@battler.name,@spriteBaseX+8-nameOffset,6,false,NAME_BASE_COLOR,NAME_SHADOW_COLOR])
  276.     # Draw Pokémon's gender symbol
  277.     case @battler.displayGender
  278.     when 0   # Male
  279.       textPos.push([_INTL("♂"),@spriteBaseX+126,6,false,MALE_BASE_COLOR,MALE_SHADOW_COLOR])
  280.     when 1   # Female
  281.       textPos.push([_INTL("♀"),@spriteBaseX+126,6,false,FEMALE_BASE_COLOR,FEMALE_SHADOW_COLOR])
  282.     end
  283.     pbDrawTextPositions(self.bitmap,textPos)
  284.     # Draw Pokémon's level
  285.     imagePos.push(["Graphics/Pictures/Battle/overlay_lv",@spriteBaseX+140,16])
  286.     pbDrawNumber(@battler.level,self.bitmap,@spriteBaseX+162,16)
  287.     # Draw shiny icon
  288.     if @battler.shiny?
  289.       shinyX = (@battler.opposes?(0)) ? 206 : -6   # Foe's/player's
  290.       imagePos.push(["Graphics/Pictures/shiny",@spriteBaseX+shinyX,36])
  291.     end
  292.     # Draw Mega Evolution/Primal Reversion icon
  293.     if @battler.mega?
  294.       imagePos.push(["Graphics/Pictures/Battle/icon_mega",@spriteBaseX+8,34])
  295.     elsif @battler.primal?
  296.       primalX = (@battler.opposes?) ? 208 : -28   # Foe's/player's
  297.       if @battler.isSpecies?(:KYOGRE)
  298.         imagePos.push(["Graphics/Pictures/Battle/icon_primal_Kyogre",@spriteBaseX+primalX,4])
  299.       elsif @battler.isSpecies?(:GROUDON)
  300.         imagePos.push(["Graphics/Pictures/Battle/icon_primal_Groudon",@spriteBaseX+primalX,4])
  301.       end
  302.     end
  303.     # Draw owned icon (foe Pokémon only)
  304.     if @battler.owned? && @battler.opposes?(0)
  305.       imagePos.push(["Graphics/Pictures/Battle/icon_own",@spriteBaseX+8,36])
  306.     end
  307.     # Draw status icon
  308.     if @battler.status>0
  309.       s = @battler.status
  310.       s = 6 if s==PBStatuses::POISON && @battler.statusCount>0   # Badly poisoned
  311.       imagePos.push(["Graphics/Pictures/Battle/icon_statuses",@spriteBaseX+24,36,
  312.          0,(s-1)*STATUS_ICON_HEIGHT,-1,STATUS_ICON_HEIGHT])
  313.     end
  314.     #Draw bonus HP bars
  315.     if @battler.pokemon.hpbars>0    
  316.       if onPlayerSide
  317.         @Column=[36,110,186]
  318.         @Row=[68,84,100]
  319.       else
  320.         @Column=[8,84,160]
  321.         @Row=[60,76,92]
  322.       end
  323.       @ColumnNo=0
  324.       @RowNo=0
  325.       for i in 0...@battler.pokemon.hpbars
  326.           if @ColumnNo>2
  327.             @ColumnNo=0
  328.             @RowNo+=1
  329.           end
  330.         imagePos.push(["Graphics/Pictures/Battle/overlay_multibar",@Column[@ColumnNo],@Row[@RowNo],0,0,66,6])
  331.         @ColumnNo+=1
  332.       end
  333.     end
  334.     pbDrawImagePositions(self.bitmap,imagePos)
  335.     refreshHP
  336.     refreshExp
  337.   end
  338.  
  339.  
  340. end
  341.  
  342.  
  343. def multibarFoe(bars,position=0)
  344.   $game_variables[BARS_VARIABLE]=bars
  345.   $game_variables[TRAINER_POSITION_VARIABLE]=position
  346. end
  347.  
  348. #Sets wild Pokemon to have bonus bars
  349.  
  350. Events.onWildPokemonCreate += proc { |_sender, e|
  351.   pokemon = e[0]
  352.   if $game_variables[BARS_VARIABLE]>0
  353.     pokemon.hpbars=$game_variables[BARS_VARIABLE]
  354.   end
  355. }
  356.  
  357.  
  358. #Sets a trainer's Pokemon to have bonus bars
  359.  
  360. Events.onTrainerPartyLoad += proc { |_sender, e|
  361.   if e[0] # Trainer data should exist to be loaded, but may not exist somehow
  362.     trainer = e[0][0] # A PokeBattle_Trainer object of the loaded trainer
  363.     items = e[0][1]   # An array of the trainer's items they can use
  364.     party = e[0][2]   # An array of the trainer's Pokémon
  365.     position=$game_variables[TRAINER_POSITION_VARIABLE]
  366.     bars=$game_variables[BARS_VARIABLE]
  367.     if bars>0
  368.       pokemon=party[position]
  369.       pokemon.hpbars=bars
  370.     end
  371.   end
  372. }
  373.  
  374.  
  375. #Blocking transform
  376.   def pbFailsAgainstTarget?(user,target)
  377.     if target.effects[PBEffects::Transform] ||
  378.        target.effects[PBEffects::Illusion] ||
  379.        target.pokemon.hpbars && target.pokemon.hpbars>0
  380.       @battle.pbDisplay(_INTL("But it failed!"))
  381.       return true
  382.     end
  383.     return false
  384.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement