Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- # [Xp/Vx] Show Event Name
- # Version: 4.21
- # Author : LiTTleDRAgo
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- #
- # Explanation:
- #
- # - This script shows event name in map
- #
- # Instructions:
- #
- # - Setup the few configurations below.
- #
- #
- # - Insert the event name
- # <Name=X> X = Name showed in map
- # <SizeX> X = Size the font
- # <Bold> Toggle Bold
- # <Italic> Toggle Italic
- # <Font[X]> X = Font name
- # <ColorX,X,X,X> X,X,X,X = Color the font(in RGB)
- #
- # - Or use call script to show the event name
- #
- # $game_map.events[2].show_name = x
- # $game_player.show_name = x
- #
- # where x is a string
- #
- # That's all
- #
- # Press Z and C together to turn on the name on / off
- #
- #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
- module EventName
- FONT = ['Calibri',16] # Font Name and Font Size
- BOLD = true # Toggle Bold
- ITALIC = true # Toggle Italic
- SWITCH = 50 # Switch for Disable Show Event Name
- PRESS_BTN = [Input::A, # (Z Keyboard XP) (Shift Keyboard VX)
- Input::C] # (C/Enter Keyboard XP) (Z/Enter Keyboard VX)
- COLOR = Color.new(0,0,0,240) # Color Default
- POSITION = "A" # A = Above, B = Below
- RANGE = 3 # Range from character to show the name
- USEPICT = nil # Show background for event name (in folder Pictures)
- # leave nil if you don't want to
- OFFSET = [0,0] # offset x and y
- end
- VX = defined?(Window_ActorCommand)
- VXA = defined?(Window_BattleActor)
- if true
- #==============================================================================
- # ** Sprite_EventName
- #------------------------------------------------------------------------------
- # This sprite is used to display Event Name. It observes a instance of the
- # Game_Character class and automatically changes sprite conditions.
- #==============================================================================
- class Sprite_EventName < RPG::Sprite
- FONT = EventName::FONT
- BOLD = EventName::BOLD
- ITALIC = EventName::ITALIC
- DIS_EV_SWITCH = EventName::SWITCH
- PRESS_BTN = EventName::PRESS_BTN
- COLOR = EventName::COLOR
- POS = EventName::POSITION
- RANGE = EventName::RANGE
- USEPICT = EventName::USEPICT
- OFFSET = EventName::OFFSET
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :character
- define_method(:cache) { VX ? Cache : RPG::Cache }
- #--------------------------------------------------------------------------
- # * Object Initialization
- # viewport : viewport
- # character : character (Game_Character)
- #--------------------------------------------------------------------------
- def initialize(v,character)
- super(v)
- @character = character
- @character.load_name
- @name_event = Sprite.new
- @name_event.bitmap = Bitmap.new(200,280)
- if USEPICT
- @back = Sprite.new
- @back.bitmap = cache.picture(USEPICT)
- @back.visible = false
- end
- @name_event.visible = true
- refresh_name
- update
- end
- #--------------------------------------------------------------------------
- # * Coloring
- #--------------------------------------------------------------------------
- def coloring
- size, name, bold, italic, color = FONT[1], FONT[0], BOLD, ITALIC, COLOR
- size = @character.fontsize if @character.fontsize
- bold = @character.bold
- italic = @character.italic
- color = @character.color if @character.color
- name = @character.font if @character.font
- if $xrxs_xas
- @char.gsub!(/<Enemy(\d+)>/i) do color = Color.new(255,0,0,240) end
- elsif $BlizzABS && @character.is_a?(Map_Battler)
- case @character.ai.group
- when 1 then color = Color.new(0 , 0 , 255, 240)
- when 2 then color = Color.new(255, 0 , 0 , 240)
- when 3 then color = Color.new(128, 128, 128, 240)
- when 4 then color = Color.new(128, 128, 128, 240)
- when 5 then color = Color.new(255, 255, 0 , 240)
- when 6 then color = Color.new(0 , 255, 0 , 240)
- end
- end
- @char.gsub!(/<Size(\d+)>/) do size = $1.to_i end
- @char.gsub!(/<Bold>/i) do bold = true end
- @char.gsub!(/<Italic>/i) do italic = true end
- @char.gsub!(/<Font\[(.*?)\]>/) do name = $1.to_s end
- @char.gsub!(/<Color(\d+),(\d+),(\d+),(\d+)>/) do
- color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i) end
- @name_event.bitmap.font.name = name
- @name_event.bitmap.font.bold = bold
- @name_event.bitmap.font.italic = italic
- @name_event.bitmap.font.size = size
- @name_event.bitmap.font.color = color
- end
- #--------------------------------------------------------------------------
- # * Check Name
- #--------------------------------------------------------------------------
- def event_name_check
- @char.gsub!(/<V([0-9]+)>/){ $game_variables[$1.to_i] }
- @char.gsub!(/<A([0-9]+)>/){ !$game_actors[$1.to_i].nil? ?
- $game_actors[$1.to_i].name : ''}
- @char.gsub!(/<Size(\d+)>/) {''}
- @char.gsub!(/<Bold>/i) {''}
- @char.gsub!(/<Italic>/i) {''}
- @char.gsub!(/<Font\[(.*?)\]>/){''}
- @char.gsub!(/<Color(\d+),(\d+),(\d+),(\d+)>/) {''}
- @char.gsub!(/<Enemy(\d+)>/i) { !$data_enemies[$1.to_i].nil? ?
- $data_enemies[$1.to_i].name : ''}
- @char.gsub!(/<\[(.*?)\]>/) do @char = $1.to_s end
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- super
- if @show_name != @character.show_name or
- @character_graphic != @character.character_name
- @character_graphic = @character.character_name
- @show_name = @character.show_name
- refresh_name
- end
- update_event_name
- update_back
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh_name
- return if @name_event.nil? or @name_event.bitmap.nil? or
- @name_event.disposed? or !@name_event.visible or
- @character.show_name.nil? or @show_name.nil?
- @name_event.bitmap.clear
- return if @character.character_name == ''
- @show_name.each {|@char| coloring; event_name_check }
- draw_name
- conf_position
- end
- #--------------------------------------------------------------------------
- # * Conf Position
- #--------------------------------------------------------------------------
- def conf_position
- @x_frame, @y_frame = 4, 4
- if POS == "A"
- bit = cache.character(@character.character_name,
- @character.character_hue)
- @cw = ((bit.width / @x_frame) + @char.length)/2
- @ch = bit.height / @y_frame + 15
- if $xrxs_xas
- @cw = ((@name_event.bitmap.width / @x_frame) + @char.length)/2
- @ch = @name_event.bitmap.height / @y_frame - 5
- end
- @ch += 5 if USEPICT
- else
- @cw = @name_event.bitmap.width / @x_frame / 2
- @ch = @name_event.bitmap.height / @y_frame - 40
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Name
- #--------------------------------------------------------------------------
- def draw_name
- coor = [OFFSET, 100, 20, @char ,4].flatten
- if defined? Bitmap.draw_hemming_text
- @name_event.bitmap.draw_hemming_text(*coor)
- else
- @name_event.bitmap.draw_text(*coor)
- end
- end
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- def dispose
- super
- [@name_event, @back].each {|i| i.dispose if !i.nil? && !i.disposed? }
- end
- #--------------------------------------------------------------------------
- # * Visibility
- #--------------------------------------------------------------------------
- def visibility
- pressed = Input.press?(PRESS_BTN[0]) && Input.trigger?(PRESS_BTN[1])
- if RANGE != nil && !@pressed
- x = ($game_player.x-@character.x).abs+($game_player.y-@character.y).abs
- @name_event.visible = (x <= RANGE)
- end
- if !@pressed && pressed
- @name_event.visible, @pressed = false, true
- elsif @pressed && pressed
- @name_event.visible, @pressed = true, false
- end
- end
- #--------------------------------------------------------------------------
- # * Update Event Name
- #--------------------------------------------------------------------------
- def update_event_name
- return @name_event.visible = false if !DIS_EV_SWITCH.nil? and
- (@character.opacity < 50 or $game_switches[DIS_EV_SWITCH])
- visibility if !PRESS_BTN.nil?
- if @name_event.visible
- @name_event.x = @character.screen_x - (@cw.nil? ? 0 : @cw)
- @name_event.y = @character.screen_y - (POS == 'A' ? @ch.nil? ? 0 : @ch : 0)
- @name_event.z = 1
- @name_event.opacity = @character.opacity
- @name_event.blend_type = @character.blend_type
- @name_event.bush_depth = @character.bush_depth
- end
- end
- #--------------------------------------------------------------------------
- # * Update Back
- #--------------------------------------------------------------------------
- def update_back
- return if !USEPICT
- @back.visible = @name_event.visible && !@char.nil? &&
- !@char.empty? && @char != ' '
- if @back.visible
- @back.opacity = @name_event.opacity - 100
- @back.x = @name_event.x - 5
- @back.y = @name_event.y - 5
- @back.z = @name_event.z - 1
- end
- end
- end
- #==============================================================================
- # ** Game_Character
- #------------------------------------------------------------------------------
- # This class deals with characters. It's used as a superclass for the
- # Game_Player and Game_Event classes.
- #==============================================================================
- class Game_Character
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :show_name,:fontsize,:bold,:italic,:font,:color
- #--------------------------------------------------------------------------
- # * Show Name
- #--------------------------------------------------------------------------
- def show_name=(v= ' ')
- @show_name=v
- record_name
- end
- #--------------------------------------------------------------------------
- # * Record Name
- #--------------------------------------------------------------------------
- def record_name
- if self == $game_player
- $game_system.player_name = @show_name
- end
- end
- #--------------------------------------------------------------------------
- # * Load Name
- #--------------------------------------------------------------------------
- def load_name
- if self == $game_player
- if !$game_system.player_name.nil?
- @show_name = $game_system.player_name
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Clear Name
- #--------------------------------------------------------------------------
- def clear_name
- @show_name = ' '
- if self == $game_player
- $game_system.player_name = @show_name
- end
- end
- #--------------------------------------------------------------------------
- # * Clear every Name
- #--------------------------------------------------------------------------
- def clear_every_name
- $game_system.record_name = {}
- $game_system.player_name = nil
- end
- end
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # This class deals with events. It handles functions including event page
- # switching via condition determinants, and running parallel process events.
- # It's used within the Game_Map class.
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # * Alias listing
- #--------------------------------------------------------------------------
- alias erase_show_name erase
- alias init_event_name initialize
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :event
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(map_id, event)
- if event.name =~ /<Name=(.*?)>/i
- @show_name = $1.to_s
- end
- if event.name =~ /<Size(\d+)>/i
- @fontsize = $1.to_i
- end
- @bold = event.name =~ /<Bold>/i
- @italic = event.name =~ /<Italic>/i
- if event.name =~ /<Font\[(.*?)\]>/i
- @font = $1.to_s
- end
- if event.name =~ /<Color(\d+),(\d+),(\d+),(\d+)>/
- @color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i)
- end
- init_event_name(map_id, event)
- end
- #--------------------------------------------------------------------------
- # * Record Name
- #--------------------------------------------------------------------------
- def record_name
- key = [@map_id, @event.id]
- clear_every_name if $game_system.record_name.nil?
- $game_system.record_name[key]=[@show_name]
- end
- #--------------------------------------------------------------------------
- # * Load Name
- #--------------------------------------------------------------------------
- def load_name
- key = [@map_id, @event.id]
- clear_every_name if $game_system.record_name.nil?
- if $game_system.record_name[key] != nil
- @show_name=$game_system.record_name[key][0]
- end
- end
- #--------------------------------------------------------------------------
- # * Clear Name
- #--------------------------------------------------------------------------
- def clear_name
- super
- key = [@map_id, @event.id]
- if $game_system.record_name[key] != nil
- $game_system.record_name[key] = nil
- end
- end
- #--------------------------------------------------------------------------
- # * Temporarily Erase
- #--------------------------------------------------------------------------
- def erase
- clear_name
- erase_show_name
- end
- end
- #==============================================================================
- # ** Game_Map
- #------------------------------------------------------------------------------
- # This class handles the map. It includes scrolling and passable determining
- # functions. Refer to "$game_map" for the instance of this class.
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # * Alias listing
- #--------------------------------------------------------------------------
- alias setup_record setup
- #--------------------------------------------------------------------------
- # * Setup
- # map_id : map ID
- #--------------------------------------------------------------------------
- def setup(map_id)
- setup_record (map_id)
- @map.events.keys.each {|i| @events[i].load_name if !events[i].nil?}
- end
- end
- #==============================================================================
- # ** Game_System
- #------------------------------------------------------------------------------
- # This class handles data surrounding the system. Backround music, etc.
- # is managed here as well. Refer to "$game_system" for the instance of
- # this class.
- #==============================================================================
- class Game_System
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :player_name, :record_name
- end
- #==============================================================================
- # ** Spriteset_Map
- #------------------------------------------------------------------------------
- # This class brings together map screen sprites, tilemaps, etc. It's used
- # within the Scene_Map class.
- #==============================================================================
- class Spriteset_Map
- PRESS_BTN = EventName::PRESS_BTN
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_accessor :eventname
- #--------------------------------------------------------------------------
- # * Main Processing
- #--------------------------------------------------------------------------
- def init_eventname
- @eventname = []
- @eventname[0] = Sprite_EventName.new(@viewport1,$game_player)
- ($game_map.events.keys.sort).each {|i|
- next if $game_map.events[i].character_name == ''
- @eventname[i] = Sprite_EventName.new(@viewport1,$game_map.events[i])}
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- alias update_eventname_earlier update
- def update
- @eventname.nil? ? init_eventname : @eventname.each {|i|i.update if !i.nil?}
- update_eventname_earlier
- end
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- alias dispose_eventname dispose
- def dispose
- @eventname.each {|i| i.dispose if !i.nil?}
- dispose_eventname
- end
- end
- end
- #--------------------------------------------------------------------------
- # END OF SCRIPT
- #--------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement