See-Through Scenery Script

Discussion in 'RGSS Scripts (RMXP)' started by cockroach, Jul 14, 2015.

  1. cockroach

    cockroach An RPG Jack-of-all-trades Member

    Messages:
    23
    Likes Received:
    51
    See-Through Scenery Script

    prev.png

    Another very simple edit I have made so you can see Characters (events in general) behind trees, houses and so on. It just changes a couple of lines in some methods in the SpriteSet_Map and Sprite_Character, so it isn't a big deal, really. But the result is quite useful and looks good :)

    Preview

    A GIF I put out showing Aluxes getting behind trees and whatnot, and he's always visible! :D

    see-through3.gif

    How to Use

    Once you imported the script, you're seeing through all scenery! If you want to alter the settings during gameplay, all you need to do is call for the following, whenever you want to change the parameters:

    • $see_thru_actor = true/false - Activates/Deactivates seeing through the scenery above the actor.
    • $see_thru_events = true/false - Activates/Deactivates seeing through the scenery above events.
    • $see_thru_opacity = 0-100 - Adjusts the opacity percentage applied to the opacity value of sprites that are behind scenery or behind other sprites
    Demo

    See-through Scenery.zip



    Script (Moderator edit - the contents of this spoiler have become corrupted. Please see post #2 for a clean version.)

    Insert this script above Main, and below others:



    Code:
    #==============================================================================#                           SEE THROUGH SCENERY#------------------------------------------------------------------------------#  This very simple script alters 2 classes of RMXP to make it able to see#  characters behind scenery objects or behind other characters. The region of#  the sprite covered by other objects can have different opacity, so the sprite#  still makes sense behind other stuff.#  What it does is basically duplicating the viewport in which the characters#  are drawn and draws translucid characters with high priority in it instead.#  By overlaying one on top of another, gives the effect of translucid scenery.#  Since the character drawing process is doubled, it may lower performance,#  depending on the amount of objects in the scene.##  All you have to do is managing global variables that define the see-through#  parameters in-game via Call Script functions:##  $see_thru_actor = true/false     -  Activate seeing through the scenery#                                      above the actor#  $see_thru_events = true/false    -  Activate seeing through the scenery#                                      above other events#  $see_thru_opacity = 0-100        -  Adjusts the opacity percentage applied#                                      to the opacity value of sprites that are#                                      behind scenery or behind other sprites##  Terms of Use: Feel free to do anything you want with this in any kind of game#  by cockroach#==============================================================================#-------------------------------------------------------------# Global Variable that defines whether scenery above the# actor is seen-through#-------------------------------------------------------------$see_thru_actor = true#-------------------------------------------------------------# Global Variable that defines whether scenery above the# events is seen-through#-------------------------------------------------------------$see_thru_events = true#-------------------------------------------------------------# Opacity percentage of characters when behind other stuff#-------------------------------------------------------------$see_thru_opacity = 20#==============================================================================# ** Alterations in Spriteset_Map#------------------------------------------------------------------------------#  All methods suffer slight changes, to include another array of characters#  to contain each actor/event#==============================================================================class Sprite_Character < RPG::Sprite  #--------------------------------------------------------------------------  # * Object Initialization  #     viewport  : viewport  #     character : character (Game_Character)  #--------------------------------------------------------------------------  def initialize(viewport, character = nil, overlay = false)    super(viewport)    @character = character    @overlaychar = overlay    update  end  #--------------------------------------------------------------------------  # * Frame Update  #--------------------------------------------------------------------------  def update    super    # If tile ID, file name, or hue are different from current ones    if @tile_id != @character.tile_id or       @character_name != @character.character_name or       @character_hue != @character.character_hue      # Remember tile ID, file name, and hue      @tile_id = @character.tile_id      @character_name = @character.character_name      @character_hue = @character.character_hue      # If tile ID value is valid      if @tile_id >= 384        self.bitmap = RPG::Cache.tile($game_map.tileset_name,          @tile_id, @character.character_hue)        self.src_rect.set(0, 0, 32, 32)        self.ox = 16        self.oy = 32      # If tile ID value is invalid      else        self.bitmap = RPG::Cache.character(@character.character_name,          @character.character_hue)        @cw = bitmap.width / 4        @ch = bitmap.height / 4        self.ox = @cw / 2        self.oy = @ch      end    end    # Set visible situation    self.visible = (not @character.transparent)    if @overlaychar      if @character == $game_player and not($see_thru_actor)        self.visible = false      elsif @character != $game_player and not($see_thru_events)        self.visible = false      end    end    # If graphic is character    if @tile_id == 0      # Set rectangular transfer      sx = @character.pattern * @cw      sy = (@character.direction - 2) / 2 * @ch      self.src_rect.set(sx, sy, @cw, @ch)    end    # Set sprite coordinates    self.x = @character.screen_x    self.y = @character.screen_y    self.z = @character.screen_z(@ch)    # Set opacity level, blend method, and bush depth    self.opacity = @character.opacity    if @overlaychar      self.opacity = self.opacity * $see_thru_opacity / 100    end    self.blend_type = @character.blend_type    self.bush_depth = @character.bush_depth    # Animation    if @character.animation_id != 0      animation = $data_animations[@character.animation_id]      animation(animation, true)      @character.animation_id = 0    end  endend#==============================================================================# ** Alterations in Spriteset_Map#------------------------------------------------------------------------------#  All methods suffer slight changes, to include another array of characters#  to contain each actor/event#==============================================================================class Spriteset_Map  #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  def initialize    # Make viewports    @viewport1 = Viewport.new(0, 0, 640, 480)    @viewport2 = Viewport.new(0, 0, 640, 480)    @viewport3 = Viewport.new(0, 0, 640, 480)    @viewport4 = Viewport.new(0, 0, 640, 480)    @viewport2.z = 200    @viewport3.z = 5000    @viewport4.z = 4000    # Make tilemap    @tilemap = Tilemap.new(@viewport1)    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)    for i in 0..6      autotile_name = $game_map.autotile_names[i]      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)    end    @tilemap.map_data = $game_map.data    @tilemap.priorities = $game_map.priorities    # Make panorama plane    @panorama = Plane.new(@viewport1)    @panorama.z = -1000    # Make fog plane    @fog = Plane.new(@viewport1)    @fog.z = 3000    # Make character sprites    @character_sprites = []        @see_thru_sprite = []    @see_thru_sprite.push(Sprite_Character.new(@viewport4, $game_player, true))        for i in $game_map.events.keys.sort      event = $game_map.events[i]      sprite = Sprite_Character.new(@viewport1, event)      @character_sprites.push(sprite)      @see_thru_sprite.push(Sprite_Character.new(@viewport4, event, true))    end    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))    # Make weather    @weather = RPG::Weather.new(@viewport1)    # Make picture sprites    @picture_sprites = []    for i in 1..50      @picture_sprites.push(Sprite_Picture.new(@viewport2,        $game_screen.pictures[i]))    end    # Make timer sprite    @timer_sprite = Sprite_Timer.new        # Frame update    update  end  #--------------------------------------------------------------------------  # * Dispose  #--------------------------------------------------------------------------  def dispose    # Dispose of tilemap    @tilemap.tileset.dispose    for i in 0..6      @tilemap.autotiles[i].dispose    end    @tilemap.dispose    # Dispose of panorama plane    @panorama.dispose    # Dispose of fog plane    @fog.dispose    # Dispose of character sprites    for sprite in @character_sprites      sprite.dispose    end    for sprite in @see_thru_sprite      sprite.dispose    end    # Dispose of weather    @weather.dispose    # Dispose of picture sprites    for sprite in @picture_sprites      sprite.dispose    end    # Dispose of timer sprite    @timer_sprite.dispose    # Dispose of viewports    @viewport1.dispose    @viewport2.dispose    @viewport3.dispose    @viewport4.dispose  end  #--------------------------------------------------------------------------  # * Frame Update  #--------------------------------------------------------------------------  def update    # If panorama is different from current one    if @panorama_name != $game_map.panorama_name or       @panorama_hue != $game_map.panorama_hue      @panorama_name = $game_map.panorama_name      @panorama_hue = $game_map.panorama_hue      if @panorama.bitmap != nil        @panorama.bitmap.dispose        @panorama.bitmap = nil      end      if @panorama_name != ""        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)      end      Graphics.frame_reset    end    # If fog is different than current fog    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue      @fog_name = $game_map.fog_name      @fog_hue = $game_map.fog_hue      if @fog.bitmap != nil        @fog.bitmap.dispose        @fog.bitmap = nil      end      if @fog_name != ""        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)      end      Graphics.frame_reset    end    # Update tilemap    @tilemap.ox = $game_map.display_x / 4    @tilemap.oy = $game_map.display_y / 4    @tilemap.update    # Update panorama plane    @panorama.ox = $game_map.display_x / 8    @panorama.oy = $game_map.display_y / 8    # Update fog plane    @fog.zoom_x = $game_map.fog_zoom / 100.0    @fog.zoom_y = $game_map.fog_zoom / 100.0    @fog.opacity = $game_map.fog_opacity    @fog.blend_type = $game_map.fog_blend_type    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy    @fog.tone = $game_map.fog_tone    # Update character sprites    for sprite in @character_sprites      sprite.update    end    # Update weather graphic    @weather.type = $game_screen.weather_type    @weather.max = $game_screen.weather_max    @weather.ox = $game_map.display_x / 4    @weather.oy = $game_map.display_y / 4    @weather.update    for sprite in @see_thru_sprite      sprite.update    end    # Update picture sprites    for sprite in @picture_sprites      sprite.update    end    # Update timer sprite    @timer_sprite.update    # Set screen color tone and shake position    @viewport1.tone = $game_screen.tone    @viewport1.ox = $game_screen.shake    # Set screen flash color    @viewport3.color = $game_screen.flash_color    # Update viewports    @viewport1.update    @viewport4.update    @viewport3.update  endend
     

    Attached Files:

    Last edited by a moderator: Aug 30, 2018
    #1
  2. lilben1992

    lilben1992 Warper Member

    Messages:
    3
    Likes Received:
    1
    First Language:
    French
    I really want that script it is awesome but the rar file is corrupt... Im 2 years late but if by chance you see this! :)


    I could take the script in the hidden contents but it all on one line....
     
    Last edited by a moderator: Jan 28, 2017
    #2
    Ghozt likes this.
  3. Ghozt

    Ghozt Warper Member

    Messages:
    4
    Likes Received:
    0
    Location:
    Ohio, USA
    First Language:
    English
    Primarily Uses:
    RMXP
    Necro-ing for easy copy-paste multi-line code

    Code:
    #==============================================================================
    #                           SEE THROUGH SCENERY
    #------------------------------------------------------------------------------
    #  This very simple script alters 2 classes of RMXP to make it able to see
    #  characters behind scenery objects or behind other characters. The region of
    #  the sprite covered by other objects can have different opacity, so the sprite
    #  still makes sense behind other stuff.
    #  What it does is basically duplicating the viewport in which the characters
    #  are drawn and draws translucid characters with high priority in it instead.
    #  By overlaying one on top of another, gives the effect of translucid scenery.
    #  Since the character drawing process is doubled, it may lower performance,
    #  depending on the amount of objects in the scene.
    #
    #  All you have to do is managing global variables that define the see-through
    #  parameters in-game via Call Script functions:
    #
    #  $see_thru_actor = true/false     -  Activate seeing through the scenery
    #                                      above the actor
    #  $see_thru_events = true/false    -  Activate seeing through the scenery
    #                                      above other events
    #  $see_thru_opacity = 0-100        -  Adjusts the opacity percentage applied
    #                                      to the opacity value of sprites that are
    #                                      behind scenery or behind other sprites
    #
    #  Terms of Use: Feel free to do anything you want with this in any kind of game
    #  by cockroach
    #==============================================================================
    
    #-------------------------------------------------------------
    # Global Variable that defines whether scenery above the
    # actor is seen-through
    #-------------------------------------------------------------
    $see_thru_actor = true
    #-------------------------------------------------------------
    # Global Variable that defines whether scenery above the
    # events is seen-through
    #-------------------------------------------------------------
    $see_thru_events = true
    #-------------------------------------------------------------
    # Opacity percentage of characters when behind other stuff
    #-------------------------------------------------------------
    $see_thru_opacity = 40
    
    #==============================================================================
    # ** Alterations in Spriteset_Map
    #------------------------------------------------------------------------------
    #  All methods suffer slight changes, to include another array of characters
    #  to contain each actor/event
    #==============================================================================
    class Sprite_Character < RPG::Sprite
    #--------------------------------------------------------------------------
    # * Object Initialization
    #     viewport  : viewport
    #     character : character (Game_Character)
    #--------------------------------------------------------------------------
      def initialize(viewport, character = nil, overlay = false)
        super(viewport)
        @character = character
        @overlaychar = overlay
        update
      end
      #--------------------------------------------------------------------------
      # * Frame Update
      #--------------------------------------------------------------------------
      def update
        super  
        # If tile ID, file name, or hue are different from current ones
        if @tile_id != @character.tile_id or
          @character_name != @character.character_name or
          @character_hue != @character.character_hue
          # Remember tile ID, file name, and hue
          @tile_id = @character.tile_id
          @character_name = @character.character_name
          @character_hue = @character.character_hue
          # If tile ID value is valid
          if @tile_id >= 384
            self.bitmap = RPG::Cache.tile($game_map.tileset_name,
            @tile_id, @character.character_hue)
            self.src_rect.set(0, 0, 32, 32)
            self.ox = 16
            self.oy = 32
            # If tile ID value is invalid
            else
              self.bitmap = RPG::Cache.character(@character.character_name,
              @character.character_hue)
              @cw = bitmap.width / 4
              @ch = bitmap.height / 4
              self.ox = @cw / 2
              self.oy = @ch
          end
        end
          # Set visible situation
          self.visible = (not @character.transparent)
          if @overlaychar
            if @character == $game_player and not($see_thru_actor)
              self.visible = false
              elsif @character != $game_player and not($see_thru_events)
                self.visible = false
            end
          end
            # If graphic is character
            if @tile_id == 0
              # Set rectangular transfer
              sx = @character.pattern * @cw
              sy = (@character.direction - 2) / 2 * @ch
              self.src_rect.set(sx, sy, @cw, @ch)
          end
            # Set sprite coordinates
            self.x = @character.screen_x
            self.y = @character.screen_y
            self.z = @character.screen_z(@ch)
            # Set opacity level, blend method, and bush depth
            self.opacity = @character.opacity
            if @overlaychar
              self.opacity = self.opacity * $see_thru_opacity / 100
          end
            self.blend_type = @character.blend_type
            self.bush_depth = @character.bush_depth
            # Animation
            if @character.animation_id != 0
              animation = $data_animations[@character.animation_id]
              animation(animation, true)
              @character.animation_id = 0
          end
        end
      end
      #==============================================================================
      # ** Alterations in Spriteset_Map
      #------------------------------------------------------------------------------
      #  All methods suffer slight changes, to include another array of characters
      #  to contain each actor/event
      #==============================================================================
      class Spriteset_Map
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize
        # Make viewports
        @viewport1 = Viewport.new(0, 0, 640, 480)
        @viewport2 = Viewport.new(0, 0, 640, 480)
        @viewport3 = Viewport.new(0, 0, 640, 480)
        @viewport4 = Viewport.new(0, 0, 640, 480)
        @viewport2.z = 200
        @viewport3.z = 5000
        @viewport4.z = 4000
        # Make tilemap
        @tilemap = Tilemap.new(@viewport1)
        @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
        for i in 0..6
          autotile_name = $game_map.autotile_names
          @tilemap.autotiles = RPG::Cache.autotile(autotile_name)
        end
        @tilemap.map_data = $game_map.data
        @tilemap.priorities = $game_map.priorities
        # Make panorama plane
        @panorama = Plane.new(@viewport1)
        @panorama.z = -1000
        # Make fog plane
        @fog = Plane.new(@viewport1)
        @fog.z = 3000
        # Make character sprites
        @character_sprites = []
        @see_thru_sprite = []
        @see_thru_sprite.push(Sprite_Character.new(@viewport4, $game_player, true))
        for i in $game_map.events.keys.sort
          event = $game_map.events
          sprite = Sprite_Character.new(@viewport1, event)
          @character_sprites.push(sprite)
          @see_thru_sprite.push(Sprite_Character.new(@viewport4, event, true))
        end
        @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
        # Make weather
        @weather = RPG::Weather.new(@viewport1)
        # Make picture sprites
        @picture_sprites = []
        for i in 1..50
          @picture_sprites.push(Sprite_Picture.new(@viewport2,        $game_screen.pictures))
        end
        # Make timer sprite
        @timer_sprite = Sprite_Timer.new
        # Frame update
        update
      end
      #--------------------------------------------------------------------------
      # * Dispose
      #--------------------------------------------------------------------------
      def dispose
        # Dispose of tilemap
        @tilemap.tileset.dispose
        for i in 0..6
          @tilemap.autotiles.dispose
        end
        @tilemap.dispose
        # Dispose of panorama plane
        @panorama.dispose
        # Dispose of fog plane
        @fog.dispose
        # Dispose of character sprites
        for sprite in @character_sprites
          sprite.dispose
        end
        for sprite in @see_thru_sprite
          sprite.dispose
        end
        # Dispose of weather
        @weather.dispose
        # Dispose of picture sprites
        for sprite in @picture_sprites
          sprite.dispose
        end
        # Dispose of timer sprite
        @timer_sprite.dispose
        # Dispose of viewports
        @viewport1.dispose
        @viewport2.dispose
        @viewport3.dispose
        @viewport4.dispose
      end
      #--------------------------------------------------------------------------
      # * Frame Update
      #--------------------------------------------------------------------------
      def update
        # If panorama is different from current one
        if @panorama_name != $game_map.panorama_name or
          @panorama_hue != $game_map.panorama_hue
          @panorama_name = $game_map.panorama_name
          @panorama_hue = $game_map.panorama_hue
          if @panorama.bitmap != nil
            @panorama.bitmap.dispose
            @panorama.bitmap = nil
          end
          if @panorama_name != ""
            @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
          end
          Graphics.frame_reset
        end
        # If fog is different than current fog
        if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
          @fog_name = $game_map.fog_name
          @fog_hue = $game_map.fog_hue
          if @fog.bitmap != nil
            @fog.bitmap.dispose
            @fog.bitmap = nil
          end
          if @fog_name != ""
            @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
          end
          Graphics.frame_reset
        end
        # Update tilemap
        @tilemap.ox = $game_map.display_x / 4
        @tilemap.oy = $game_map.display_y / 4
        @tilemap.update
        # Update panorama plane
        @panorama.ox = $game_map.display_x / 8
        @panorama.oy = $game_map.display_y / 8
        # Update fog plane
        @fog.zoom_x = $game_map.fog_zoom / 100.0
        @fog.zoom_y = $game_map.fog_zoom / 100.0
        @fog.opacity = $game_map.fog_opacity
        @fog.blend_type = $game_map.fog_blend_type
        @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
        @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
        @fog.tone = $game_map.fog_tone
        # Update character sprites
        for sprite in @character_sprites
          sprite.update
        end
        # Update weather graphic
        @weather.type = $game_screen.weather_type
        @weather.max = $game_screen.weather_max
        @weather.ox = $game_map.display_x / 4
        @weather.oy = $game_map.display_y / 4
        @weather.update
        for sprite in @see_thru_sprite
          sprite.update
        end
        # Update picture sprites
        for sprite in @picture_sprites
          sprite.update
        end
        # Update timer sprite
        @timer_sprite.update
        # Set screen color tone and shake position
        @viewport1.tone = $game_screen.tone
        @viewport1.ox = $game_screen.shake
        # Set screen flash color
        @viewport3.color = $game_screen.flash_color
        # Update viewports
        @viewport1.update
        @viewport4.update
        @viewport3.update
      end
    end
    
     
    #3
  4. Kes

    Kes Global Moderators Global Mod

    Messages:
    20,766
    Likes Received:
    10,579
    First Language:
    English
    Primarily Uses:
    RMVXA
    @Ghozt Actually, you're safe. Script threads don't have the same necroposting rules as other sections, especially if you are restoring a corrupted copy.
     
    #4
    Ghozt likes this.

Share This Page