• 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.

Script: [v13+] Triple Triad Booster Pack

Hello, FL. I've implemented your Triple Triad system into my game, and it works fine. However, when the player wins matches, the card given is random, making it difficult to collect them.
Do you know a way in which the player could choose any card they want? That would make the game much better!
Thank you so much again! Cheers :)
 
Hello, FL. I've implemented your Triple Triad system into my game, and it works fine. However, when the player wins matches, the card given is random, making it difficult to collect them.
Do you know a way in which the player could choose any card they want? That would make the game much better!
Thank you so much again! Cheers :)
Yes. Edit this part:

Code:
          # Gain 1 random card from opponent's deck
          card=originalOpponentCards[rand(originalOpponentCards.length)]
          if $PokemonGlobal.triads.pbStoreItem(card)
            cardname=PBSpecies.getName(card)
            @scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname))
          end
 
Hey FL, I'm having some trouble with getting this to work in v19.1

I added this to try to get PBSpecies and PBItems to be initialized but i don't really know how to make it work.
Code:
def getName(item)
  return GameData::Item.get(item).name
end

def PBSpecies(species)
  return GameData::Species.species
end

Can you help?
Code:
[Pokémon Essentials version 19.1]
[EBDX v1.1.6]

Exception: NameError
Message: uninitialized constant PBSpecies

Backtrace:
387::89:in `block in getRandomTriadCard'
387::86:in `loop'
387::86:in `getRandomTriadCard'
387::61:in `fillBoosterStock'
387::68:in `getFirstBoosterAtStock'
387::107:in `block in giveBoosterPack'
387::104:in `each'
387::104:in `giveBoosterPack'
387::132:in `block in <main>'
036:Event_Handlers:199:in `trigger'
 
I got this working with help from GosilopodUser and ThatWelshOne_ on discord, here is the code.
Code:
#===============================================================================
# * Triple Triad Booster Pack - by FL (Credits will be appreciated)
#===============================================================================
#
# This script is for Pokémon Essentials. It's a booster pack item for 
# Triple Triad minigame.
#
#===============================================================================
#
# To this script works, put it above main. Put an item into item.txt like:
#
# 712,BOOSTERPACK,Booster Pack,Booster Packs,1,500,An booster pack for Triple Triad game. Contains 3 cards ,2,0,0,
#
# You can set a BOOSTER_LIST lists. So, you can create several types of 
# packs. For helping in making these lists, this script includes a 
# method (getSpeciesOfType) that return the index of a pokémon type. An 
# example: if you call the line 'p getSpeciesOfType(PBTypes::DRAGON)', you can
# copy/paste the species array of all Dragon pokémon in pokemon.txt. If you
# copy into the index 2 (remember that the first index is 0), all that you need
# to do in the item script is:
#
# ItemHandlers::UseFromBag.add(:DRAGONPACK,proc{|item|
#   giveBoosterPack(item,3,2)
# })
#
# This script generates random cards, but generate some cards in order to a
# player won't reset the game trying to get other cards. The variable
# MIN_BOOSTER_STOCK defines how many cards are stocked in save. If the number
# in this variable is 5, by example, and the values are initialized. Even if
# the player saves and keep opening the packs and resetting, he gets the same
# first 5 cards, since these cards are randomized only the 5 cards ahead. To
# disable this feature, just make the variable value as 0.
#
# I suggest you to initialize this list after the professor lecture, for all 
# packs. If, in your game, the last pack index that you use is 2, after
# professor lecture add the script commands:
#
# $PokemonGlobal.fillBoosterStock(0)
# $PokemonGlobal.fillBoosterStock(1)
# $PokemonGlobal.fillBoosterStock(2)
#
#===============================================================================
#
MIN_BOOSTER_STOCK=15
#
#
BOOSTER_LIST=[
  nil,
  # The below line is the booster of index 1
  [1,4,9,152,155,158,252,255,258,387,390,393,495,498,501],
  [16, 17, 18, 19, 20, 21, 22, 35, 36, 39, 40, 52, 53, 83, 84, 85, 108, 113,
    115, 128, 132, 133, 137, 143]
]


if MIN_BOOSTER_STOCK>0
  class PokemonGlobalMetadata
    def fillBoosterStock(boosterIndex)
      @boosterStock=[]  if !@boosterStock
      @boosterStock[boosterIndex]=[] if @boosterStock.size<=boosterIndex
      while @boosterStock[boosterIndex].size<MIN_BOOSTER_STOCK
        randomCard = getRandomTriadCard(boosterIndex)
        @boosterStock[boosterIndex].push(randomCard)
      end
    end
    
    def getFirstBoosterAtStock(boosterIndex)
      # Called twice since the variable maybe isn't initialized
      fillBoosterStock(boosterIndex)
      newCard = @boosterStock[boosterIndex].shift
      fillBoosterStock(boosterIndex)
      return newCard
    end
  end
end  

def getName(item)
  return GameData::Item.get(item).name
end
  
def getRandomTriadCard(boosterIndex)
  overflowCount=0
  max=0
  arr = []
  GameData::Species.each { |s| arr.push(s.id) if s.form==0 && s.generation <6}
  loop do
    overflowCount+=1
    raise "Can't draw a random card!" if overflowCount>10000
    randomPokemon = arr[rand(arr.length)]
    cname = randomPokemon.to_s rescue nil
    next if !cname
    if (!BOOSTER_LIST[boosterIndex] || BOOSTER_LIST[boosterIndex].empty? || 
        BOOSTER_LIST[boosterIndex].include?(randomPokemon))
     return randomPokemon 
    end
  end 
end  

def giveBoosterPack(item,numberOfCards,boosterIndex=0)
  Kernel.pbMessage(_INTL("{1} opened the {2}.",
      $Trainer.name,getName(item)))
  cardEarned = 0
  overflowCount = 0
  for i in 0...numberOfCards
    card=-1
    if MIN_BOOSTER_STOCK>0
      card = $PokemonGlobal.getFirstBoosterAtStock(boosterIndex)
    else
      card = getRandomTriadCard(boosterIndex)
    end
    pbGiveTriadCard(card,1)
    Kernel.pbMessage(_INTL("{1} draws {2} card!",
        $Trainer.name,GameData::Species.get(card).id))
  end
  return 3
end

def getSpeciesOfType(type)
  ret = []
  dexdata=pbOpenDexData
  for species in 1..species_keys.length #NOT WORKING
    # Type
    pbDexDataOffset(dexdata,species,8)
    type1=dexdata.fgetb
    type2=dexdata.fgetb
    ret.push(species) if type==type1 || type==type2
  end
  return ret
end  

ItemHandlers::UseFromBag.add(:BOOSTERPACK,proc{|item|
  giveBoosterPack(item,3)
})
 
Nice, dude! Glad to have helped.
I see that the getSpeciesOfType method at the end of the script isn't working? Funnily enough, I wrote something like this recently! The following bit of code returns a random species of the given type. You can get it to return an array of all species of the given type by changing the return line to just return ret.
Code:
def getRandomSpeciesFromType(type)
  ret = []
  GameData::Species.each { |s| ret.push(s.id) if s.form==0 && (s.type1==type || s.type2==type) }
  return ret[rand(ret.length)]
end
 
That works great Welsh thank you!

I have a new problem though.
Code:
if MIN_BOOSTER_STOCK>0
  class PokemonGlobalMetadata
    def fillBoosterStock(boosterIndex)
      @boosterStock=[]  if !@boosterStock
      @boosterStock[boosterIndex]=[] if @boosterStock.size<=boosterIndex
      while @boosterStock[boosterIndex].size<MIN_BOOSTER_STOCK
        randomCard = getRandomTriadCard(boosterIndex)
        @boosterStock[boosterIndex].push(randomCard)
      end
    end
    
    def getFirstBoosterAtStock(boosterIndex)
      # Called twice since the variable maybe isn't initialized
      fillBoosterStock(boosterIndex)
      newCard = @boosterStock[boosterIndex].shift
      fillBoosterStock(boosterIndex)
      return newCard
    end
  end
end
[PokeCommunity.com] [v13+] Triple Triad Booster Pack
 
Spoiler:


Well, the error says that you're trying to call the method size on something that's nil. My guess would be that that something shouldn't be nil.
I'm not sure why that would happen. Maybe FL can tell us.
 
Well, the error says that you're trying to call the method size on something that's nil. My guess would be that that something shouldn't be nil.
I'm not sure why that would happen. Maybe FL can tell us.
If getFirstBoosterAtStock is called twice, and the second time the parameter is a lower index, the game try to check size on nil and crashes. Just change:

Code:
@boosterStock[boosterIndex]=[] if @boosterStock.size<=boosterIndex
to
Code:
@boosterStock[boosterIndex]=[] if @boosterStock.size<=boosterIndex || !@boosterStock[boosterIndex]

I updated the thread.
 
I realise it's been over a year since this thread was last used so please close if it breaks a necroposting rule of some kind.

I've tried to implement the script in Essentials version 19.1 that everyone here has provided.
I've tried to use it in two ways but encountered problems for both.

Any help would be massively appreciated.

Method 1 script:
Spoiler:
Problem with this method:
Both the BOOSTERPACK and COLOSSEUMPACK produce 3 random cards.

Method 2 script:
Spoiler:
 
Method 2 script:
Spoiler:
Spoiler:
 
Thank you, FL!
It works beautifully now.

Here's the whole script fully working if anyone else is interested:
Spoiler:
 
Yes. Edit this part:

Code:
          # Gain 1 random card from opponent's deck
          card=originalOpponentCards[rand(originalOpponentCards.length)]
          if $PokemonGlobal.triads.pbStoreItem(card)
            cardname=PBSpecies.getName(card)
            @scene.pbDisplayPaused(_INTL("Got opponent's {1} card.",cardname))
          end
I was asked how to do it. On PMinigame_TripleTriad, before 'def pbDisplay(text)' add:
Code:
  def pbShowCommands(text, commands)
    return UIHelper.pbShowCommands(@sprites["helpwindow"],text,commands){ pbUpdate }
  end

After 'card = originalOpponentCards[rand(originalOpponentCards.length)]' add:
Code:
          cmd = -1
          while cmd==-1
            cmd = @scene.pbShowCommands(_INTL("Choose a card."),originalOpponentCards.map{|pkmn|
              next PBSpecies.getName(pkmn)
            })
          end
          card = originalOpponentCards[cmd]
Tested on Essentials v18.1.
 
Last edited:
Hello all. I've recently inserted this kit into my game (v21.1) and so far it's working great. I was wondering if there is a way to make it so opponents will only use cards from the regional dex I put together. Also, some of the cards aren't finding their sprites. Is it because I'm not using the default dex? I assumed it was later gen pokemon I had no sprites for until I saw a pichu card with no sprite. I have done a little digging into how prizes are given and I cant seem to figure out how to let the player to pick a card instead of being given a random one from the opponent upon victory. I found one thing in this thread but I dont know if its for an older version and idk how well it would translate to 21.1. Thanks in advance.
 
Last edited:
I was wondering if there is a way to make it so opponents will only use cards from the regional dex I put together.
The Camper has a fixed Deck. You can do something similar OR in Minigame TripleTriad script section, add line `next if pbGetRegionalNumber(1, card) <= 0` before line 'card = species_keys.sample' where "1" is your region (in the defalt essentials, 1 is johto).

Also, some of the cards aren't finding their sprites. Is it because I'm not using the default dex? I assumed it was later gen pokemon I had no sprites for until I saw a pichu card with no sprite.
All pokémon have their icons in your game? Remember than Pichu have an other form

I have done a little digging into how prizes are given and I cant seem to figure out how to let the player to pick a card instead of being given a random one from the opponent upon victory.
This needs customization. The nearst things are these two last rules here: https://essentialsengine.miraheze.org/wiki/Triple_Triad#Rule_variations
 
The Camper has a fixed Deck. You can do something similar OR in Minigame TripleTriad script section, add line `next if pbGetRegionalNumber(1, card) <= 0` before line 'card = species_keys.sample' where "1" is your region (in the defalt essentials, 1 is johto).

All pokémon have their icons in your game? Remember than Pichu have an other form

This needs customization. The nearst things are these two last rules here: https://essentialsengine.miraheze.org/wiki/Triple_Triad#Rule_variations
It's possible I don't have all of the icons. I only have what came with essentials when I downloaded it. Is there a good place I can go get the rest of them?

I made a fixed deck for a couple of people but it doesnt feel right for an npc to keep using the same cards no matter how many of them I take away. So if I can limit them to using only what's able to be caught in game, that would make my life a lot easier overall. I'll try to change the script when I get home from work.

Maybe someday someone can get around to adding that prize rule into the mix but it won't break my game if it can't be done. I did try to use the "samewins" rule though and couldn't get it to work so I gave up on it.

Thank you for your help and your reply. I really appreciate it.
 
Last edited:
Back
Top