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)
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
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'.
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.