The PokéCommunity Forums Fan Games Game Development Scripts & Tutorials
Essentials Script Region Map Shows Encounters

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.


Reply
 
Thread Tools
  #1    
Old 1 Week Ago (2:33 PM). Edited 1 Week Ago by Ulithium_Dragon.
Ulithium_Dragon's Avatar
Ulithium_Dragon Ulithium_Dragon is offline
     
    Join Date: Jul 2015
    Gender: Male
    Nature: Timid
    Posts: 74
    Region Map Shows Encounters
    Current Version: 1.1


    *This script will work with both PE v16.2 and v17+!
    **This script might be incompatible with other scripts that edit the Region Map! If you find an incompatibility, let me know and I will attempt to resolve it.
    ***Place this script somewhere above Main.


    -------
    Shows a note on whether or not an area has Wild Pokémon encounters on the Region Map screen.

    I've included some options that can be used to control things like when the text should display, what message to use, etc. at the top of the script section.

    External Script Download

    Changelog:
    Spoiler:

    v1.1:
    - Added some options to control if the message should only be shown if a certain key is held down.

    v1.0:
    - Initial Release


    Script:
    Code:
    #==============================================================================#
    #//////////////////////////////////////////////////////////////////////////////#
    #==============================================================================#
    #                                                                              #
    #                    Region Map Shows Encounters v1.1                          #
    #                          By Ulithium_Dragon                                  #
    #                                                                              #
    #==============================================================================#
    #         ------------------------------------------------------               #
    # Displays if a map has wild encounters on hover when viewing the Region Map.  #
    #         ------------------------------------------------------               #
    #==============================================================================#
    #                                                                              #
    #       **Place this script somewhere above Main and below Compiler.**         #
    #                                                                              #
    #==============================================================================#
    #------------------------------------------------------------------------------#
    #==============================================================================#
    # ____________________________________________________________________________ #
    #                                                                              #
    #                            ::::Options::::                                   #
    #                                --------                                      #
    #       Below are the options for toggling certain features on or off:         #
    # ____________________________________________________________________________ #
    #                                                                              #
    #---------------------------#                                                  #
    #  Shows the Wild Pokemon note only if the player has visited that map before. #
        ONLYSHOWAFTERVISIT = false    #Default: false
    #---------------------------#                                                  #
    #  Controls whether the Wild Pokemon note should be display on the Fly Map.    #
        DISPLAYONFLYMAP = true    #Default: true
    #---------------------------#                                                  #
    #  Makes every map show Unknown text regardless of if they have encounters.    #
    #  *NOTE: Without this enabled, players could figure out if a map has          #
    #   encounters simply by seeing if the Unknown text is displayed or not.       #
        UNKNOWNMSG_ALLMAPS = true    #Default: true
    #---------------------------#                                                  #
    #  Sets the text to display for Unknown maps                                   #
    #   *NOTE: This does nothing unless ONLYSHOWAFTERVISIT is set to "true"        #
        UNKNOWNMAP_ENCMSG = "Unknown"    #Default: "Unknown"
    #---------------------------#                                                  #
    #  Sets the text to display for maps with Wild Pokémon.                        #
        WILDPOKEMON_MAPMSG = "Wild Pokémon"    #Default: "Wild Pokémon"
    #---------------------------#                                                  #
    #  Controls if the display should only show up when a certain key is held.     #
        SHOWON_KEYHOLD = false    #Default: false
    #---------------------------#                                                  #
    #  Defines the key that toggles the display on/off for a specific square.      #
    #   *NOTE: Don't set set this to the same key as Activate. If you do, it will  #
    #    cause the player to fly to that destination if used on the Fly Map!       #
    #   **VERY IMPORTANT!!!: The key you pick here MUST be defined properly in     #
    #    in "PSystem_Controls" OR THIS WON'T DO ANYTHING!                          #
        DISPLAYACTIVATE_KEY = Input::CTRL    #Default: Input::CTRL
    #------------------------------------------------------------------------------#
    #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
    #==============================================================================#
    
    class MapBottomSprite < SpriteWrapper
      # An edited version of the function from PScreen_RegionMap.
      def initialize(viewport=nil)
        super(viewport)
        @mapname=""
        @maplocation=""
        @mapdetails=""
        @mapencounters=""  #For Map Encounters
        @nonests=false
        @thisbitmap=BitmapWrapper.new(Graphics.width,Graphics.height)
        pbSetSystemFont(@thisbitmap)
        self.y=0
        self.x=0
        [email protected]
        refresh
      end
    
      #For Map Encounters
      def mapencounters=(value)
        if @mapencounters!=value
          @mapencounters=value
          refresh
        end
      end
    
      def refresh
        self.bitmap.clear
        if @nonests
          imagepos=[[sprintf("Graphics/Pictures/pokedexNestUnknown"),108,172,0,0,-1,-1]]
          pbDrawImagePositions(self.bitmap,imagepos)
        end
        textpos=[
           [@mapname,18,-2,0,Color.new(248,248,248),Color.new(0,0,0)],
           [@maplocation,18,354,0,Color.new(248,248,248),Color.new(0,0,0)],
           [@mapdetails,Graphics.width-16,354,1,Color.new(248,248,248),Color.new(0,0,0)],
           #For Map Encounters
           [@mapencounters,Graphics.width-16,3-2,1,Color.new(248,248,248),Color.new(0,0,0)]
        ]
        if @nonests
          textpos.push([_INTL("Area Unknown"),Graphics.width/2,Graphics.height/2-16,2,
             Color.new(88,88,80),Color.new(168,184,184)])
        end
        pbDrawTextPositions(self.bitmap,textpos)
      end
    end
    
    
    class PokemonRegionMapScene
      # An edited version of the function from PScreen_RegionMap.
      def pbStartScene(aseditor=false,mode=0)
        $mapisfly_mode = mode  #For Map Encounters
        @editor=aseditor
        @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
        @viewport.z=99999
        @sprites={}
        pbRgssOpen("Data/townmap.dat","rb"){|f|
           @mapdata=Marshal.load(f)
        }
        playerpos=!$game_map ? nil : pbGetMetadata($game_map.map_id,MetadataMapPosition)
        if !playerpos
          mapindex=0
          @[email protected][0]
          @mapX=LEFT
          @mapY=TOP
        elsif @region>=0 && @region!=playerpos[0] && @mapdata[@region]
          [email protected]
          @[email protected][@region]
          @mapX=LEFT
          @mapY=TOP
        else
          mapindex=playerpos[0]
          @[email protected][playerpos[0]]
          @mapX=playerpos[1]
          @mapY=playerpos[2]
          mapsize=!$game_map ? nil : pbGetMetadata($game_map.map_id,MetadataMapSize)
          if mapsize && mapsize[0] && mapsize[0]>0
            sqwidth=mapsize[0]
            sqheight=(mapsize[1].length*1.0/mapsize[0]).ceil
            if sqwidth>1
              @mapX+=($game_player.x*sqwidth/$game_map.width).floor
            end
            if sqheight>1
              @mapY+=($game_player.y*sqheight/$game_map.height).floor
            end
          end
        end
        if [email protected]
          Kernel.pbMessage(_INTL("The map data cannot be found."))
          return false
        end
        addBackgroundOrColoredPlane(@sprites,"background","mapbg",Color.new(0,0,0),@viewport)
        @sprites["map"]=IconSprite.new(0,0,@viewport)
        @sprites["map"].setBitmap("Graphics/Pictures/#{@map[1]}")
        @sprites["map"].x+=([email protected]["map"].bitmap.width)/2
        @sprites["map"].y+=([email protected]["map"].bitmap.height)/2
        for hidden in REGIONMAPEXTRAS
          if hidden[0]==mapindex && ((@wallmap && hidden[5]) ||
             ([email protected] && hidden[1]>0 && $game_switches[hidden[1]]))
            if [email protected]["map2"]
              @sprites["map2"]=BitmapSprite.new(480,320,@viewport)
              @sprites["map2"][email protected]["map"].x; @sprites["map2"][email protected]["map"].y
            end
            pbDrawImagePositions(@sprites["map2"].bitmap,[
               ["Graphics/Pictures/#{hidden[4]}",hidden[2]*SQUAREWIDTH,hidden[3]*SQUAREHEIGHT,0,0,-1,-1]
            ])
          end
        end
        @sprites["mapbottom"]=MapBottomSprite.new(@viewport)
        @sprites["mapbottom"].mapname=pbGetMessage(MessageTypes::RegionNames,mapindex)
        @sprites["mapbottom"].maplocation=pbGetMapLocation(@mapX,@mapY)
        @sprites["mapbottom"].mapdetails=pbGetMapDetails(@mapX,@mapY)
        #For Map Encounters
        @sprites["mapbottom"].mapencounters=pbGetMapHasEncounters(@mapX,@mapY)
        if playerpos && mapindex==playerpos[0]
          @sprites["player"]=IconSprite.new(0,0,@viewport)
          @sprites["player"].setBitmap(pbPlayerHeadFile($Trainer.trainertype))
          @sprites["player"].x=-SQUAREWIDTH/2+(@mapX*SQUAREWIDTH)+([email protected]["map"].bitmap.width)/2
          @sprites["player"].y=-SQUAREHEIGHT/2+(@mapY*SQUAREHEIGHT)+([email protected]["map"].bitmap.height)/2
        end
        if mode>0
          k=0
          for i in LEFT..RIGHT
            for j in TOP..BOTTOM
              healspot=pbGetHealingSpot(i,j)
              if healspot && $PokemonGlobal.visitedMaps[healspot[0]]
                @sprites["point#{k}"]=AnimatedSprite.create("Graphics/Pictures/mapFly",2,30)
                @sprites["point#{k}"][email protected]
                @sprites["point#{k}"].x=-SQUAREWIDTH/2+(i*SQUAREWIDTH)+([email protected]["map"].bitmap.width)/2
                @sprites["point#{k}"].y=-SQUAREHEIGHT/2+(j*SQUAREHEIGHT)+([email protected]["map"].bitmap.height)/2
                @sprites["point#{k}"].play
                k+=1
              end
            end
          end
        end
        @sprites["cursor"]=AnimatedSprite.create("Graphics/Pictures/mapCursor",2,15)
        @sprites["cursor"][email protected]
        @sprites["cursor"].play
        @sprites["cursor"].x=-SQUAREWIDTH/2+(@mapX*SQUAREWIDTH)+([email protected]["map"].bitmap.width)/2
        @sprites["cursor"].y=-SQUAREHEIGHT/2+(@mapY*SQUAREHEIGHT)+([email protected]["map"].bitmap.height)/2
        @changed=false
        pbFadeInAndShow(@sprites){ pbUpdate }
        return true
      end
    
      #For Map Encounters
      def pbGetMapHasEncounters(x,y)
        data=load_data("Data/encounters.dat")
        return nil if [email protected][2]
        for loc in @map[2]
          if loc[0]==x && loc[1]==y
            hovermap_id = loc[4]
            # Doesn't show the info if displaying on the Fly Map is disabled.
            return "" if !DISPLAYONFLYMAP && $mapisfly_mode>0
            if data.is_a?(Hash) && data[hovermap_id]
              # If true, only show the info after the map has been visited before.
              if ONLYSHOWAFTERVISIT
                if $PokemonGlobal.visitedMaps[hovermap_id]
                  if SHOWON_KEYHOLD
                    if Input.press?(DISPLAYACTIVATE_KEY)
                      return WILDPOKEMON_MAPMSG
                    else 
                      return ""
                    end
                  end
                else
                  # Returns the message set to show when the map encounter is unknown.
                  if SHOWON_KEYHOLD
                    if Input.press?(DISPLAYACTIVATE_KEY)
                      return UNKNOWNMAP_ENCMSG
                    else
                      return ""
                    end
                  end
                  return ""
                end
              else
                if SHOWON_KEYHOLD
                  if Input.press?(DISPLAYACTIVATE_KEY)
                    return WILDPOKEMON_MAPMSG
                  else
                    return ""
                  end
                else
                  if SHOWON_KEYHOLD
                    if Input.press?(DISPLAYACTIVATE_KEY)
                      return UNKNOWNMAP_ENCMSG
                    else
                      return ""
                    end
                  end
                  return ""
                end
              end
            else
              # Returns the Unknown message for all maps regardless of if they
              # actually have encounters or not if UNKNOWNMSGALLMAPS is enabled.
              if UNKNOWNMSG_ALLMAPS && ONLYSHOWAFTERVISIT
                if SHOWON_KEYHOLD
                  if Input.press?(DISPLAYACTIVATE_KEY)
                    return UNKNOWNMAP_ENCMSG
                  else
                    return ""
                  end
                else
                  return UNKNOWNMAP_ENCMSG
                end
              else 
                return ""
              end
            end
          end
        end
        return ""
      end
    
    
      # An edited version of the function from PScreen_RegionMap.
      def pbMapScene(mode=0)
        xOffset=0
        yOffset=0
        newX=0
        newY=0
        @sprites["cursor"].x=-SQUAREWIDTH/2+(@mapX*SQUAREWIDTH)+([email protected]["map"].bitmap.width)/2
        @sprites["cursor"].y=-SQUAREHEIGHT/2+(@mapY*SQUAREHEIGHT)+([email protected]["map"].bitmap.height)/2
        loop do
          Graphics.update
          Input.update
          pbUpdate
          if xOffset!=0 || yOffset!=0
            xOffset+=xOffset>0 ? -4 : (xOffset<0 ? 4 : 0)
            yOffset+=yOffset>0 ? -4 : (yOffset<0 ? 4 : 0)
            @sprites["cursor"].x=newX-xOffset
            @sprites["cursor"].y=newY-yOffset
            next
          end
          @sprites["mapbottom"].maplocation=pbGetMapLocation(@mapX,@mapY)
          @sprites["mapbottom"].mapdetails=pbGetMapDetails(@mapX,@mapY)
          #For Map Encounters
          @sprites["mapbottom"].mapencounters=pbGetMapHasEncounters(@mapX,@mapY)
          ox=0
          oy=0
          case Input.dir8
          when 1 # lower left
            oy=1 if @mapY<BOTTOM
            ox=-1 if @mapX>LEFT
          when 2 # down
            oy=1 if @mapY<BOTTOM
          when 3 # lower right
            oy=1 if @mapY<BOTTOM
            ox=1 if @mapX<RIGHT
          when 4 # left
            ox=-1 if @mapX>LEFT
          when 6 # right
            ox=1 if @mapX<RIGHT
          when 7 # upper left
            oy=-1 if @mapY>TOP
            ox=-1 if @mapX>LEFT
          when 8 # up
            oy=-1 if @mapY>TOP
          when 9 # upper right
            oy=-1 if @mapY>TOP
            ox=1 if @mapX<RIGHT
          end
          if ox!=0 || oy!=0
            @mapX+=ox
            @mapY+=oy
            xOffset=ox*SQUAREWIDTH
            yOffset=oy*SQUAREHEIGHT
            [email protected]["cursor"].x+xOffset
            [email protected]["cursor"].y+yOffset
          end
          if Input.trigger?(Input::B)
            if @editor && @changed
              if Kernel.pbConfirmMessage(_INTL("Save changes?")) { pbUpdate }
                pbSaveMapData
              end
              if Kernel.pbConfirmMessage(_INTL("Exit from the map?")) { pbUpdate }
                break
              end
            else
              break
            end
          elsif Input.trigger?(Input::C) && mode==1 # Choosing an area to fly to
            healspot=pbGetHealingSpot(@mapX,@mapY)
            if healspot
              if $PokemonGlobal.visitedMaps[healspot[0]] ||
                 ($DEBUG && Input.press?(Input::CTRL))
                return healspot
              end
            end
          elsif Input.trigger?(Input::C) && @editor # Intentionally placed after other C button check
            pbChangeMapLocation(@mapX,@mapY)
          end
        end
        return nil
      end
    end
    Reply With Quote

    Relevant Advertising!

      #2    
    Old 1 Week Ago (2:52 AM). Edited 1 Week Ago by Feark.
    Feark's Avatar
    Feark Feark is offline
       
      Join Date: Nov 2017
      Posts: 3
      amazing <3. Question I gave a quick look cuz I'm in a hurry but there is a key to press for it to appear?
      Reply With Quote
        #3    
      Old 1 Week Ago (10:27 AM).
      Ulithium_Dragon's Avatar
      Ulithium_Dragon Ulithium_Dragon is offline
         
        Join Date: Jul 2015
        Gender: Male
        Nature: Timid
        Posts: 74
        Quote:
        Originally Posted by Feark View Post
        amazing <3. Question I gave a quick look cuz I'm in a hurry but there is a key to press for it to appear?
        No, but I suppose I could add one. Shouldn't be too hard.
        __________________

        [PokéMounts] [Warp Tile Animation Tutorial] [Fall Down Hole Animation Tutorial] [PokéCenter Monitor Icons]
        Reply With Quote
          #4    
        Old 1 Week Ago (12:25 PM).
        Ulithium_Dragon's Avatar
        Ulithium_Dragon Ulithium_Dragon is offline
           
          Join Date: Jul 2015
          Gender: Male
          Nature: Timid
          Posts: 74
          Update Released:

          v1.1:
          - Added some options to control if the message should only be shown if a certain key is held down.
          __________________

          [PokéMounts] [Warp Tile Animation Tutorial] [Fall Down Hole Animation Tutorial] [PokéCenter Monitor Icons]
          Reply With Quote
          Reply

          Quick Reply

          Join the conversation!

          Create an account to post a reply in this thread, participate in other discussions, and more!

          Create a PokéCommunity Account

          Sponsored Links
          Thread Tools

          Posting Rules
          You may not post new threads
          You may not post replies
          You may not post attachments
          You may not edit your posts

          BB code is On
          Smilies are On
          [IMG] code is On
          HTML code is Off

          Forum Jump


          All times are GMT -8. The time now is 5:50 PM.