Some Popup 2.8

Discussion in 'RGSS Scripts (RMXP)' started by mikb89, Jul 14, 2012.

  1. mikb89

    mikb89 Villager Member

    Messages:
    10
    Likes Received:
    6
    First Language:
    Italian
    Some Popup 2.8

    mikb89


    Introduction

    With this script you can specify some text to be drawn when the player face an event. Text can be binded above the event or above the player or in center of the screen. There are many transition effects and it's possible to use picture instead of text. You can also play a SE, ME, BGM or BGS, on every popup event or for specific ones.

    Features

    • show simple text
    • bind in the middle of screen
    • bind above the player
    • bind above the event
    • show text grayed out
    • show picture
    • play SE/ME/BGM/BGS
    • fade text transition
    • move text transition
    • zoom text transition
    • transitions mixed together

    Screenshots

    [​IMG]

    How to Use

    Copy the script under Materials to use.

    Info on how to create popup event inside the script.

    Demo

    Multilanguage demo v. 2.8 (800 KB)

    http://www.mediafire.com/?mmg50jxofjq9jtl

    Script

    Code:
    # Some Popup v 2.8
    # XP version
    # by mikb89
    
    # Details:
    #  Show some popup text when facing an event.
    #  Text can be placed in center of screen, over the player or over the event.
    #  Write [pop] in a comment to assign the popup to an event and write in the
    #   next comment the text that will be shown.
    # NOTE: [pop] is by default, but you can change it in the settings.
    #  Text can be also grayed, to indicate a non-available something. To do so,
    #   write [npop] instead of [pop].
    #  You can also show a picture instead of text. In order to do this, the first
    #   comment must be [ppop] and the second will contain the name of the Picture.
    #  It is possible to play a sound/music effect for each event. Just write in a
    #   third comment these lines:
    #    SE (or ME or BGM or BGS)
    #    Audio filename
    #    Volume (1-100)
    #    Pitch (50-150)
    #    You can omit the two last lines, and they will be set by default:
    #    Volume 80 for BGS and SE, 100 for BGM and ME
    #    Pitch 100
    # ATTENTION: comments have to be the first two (or three) commands of the event.
    #
    #  You can also call a script with:
    #    $game_player.remove_town_sprite
    #   in it to remove the sprite. For example if you put the sprite on an event
    #   which you'll speak, with this code you can remove the popup.
    
    # Configurations:
    module SPOP
      ID = "pop" # set "loc" for old version compatibility.
       # What you have to write on a event to be identified as popup one.
       # If the value here is for example "pop" you'll have to write:
       #  - [pop] for the common text popup;
       #  - [npop] for the grayed out popup;
       #  - [ppop] for the picture popup.
      AUTO_REMOVE_AT_TRANSFER = true
       # Test to understand what I mean.
       #  true - gives the same effect as the one in Chrono Trigger towns.
       #  false - let the popup be visible after the teleport. Will fade out at the
       #          first player movement.
      GRAYED_COLOR = Color.new(255,245,255,175)
       # Value of grey color. Red, green, blue, alpha. From 0 to 255.
      WALK_8_DIR = true
       # You don't have to include the 8dir script. Just set true this.
      POPUP_TRANSITION = 9
       # The effect of the popup appearing/disappearing.
       #  0: no effect
       #  1: fading in/out
       #  2: movement up/down
       #  3: movement & fading
       #  4: reduced movement
       #  5: reduced movement & fading
       #  6: zoom in/out
       #  7: zoom & fading
       #  8: zoom & movement
       #  9: zoom, movement, fading
       # 10: zoom & reduced movement
       # 11: zoom, reduced movement, fading
      POPUP_SOUND = ["SE", "046-Book01", 80, 100]
       # Play something on popup.
       # 4 parameters:
       #  1. Sound kind ("SE", "ME", "BGS", "BGM");
       #  2. Name of the file;
       #  3. Volume (0-100);
       #  4. Pitch (50-150 (or 15-453 if you want MAXIMUM values)).
       # To deactivate sound just set "" the 2. or set 0 to 3. Examples:
       #  POPUP_SOUND = ["SE", "", 80, 100]
       #  POPUP_SOUND = ["SE", "046-Book01", 0, 100]
       # Won't be played.
       # Eventual BGM or BGS playing will fade as the graphic fade/zoom/move and
       #  will start after the popup close. Obviously not valid if using SE/ME.
    
       # Examples with ME, BGM, BGS:
       #  POPUP_SOUND = ["ME", "010-Item01", 100, 100]
       #  POPUP_SOUND = ["BGM", "023-Town01", 100, 100]
       #  POPUP_SOUND = ["BGS", "016-Drips01", 100, 100]
      POPUP_BINDING = 2
       # Where the popup should be binded.
       #  0: center of the screen
       #  1: over the player
       #  2: over the event
    end
    
    # Others:
    #  You'll see 'town' everywhere in the script. This is because of the SECOND
    #   name given to this script: "Popup town name".
    #  The FIRST original name was "Location system", from this the [loc] to add in
    #   event comments. By the way I never publicated the version with this name, so
    #   you won't find anything.
    
    #Codename: spop
    
    ($imported ||= {})[:mikb89_spop] = true
    
    # License:
    # - You can ask me to include support for other scripts as long as these scripts
    #   use the $imported[script] = true;
    # - You can modify and even repost my scripts, after having received a response
    #   by me. For reposting it, anyway, you must have done heavy edit or porting,
    #   you can't do a post with the script as is;
    # - You can use my scripts for whatever you want, from free to open to
    #   commercial games. I'd appreciate by the way if you let me know about what
    #   you're doing;
    # - You must credit me, if you use this script or part of it.
    
    class Game_Player < Game_Character
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
    #class Game_Player#def initialize()
      def initialize
        super
        @town_sprite = nil
        @town_text = ""
        reset_audio
        @town_ex_audio = [nil, ""]
        @sync_event = nil
      end
      #--------------------------------------------------------------------------
      # * Frame Update
      #--------------------------------------------------------------------------
    #class Game_Player#def update() <- rewritten
      def update
        # Remember whether or not moving in local variables
        last_moving = moving?
        # If moving, event running, move route forcing, and message window
        # display are all not occurring
        unless moving? or $game_system.map_interpreter.running? or
               @move_route_forcing or $game_temp.message_window_showing
          # Move player in the direction the directional button is being pressed
          move_by_input # Edited from the original
        end
        # Remember coordinates in local variables
        last_real_x = @real_x
        last_real_y = @real_y
        super
        # Some Popup addition START
        update_town_sprite
        # Some Popup addition END
        # If character moves down and is positioned lower than the center
        # of the screen
        if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
          # Scroll map down
          $game_map.scroll_down(@real_y - last_real_y)
        end
        # If character moves left and is positioned more let on-screen than
        # center
        if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
          # Scroll map left
          $game_map.scroll_left(last_real_x - @real_x)
        end
        # If character moves right and is positioned more right on-screen than
        # center
        if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
          # Scroll map right
          $game_map.scroll_right(@real_x - last_real_x)
        end
        # If character moves up and is positioned higher than the center
        # of the screen
        if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
          # Scroll map up
          $game_map.scroll_up(last_real_y - @real_y)
        end
        # If not moving
        unless moving?
          # If player was moving last time
          if last_moving
            # Event determinant is via touch of same position event
            result = check_event_trigger_here([1,2])
            # If event which started does not exist
            if result == false
              # Disregard if debug mode is ON and ctrl key was pressed
              unless $DEBUG and Input.press?(Input::CTRL)
                # Encounter countdown
                if @encounter_count > 0
                  @encounter_count -= 1
                end
              end
            end
          end
          # If C button was pressed
          if Input.trigger?(Input::C)
            # Same position and front event determinant
            check_event_trigger_here([0])
            check_event_trigger_there([0,1,2])
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Part of the update
      #--------------------------------------------------------------------------
    #class Game_Player#def update_town_sprite()
      def update_town_sprite
        if @town_sprite != nil
          case SPOP::POPUP_BINDING
          when 1
            @town_sprite.x = screen_x
            if @town_sprite.y != screen_y && screen_y != @sync_y
              @town_sprite.y = screen_y - (@town_sprite.y - @sync_y).abs
              @sync_y = screen_y
            end
          when 2
            if @sync_event != nil
              @town_sprite.x = @sync_event.screen_x
              if @town_sprite.y != @sync_event.screen_y && @sync_event.screen_y != @sync_y
                @town_sprite.y = @sync_event.screen_y - (@town_sprite.y - @sync_y).abs
                @sync_y = @sync_event.screen_y
              end
              sx = @sync_event.x - @x
              sy = @sync_event.y - @y
              remove_town_sprite if Math.hypot(sx, sy) > 2
            end
          end
          rem = false
          @town_sprite.update
          if [1,3,5,7,9,11].include?(SPOP::POPUP_TRANSITION)
            @town_sprite.opacity -= 15 if @town_sprite.z == 5 && @town_sprite.opacity > 0
            @town_sprite.opacity += 15 if @town_sprite.z == 10 && @town_sprite.opacity < 255
            rem = true if @town_sprite.opacity <= 0
          end
          if [2,3,4,5,8,9,10,11].include?(SPOP::POPUP_TRANSITION)
            mov = [4,5,10,11].include?(SPOP::POPUP_TRANSITION) ? 32 : 64
            val = mov/16
            t = @town_sprite.y
            @town_sprite.y += val if @town_sprite.z == 5 && @toadd > -mov
            @town_sprite.y -= val if @town_sprite.z == 10 && @toadd > 0
            @toadd -= val if t != @town_sprite.y
            rem = true if @toadd <= -mov
          end
          if [6,7,8,9,10,11].include?(SPOP::POPUP_TRANSITION)
            if @town_sprite.z == 5 && @town_sprite.zoom_x > 0
              @town_sprite.zoom_x -= 0.25
              @town_sprite.zoom_y -= 0.25
            end
            if @town_sprite.z == 10 && @town_sprite.zoom_x < 1
              @town_sprite.zoom_x += 0.25
              @town_sprite.zoom_y += 0.25
            end
            rem = true if @town_sprite.zoom_x <= 0
          end
          if @town_ex_audio[0] != nil
            if @audiowait > 0
              @audiowait -= 1
            elsif @audiowait == 0
              if @town_audio[0] != nil
                $game_system.method("#{@town_audio[1]}_play").call(@town_audio[0])
                if @town_ex_audio[1] != @town_audio[1]
                  $game_system.method("#{@town_ex_audio[1]}_play").call(@town_ex_audio[0])
                  @town_ex_audio = [nil, ""]
                end
                reset_audio if @town_audio[0].name != SPOP::POPUP_SOUND[1]
              end
              @audiowait = -1
            end
          end
          remove_town_sprite(true) if rem
        end
      end
      #--------------------------------------------------------------------------
      # * Popup removal at straighten (scene change)
      #--------------------------------------------------------------------------
    if method_defined?(:straighten)
      alias_method(:straighten_b4_spop, :straighten) unless method_defined?(:straighten_b4_spop)
    end
    #class Game_Player#def straighten() <- aliased/added
      def straighten
        remove_town_sprite(true)
        if respond_to?(:straighten_b4_spop)
          straighten_b4_spop
        else
          super
        end
      end
      #--------------------------------------------------------------------------
      # * Player has moved?
      #--------------------------------------------------------------------------
      alias_method(:increase_steps_b4_spop, :increase_steps) unless method_defined?(:increase_steps_b4_spop)
    #class Game_Player#def increase_steps() <- aliased
      def increase_steps
        increase_steps_b4_spop
        @move_failed = false
      end
      #--------------------------------------------------------------------------
      # * Processing of Movement via input from the Directional Buttons
      #--------------------------------------------------------------------------
    #class Game_Player#def move_by_input()
      def move_by_input
        x, y = self.x, self.y
        @move_failed = true
        case SPOP::WALK_8_DIR ? Input.dir8 : Input.dir4
        when 1
          move_lower_left
          if @move_failed
            check_town(x-1, y+1)
          else
            check_town(x-2, y+2)
          end
        when 2
          move_down
          if @move_failed
            check_town(x, y+1)
          else
            check_town(x, y+2)
          end
        when 3
          move_lower_right
          if @move_failed
            check_town(x+1, y+1)
          else
            check_town(x+2, y+2)
          end
        when 4
          move_left
          if @move_failed
            check_town(x-1, y)
          else
            check_town(x-2, y)
          end
        when 6
          move_right
          if @move_failed
            check_town(x+1, y)
          else
            check_town(x+2, y)
          end
        when 7
          move_upper_left
          if @move_failed
            check_town(x-1, y-1)
          else
            check_town(x-2, y-2)
          end
        when 8
          move_up
          if @move_failed
            check_town(x, y-1)
          else
            check_town(x, y-2)
          end
        when 9
          move_upper_right
          if @move_failed
            check_town(x+1, y-1)
          else
            check_town(x+2, y-2)
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Operations for sprite removal and audio stopping
      #--------------------------------------------------------------------------
    #class Game_Player#def remove_town_sprite(instant, audio)
      def remove_town_sprite(instant=false, audio=true)
        if @town_sprite != nil
          if instant || SPOP::POPUP_TRANSITION == 0
            if audio
              $game_system.method("#{@town_audio[1]}_stop").call if @town_audio[1] != ""
              $game_system.method("#{@town_ex_audio[1]}_play").call(@town_ex_audio[0]) if @town_ex_audio[1] != ""
            end
            @town_ex_audio = [nil, ""]
            @town_sprite.dispose
            @town_sprite = nil
            @sync_event = nil
          else
            @town_sprite.z = 5
            unless ["se", "me", ""].include?(@town_audio[1])
              $game_system.method("#{@town_audio[1]}_fade").call(4)
            end
          end
        end
      end
      #--------------------------------------------------------------------------
      # * Set the audio as the one specified in SPOP or passed
      #--------------------------------------------------------------------------
    #class Game_Player#def reset_audio(spn)
      def reset_audio(spn = SPOP::POPUP_SOUND)
        @town_audio = [(spn[1] == "" || spn[2] <= 0) ? nil :
                        RPG::AudioFile.new(spn[1], spn[2], spn[3]),
                        spn[0].downcase]
      end
      #--------------------------------------------------------------------------
      # * Check if there is a town event in front of the player
      #--------------------------------------------------------------------------
    #class Game_Player#def check_town(x, y)
      def check_town(x, y)
        return false if $game_system.map_interpreter.running?
        result = false
        for event in $game_map.events_xy(x, y)
          unless [1,2].include?(event.trigger) and event.priority_type == 1
            if event.list != nil
              if event.list[0].code == 108 and
                ["[#{SPOP::ID}]", "[n#{SPOP::ID}]", "[p#{SPOP::ID}]"].include?(event.list[0].parameters[0])
                result = true
                next if @town_sprite != nil && @town_sprite.z == 10 && @town_text == event.list[1].parameters[0]
                remove_town_sprite(true)
                @town_sprite = Sprite.new
                @town_sprite.z = 10
                if [6,7,8,9,10,11].include?(SPOP::POPUP_TRANSITION)
                  @town_sprite.zoom_x = @town_sprite.zoom_y = 0.0
                end
                @town_sprite.opacity = 15 if [1,3,5,7,9,11].include?(SPOP::POPUP_TRANSITION)
                if event.list[0].parameters[0] != "[p#{SPOP::ID}]"
                  @town_sprite.bitmap ||= Bitmap.new(1,1)
                  siz = @town_sprite.bitmap.text_size(event.list[1].parameters[0])
                  h = siz.height
                  s = siz.width
                  @town_sprite.bitmap.dispose
                  @town_sprite.bitmap = Bitmap.new(s, 24)
                  if event.list[0].parameters[0] == "[n#{SPOP::ID}]"
                    ex = @town_sprite.bitmap.font.color
                    @town_sprite.bitmap.font.color = SPOP::GRAYED_COLOR
                  end
                  @town_sprite.bitmap.draw_text(0,2,s,22,event.list[1].parameters[0],1)
                  @town_sprite.bitmap.font.color = ex if event.list[0].parameters[0] == "[n#{SPOP::ID}]"
                else
                  @town_sprite.bitmap = Cache.picture(event.list[1].parameters[0])
                  s = @town_sprite.bitmap.width
                  h = @town_sprite.bitmap.height
                end
                @town_text = event.list[1].parameters[0]
                @town_sprite.ox = s/2
                @town_sprite.oy = h/2
                case SPOP::POPUP_BINDING
                when 1
                  @town_sprite.x = screen_x#*32+16
                  @town_sprite.y = @sync_y = screen_y#*32+16
                when 2
                  @town_sprite.x = event.screen_x#*32+16
                  @town_sprite.y = @sync_y = event.screen_y#*32+16
                  @sync_event = event
                else
                  @town_sprite.x = 544/2# - s/2
                  @town_sprite.y = 416/2# - h/2
                end
                @town_sprite.y -= 64 if [0,1,6,7].include?(SPOP::POPUP_TRANSITION)
                @town_sprite.y -= 32 if [4,5,10,11].include?(SPOP::POPUP_TRANSITION)
                @toadd = [2,3,4,5,8,9,10,11].include?(SPOP::POPUP_TRANSITION) ? 64 : 0
                @toadd -= 32 if [4,5,10,11].include?(SPOP::POPUP_TRANSITION)
                if @town_audio[0] != nil || event.list[2].code == 108
                  if ["BGM", "ME", "BGS", "SE"].include?(event.list[2].parameters[0]) &&
                    event.list[3].code == 408
                    arr = []
                    arr.push(event.list[2].parameters[0])
                    arr.push(event.list[3].parameters[0])
                    if event.list[4].code == 408
                      arr.push(event.list[4].parameters[0].to_i)
                      arr.push(event.list[5].parameters[0].to_i) if event.list[5].code == 408
                    else
                      arr.push(["BGS", "SE"].include?(event.list[2].parameters[0]) ? 80 : 100)
                    end
                    arr.push(100) if arr.size < 4
                    reset_audio(arr)
                  end
                  if ["bgm", "bgs"].include?(@town_audio[1])
                    @town_ex_audio = [$game_system.method("playing_#{@town_audio[1]}").call,
                                      @town_audio[1]]
                  else
                    @town_ex_audio[0] = nil
                  end
                  if @town_ex_audio[0] != nil
                    $game_system.method("#{@town_ex_audio[1]}_fade").call(4)
                    @audiowait = 4
                  else
                    $game_system.method("#{@town_audio[1]}_play").call(@town_audio[0])
                    reset_audio if arr != nil
                  end
                end
              end
            end
          end
        end
        remove_town_sprite unless result
        return result
      end
    end
    
    if SPOP::AUTO_REMOVE_AT_TRANSFER
    class Scene_Map
      #--------------------------------------------------------------------------
      # * Removing of town sprite when changing map
      #--------------------------------------------------------------------------
      alias_method(:transfer_player_b4_spop, :transfer_player) unless method_defined?(:transfer_player_b4_spop)
    #class Scene_Map#def transfer_player() <- aliased
      def transfer_player
        $game_player.remove_town_sprite(true, false)
        transfer_player_b4_spop
      end
    end
    end
    
    class Game_Map
      #--------------------------------------------------------------------------
      # * Get event list in x, y
      #--------------------------------------------------------------------------
    #class Game_Map#def events_xy(x, y)
      unless method_defined?(:events_xy)
      def events_xy(x, y)
        result = []
        for event in $game_map.events.values
          result.push(event) if event.x == x and event.y == y
        end
        return result
      end
      end
    end
    Also visible on Pastebin.FAQ

    Q: Can I use the 8 directions script?

    A: No, but the 8 dir functionality is included, just enable it in settings.

    Credit and Thanks

    Thanks Guardian of Irael for various suggestions.

    Author's Notes

    N/A
     
    #1
    CeryliaRectris, istathhgkbp and Ally like this.
  2. CeryliaRectris

    CeryliaRectris Warper Member

    Messages:
    4
    Likes Received:
    0
    First Language:
    Indonesian
    I've got an error massage when I want a popup using picture ?? :(
     
    #2
  3. slimmmeiske2

    slimmmeiske2 Little Red Riding Hood Moderator

    Messages:
    5,309
    Likes Received:
    3,957
    Location:
    Belgium
    First Language:
    Dutch
    Primarily Uses:
    RMXP
    Cerylia, what's the exact error message you're getting? Without it, none of us can help you.
     
    #3
  4. CeryliaRectris

    CeryliaRectris Warper Member

    Messages:
    4
    Likes Received:
    0
    First Language:
    Indonesian
    Can you help me? This is the error message.

    Script 'some Popup 2.8' line 419: NameError occured.

    uninitialized constant Game_Player::Cache
     
    Last edited by a moderator: Nov 8, 2012
    #4
  5. CeryliaRectris

    CeryliaRectris Warper Member

    Messages:
    4
    Likes Received:
    0
    First Language:
    Indonesian
    How can I fix that error message ? :(
     
    #5
  6. ThallionDarkshine

    ThallionDarkshine Veteran Veteran

    Messages:
    83
    Likes Received:
    4
    First Language:
    English
    Go to line 419 of the script, and replace "Cache" with "RPG::Cache".
     
    #6
    CeryliaRectris likes this.
  7. CeryliaRectris

    CeryliaRectris Warper Member

    Messages:
    4
    Likes Received:
    0
    First Language:
    Indonesian
    Hey That worked! thank you Thallion...
     
    #7
  8. ThallionDarkshine

    ThallionDarkshine Veteran Veteran

    Messages:
    83
    Likes Received:
    4
    First Language:
    English
    You're welcome. I always love to help people with scripts. :) At least if they're not impossible, like a full abs or something.
     
    #8
  9. whydoihavetosignup

    whydoihavetosignup Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    英語
    Can somebody add a script call to add back the popup? That would be the opposite of "$game_player.remove_town_sprite" which removes it. Thanks in advance.
     
    #9

Share This Page