• 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] Custom Encounter Type Not Working

21
Posts
12
Years
    • Seen Jun 22, 2023
    Hi everyone! I'm on version 18 of Essentials and I'm a little stuck on the Desert encounters I made for my game. They used to work, but they don't anymore. I can run on the sand all I want, but no Pokémon will show up, even though I have set Desert encounters in encounters.txt. I've been tinkering for hours, but to no avail. Can anybody spot the mistake in my code of PBTerrain and/or PField_Encounters?

    PBTerrain:
    Spoiler:

    PField_Encounters:
    Spoiler:
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Hmm, I don't see any error in the scripts.
    Maybe you didn't give the terrain tag to the tileset? (You have to do it ingame, in the Debug menu > Information Editor > Edit Terrain Tags)

    Otherwise, when you don't see an error, it's time to scan the whole file execution.

    In your game, go to a place with the desert terrain. Do it, because what I'm going to propose is going to make a message pop at every step lol.

    At the end of PField_Encounters, but inside the class PokemonEncounters, paste this:

    Spoiler:


    Tell us what the messages show when you're walking on the Desert terrain.

    PS: Thanks for making it easy to read the code :)
     
    21
    Posts
    12
    Years
    • Seen Jun 22, 2023
    I'll try what you proposed! The tiles have the correct tag, which I had previously already assigned the way you described. I'll get back to you! :)
    Thanks for helping.
     
    21
    Posts
    12
    Years
    • Seen Jun 22, 2023
    Hmm, I don't see any error in the scripts.
    Maybe you didn't give the terrain tag to the tileset? (You have to do it ingame, in the Debug menu > Information Editor > Edit Terrain Tags)

    Otherwise, when you don't see an error, it's time to scan the whole file execution.

    In your game, go to a place with the desert terrain. Do it, because what I'm going to propose is going to make a message pop at every step lol.

    At the end of PField_Encounters, but inside the class PokemonEncounters, paste this:

    Spoiler:


    Tell us what the messages show when you're walking on the Desert terrain.

    PS: Thanks for making it easy to read the code :)

    Hi there! I get "isDesert?: true" at every step, no matter if I'm standing on Desert tiles or not... Could that be because I configured it as a Cave encounter? Or because I have a tile (regular sand) underneath the Desert sand tile?
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    Could that be because I configured it as a Cave encounter?
    I assume so, because you have defined some specific encounter type ^^ Look in the function:
    Code:
      def pbEncounterType
        if $PokemonGlobal.surfing
          return EncounterTypes::Water
        elsif self.isDesert?
          return EncounterTypes::Desert # Here is the encounter type of a Desert, not a Cave.
        elsif self.isCave?
          return EncounterTypes::Cave
        elsif self.isGrass?
          time = pbGetTimeNow
          enctype = EncounterTypes::Land
          enctype = EncounterTypes::LandNight if self.hasEncounter?(EncounterTypes::LandNight) && PBDayNight.isNight?(time)
          enctype = EncounterTypes::LandDay if self.hasEncounter?(EncounterTypes::LandDay) && PBDayNight.isDay?(time)
          enctype = EncounterTypes::LandMorning if self.hasEncounter?(EncounterTypes::LandMorning) && PBDayNight.isMorning?(time)
          if pbInBugContest? && self.hasEncounter?(EncounterTypes::BugContest)
            enctype = EncounterTypes::BugContest
          end
          return enctype
        end
        return -1
      end

    Or because I have a tile (regular sand) underneath the Desert sand tile?
    It would be the opposite I think (desert tiles under other tiles).
     
    21
    Posts
    12
    Years
    • Seen Jun 22, 2023
    I assume so, because you have defined some specific encounter type ^^ Look in the function:
    Code:
      def pbEncounterType
        if $PokemonGlobal.surfing
          return EncounterTypes::Water
        elsif self.isDesert?
          return EncounterTypes::Desert # Here is the encounter type of a Desert, not a Cave.
        elsif self.isCave?
          return EncounterTypes::Cave
        elsif self.isGrass?
          time = pbGetTimeNow
          enctype = EncounterTypes::Land
          enctype = EncounterTypes::LandNight if self.hasEncounter?(EncounterTypes::LandNight) && PBDayNight.isNight?(time)
          enctype = EncounterTypes::LandDay if self.hasEncounter?(EncounterTypes::LandDay) && PBDayNight.isDay?(time)
          enctype = EncounterTypes::LandMorning if self.hasEncounter?(EncounterTypes::LandMorning) && PBDayNight.isMorning?(time)
          if pbInBugContest? && self.hasEncounter?(EncounterTypes::BugContest)
            enctype = EncounterTypes::BugContest
          end
          return enctype
        end
        return -1
      end


    It would be the opposite I think (desert tiles under other tiles).

    I'd shelved the whole Desert debacle for a moment, because I just couldn't get it fixed. Today I decided to have another go at it, but I still don't get any encounters, even after whiping the slate clean. I used your little function again to see what message pops up every step I take and I still only get "isDesert?: true" at every step. I removed the top bit of your code to see if I'd also get the message "isEncounterPossibleHere?: true/false", like in your middle bit of code, but that one won't show up, no matter what. I've meddled some more with the code in PField_Encounters, so now it looks like the code attached. Do you maybe see something wrong with my code this time?

    Spoiler:
     
    Last edited:

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    I'd shelved the whole Desert debacle for a moment, because I just couldn't get it fixed. Today I decided to have another go at it, but I still don't get any encounters, even after whiping the slate clean. I used your little function again to see what message pops up every step I take and I still only get "isDesert?: true" at every step. I removed the top bit of your code to see if I'd also get the message "isEncounterPossibleHere?: true/false", like in your middle bit of code, but that one won't show up, no matter what. I've meddled some more with the code in PField_Encounters, so now it looks like the code attached. Do you maybe see something wrong with my code this time?
    I don't have much time this week. I'll check this week-end. I'll install your script and see what I get.
    You mentioned it in your first post, but do you have a Desert encounter in your PBS file encounters.txt?

    Also, find the following function and add a few debug messages here just to see what you get when on a Desert tile:
    Code:
    def pbBattleOnStepTaken(repel = false)
      debug = $game_switches[XXX] # Set a Game Switch so you can control in game if you want to see these messages
      pbMessage("pbBattleOnStepTaken: entered") if debug
      return if $Trainer.ablePokemonCount == 0
      pbMessage("pbBattleOnStepTaken: enough Pokémons") if debug
      encounterType = $PokemonEncounters.pbEncounterType
      pbMessage(_INTL("pbBattleOnStepTaken: encounterType = {1}", encounterType )) if debug
      return if encounterType < 0
      pbMessage(_INTL("pbBattleOnStepTaken: checking if encounter possible)) if debug
      return if !$PokemonEncounters.isEncounterPossibleHere?
      pbMessage(_INTL("pbBattleOnStepTaken: encounter is possible)) if debug
      $PokemonTemp.encounterType = encounterType
    # Leave the rest unchanged.
     

    StCooler

    Mayst thou thy peace discover.
    9,301
    Posts
    4
    Years
    • Seen May 5, 2024
    I'd shelved the whole Desert debacle for a moment, because I just couldn't get it fixed. Today I decided to have another go at it, but I still don't get any encounters, even after whiping the slate clean. I used your little function again to see what message pops up every step I take and I still only get "isDesert?: true" at every step. I removed the top bit of your code to see if I'd also get the message "isEncounterPossibleHere?: true/false", like in your middle bit of code, but that one won't show up, no matter what. I've meddled some more with the code in PField_Encounters, so now it looks like the code attached. Do you maybe see something wrong with my code this time?

    So, I checked out the code as promised (a bit later because I had forgotten, sorry), and it turns out it works correctly. (Actually I have a slightly different version than v18).

    I tested the code in your first post (not the second, but from what I saw, there is no significant difference).

    Did you try to edit:
    Code:
    def pbBattleOnStepTaken(repel = false)
    as suggested in my previous post? I actually used this to debug my installation of your script and it made me realise that:
    • At some point, there was no encounter defined.
    • Actually, I defined the encounters in the wrong map.
    • Actually bis, I forgot to change the tags of the tileset XD
    I don't mean you made the same mistakes as I did, but I think the error is not related with your code, but more with "how it's used".
     
    Back
    Top