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

Special event depending on the contents of the party

199
Posts
14
Years
    • Seen Jul 6, 2022
    Hi!
    I want to do that something happens if I take one Celebi and five pokemon Water type in the team. (To open the entry to a cave.)

    I tried to do this, but it me did not work:

    Condition and effect--> $Trainer.ablePokemonCount<=1
    Condition and effect--> pbHasSpecies?(PBSpecies::CELEBI)
    Condition and effect--> $Trainer.ablePokemonCount<=2
    Condition and effect--> pbHasType?(PBTypes::WATER)
    Condition and effect--> $Trainer.ablePokemonCount<=3
    Condition and effect--> pbHasType?(PBTypes::WATER)
    Condition and effect--> $Trainer.ablePokemonCount<=4
    Condition and effect--> pbHasType?(PBTypes::WATER)
    Condition and effect--> $Trainer.ablePokemonCount<=5
    Condition and effect--> pbHasType?(PBTypes::WATER)
    Condition and effect--> $Trainer.ablePokemonCount<=6
    Condition and effect--> pbHasType?(PBTypes::WATER)

    Have I been wrong in something?
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    I would use this instead... Paste this in to a new script section above Main.
    Code:
      def countType?(type)
        $game_variables[90]=0
        $game_variables[90]+=1 if $Trainer.party[0].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[1].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[2].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[3].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[4].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[5].hasType?(type)
      end
    Change 90 to another variable number or don't, whatever.
     
    Last edited:
    1,748
    Posts
    14
    Years
  • I would use this instead... Paste this in to a new script section above Main.
    Code:
      def countType?(type)
        $game_variables[90]+=1 if $Trainer.party[0].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[1].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[2].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[3].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[4].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[5].hasType?(type)
      end
    Change 90 to another variable number or don't, whatever.

    you have a small error:

    Code:
      def countType?(type)
        [COLOR="Red"]$game_variables[90]=0[/COLOR]
        $game_variables[90]+=1 if $Trainer.party[0].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[1].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[2].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[3].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[4].hasType?(type)
        $game_variables[90]+=1 if $Trainer.party[5].hasType?(type)
      end

    without that extra line activating the function multiple COULD (not saying will as it could get reset elsewhere) get the variable to 6+ which would be a bad glitch
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    Forgot to mention that I use this for something similar and the Variable is changed in the event to something else lol. Thanks.
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen yesterday
    Personally I'd put the call to the method in the parameter of a Conditional Branch, and have the method return true if all the conditions match and false otherwise. It saves mucking around with a variable.

    Also, the code provided above doesn't answer the question as stated, as it will neither count Celebi (which isn't Water type) nor will it ignore eggs. The method may as well be tailored specifically to this use.

    Code:
    def pbCanOpenCelebiCave
      return false if !pbHasSpecies?(:CELEBI)
      count=0
      for poke in $Trainer.pokemonParty
        next if isConst?(poke.species,PBSpecies,:CELEBI)
        count+=1 if poke.hasType?(:WATER)
      end
      return (count==5)
    end
    I believe that'll work without fail. It doesn't matter which position the Celebi is in, just as long as there's one in there. Eggs are ignored, and both pure-Water and half-Water Pokémon are counted. Fainted Pokémon can also be counted, which I'm guessing is acceptable since fainted Pokémon can do other things in the overworld anyway (i.e. use HMs).
     

    Nickalooose

    --------------------
    1,309
    Posts
    16
    Years
    • Seen Dec 28, 2023
    That's nice code there Maruno, and just to let you know, the code I wrote is part of a bigger class, and does something in my game where variable 90 needs to be something, then is changed to something else, however, it pretty much does what he wanted :D so I shared... Which is why it doesn't check for Celebi.

    But the reason I am commenting was, I couldn't find on wiki or in the scripts (because I didn't know what I was searching for), how to search an entire party... Is the $Trainer.pokemonParty, what checks a whole party?
     
    199
    Posts
    14
    Years
    • Seen Jul 6, 2022
    Personally I'd put the call to the method in the parameter of a Conditional Branch, and have the method return true if all the conditions match and false otherwise. It saves mucking around with a variable.

    Also, the code provided above doesn't answer the question as stated, as it will neither count Celebi (which isn't Water type) nor will it ignore eggs. The method may as well be tailored specifically to this use.

    Code:
    def pbCanOpenCelebiCave
      return false if !pbHasSpecies?(:CELEBI)
      count=0
      for poke in $Trainer.pokemonParty
        next if isConst?(poke.species,PBSpecies,:CELEBI)
        count+=1 if poke.hasType?(:WATER)
      end
      return (count==5)
    end
    I believe that'll work without fail. It doesn't matter which position the Celebi is in, just as long as there's one in there. Eggs are ignored, and both pure-Water and half-Water Pokémon are counted. Fainted Pokémon can also be counted, which I'm guessing is acceptable since fainted Pokémon can do other things in the overworld anyway (i.e. use HMs).

    Thank you very much. It works perfectly. :)
     

    Maruno

    Lead Dev of Pokémon Essentials
    5,286
    Posts
    16
    Years
    • Seen yesterday
    But the reason I am commenting was, I couldn't find on wiki or in the scripts (because I didn't know what I was searching for), how to search an entire party... Is the $Trainer.pokemonParty, what checks a whole party?
    $Trainer.pokemonParty is the same as $Trainer.party but without the eggs.
    $Trainer.ablePokemonParty is the same as $Trainer.pokemonParty but without the fainted Pokémon.

    You check through them by using a for poke in $Trainer.pokemonParty loop.

    I've added some information to the Party page.
     
    Back
    Top