Scripts, Tutorials & Tools This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Ad Content
Reply
 
Thread Tools
  #1   Link to this post, but load the entire thread.  
Old October 31st, 2012 (4:25 AM).
FL's Avatar
FL FL is offline
Pokémon Island Creator
     
    Join Date: Sep 2010
    Gender: Male
    Posts: 1,774
    Code:
    #===============================================================================
    # * Pokémon Selection - by FL (Credits will be apreciated)
    #===============================================================================
    #
    # This script is for Pokémon Essentials. It makes a pokémon selection system
    # similar to Stadium/Battle Tower, where you can choose a certain number and
    # order of pokémon.
    #
    #===============================================================================
    #
    # To this script works, put it above main and use in script command 
    # 'PokemonSelection.choose(min, max, canCancel, acceptFainted)' where min and
    # max are the minimum and maximum pokémon number selection (default values are
    # 1 and 6), canCancel when true the player can cancel the selection (default
    # is false) and acceptFainted that when true the player can choose fainted
    # pokémon and eggs (default is false). This method return if a party is choosen.
    #
    # To restore the previous party, use 'PokemonSelection.restore'. This do nothing
    # is there's no party to restore. Ths method returns if the party is restored.
    #
    # Between the two commands, don't allow the player to caught or deposit/withdraw
    # any pokémon or the pokémon will be lost! However, you pokémon can gain
    # exp/level, evolve, change hold item/moves normally. If you try to choose a
    # new party before restore the old one, the game raises an error. This won't
    # occurs if the previous selection is only an order change. ONLY in Debug mode
    # you get the phrase "Generate Pokemon teams for this challenge?", always
    # choose "No".
    #
    # 'PokemonSelection.hasValidTeam?(min, max, canCancel, acceptFainted)' returns
    # if your team is valid. If you try to use a invalid team (like putting the
    # minimum pokémon number as 3, but only having 2 pokémon), the selection is
    # treats as canceled. If the canCancel=false, the game goes in an infinite loop.
    #
    # Example: To make a 3vs3 battle, use 'PokemonSelection.choose(3,3)' and, after
    # the battle (regardless of result) use 'PokemonSelection.restore'. Only allows
    # the player to go in the battle if 'PokemonSelection.hasValidTeam?(3,3)' is
    # true, or set the minimum as 1.
    #
    # To perform only an order change, use
    # 'PokemonSelection.choose($Trainer,party.size,$Trainer,party.size,true,true)'.
    #
    # If you take a look in PokemonChallengeRules applications in scripts you can
    # customize some others choice conditions like have a certain level or ban
    # certain pokémon.
    # 
    #===============================================================================
    
    module PokemonSelection
      def self.rules(min=1, max=6, canCancel=false, acceptFainted=false)
        ret=PokemonChallengeRules.new
        ret.setLevelAdjustment(OpenLevelAdjustment.new(PBExperience::MAXLEVEL))
        ret.addPokemonRule(AblePokemonRestriction.new) if !acceptFainted
        ret.ruleset.setNumberRange(min,max)
        return ret
      end
      
      def self.hasValidTeam?(min=1, max=6, canCancel=false, acceptFainted=false)
        pbBattleChallenge.set("pokemonSelectionRules",7,self.rules(min,max))
        ret=pbHasEligible?
        pbBattleChallenge.pbCancel
        return ret
      end  
      
      def self.choose(min=1, max=6, canCancel=false, acceptFainted=false)
        if $PokemonGlobal.pokemonSelectionOriginalParty
          raise "Can't choose a new party until restore the old one"
        end
        validPartyChosen=false
        pbBattleChallenge.set("pokemonSelectionRules",7,self.rules(min,max))
        loop do
          pbEntryScreen
          validPartyChosen=(pbBattleChallenge.getParty!=nil)
          break if(canCancel || validPartyChosen)
          Kernel.pbMessage(_INTL("Choose a Pokémon."))
        end
        if validPartyChosen
          # If the party size is the same, it is only an order change 
          if($Trainer.party.size != pbBattleChallenge.getParty.size)
            $PokemonGlobal.pokemonSelectionOriginalParty=$Trainer.party
          end 
          $Trainer.party=pbBattleChallenge.getParty
        end
        pbBattleChallenge.pbCancel
        return validPartyChosen
      end
      
      def self.restore(*args)
        hasSavedTeam=($PokemonGlobal.pokemonSelectionOriginalParty!=nil)
        if hasSavedTeam
          $Trainer.party=$PokemonGlobal.pokemonSelectionOriginalParty
          $PokemonGlobal.pokemonSelectionOriginalParty=nil
        end
        return hasSavedTeam
      end
    end
    
    class PokemonRuleSet # Redefined to fix a bug
      def hasValidTeam?(team)
        if !team || team.length<self.minTeamLength
          return false
        end
        teamNumber=[self.maxLength,team.length].min
        validPokemon=[]
        for pokemon in team
          if isPokemonValid?(pokemon)
            validPokemon.push(pokemon)
          end
        end
        #if validPokemon.length<teamNumber # original
        if validPokemon.length<self.minLength # fixed
          return false
        end
        if @teamRules.length>0
          pbEachCombination(team,teamNumber){|comb|
             if isValid?(comb)
               return true
             end
          }
          return false
        end
        return true
      end
    end  
    
    class BattleChallenge; def getParty; return @bc.party; end; end
    
    class PokemonGlobalMetadata; attr_accessor :pokemonSelectionOriginalParty; end
    Attached Images
    File Type: png pokemonselectionscreen.png‎ (5.7 KB, 487 views) (Save to Dropbox)
    __________________
    Reply With Quote
      #2   Link to this post, but load the entire thread.  
    Old October 31st, 2012 (7:15 PM).
    UpliftKnight UpliftKnight is offline
       
      Join Date: Oct 2012
      Posts: 14
      Thanks FL. its going to be useful for me.
      Reply With Quote
        #3   Link to this post, but load the entire thread.  
      Old November 1st, 2012 (10:35 AM).
      ppooookkkkkkk ppooookkkkkkk is offline
      Banned
         
        Join Date: May 2012
        Location: Newbud town (Pokemon Morning/Night)
        Age: 17
        Gender: Male
        Nature: Gentle
        Posts: 229
        Thank you for this (finally a great script for making the frontier)
        Reply With Quote
          #4   Link to this post, but load the entire thread.  
        Old November 10th, 2012 (2:06 PM).
        FL's Avatar
        FL FL is offline
        Pokémon Island Creator
           
          Join Date: Sep 2010
          Gender: Male
          Posts: 1,774
          I'm glad that people will use this, despite the big instructions.
          __________________
          Reply With Quote
            #5   Link to this post, but load the entire thread.  
          Old November 21st, 2012 (4:43 AM).
          UpliftKnight UpliftKnight is offline
             
            Join Date: Oct 2012
            Posts: 14
            I tried to use this but when i try this script it directly goes in battle without selection.
            Can you write a example script? with battle.
            Reply With Quote
              #6   Link to this post, but load the entire thread.  
            Old November 21st, 2012 (5:04 AM).
            IceGod64's Avatar
            IceGod64 IceGod64 is offline
            In the Lost & Found bin!
               
              Join Date: Oct 2008
              Location: Castelia City
              Age: 30
              Gender: Male
              Nature: Naive
              Posts: 624
              Quote:
              Originally Posted by UpliftKnight View Post
              I tried to use this but when i try this script it directly goes in battle without selection.
              Can you write a example script? with battle.
              Follow the instructions. Notice n the first post:

              Quote:
              # To this script works, put it above main and use in script command # 'PokemonSelection.choose(min, max, canCancel, acceptFainted)'
              __________________

              Reply With Quote
                #7   Link to this post, but load the entire thread.  
              Old November 21st, 2012 (5:56 AM).
              UpliftKnight UpliftKnight is offline
                 
                Join Date: Oct 2012
                Posts: 14
                Quote:
                Originally Posted by IceGod64 View Post
                Follow the instructions. Notice n the first post:
                I used the script command but still goes to the battle
                Reply With Quote
                  #8   Link to this post, but load the entire thread.  
                Old November 24th, 2012 (11:36 AM).
                FL's Avatar
                FL FL is offline
                Pokémon Island Creator
                   
                  Join Date: Sep 2010
                  Gender: Male
                  Posts: 1,774
                  Quote:
                  Originally Posted by UpliftKnight View Post
                  I tried to use this but when i try this script it directly goes in battle without selection.
                  Can you write a example script? with battle.
                  Code:
                  PokemonSelection.choose(3,3)
                  pbTrainerBattle(
                    PBTrainers::YOUNGSTER,"Ben",
                    _I("\bAww, I lost."))
                  PokemonSelection.restore
                  __________________
                  Reply With Quote
                    #9   Link to this post, but load the entire thread.  
                  Old December 1st, 2013 (12:51 PM).
                  Nickalooose Nickalooose is offline
                  --------------------
                     
                    Join Date: Mar 2008
                    Gender: Female
                    Posts: 1,309
                    Wow, FL . nice script... However, It's always nice to see one of my features become less of a unique feature though lol.

                    It's great to see you're still giving to the community too.
                    Reply With Quote
                      #10   Link to this post, but load the entire thread.  
                    Old January 2nd, 2014 (10:36 AM).
                    dydd90's Avatar
                    dydd90 dydd90 is offline
                       
                      Join Date: Dec 2013
                      Location: Italy
                      Gender: Male
                      Posts: 246
                      Thank you very much i like this and i will use it :)
                      __________________


                      Reply With Quote
                        #11   Link to this post, but load the entire thread.  
                      Old October 3rd, 2014 (5:31 AM).
                      RyanReffell RyanReffell is offline
                         
                        Join Date: May 2013
                        Gender: Male
                        Posts: 8
                        Little help with this...
                        Tried to follow instructions here but I'm getting a
                        'PokemonSelection' Line60:SyntaxError

                        I'm trying to set it up so that you can enter a 'Fighting Type' only contest, and I have put in all the species allowed to compete and placed it above Main in the scripts sections,
                        ADVICE PLEASE???
                        Reply With Quote
                          #12   Link to this post, but load the entire thread.  
                        Old October 4th, 2014 (7:57 AM).
                        FL's Avatar
                        FL FL is offline
                        Pokémon Island Creator
                           
                          Join Date: Sep 2010
                          Gender: Male
                          Posts: 1,774
                          Quote:
                          Originally Posted by RyanReffell View Post
                          Little help with this...
                          Tried to follow instructions here but I'm getting a
                          'PokemonSelection' Line60:SyntaxError

                          I'm trying to set it up so that you can enter a 'Fighting Type' only contest, and I have put in all the species allowed to compete and placed it above Main in the scripts sections,
                          ADVICE PLEASE???
                          Pokécommunity is breaking my scripts. How to solve this:
                          Quote:
                          Originally Posted by mej71 View Post
                          Click Thread Tools, and then Show Printable Version, and copy that instead.
                          Or use the thread print url: http://www.pokecommunity.com/printthread.php?t=290931




                          How to limit selection by pokémon type

                          Code:
                          # This class uses a type array that only allows the pokémon as valid if it
                          # has one of these types when bannedTypes=false or the reverse 
                          # when bannedTypes=true
                          class TypeRestriction
                            def initialize(types, bannedTypes=true)
                              @types=types
                              @bannedTypes = bannedTypes
                            end
                          
                            def isValid?(pokemon)
                              ret=false
                              for singleType in @types
                                if pokemon.hasType?(singleType)
                                  ret = true
                                  break
                                end
                              end
                              ret = !ret if @bannedTypes
                              return ret
                            end
                          end
                          Copy this code after my script last line. After line 'ret.ruleset.setNumberRange(min,max)' add 'ret.addPokemonRule(TypeRestriction.new([:FIGHTING],false))'.

                          If you, instead of adding 'TypeRestriction.new([:FIGHTING],false))', you add 'TypeRestriction.new([:FIRE,:ICE],false))', only Fire and Ice pokémon would be allowed. If the call is 'TypeRestriction.new([:DRAGON,:FLYING],true))', Flying and Dragon pokémon will be banned.
                          __________________
                          Reply With Quote
                            #13   Link to this post, but load the entire thread.  
                          Old October 4th, 2014 (11:15 AM).
                          RyanReffell RyanReffell is offline
                             
                            Join Date: May 2013
                            Gender: Male
                            Posts: 8
                            Ah that's got rid of the error nicely! Thanks.
                            What script exactly would I need to use to open the battle now?

                            Tried the one suggested near the start of the thread but that's giving me a large error now in game
                            Reply With Quote
                              #14   Link to this post, but load the entire thread.  
                            Old October 8th, 2014 (4:34 PM).
                            FL's Avatar
                            FL FL is offline
                            Pokémon Island Creator
                               
                              Join Date: Sep 2010
                              Gender: Male
                              Posts: 1,774
                              Quote:
                              Originally Posted by RyanReffell View Post
                              Ah that's got rid of the error nicely! Thanks.
                              What script exactly would I need to use to open the battle now?

                              Tried the one suggested near the start of the thread but that's giving me a large error now in game
                              Code:
                              PokemonSelection.choose(3,3)
                              pbTrainerBattle(
                                PBTrainers::YOUNGSTER,"Ben",
                                _I("\bAww, I lost."))
                              PokemonSelection.restore
                              Use extendtext.exe or, probably, the small script command window will mess the text.
                              __________________
                              Reply With Quote
                                #15   Link to this post, but load the entire thread.  
                              Old June 14th, 2018 (10:23 AM). Edited June 14th, 2018 by secondcoming222.
                              secondcoming222 secondcoming222 is offline
                                 
                                Join Date: Aug 2012
                                Gender: Male
                                Posts: 9
                                Great script! I have a couple questions / issues. I am using essentials 17.2 and I have installed all scripts as instructed and everything seems to be working except one thing. Even with it set to not be able cancel the selection I am still able to do so in game. Any idea what the issue might be?

                                Any help would be greatly appreciated!
                                Reply With Quote
                                  #16   Link to this post, but load the entire thread.  
                                Old June 17th, 2018 (4:40 AM). Edited June 17th, 2018 by FL.
                                FL's Avatar
                                FL FL is offline
                                Pokémon Island Creator
                                   
                                  Join Date: Sep 2010
                                  Gender: Male
                                  Posts: 1,774
                                  Quote:
                                  Originally Posted by secondcoming222 View Post
                                  Great script! I have a couple questions / issues. I am using essentials 17.2 and I have installed all scripts as instructed and everything seems to be working except one thing. Even with it set to not be able cancel the selection I am still able to do so in game. Any idea what the issue might be?
                                  When "canCancel" is false, the player is prompt to select the pokémon again when pressing cancel. This is happening? If so, the system was worked as should be.
                                  __________________
                                  Reply With Quote
                                    #17   Link to this post, but load the entire thread.  
                                  Old September 26th, 2018 (2:43 PM).
                                  WolfPP's Avatar
                                  WolfPP WolfPP is online now
                                     
                                    Join Date: Aug 2018
                                    Location: Brazil
                                    Gender: Male
                                    Nature: Jolly
                                    Posts: 177
                                    Oh God. Crash to EBS:

                                    Spoiler:
                                    Code:
                                    [Pokémon Essentials version 17.2]
                                    Exception: RuntimeError
                                    Message: Script error within event 28 (coords 23,2), map 3 (Wolf's house):
                                    Exception: NoMethodError
                                    Message: Elite Battle Battle:148:in `pbStartBattleCore'undefined method `sendingOut=' for #<PokeBattle_DebugSceneNoLogging:0xa4f8a18>
                                    ***Full script:
                                    PokemonSelection.choose(1,6,true,false)
                                    
                                    Interpreter:243:in `pbExecuteScript'
                                    PokeBattle_Battle:2413:in `pbStartBattle'
                                    PokeBattle_BattleRecord:59:in `pbStartBattle'
                                    PBattle_OrgBattleGenerator:1020:in `pbRuledBattle'
                                    PBattle_OrgBattleGenerator:1383:in `pbGenerateChallenge'
                                    PBattle_OrgBattleGenerator:1375:in `times'
                                    PBattle_OrgBattleGenerator:1375:in `pbGenerateChallenge'
                                    PBattle_OrgBattleGenerator:1373:in `loop'
                                    PBattle_OrgBattleGenerator:1403:in `pbGenerateChallenge'
                                    PBattle_OrgBattleGenerator:1339:in `times'
                                    
                                    Interpreter:276:in `pbExecuteScript'
                                    Interpreter:1606:in `command_355'
                                    Interpreter:494:in `execute_command'
                                    Interpreter:193:in `update'
                                    Interpreter:106:in `loop'
                                    Interpreter:198:in `update'
                                    Scene_Map:163:in `updateold'
                                    Scene_Map:161:in `loop'
                                    Scene_Map:170:in `updateold'
                                    Unreal Time System:151:in `update'
                                    Reply With Quote
                                      #18   Link to this post, but load the entire thread.  
                                    Old 4 Weeks Ago (8:40 AM).
                                    Nessis's Avatar
                                    Nessis Nessis is offline
                                       
                                      Join Date: Jan 2017
                                      Location: The Netherlands
                                      Gender: Male
                                      Posts: 10
                                      If i press cancel. I still have to choose pokemon?? I want that cancel button to cancel the battle.
                                      Can anyone that has had the same problem tell me how to fix it?
                                      Reply With Quote
                                        #19   Link to this post, but load the entire thread.  
                                      Old 2 Weeks Ago (3:04 AM).
                                      FL's Avatar
                                      FL FL is offline
                                      Pokémon Island Creator
                                         
                                        Join Date: Sep 2010
                                        Gender: Male
                                        Posts: 1,774
                                        Quote:
                                        Originally Posted by Nessis View Post
                                        If i press cancel. I still have to choose pokemon?? I want that cancel button to cancel the battle.
                                        Can anyone that has had the same problem tell me how to fix it?
                                        Pass 'canCancel' parameter as true. The method return 'false' if cancelled, use this on a conditional to skip the battle.
                                        __________________
                                        Reply With Quote
                                        Reply

                                        Quick Reply

                                        Join the conversation!

                                        Create an account to post a reply in this thread, participate in other discussions, and more!

                                        Create a PokéCommunity Account
                                        Ad Content
                                        Thread Tools

                                        Posting Rules
                                        You may not post new threads
                                        You may not post replies
                                        You may not post attachments
                                        You may not edit your posts

                                        BB code is On
                                        Smilies are On
                                        [IMG] code is On
                                        HTML code is Off

                                        Forum Jump


                                        All times are GMT -8. The time now is 12:49 PM.