• 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!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • 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
    5
    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
     
    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