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

Random Pokemon Selection

10
Posts
7
Years
  • I'm looking to create an event where you receive a random Pokemon from a list of pre selected choices. How would you do this?
     

    SpartaLazor

    Doofus Lunarius
    184
    Posts
    8
    Years
  • I'm no expert coder or anything - in fact, I'm pretty sure this isn't the best way to do it - but I got this to work.

    You'll want to add a script section in the event that looks like this:

    Random.PNG


    You'd probably want to run ExtendText from the main project folder, as that you give you more room to add the code.

    Now, how it works.

    You'd want to set that first line 'random3=rand(5)' is set to the same number of Pokemon that you want. You'd be changing the number in parenthesis. So if you have ten Pokemon on the list, then set it to 'random3=rand(10)' and such.

    Then the next line 'if random3==0' tells it what to do if the random number selected is 0 (these numbers start a 0 instead of 1, so you'd only go up to 4). In this case, it would be to give the player a Bulbasaur. The next line, 'if random3==1' tells it that if the number selected is 1, then the player gets a Charmander. You'd want to do that for each Pokemon that they player can get, going up by one each time.

    Then make sure that you have that nice 'end' at the very bottom, which tells the code to end.

    I hope that helps - I'm not a coder by a long shot, but it's something I was able to piece together that functions. Someone more experienced might be able to give you a much better method of doing it.
     
    971
    Posts
    7
    Years
    • Age 21
    • Seen Nov 28, 2022
    That will work, nice Sparta! ;)

    I would personally make it easier, something like this (untested):
    Code:
    species = [:BULBASAUR,:CHARMANDER,:SQUIRTLE,
               :MEWTWO,:MEW]
    pbAddPokemon(species[rand(species.size)],5)

    This is setting an array of symbols (preceded with a ':'). In the adding Pok?mon part, we're randomly picking one of those with a range of 0 to the size of the array (last number is excluded so we don't have to say - 1, as you often do need to). This means you can just add one to the list and it'll dynamically so the rest for you.
     
    Last edited:
    35
    Posts
    8
    Years
    • Seen Jun 3, 2023
    Hello.
    Is it possible generate shiny Pokemon?
    pkmn.makeShiny, p.makeShiny and etc. doen't work me.
    Thank you!
     
    295
    Posts
    6
    Years
    • Seen Aug 15, 2022
    Hello.
    Is it possible generate shiny Pokemon?
    pkmn.makeShiny, p.makeShiny and etc. doen't work me.
    Thank you!

    You should write the script like this:
    Code:
    species = [:BULBASAUR,:CHARMANDER,:SQUIRTLE,:MEWTWO,:MEW]
    poke=PokeBattle_Pokemon.new(species[rand(species.size)],5,$Trainer)
    poke.makeShiny
    pbAddPokemon(poke)
     
    35
    Posts
    8
    Years
    • Seen Jun 3, 2023
    You should write the script like this:
    Code:
    species = [:BULBASAUR,:CHARMANDER,:SQUIRTLE,:MEWTWO,:MEW]
    poke=PokeBattle_Pokemon.new(species[rand(species.size)],5,$Trainer)
    poke.makeShiny
    pbAddPokemon(poke)

    Thank you! It works perfectly! :wink-right-eye:
     
    Back
    Top