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

How to use a Trainer modifier

10
Posts
11
Years
    • Seen Sep 11, 2016
    Hello! In the script for Pokemon encounter modifiers there is a way to manipulate the levels of Pokemon for wild battles. I was able to figure out how to use that pretty easy. However under that same script is a way to do the same for trainers. However I can not figure out how to make it work properly. If someone could please give an example on how to properly use the script would be great thanks!
     
    129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    What is it you are trying to do? What went wrong? The commented code there looks pretty straightforward.
     
    10
    Posts
    11
    Years
    • Seen Sep 11, 2016
    I know that to many people it is very easy to understand the code but if you could please just leave an example of how to set up the code properly. So here is the code that it uses for wild encounters which I got down.

    Events.onWildPokemonCreate+=proc {|sender,e|
    pokemon=e[0]
    if $game_map.map_id==334
    pokemon.level=pbBalancedLevel($Trainer.party) - 4 + rand(5) # For variety
    pokemon.calcStats
    pokemon.resetMoves
    end
    }

    Now I'm trying to make trainer LASS Crissy who has a PURRLOIN follow this same formula. The code it says to use is this.

    Events.onTrainerPartyLoad+=proc {|sender,e|
    if e[0] # Trainer data should exist to be loaded, but may not exist somehow
    trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
    items=e[0][1] # An array of the trainer's items they can use
    party=e[0][2] # An array of the trainer's Pokémon
    YOUR CODE HERE
    end
    }

    Where do I plug in the information for the trainer and their Pokemon. As well as if I wanted a trainer to have items? Thanks for helping a Newb!
     
    129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    I mean, I know I'm pretty good at coding, but the code is commented with what each of those variables are. Checking them should be pretty straightforward.

    You should be creating a Lass Crissy the normal way, by modifying your trainers PBS file. Then you can check to see if the trainer passed is Crissy, and modify the party accordingly.

    Code:
    if trainer.trainertype==PBTrainers::LASS && trainer.name=="Crissy"
      if party[0].species == PBSpecies::PURRLOIN
        party[0].level=pbBalancedLevel($Trainer.party) - 4 + rand(5) # For variety
        party[0].calcStats
        party[0].resetMoves
      end
    end

    Note: I did not test the above code.

    Fun side note for the maintainers of Essentials: this onTrainerPartyLoad has a bit of an oversight, in that the way we identify trainers is via their trainer class, trainer name, and party id. We're missing two out of those three inside this method: we only have trainer class. The name in trainer.name is the localized trainer name, but we use the unlocalized trainer name as the trainer's identifier, and you can't "unlocalize" a name. And of course we aren't passed the party id. So it's impossible to pin down exactly which trainer we're given in this function. The most it can be used for, really, is general modifications.

    (Also, the comment above onTrainerPartyLoad in PField_EncounterModifiers is patently false: the function is handed the trainer, items, and party every time it is generated, so you can modify all of that in the function perfectly fine. Everything is generated from scratch every battle, but the function is called after every time it is generated.)
     
    10
    Posts
    11
    Years
    • Seen Sep 11, 2016
    For the code you gave me where would I put that in the scripts. I got an error when I copied and paste the script you gave to me under PField_EncounterModifiers. When I went to test it gave me this error.

    SCRIPT 'PField_EncounterModifiers'line 113: NameError occurred.
    Undefined local variable or method 'trainer' for nil:nil:NilClass
     
    10
    Posts
    11
    Years
    • Seen Sep 11, 2016
    I apperciate your patience with me. So I inputed your code where you told me to and now I have the following code.


    if e[0] # Trainer data should exist to be loaded, but may not exist somehow
    trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
    items=e[0][1] # An array of the trainer's items they can use
    party=e[0][2] # An array of the trainer's Pokémon
    if trainer.trainertype==PBTrainers::LASS && trainer.name=="Crissy"
    if party[0].species == PBSpecies::PURRLOIN
    party[0].level=pbBalancedLevel($Trainer.party) - 4 + rand(5) # For variety
    party[0].calcStats party
    party[0].resetMoves
    end
    end
    end
    }


    Is this correct? I am getting a SyntaxError. Please help.
     
    129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    If you're getting syntax error, paste it here. You can Ctrl+C the error dialogs. Also use
    Code:
     tags when pasting code.
    
    What's with the random "party" after calcStats? Is that the problem?
     
    10
    Posts
    11
    Years
    • Seen Sep 11, 2016
    That random "party" was a mistake I made when I copied the code over but was not in my script when I went to upload the game. The following syntax error is what I get. I have messed around with deleting certain "ends" to see if it would make a difference but nothing.

    Code:
    Script 'PField_EncounterModifiers' line 125: SyntaxError occurred.
     
    129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    Wow, your version of that script section is long. I can't really determine what the problem is without knowing what's on line 125. I could have made a guess looking at my version, but my version is only 44 lines long...

    Fun fact: if you run your program and get a syntax error, usually when you open the script manager again after, it will put your cursor on the thing (or at least the line) it's having a problem with.
     
    10
    Posts
    11
    Years
    • Seen Sep 11, 2016
    It's only that long because I added all the modifiers for each map I wanted the wild encounters to be modified. It always shows the last line of the script being in the issue. Can you test the code you gave me and see if it works for you?
     
    129
    Posts
    8
    Years
    • Seen Mar 23, 2023
    I threw the code block I gave you into a clean 16.2 project just now and got no syntax errors.

    Check to see if you have some if statements without proper end statements above somewhere. Such things can confuse the parser into not giving a proper line of the error ("I got to the end of this file, but there's still unclosed code blocks! What is this?!").

    Barring that, you can do the age-old ritual called "comment everything and uncomment slowly until it breaks again!". :j
     
    10
    Posts
    11
    Years
    • Seen Sep 11, 2016
    So I figured it out. Well kind of. I deleted one portion of your code and was left with the following code that works.

    Code:
    Events.onTrainerPartyLoad+=proc {|sender,e|
       if e[0] # Trainer data should exist to be loaded, but may not exist somehow
         trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
         items=e[0][1]   # An array of the trainer's items they can use
         party=e[0][2]   # An array of the trainer's Pokémon
        party[0].level=pbBalancedLevel($Trainer.party) - 4 + rand(5) # For variety
        party[0].calcStats
        party[0].resetMoves
         end
    }

    However this works for all trainers and not for a specific trainer. The trainer specific code that you gave me does not work. That specific trainer was a key asset I needed in my game. Is there any way else you know of how to make work for a specific trainer? Thanks man

    Edit:
    Thanks Tustin2121! I finally got it to work perfectly! This is the following code for all others!

    Code:
    Events.onTrainerPartyLoad+=proc {|sender,e|
       if e[0] # Trainer data should exist to be loaded, but may not exist somehow
         trainer=e[0][0] # A PokeBattle_Trainer object of the loaded trainer
         items=e[0][1]   # An array of the trainer's items they can use
         party=e[0][2]   # An array of the trainer's Pokémon
        if trainer.trainertype==PBTrainers::LASS && trainer.name=="Crissy"
         party[0].level=pbBalancedLevel($Trainer.party) - 4 + rand(5) # For variety
        party[0].calcStats
        party[0].resetMoves
         end
       end
    }

    Of course the trainer I have is an example and simply needs to be changed for your liking!
     
    Last edited by a moderator:
    Back
    Top