The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Resources > Scripts & Tutorials
Register New Account FAQ/Rules Chat Blogs Mark Forums Read

Notices

Scripts & Tutorials 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.



Reply
Thread Tools
  #1  
Unread October 31st, 2012, 12:25 PM
FL .'s Avatar
FL .
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
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 Thumbnails
pokemonselectionscreen.png‎  
__________________
Reply With Quote
  #2  
Unread November 1st, 2012, 03:15 AM
UpliftKnight
Unhatched Egg
 
Join Date: Oct 2012
Thanks FL. its going to be useful for me.
Reply With Quote
  #3  
Unread November 1st, 2012, 06:35 PM
ppooookkkkkkk's Avatar
ppooookkkkkkk
Creator of Amberstonè Studios.
 
Join Date: May 2012
Location: Newbud town (Pokemon Morning/Night)
Age: 12
Gender: Male
Nature: Gentle
Thank you for this (finally a great script for making the frontier)
Reply With Quote
  #4  
Unread November 10th, 2012, 10:06 PM
FL .'s Avatar
FL .
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
I'm glad that people will use this, despite the big instructions.
__________________
Reply With Quote
  #5  
Unread November 21st, 2012, 12:43 PM
UpliftKnight
Unhatched Egg
 
Join Date: Oct 2012
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  
Unread November 21st, 2012, 01:04 PM
IceGod64's Avatar
IceGod64
My imagination.
 
Join Date: Oct 2008
Location: Castelia City
Age: 25
Gender: Male
Nature: Naive
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  
Unread November 21st, 2012, 01:56 PM
UpliftKnight
Unhatched Egg
 
Join Date: Oct 2012
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  
Unread November 24th, 2012, 07:36 PM
FL .'s Avatar
FL .
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
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
Reply
Quick Reply

Sponsored Links


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 UTC. The time now is 12:06 AM.


Style by Perdition Haze, artwork by Sa-Dui.
Like our Facebook Page Follow us on TwitterMessage Board Statistics | © 2002 - 2013 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to Pokémon USA, Inc. and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company, Pokémon USA, Inc., The Pokémon Company International, or Wizards of the Coast. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2013 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User posts belong to the user.