Jump to content
Death10

Event Text Display

Recommended Posts

Event Text Display

Author: Ãص¹ (RGSS)

Edited by Death10 (RGSS3)

 

Introduction

-Display text above Actor and Event

 

Features

-New nickname line

-Can update in map

 

Script

Comment in Event Page: [ETDname][NNnickname]

#==============================================================================

# ** Event Text Display

#==============================================================================

# Author: Ãص¹ (RGSS)

# Edited by Death10 (RGSS3)

# http://itbinhdan.com

#==============================================================================

# Comment: [ETDname][NNnickname]

#==============================================================================

 

#==============================================================================

# ** Game_Character

#==============================================================================

 

class Game_Character

#--------------------------------------------------------------------------

# * Defaults

#

# ~ Default Player Display Options (Non-Case Sensitive):

# 'Name', 'Nickname', 'Class', 'Level', 'Hp', 'Sp'

#--------------------------------------------------------------------------

ETD_Default_EventText_Color = Color.new(255, 255, 255)

ETD_Default_PlayerText_Color = Color.new(255, 255, 255)

ETD_Default_EventText_Color2 = Color.new(255, 255, 255)

ETD_Default_PlayerText_Color2 = Color.new(255, 255, 255)

ETD_Default_PlayerText = 'name'

ETD_Default_PlayerText2 = 'nickname'

#--------------------------------------------------------------------------

# * Public Instance Variables

#--------------------------------------------------------------------------

attr_accessor :etd_display_shadow_color

attr_accessor :etd_display_color

attr_accessor :etd_display_text

attr_accessor :etd_display_shadow_color2

attr_accessor :etd_display_color2

attr_accessor :etd_display_text2

#--------------------------------------------------------------------------

# * Alias Listings

#--------------------------------------------------------------------------

alias seph_etd_gmchr_init initialize

#--------------------------------------------------------------------------

# * Object Initialization

#--------------------------------------------------------------------------

def initialize

# Sets ETD Options

@etd_display_color = self.is_a?(Game_Player) ?

ETD_Default_PlayerText_Color : ETD_Default_EventText_Color

@etd_display_color2 = self.is_a?(Game_Player) ?

ETD_Default_PlayerText_Color2 : ETD_Default_EventText_Color2

# Original Initialization

seph_etd_gmchr_init

end

end

 

#==============================================================================

# ** Game_Event

#==============================================================================

 

class Game_Event < Game_Character

#--------------------------------------------------------------------------

# * Alias Listings

#--------------------------------------------------------------------------

alias seph_etd_gmevt_refresh refresh

#--------------------------------------------------------------------------

# * Refresh

#--------------------------------------------------------------------------

def refresh

# Original Refresh Method

seph_etd_gmevt_refresh

# Erase ETD Display Text

@etd_display_text = nil

@etd_display_text2 = nil

# Checks to see if display text

unless @list.nil? || @erased

for i in 0...@list.size

if @list.code == 108

@list.parameters[0].dup.gsub!(/\[[Ee][Tt][Dd](.+?)\]/) do

@etd_display_color = ETD_Default_EventText_Color

@etd_display_text = $1

end

if @list.code == 108

@list.parameters[0].dup.gsub!(/\[[Nn][Nn](.+?)\]/) do

@etd_display_color2 = ETD_Default_EventText_Color2

@etd_display_text2 = $1

end

end

end

end

end

end

end

#==============================================================================

# ** Game_Player

#==============================================================================

 

class Game_Player < Game_Character

#--------------------------------------------------------------------------

# * Alias Listings

#--------------------------------------------------------------------------

alias seph_etd_gmplyr_refresh refresh

alias etd_update update

#--------------------------------------------------------------------------

# * Refresh

#--------------------------------------------------------------------------

def etd

# Gets First Actor

actor = $game_party.members[0]

# Determines Text

case ETD_Default_PlayerText.dup.downcase

when 'name' ; txt = actor.name

when 'nickname' ; txt = actor.nickname

when 'class' ; txt = actor.class.name

when 'level' ; txt = "Level: #{actor.level}"

when 'hp' ; txt = "HP: #{actor.hp} / #{actor.mhp}"

when 'sp' ; txt = "SP: #{actor.sp} / #{actor.msp}"

else ; txt = ''

end

# Determines Text

case ETD_Default_PlayerText2.dup.downcase

when 'name' ; txt2 = actor.name

when 'nickname' ; txt2 = actor.nickname

when 'class' ; txt2 = actor.class.name

when 'level' ; txt2 = "Level: #{actor.level}"

when 'hp' ; txt2 = "HP: #{actor.hp} / #{actor.mhp}"

when 'sp' ; txt2 = "SP: #{actor.sp} / #{actor.msp}"

else ; txt2 = ''

end

# Creates Text Display

@etd_display_color = ETD_Default_PlayerText_Color

@etd_display_text = txt

@etd_display_color2 = ETD_Default_PlayerText_Color2

@etd_display_text2 = txt2

end

def refresh

seph_etd_gmplyr_refresh

etd

end

def update

etd_update

etd

end

end

#==============================================================================

# ** Sprite_Character

#==============================================================================

 

class Sprite_Character < Sprite_Base

#--------------------------------------------------------------------------

# * Alias Listings

#--------------------------------------------------------------------------

if @seph_etd_spchr.nil?

alias seph_etd_spchr_update update

alias seph_etd_spchr_dispose dispose

@seph_etd_spchr = true

end

#--------------------------------------------------------------------------

# * Frame Update

#--------------------------------------------------------------------------

def update

# Original update Method

seph_etd_spchr_update

# Character Display Update Method

update_display_text

update_display_text2

end

#--------------------------------------------------------------------------

# * Dispose

#--------------------------------------------------------------------------

def dispose

# Original Dispose

seph_etd_spchr_dispose

# Dispose ETD Sprite

dispose_etd_sprite

dispose_etd_sprite2

end

#--------------------------------------------------------------------------

# * Dispose ETD Sprite

#--------------------------------------------------------------------------

def dispose_etd_sprite

# Dispose ETD Sprite

unless @_etd_text_sprite.nil?

@_etd_text_sprite.dispose

@_etd_text_sprite = nil

end

end

 

def dispose_etd_sprite2

# Dispose ETD Sprite

unless @_etd_text_sprite2.nil?

@_etd_text_sprite2.dispose

@_etd_text_sprite2 = nil

end

end

#--------------------------------------------------------------------------

# * Update Display Sprite

#--------------------------------------------------------------------------

def update_display_text

# If Character Has No ETD

if @character.etd_display_text.nil?

# Dispose ETD Sprite

dispose_etd_sprite

return

end

# If ETD Text Sprite Doesn't Exist

if @_etd_text_sprite.nil?

# Create ETD Text Sprite

create_etd_sprite

return

end

# If ETD Sprite Parameters Don't Match Characters

unless @_etd_display_text == @character.etd_display_text &&

@_etd_display_color == @character.etd_display_color &&

@_etd_display_shadow_color == @character.etd_display_shadow_color

# Dispose Sprite

dispose_etd_sprite

# Recreate Sprite

create_etd_sprite

end

# Update ETD Sprite Position

@_etd_text_sprite.x = self.x

@_etd_text_sprite.y = self.y - self.oy / 2 - 41

end

 

def update_display_text2

# If Character Has No ETD

if @character.etd_display_text2.nil?

# Dispose ETD Sprite

dispose_etd_sprite2

return

end

# If ETD Text Sprite Doesn't Exist

if @_etd_text_sprite2.nil?

# Create ETD Text Sprite

create_etd_sprite2

return

end

# If ETD Sprite Parameters Don't Match Characters

unless @_etd_display_text2 == @character.etd_display_text2 &&

@_etd_display_color2 == @character.etd_display_color2 &&

@_etd_display_shadow_color2 == @character.etd_display_shadow_color2

# Dispose Sprite

dispose_etd_sprite2

# Recreate Sprite

create_etd_sprite2

end

# Update ETD Sprite Position

@_etd_text_sprite2.x = self.x

@_etd_text_sprite2.y = self.y - self.oy / 2 - 24

end

#--------------------------------------------------------------------------

# * Create ETD Sprite

#--------------------------------------------------------------------------

def create_etd_sprite

# Creates Display Bitmap

bitmap = Bitmap.new(162, 40)

# Draws ETD Display Text

bitmap.font.color = @character.etd_display_color

bitmap.font.size = 22

bitmap.draw_text(0, 0, 161, 40, @character.etd_display_text, 1)

# Creates Display Text Sprite

@_etd_text_sprite = Sprite.new(self.viewport)

@_etd_text_sprite.bitmap = bitmap

@_etd_text_sprite.ox = 80

@_etd_text_sprite.oy = 20

@_etd_text_sprite.x = self.x

@_etd_text_sprite.y = self.y - self.oy / 2 - 41

@_etd_text_sprite.z = 3000

@_etd_text_sprite.visible = true

# Saves ETD Text

@_etd_display_text = @character.etd_display_text

@_etd_display_color = @character.etd_display_color

@_etd_display_shadow_color = @character.etd_display_shadow_color

end

 

def create_etd_sprite2

# Creates Display Bitmap

bitmap2 = Bitmap.new(162, 40)

# Draws ETD Display Text

bitmap2.font.color = @character.etd_display_color2

bitmap2.font.size = 22

bitmap2.draw_text(0, 0, 161, 40, @character.etd_display_text2, 1)

# Creates Display Text Sprite

@_etd_text_sprite2 = Sprite.new(self.viewport)

@_etd_text_sprite2.bitmap = bitmap2

@_etd_text_sprite2.ox = 80

@_etd_text_sprite2.oy = 20

@_etd_text_sprite2.x = self.x

@_etd_text_sprite2.y = self.y - self.oy / 2 - 24

@_etd_text_sprite2.z = 3000

@_etd_text_sprite2.visible = true

# Saves ETD Text

@_etd_display_text2 = @character.etd_display_text2

@_etd_display_color2 = @character.etd_display_color2

@_etd_display_shadow_color2 = @character.etd_display_shadow_color2

end

end

 

 

 

 

Screenshot

112f462b5dc0cdc68c245b957aef494b_39100592.untitled.png

 

FAQ

 

 

-Remove the game actor name and nickname:

 

Change

ETD_Default_PlayerText = 'name'
ETD_Default_PlayerText2 = 'nickname'

to

ETD_Default_PlayerText = ''
ETD_Default_PlayerText2 = ''

 

 

Edited by Death10

Share this post


Link to post
Share on other sites

Change

ETD_Default_PlayerText = 'name'
ETD_Default_PlayerText2 = 'nickname'

to

ETD_Default_PlayerText = ''
ETD_Default_PlayerText2 = ''

Edited by Death10

Share this post


Link to post
Share on other sites

I want to make and Add-On to this scripts, simply can see variables, explaining myself: if I put [ETD\v[2]] and the \v[2]=4, the the char will show "4" without quotations

 

EDIT: this give me a question... If the variable number 2, change the "4" for "8", the text will change inmediatly? if not, what can I do that?

Edited by Shadow

Share this post


Link to post
Share on other sites

Can you add the feature to add a border around the text that appears? Or a small window/hud.

It'll make it easier for players to read and also improve its attractiveness.

 

(Or can anyone tell me what I have to add to the script to achieve this?)

Share this post


Link to post
Share on other sites

Let me try to contact with Death, may he will respond your question as soon as if he can :D ~

 

@ Of course if i can ~_~

Edited by Lanechology

Share this post


Link to post
Share on other sites

I am too lazy to fix anything ~.~

Just ask someone else to fix it

And the window/hud is too ugly for me to add it on (i can not see the map @.@)

Sorry :-??

Share this post


Link to post
Share on other sites

If you can give me permission, I think I'll have a new version up by tomorrow. I've already finished most of it.

 

Is that with shadow's request alone :@ or mines too? :D

Share this post


Link to post
Share on other sites

As of now, I've made a cleaner version of the original. What will further be included is:

  • Backgrounds for the text
  • Useful codes like \v[x] and \n[x]
  • Support for changing font colors with \c[x]

However, due several bug fixes I had to make and things I had already planned for today, the edited version will probably have to wait another day.

Share this post


Link to post
Share on other sites

Would be cool as well if the event names showed up if the player was near it.

For example a town with multiple exits, if you get close to the north exit the text appears reading "The Forest". Or something

Share this post


Link to post
Share on other sites

VERSION 2 WITH A FEW BUGFIXES

 

 

#==============================================================================
# ** Event Text Display v2
#==============================================================================
# Author: Ãص¹ (RGSS)
# Edited by Death10 (RGSS3)
# Edited by Emerald (v2)
#
# http://itbinhdan.com
#------------------------------------------------------------------------------
# Instructions
#------------------------------------------------------------------------------
# Create a new comment in an event with one of the following tags:
# <ETD>  - Upper line of text.
# <NN>   - Lower line of text.
# <ETDB> - Background file.
# Note that EVERYTHING in the comment is used for the text/filename if one of
# the tags is present.
#
# Instructions for module ETD are above every constant.
# In the text, the following stuff have a function:
#
# \\	- Becomes a singe '\'.
# \V[x] - Becomes the value of variable with ID x.
# \N[x] - Becomes the name of actor x.
# \P[x] - Becomes the name of party member x.
# \G	- Displays current amount of gold.
# \C[x] - Changes the font color to color x. Use -1 for STANDARD_COLOR.
#
# Actors and followers only:
# \HP  - Becomes own HP.
# \MHP - Becomes own Max HP.
# \MP  - Becomes own MP.
# \MMP - Becomes own max MP.
# \L   - Becomes own Level.
#============================================================================
#
# CONFIGURATION
#
#============================================================================

module ETD

 # An array containing fonts. If one the left one doesn't exist, the one to the
 # right will be used instead. Leave nil for the system fonts.
 STANDARD_FONT  = nil  

 # Red, Blue, Green, Opacity. Use \c[-1] for standard color.
 STANDARD_COLOR = Color.new(255,255,255,255)

 # Standard max distance for the name box to appear. Doesn't apply for the player
 # and followers.
 VIEW_DISTANCE  = 3

 # Text to display above actors.
 # actor_id => ["line_1", "line_2", "background filename"]
 # actor_id 0 is used for actors which IDs aren't present in the list.
 # If it's not the last entry to the list, add a comma after the ']'.
 ACTOR_TEXT = {
 0 => ["", "", "Test Background"]
 }

 # Text to display above actors.
 # actor_id => ["line_1", "line_2", "background filename"]
 # actor_id 0 is used for actors which IDs aren't present in the list.
 # If it's not the last entry to the list, add a comma after the ']'.
 FOLLOWER_TEXT = {
 0 => ["I'm a followah!", "", ""]
 }

 # Text to display above actors.
 # vehicle_type => ["line_1", "line_2", "background filename"]
 # vehicle type :all is used for vehicles which types aren't in the list.
 # If it's not the last entry to the list, add a comma after the ']'.
 VEHICLE_TEXT = {
 :all => ["", "", ""],
 :boat => ["", "", ""],
 :ship => ["", "", ""],
 :airship => ["", "", ""]
 }

end

#==============================================================================
# Game_Vehicle
#==============================================================================

class Game_Vehicle

 attr_reader :type

end

#==============================================================================
# Sprite_Character
#==============================================================================

class Sprite_Character < Sprite_Base

 alias eme_etd_init initialize
 def initialize(viewport, character = nil)
@display_box = false
@etd_max_distance = ETD::VIEW_DISTANCE
eme_etd_init(viewport, character)
 end

 alias eme_etd_dispose dispose
 def dispose
eme_etd_dispose
@etd_text.dispose if @etd_text != nil
@etd_background.dispose if @etd_background != nil
 end

 def init_etd_sprite
@etd_text = Sprite.new
@etd_text.bitmap = Bitmap.new(544, 32)
@etd_text.bitmap.font.size = 16
@etd_text.z = 301
@etd_background = Sprite.new
@etd_background.bitmap = Bitmap.new(1, 1)
@etd_background.z = 300
 end

 def init_etd_text
@etd_text_1 = ""
@etd_text_2 = ""
@etd_text_back = ""
@etd_max_distance = ETD::VIEW_DISTANCE
if character.is_a?(Game_Event)
  for a in 0...character.list.size
	if character.list[a].code == 108
	  copy = character.list[a].parameters[0].upcase
	  if copy.include?("<ETD>")
		@etd_text_1 = character.list[a].parameters[0].gsub(/<[Ee][Tt][Dd]>/) {""}
	  elsif copy.include?("<NN>")
		@etd_text_2 = character.list[a].parameters[0].gsub(/<[Nn][Nn]>/) {""}
	  elsif copy.include?("<ETDB>")
		@etd_text_back = character.list[a].parameters[0].gsub(/<[Ee][Tt][Dd][bb]>/) {""}
	  end
	end
  end
elsif character.is_a?(Game_Vehicle)
  if ETD::VEHICLE_TEXT.has_key?(character.type)
	@etd_text_1 = ETD::VEHICLE_TEXT[character.type][0]
	@etd_text_2 = ETD::VEHICLE_TEXT[character.type][1]
	@etd_text_back = ETD::VEHICLE_TEXT[character.type][2]
  else
	@etd_text_1 = ETD::VEHICLE_TEXT[:all][0]
	@etd_text_2 = ETD::VEHICLE_TEXT[:all][1]
	@etd_text_back = ETD::VEHICLE_TEXT[:all][2]
  end
elsif character.is_a?(Game_Player)
  if ETD::ACTOR_TEXT.has_key?(character.actor.id)
	@etd_text_1 = ETD::ACTOR_TEXT[character.actor.id][0]
	@etd_text_2 = ETD::ACTOR_TEXT[character.actor.id][1]
	@etd_text_back = ETD::ACTOR_TEXT[character.actor.id][2]
  else
	@etd_text_1 = ETD::ACTOR_TEXT[0][0]
	@etd_text_2 = ETD::ACTOR_TEXT[0][1]
	@etd_text_back = ETD::ACTOR_TEXT[0][2]
  end
elsif character.is_a?(Game_Follower) and character.actor != nil
  if ETD::FOLLOWER_TEXT.has_key?(character.actor.id)
	@etd_text_1 = ETD::FOLLOWER_TEXT[character.actor.id][0]
	@etd_text_2 = ETD::FOLLOWER_TEXT[character.actor.id][1]
	@etd_text_back = ETD::FOLLOWER_TEXT[character.actor.id][2]
  else
	@etd_text_1 = ETD::FOLLOWER_TEXT[0][0]
	@etd_text_2 = ETD::FOLLOWER_TEXT[0][1]
	@etd_text_back = ETD::FOLLOWER_TEXT[0][2]
  end
end
 end

 def refresh_etd_sprite
@etd_text.bitmap.clear
create_etd_background
etd_display_text(@etd_text_1, 0)
etd_display_text(@etd_text_2, 14)
 end

 def create_etd_text
init_etd_sprite if @etd_text == nil
temporare_1, temporare_2, temporare_3 = @etd_text_1, @etd_text_2, @etd_text_back
init_etd_text
refresh_etd_sprite if temporare_1 != @etd_text_1 or temporare_2 != @etd_text_2 or temporare_3 != @etd_text_back
@etd_text.x = self.x - 272
@etd_text.y = self.y - self.height - 32
@etd_background.x = @etd_text.x + @etd_text.width / 2 - @etd_background.width / 2
@etd_background.y = @etd_text.y + @etd_text.height / 2 - @etd_background.height / 2
 end

 def create_etd_background
@etd_background.bitmap.clear
@etd_background.bitmap = Cache.system(@etd_text_back)
 end

 def etd_display_text(string, y)
init_etd_sprite if @etd_text == nil
string = convert_escape_characters(string)
string = extra_convert(string) if character.is_a?(Game_Player) or character.is_a?(Game_Follower)
temporare = string.to_s.clone
temporare.gsub!(/\eC\[(\d+)\]/i) { "" }
@x_pos = 272 - @etd_text.bitmap.text_size(temporare).width / 2
@etd_text.bitmap.font.color.set(ETD::STANDARD_COLOR)
@etd_text.bitmap.font.name = ETD::STANDARD_FONT if ETD::STANDARD_FONT != nil
process_character(string.slice!(0, 1), string, y) until string.empty?
 end

 def text_color(n)
return ETD::STANDARD_COLOR if n == -1
Cache.system("Window").get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
 end

 def convert_escape_characters(text)
result = text.to_s.clone
result.gsub!(/\\/)			{ "\e" }
result.gsub!(/\e\e/)		  { "\\" }
result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
result.gsub!(/\eG/i)		  { Vocab::currency_unit }
result
 end

 def extra_convert(text)
result = text.to_s.clone
result.gsub!(/\eH\eP/i)	{ character.actor.hp }
result.gsub!(/\eM\eH\eP/i) { character.actor.maxhp }
result.gsub!(/\eM\eP/i)	{ character.actor.mp }
result.gsub!(/\eM\eM\eP/i) { character.actor.maxmp }
result.gsub!(/\eL/i)	   { character.actor.level }
result
 end

 def process_character(c, text, y)
case c
when "\e"
  code = text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]+/i)
  case code.upcase
  when 'C'
	param = text.slice!(/^\[\d+\]/)[/\d+/].to_i rescue -1
	@etd_text.bitmap.font.color.set(text_color(param))
  end
else
  process_normal_character(c, y)
end
 end

 def process_normal_character(c, y)
text_width = @etd_text.bitmap.text_size(c) .width
@etd_text.bitmap.draw_text(@x_pos, y, text_width * 2, 16, c, 1)
@x_pos += text_width
 end

 alias eme_etd_update update
 def update
eme_etd_update
create_etd_text if @display_box
create_etd_text unless character.is_a?(Game_Event) or character.is_a?(Game_Vehicle)
distance_check if character.is_a?(Game_Event) or character.is_a?(Game_Vehicle)
 end

 def distance_check
player_x = $game_player.x; own_x = self.x / 32 + 1; dif_x = own_x - player_x
dif_x *= -1 if dif_x < 0
if dif_x > @etd_max_distance
  etd_hide_box
else
  player_y = $game_player.y; own_y = self.y / 32 + 1; dif_y = own_y - player_y
  dif_y *= -1 if dif_y < 0
  if dif_y > @etd_max_distance
	etd_hide_box
  else
	if !@display_box and @etd_text != nil
	  @etd_text.opacity = 255 if @etd_text != nil
	  @etd_background.opacity = 255 if @etd_background != nil
	  $game_variables[1] = @etd_text_back if character.id == 2
	end
	@display_box = true
  end
end
 end

 def etd_hide_box
if @display_box
  @etd_text.opacity = 0 if @etd_text != nil
  @etd_background.opacity = 0 if @etd_background != nil
  @display_box = false
end
 end

end

 

 

All requests included. Script works slightly different than the previous one.

Edited by Emerald

Share this post


Link to post
Share on other sites

Hmm, syntax error on line 73

 

Unexpected tSYMBEG, expecting '}'

:boat => ["", "", ""]

 

(I tried putting words within the quotes, then replacing them with nil and then removing the boat vehicle's starting position I had on another map; same error)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted