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

[Scripting Question] How to make the starter Pokemon random?

1
Posts
2
Years
    • Seen Feb 21, 2022
    This is my first foray into scripting. I did some research prior and have tried a couple different inputs. So far this is the only one I've tried that doesn't crash the game with a scripting error but it doesn't actually give the player any pokemon:

    random3=rand(4)
    if random3==0
    pbAddPokemon(PBSpecies::CHARMANDER,5)
    elseif random3==1
    pbAddPokemon(PBSpecies::TORCHIC,5)
    elseif random3==2
    pbAddPokemon(PBSpecies::FENNEKIN,5)
    elseif random3==3
    pbAddPokemon(PBSpecies::LITTEN,5)
    end

    What is the appropriate way to make an event tile give a random reward?
     
    95
    Posts
    4
    Years
  • I would advise you to use a RMXP variable and assign your random value to it. I would advise you to use a RMXP variable and assign your random value to it. By default, it is variable 7 for Essentials.

    Afterwards, you can use the conditions "If variable = 0, 1, 2 or 3" to give the appropriate consequences to the continuation of your adventure (for example: quote the good name of your starter or modify the team of the rival).

    Code:
    $game_variables[7] = rand(4)
    if $game_variables[7] == 0
      pbAddPokemon(PBSpecies::CHARMANDER,5)
    elsif $game_variables[7] == 1
      pbAddPokemon(PBSpecies::TORCHIC,5)
    elsif $game_variables[7] == 2
      pbAddPokemon(PBSpecies::FENNEKIN,5)
    else #Ensure that at least one starter is given
      pbAddPokemon(PBSpecies::LITTEN,5)
    end
    $game_switches[3] = false #Switch used *in Essentials to determine whether the player is in the middle of choosing a starter.

    Also, Beware of the ruby syntax : it's "elsif" and not "elseif".
    If the script is entered in an event-making command, it must be in one block. Otherwise, your instance variable "random3" is lost and returns "nil", which will generate an inequality on all your comparisons, so only false conditions.
     
    Back
    Top