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

Problem random rival generator script

13
Posts
11
Years
  • After seeing the tutorial Weighted Egg Generator made ​​by GReusch on Essentials Wiki, I decided to put in my game a system of random starter. This far everything is ok. The problem started after I put that even the rival receives his starter randomly according to the type supereffective on your. What can be the problem in the script put below (the numbers represent the number of the type in the file types.txt)

    def Random_Rival_Supereffective

    if $Trainer.pokemonParty[0].type1==PBTypes::NORMAL
      Rival=[1]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::FIGHTING
      Rival=[2, 14, 18]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::FLYING
      Rival=[5, 13, 15]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::POISON
      Rival=[4, 14]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::GROUND
      Rival=[11, 12, 15]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::ROCK
      Rival=[1, 4, 8, 11, 12]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::BUG
      Rival=[2, 5, 10]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::GHOST
      Rival=[7, 17]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::STEEL
      Rival=[1, 4, 10]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::FIRE
      Rival=[4, 5, 11]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::WATER
      Rival=[12, 13]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::GRASS
      Rival=[2, 3, 6, 10, 15]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::ELECTRIC
      Rival=[4]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::PSYCHIC
      Rival=[6, 7, 17]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::ICE
      Rival=[1, 5, 7, 10]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::DRAGON
      Rival=[15, 16, 18]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::DARK
      Rival=[1, 6, 18]
    elsif $Trainer.pokemonParty[0].type1==PBTypes::FAIRY
      Rival=[3, 8]
    end
      
    $game_variables[26]=Rival[rand(Rival.length)]
      
    end
     

    G-Master

    Lead of Pokémon Roll
    61
    Posts
    10
    Years
    • AZ
    • Seen May 10, 2022
    Question, is the egg hatched by the time the rival is getting his starter? If not, the egg wouldn't have a type and that would cause problems.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    Lexor, you haven't explained what your problem is. You've barely explained half of what you were trying to do.

    Do bear in mind that $Trainer.pokemonParty only looks for Pokémon. It will ignore eggs. The name's a bit of a give-away. You may want to just use $Trainer.party.
     
    13
    Posts
    11
    Years
  • Sorry I forgot to explain it. I wanted to call the function when the egg was hatched but perhaps it's better change it as you say Maruno. The real problem I have is a syntax error in the lines of the declaration of the array, but I can't find it
     
    Last edited:

    FL

    Pokémon Island Creator
    2,453
    Posts
    13
    Years
    • Seen yesterday
    In the ruby, the standard are to declare variables with lowercase (except constants). so declarate 'Rival' as 'rival'. If you initialize a variable in a if/elsif/else this variable only remains until the conditional is finished. So put 'rival=nil' before the 'if'.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen May 3, 2024
    You don't need to do anything when the egg hatches. You can choose the rival's starter immediately after the player receives their egg. Eggs are identical to Pokémon, except a single value is different. This means they have a type already, so you can look at the egg's type immediately and come up with a starter for the rival based on it.

    Like I said, use $Trainer.party instead of $Trainer.pokemonParty.
     
    13
    Posts
    11
    Years
  • Thanks to you FL now it works, but when I call the function I get this error. What could be the error?

    ---------------------------
    Pokemon Essentials
    ---------------------------
    Exception: RuntimeError

    Message: Script error within event 20, map 3 (Alex's house):

    Exception: NameError

    Message: (eval):1:in `pbExecuteScript'uninitialized constant Interpreter::Random_Rival_Supereffective

    ***Full script:

    Random_Rival_Supereffective


    Interpreter:243:in `pbExecuteScript'

    Interpreter:1600:in `eval'

    Interpreter:243:in `pbExecuteScript'

    Interpreter:1600:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:103:in `update'

    Scene_Map:101:in `loop'



    Interpreter:276:in `pbExecuteScript'

    Interpreter:1600:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:103:in `update'

    Scene_Map:101:in `loop'

    Scene_Map:114:in `update'

    Scene_Map:68:in `main'



    This exception was logged in

    C:\Users\User\Saved Games/Pokemon Essentials/errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------
     

    FL

    Pokémon Island Creator
    2,453
    Posts
    13
    Years
    • Seen yesterday
    In the ruby, the standard are to declare methods with lowercase. Try to change all 'Random_Rival_Supereffective' to 'random_Rival_Supereffective'.
     
    Back
    Top