• 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] I need help with pokemon encounters.

  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen today
    I tried to create new encounter types, and I managed to make new ones under desert, mud, and dirt tiles, but now that I'm able to play the game, not only do the encounters not work, but grass no longer works as well, even on routes separate from the map I was setting encounters on. However, water encounters still work perfectly fine. The version number is correct, I set my new terrain tags, and I have Pokemon on my team, so I don't know why it's acting like this. Here's all the code I added if you can see the problem. It took me a while to even figure out how to do it.

    Spoiler:
     
    Last edited:
  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    I am going to assume that each part of this are in the correct section of the script.

    That last section should say "elsif" not "end" after each one, and should be apart of "def encounter_type" if they aren't.

    Code:
    if has_desert_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).desert_wild_encounters
    ret = find_valid_encounter_type_for_time(:Desert, time) if !ret
    elsif

    I basically followed what you did for everything else and it worked for me.
     
  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen today
    I did what you said, but for some reason I got this error message, and I can't figure out how to fix it.

    Script " line e: SyntaxError occured.

    244Overworld_WildEncounters:513: syntax error, unexpected end-of-input, expecting `end'

    There is an end on line 513, so I don't know why it's being confused. I remember having this error before but I forgot what fixed it. Here's my updated code if you want to figure out the problem.

    Spoiler:

    I originally had elsif under mud, but I changed to see if that was the issue, but nope. Here's the final code under Overworld_WildEncounters if that's what it's really complaining about.

    Spoiler:
     
  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    Lets start with the error. Whenever you see a "syntax error, unexpected end-of-input, expecting `end", your next step should always be, add an "end" to the very end of the script in question. If it says it again, add another, until it either works or you get different error.

    Also, you don't need "elsif" if you keep the "if" in front of the script. You should just use "else" at that point. "elsif" is code jargon for "else" and "if", when you have both, your basically saying "else if, if", which may cause problems.

    Finally, here is my example script for you. I only made one encounter type, but you can just repeat the process.

    Code:
    # Returns the encounter method that the current encounter should be generated
      # from, depending on the player's current location.
      def encounter_type
        time = pbGetTimeNow
        ret = nil
        if $PokemonGlobal.surfing
          ret = find_valid_encounter_type_for_time(:Water, time)
        elsif has_mud_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).mud_wild_encounters
          ret = find_valid_encounter_type_for_time(:Mud, time) if !ret
        else   # Land/Cave (can have both in the same map)
          if has_land_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).land_wild_encounters
            ret = :BugContest if pbInBugContest? && has_encounter_type?(:BugContest)
            ret = find_valid_encounter_type_for_time(:Land, time) if !ret
          end
          if !ret && has_cave_encounters?
            ret = find_valid_encounter_type_for_time(:Cave, time)
          end
        end
        return ret
      end
     
  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen today
    I'm sorry to say I did exactly what you did, but then the exact same issue popped up again that I originally had. It's playable now, but the encounters outside of water just do not work. Here's the code.

    Spoiler:


    I did put it under surfing like you did originally, but I changed it to under land to see if that was the problem, but no.
     
  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    Alright, lets go step by step from the beginning then. I will only be making one encounter type for simplicity sake. Btw, code becomes much easier to read if you use the "</>" function in the full editor.

    So first start with adding your encounters names underneath "Class TerrainTag".
    Spoiler:

    Next go, to "def initialize(hash)" on the same script page, and add your encounters there too. (Looking back at what you did, you may have named them wrong here. It looks like you gave them the same name as land_encounters, which is possibly causing a conflict).
    Spoiler:

    Next go to the bottom of the TerrainTag page and add your new Terrain Tag to prompt encounters.
    Spoiler:

    Next, we move to the "EncounterType" page and add our new encounter type to the bottom of the page.
    Spoiler:

    Next, we move to the "Overworld_WildEncounters" page and copy and adjust "def has land_encounters" or "def has normal_land_encounters" for use with our new encounter (Both work as a base). Put the new encounter in the same section of the page (I put my in between land and cave as shown below).
    Spoiler:

    On the same page, scroll down to "def encounter_possible_here" and add your new encounter types as possibilities if you are on a tile tagged to have them possible.
    Spoiler:

    The last step in the scripts is to add your new encounter type to the "def encounter_type" (which is what we've been messing with). I put my new encounter above the "land" encounter because "land" has its own conditional branch going on with :contest encounters, and figured it was easier to avoid messing that up.
    Spoiler:

    There are two steps that have to be done outside of the scripts. The first is setting a tile to your new terrain tag, which has to be done in game using the debug Information Editor. I made my Mud Terrain Tag 18, so I made my tile Terrain Tag 18.

    The last step is to add an encounter to your pbs that uses your new encounter step. The name of the encounter should match the id you put in the Encounter Type section.
    Spoiler:



    And thats all the steps to make a new encounter. I know you didn't need me to go through them one by one, but obviously where I thought the problem was is not the correct spot. So the easiest way is probably just to redo them. I would start with getting one to work, then adding the other type of encounters once you got a template to copy.
     
  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen today
    Well, I did everything you said, and grass is working again, but it still doesn't recognize the new encounters. The encounter types are there, but when I walk over the mud and dirt tiles, nothing happens. I set the terrain tags and everything, so I don't know what could even be the issues anymore. I hate having to bother you like this but I really don't know what to do at this rate.
     
  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    Your land encounters working means we fixed something, so thats good.
    After setting the terrain tags, did you reset your RPG Maker? Not just your debug game, but the whole thing? The terrain tag doesn't accurately update if you don't. Also make sure the tile is the same as the one your are changing the tag on, as well as apart of the correct tileset. Some tilesets look alike and have duplicate tiles, and corners/edges of paths are different tiles then the center.
     
  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen today
    Yes to all of this. I even tried doing it on different tiles with the same tags in a different area. Still no encounters.
     
  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen today
    Okay here it is:

    Code:
    module GameData
      class TerrainTag
        attr_reader :id
        attr_reader :id_number
        attr_reader :real_name
        attr_reader :can_surf
        attr_reader :waterfall   # The main part only, not the crest
        attr_reader :waterfall_crest
        attr_reader :can_fish
        attr_reader :can_dive
        attr_reader :deep_bush
        attr_reader :shows_grass_rustle
        attr_reader :land_wild_encounters
        attr_reader :double_wild_encounters
        attr_reader :battle_environment
        attr_reader :ledge
        attr_reader :ice
        attr_reader :bridge
        attr_reader :shows_reflections
        attr_reader :must_walk
        attr_reader :ignore_passability
        attr_reader :desert_wild_encounters  #New Encounter Method
        attr_reader :mud_wild_encounters  #New Encounter Method
        attr_reader :dirt_wild_encounters #New Encounter Method

    Code:
     def initialize(hash)
          @id                     = hash[:id]
          @id_number              = hash[:id_number]
          @real_name              = hash[:id].to_s                || "Unnamed"
          @can_surf               = hash[:can_surf]               || false
          @waterfall              = hash[:waterfall]              || false
          @waterfall_crest        = hash[:waterfall_crest]        || false
          @can_fish               = hash[:can_fish]               || false
          @can_dive               = hash[:can_dive]               || false
          @deep_bush              = hash[:deep_bush]              || false
          @shows_grass_rustle     = hash[:shows_grass_rustle]     || false
          @land_wild_encounters   = hash[:land_wild_encounters]   || false
          @double_wild_encounters = hash[:double_wild_encounters] || false
          @battle_environment     = hash[:battle_environment]
          @ledge                  = hash[:ledge]                  || false
          @ice                    = hash[:ice]                    || false
          @bridge                 = hash[:bridge]                 || false
          @shows_reflections      = hash[:shows_reflections]      || false
          @must_walk              = hash[:must_walk]              || false
          @ignore_passability     = hash[:ignore_passability]     || false
          @desert_wild_encounters = hash[:desert_wild_encounters] || false
          @mud_wild_encounters    = hash[:mud_wild_encounters]    || false
          @dirt_wild_encounters   = hash[:dirt_wild_encounters]   || false
        end

    Code:
    GameData::TerrainTag.register({
      :id                     => :Desert,
      :id_number              => 18,
      :desert_wild_encounters => true,
      :battle_environment     => :Sand,
    })
    
    GameData::TerrainTag.register({
      :id                     => :Mud,
      :id_number              => 19,
      :mud_wild_encounters    => true,
      :battle_environment     => :Sand,
    })
    
    GameData::TerrainTag.register({
      :id                     => :Dirt,
      :id_number              => 20,
      :dirt_wild_encounters   => true,
      :battle_environment     => :Sand,
    })

    Code:
    module GameData
      class EncounterType
        attr_reader :id
        attr_reader :real_name
        attr_reader :type   # :land, :cave, :water, :fishing, :contest, :mud, :dirt, :desert, :none
        attr_reader :trigger_chance

    Code:
    GameData::EncounterType.register({
      :id             => :Desert,
      :type           => :desert,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :DesertDay,
      :type           => :desert,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :DesertNight,
      :type           => :desert,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :DesertMorning,
      :type           => :desert,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :DesertAfternoon,
      :type           => :desert,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :DesertEvening,
      :type           => :desert,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :Mud,
      :type           => :mud,
      :trigger_chance => 10
    })
    GameData::EncounterType.register({
      :id             => :MudDay,
      :type           => :mud,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :MudNight,
      :type           => :mud,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :MudMorning,
      :type           => :mud,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :MudAfternoon,
      :type           => :mud,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :MudEvening,
      :type           => :mud,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :Dirt,
      :type           => :dirt,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :DirtDay,
      :type           => :dirt,
      :trigger_chance => 10
    })
    
    GameData::EncounterType.register({
      :id             => :DirtNight,
      :type           => :dirt,
      :trigger_chance => 10
    })

    Code:
    # Returns whether land-like encounters have been defined for the current map.
      # Applies only to encounters triggered by moving around.
      def has_desert_encounters?
        GameData::EncounterType.each do |enc_type|
          next if ![:Desert].include?(enc_type.type)
          return true if has_encounter_type?(enc_type.id)
        end
        return false
      end
      
      # Returns whether land-like encounters have been defined for the current map.
      # Applies only to encounters triggered by moving around.
      def has_mud_encounters?
        GameData::EncounterType.each do |enc_type|
          next if ![:Mud].include?(enc_type.type)
          return true if has_encounter_type?(enc_type.id)
        end
        return false
      end
      
      # Returns whether land-like encounters have been defined for the current map.
      # Applies only to encounters triggered by moving around.
      def has_dirt_encounters?
        GameData::EncounterType.each do |enc_type|
          next if ![:Dirt].include?(enc_type.type)
          return true if has_encounter_type?(enc_type.id)
        end
        return false
      end

    Code:
      # Returns whether the player's current location allows wild encounters to
      # trigger upon taking a step.
      def encounter_possible_here?
        return true if $PokemonGlobal.surfing
        terrain_tag = $game_map.terrain_tag($game_player.x, $game_player.y)
        return false if terrain_tag.ice
        return true if has_desert_encounters? && terrain_tag.desert_wild_encounters
        return true if has_mud_encounters?    && terrain_tag.mud_wild_encounters
        return true if has_dirt_encounters?   && terrain_tag.dirt_wild_encounters
        return true if has_cave_encounters?   # i.e. this map is a cave
        return true if has_land_encounters?   && terrain_tag.land_wild_encounters
        return false
      end

    Code:
      # Returns the encounter method that the current encounter should be generated
      # from, depending on the player's current location.
      def encounter_type
        time = pbGetTimeNow
        ret = nil
        if $PokemonGlobal.surfing
          ret = find_valid_encounter_type_for_time(:Water, time)
        elsif has_desert_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).mud_wild_encounters
            ret = find_valid_encounter_type_for_time(:Desert, time) if !ret
        elsif has_mud_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).desert_wild_encounters
            ret = find_valid_encounter_type_for_time(:Mud, time) if !ret
        elsif has_dirt_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).dirt_wild_encounters
            ret = find_valid_encounter_type_for_time(:Dirt, time) if !ret
        else   # Land/Cave (can have both in the same map)
          if has_land_encounters? && $game_map.terrain_tag($game_player.x, $game_player.y).land_wild_encounters
            ret = :BugContest if pbInBugContest? && has_encounter_type?(:BugContest)
            ret = find_valid_encounter_type_for_time(:Land, time) if !ret      
          end
          if !ret && has_cave_encounters?
            ret = find_valid_encounter_type_for_time(:Cave, time)
          end
        end
        return ret
      end
     
  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    When you define your encounter types, make it uppercase since you used uppercase in later scripts. Example below.
    Code:
    GameData::EncounterType.register({
      :id             => :Desert,
      :type           => :Desert,  #Make this one uppercase for all the encounter type registered
      :trigger_chance => 10
    })

    Also note that anything behind a # doesn't actually effect the script, its just there for organizational and instructive purposes.
     
  • 19
    Posts
    1
    Years
    • Age 21
    • He/Him
    • Seen today
    It finally worked! Mostly. The encounters work fine when I go over the tiles, but for some reason the game mixed up the mud and desert encounters, so I had to switch it around so the desert pokemon were assigned to mud and vice versa. The terrain tags are set right so I don't know why it's doing that, but it's not really a big deal. Thanks for being so patient and sticking with me.
     
    Back
    Top