• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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.

Efficient Script for Beast Boost Ability

7
Posts
4
Years
  • Hey all, I made a script for Beast Boost that utilizes for loops to check which stat of the Pokémon should be raised. I tried my best to condense it, but this is about as short as I could make it. It works really well in game and I haven't had any issues yet. If you want to use it, just paste it under '# Moxie' in the 'PokeBattle_Battler' script section. If you have any questions don't hesitate to ask!

    Code:
        # Beast Boost
        if user.hasWorkingAbility(:BEASTBOOST) && target.fainted?
          
          # Store user's current stats and boostable stats in seperate arrays
          userStats=[user.attack,user.defense,user.spatk,user.spdef,user.speed]
          statBoost=[PBStats::ATTACK,PBStats::DEFENSE,PBStats::SPATK,PBStats::SPDEF,PBStats::SPEED]
          statCheck=0
          statToBoost=0
          boost=0
          
          # Check which user stat is the most proficient
          for i in userStats
            if i>statCheck
              statCheck=i
              statToBoost=userStats.index(i)
            end
            for j in statBoost
              if statBoost.index(j)==statToBoost
                boost=statBoost.index(j)
              end
            end            
          end
          if !user.pbCanIncreaseStatStage?(boost,user)
            @battle.pbDisplay(_INTL("{1}'s stats won't go any higher!",userFb.pbThis))
          end
          if user.pbIncreaseStatWithCause(boost,1,user,PBAbilities.getName(user.ability))
            PBDebug.log("[Ability triggered] #{user.pbThis}'s Beast Boost")
          end
        end
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    I think you might be interested to learn about #max_by which encapsulates iterating an array and finding the maximum value based on some logic, which here encapsulates "return :attack if user.attack is the biggest" (via #send because user.send(:attack) = user.attack). I'm also doing something a bit cheeky to convert from :attack to :ATTACK via #upcase (which works like String's #upcase), and then using getConst to get that value from PBStats (i.e. getConst(PBStats, :attack.upcase) = getConst(PBStats, :ATTACK) = PBStats::ATTACK).

    Also I think you can use elsif for pbIncreaseStatWithCause because presumably it's not going to do anything if we can't increase stat stage?

    Code:
    if user.hasWorkingAbility(:BEASTBOOST) && target.fainted?
      stats = [:attack, :defense, :spatk, :spdef, :speed]
      max_stat = stats.max_by {|stat| user.send(stat)}.upcase
      boost = getConst(PBStats, max_stat)
      if !user.pbCanIncreaseStatStage?(boost, user)
        @battle.pbDisplay(_INTL("{1}'s stats won't go any higher!", userFb.pbThis))
      elsif user.pbIncreaseStatWithCause(boost, 1, user, PBAbilities.getName(user.ability))
        PBDebug.log("[Ability triggered] #{user.pbThis}'s Beast Boost")
      end

    I'm not sure if the version of Ruby in RMXP actually supports max_by, but I hope so!

    If not…
    Spoiler:
     
    Last edited:
    Back
    Top