08-03-2015, 10:14 PM
(This post was last modified: 09-02-2024, 05:26 PM by DerVVulfman.)
Portrait Messaging
Version: 1.1
Version: 1.1
Introduction
This script creates a system which can easily implement use of the large portraits for your dialogue scenes.
Features
- Use Portraits with your message system
- Runs on a switch
- can set actors portraits in settings
- uses simple script calls
- change portrait size in settings
- can display multiple portraits at once
- technically, can run animations on portraits
- easily change the position of the portraits
- can mirror the portraits so that they face opposing directions
Screenshots
This is not a really good screenshot for sure. But it shows the image up there. I will try and get a better one up soon, showing more of the capability of the script!
Content Hidden
Script
"script"
Code:
################################################################################
# PORTRAIT MESSAGING VX
# By: Ixfuru
# Version 1.1
# Created 1.3.15
################################################################################
# ******************************************************************************
# VERSION 1.1
# March 7, 2015:
# Fixed a critical error which caused games to crash when saving. The reason
# for the bug is because Viewports cannot be dumped into a save file, and the
# viewport which is used to display the Portrait sprites was being saved as
# part of the $game_message global variable.
#*******************************************************************************
# This system adds the ability to use portraits with your message system. It's
# a pretty straightup script, but there is a little set up. Mainly, you need
# to create a folder called 'Portraits' in your projects Graphics folder. Then
# add the portraits you want to use in there with it. Once that's complete,
# you just need to set up the module settings. Then, you can call portraits into
# the game by simply placing a text tag in your message box when you use the
# show text command.
#
# <msgport portrait_base, portrait_id, alignment, mirror>
#
# Here's an example:
#
# <msgprt 0, 2, 1, 1>
#
# And here's an explanation of the four values you must place in the tag.
#
# portrait_base : This tells the system which portrait base you want to use
# to select and draw the image. You can place either a
# zero, 1 or 2 for this. Placing zero calls a portrait from
# the 'ACTOR_PORTRAITS' hash below by searching the database
# actor's ID. Again, this calls the actor's portrait based on
# his/her database ID which has been placed as the second value
# of the tag. However, if you use a '1' for the first
# tag value, the system will call a portrait from the same
# 'ACTOR_PORTRAITS' base. But instead of searching for the
# actor's direct ID, it will instead use the second value of the
# tag to find a party member in that position. Lastly, you can
# place a '2' for the first value. And if you do, the system
# will choose a portrait by using the second value and linking it
# to the 'NPC_PORTRAITS' hash below. This will allow you to set
# up unlimited number of portraits to use in your events of people
# not found in the actors or party members.
#
# portrait_id : Dependent upon the value you chose in the 'portrait_base', this
# value is used to identify which portrait to pull from the hash
# you declared. If you call for a zero base in the first value,
# then use this to declare the database actor's ID that you want
# to use. If you used '1', then use this second value to store a
# party member's position. Or, use it to call a special portrait
# from the NPC_PORTRAITS hash below. In that case, the number you
# provide here, will link directly to the keys found in the hash.
#
# alignment : Simple. 0 sets the portrait to the left, 1 to the center, 2 to the right
#
# mirror : This value simply determines how you want the portrait displayed. This
# gives you the ability to horizontally flip the portrait to face in the
# other direction. This is good if you have one showing on the right and
# you don't want it facing the side of the screen.
#
##################################################################################
# SCRIPT VERSATILITY
#
# This script has a lot of versatility. Since it stores the portraits in an
# array in Game Message, it allows you to call multiple portraits to the screen
# at once. This is VERY useful for holding conversations between two characters.
# To do this, you can use the following two script calls from the third page,
# 'Script' command in an event:
#
# collect_portraits
#
# This will tell the system to keep the portraits showing on the screen. Meaning,
# that if another one is called, it will share the screen with the first one.
#
# release_portraits
#
# That call is important. Because if you use the first call, the system will just
# continue to stack up portraits. So after you've carried out the conversation,
# you will need to call this second call to make the portraits disappear. Again,
# it is NOT necessary to use this call unless you have used a multi-portrait scene
# and activated the stack with the first script call.
#
# Finally, this script creates all portraits as 'Sprite_Base' sprites. That means
# that technically, you could call animations on them. To get them, (and this is
# mainly for scripters), you can call $game_message.portraits. That's the array
# that holds them.
#
# When you call a portrait, you will not have to use a face graphic. In fact, even
# if you do, the system will NOT draw it at all.
#
# Also, you can call off the system completely to go back to using faces and the
# normal system, by way of an in game switch that you provide in the module.
#
# Lastly, the script places the portraits' 'y' position based on the size of the
# portraits and the height of the message window. By default, it uses
# 272 x 288 size portraits. And it will always place the portrait so that it
# is half the height of the message window off the bottom of the screen.
#
#################################################################################
# This script was created by Ixfuru. If you use this script in your project, you
# must credit him. It is free to use non-commercially. If you intend to use
# it commercially, you must contact Ixfuru @ Rpgarden.com and get his
# permission first. Do NOT claim this as a work of your own. Don't post
# elsewhere on the web without Ixfuru's permission.
################################################################################
module Ixfuru
module PortraitMessagingVX
DEFAULT_PORTRAIT_SIZE = [272, 288] # size of the portraits you're using:
#[width, height]
PORTRAIT_SWITCH = 8 # In-game switch that activates the use of
# portraits
# Here, you link the ID of actors with the portrait which represents them
ACTOR_PORTRAITS = {
1 => "People2_2",
2 => "Actor1_1",
3 => "Actor1_2",
4 => "Actor1_3",
5 => "Actor1_4",
6 => "Actor1_5",
7 => "Actor1_6",
8 => "Actor1_7",
}
# Here, you can create non-actor portrait links that you can call
NPC_PORTRAITS = {
0 => "People1_6",
1 => "People1_0",
}
end
end
#===============================================================================
# Cache
#===============================================================================
module Cache
def self.portrait(filename)
load_bitmap("Graphics/Pictures/", filename)
end
end
#===============================================================================
# Game Message
#===============================================================================
class Game_Message
attr_accessor :portrait_size
attr_accessor :portrait_offset_y
attr_accessor :keep_portraits
#-----------------------------------------------------------------------------
# Initialize(Aliased)
#-----------------------------------------------------------------------------
alias ixvxportmessgmmessini initialize unless $@
def initialize
ixvxportmessgmmessini
@keep_portraits = false
end
#-----------------------------------------------------------------------------
# Clear (Aliased)
#-----------------------------------------------------------------------------
alias ixvxportmessgmmessclr clear unless $@
def clear
ixvxportmessgmmessclr
@portrait_offset_y = 0
@portrait_size = Ixfuru::PortraitMessagingVX::DEFAULT_PORTRAIT_SIZE
end
end
#===============================================================================
# Window Message
#===============================================================================
class Window_Message < Window_Selectable
#-----------------------------------------------------------------------------
# Initialize (Aliased)
#-----------------------------------------------------------------------------
alias ixfuru_portmessvx_win_mess_ini initialize unless $@
def initialize
@portraits = []
@portrait_viewport = Viewport.new(0, 0, 544, 416)
ixfuru_portmessvx_win_mess_ini
end
#-----------------------------------------------------------------------------
# New Page (Aliased)
#-----------------------------------------------------------------------------
alias ixvxportmessgmmessnwpg new_page unless $@
def new_page
if $game_switches[Ixfuru::PortraitMessagingVX::PORTRAIT_SWITCH]
contents.clear
@contents_x = 0
process_portraits
@contents_y = 0
@line_count = 0
@show_fast = false
@line_show_fast = false
@pause_skip = false
contents.font.color = text_color(0)
else
process_portraits
ixvxportmessgmmessnwpg
end
end
#-----------------------------------------------------------------------------
# Process Portrait
#-----------------------------------------------------------------------------
def process_portraits
tag = /<msgprt[\s]*(\d+),[\s]*(\d+),[\s]*(\d+),[\s]*(\d+)>/i
if tag =~ @text
m = $4.to_i == 0 ? false : true
$game_message.portrait_offset_y = self.height / 2
if $game_switches[Ixfuru::PortraitMessagingVX::PORTRAIT_SWITCH]
create_message_portrait($1.to_i, $2.to_i, $3.to_i, m)
end
@text.gsub!(tag) { |i| i = "" }
end
end
#--------------------------------------------------------------------------
# * Frame Update (Aliased)
#--------------------------------------------------------------------------
alias ixvxportmesswinmessupd update unless $@
def update
update_portraits
ixvxportmesswinmessupd
end
#-----------------------------------------------------------------------------
# Dispose (Aliased)
#-----------------------------------------------------------------------------
alias ixvxportmesswinmessdisp dispose unless $@
def dispose
ixvxportmesswinmessdisp
dispose_portraits
end
#-----------------------------------------------------------------------------
# Create Message Portrait
#
# base : 0 for actor, 1 for party member, 2 for npc
# portrait_id : actor's database ID, members position, or npc key from module
# alignment : 0 : left, 1 : center, 2: right
# mirror : flips the portrait
#-----------------------------------------------------------------------------
def create_message_portrait(base, portrait_id, alignment, mirror = false)
case base
when 0 # Actor
portrait_filename = Ixfuru::PortraitMessagingVX::ACTOR_PORTRAITS[portrait_id]
when 1
portrait_filename =
Ixfuru::PortraitMessagingVX::ACTOR_PORTRAITS[$game_party.members[portrait_id].id]
when 2 # Npc
portrait_filename = Ixfuru::PortraitMessagingVX::NPC_PORTRAITS[portrait_id]
end
case alignment
when 0 # Left
x = 0
when 1 # Center
x = 272 - ($game_message.portrait_size[0] / 2)
when 2 # Right
x = 544 - $game_message.portrait_size[0]
end
y = 416 - $game_message.portrait_size[1]
sprite = Sprite_Base.new(@portrait_viewport)
sprite.bitmap = Cache.portrait(portrait_filename)
sprite.x = x
sprite.y = y - $game_message.portrait_offset_y
sprite.mirror = mirror
@portraits.push(sprite)
end
#-----------------------------------------------------------------------------
# Update Portraits
#-----------------------------------------------------------------------------
def update_portraits
return if @portraits.nil? || @portraits.empty?
for portrait in @portraits
portrait.update
end
end
#-----------------------------------------------------------------------------
# Dispose Portraits
#-----------------------------------------------------------------------------
def dispose_portraits
return if @portraits.nil? || @portraits.empty?
for portrait in @portraits
portrait.dispose
end
@portraits = []
end
#-----------------------------------------------------------------------------
# Dispose Viewport
#-----------------------------------------------------------------------------
def dispose_portrait_viewport
@portrait_viewport.dispose
end
#-----------------------------------------------------------------------------
# Collect Portraits
#-----------------------------------------------------------------------------
def collect_portraits
$game_message.keep_portraits = true
end
#-----------------------------------------------------------------------------
# Release Portraits
#-----------------------------------------------------------------------------
def release_portraits
$game_message.keep_portraits = false
end
#--------------------------------------------------------------------------
# Terminate Message (Aliased)
#--------------------------------------------------------------------------
alias ixfuru_port_mess_vx_win_mess_term_mess terminate_message unless $@
def terminate_message
dispose_portraits unless $game_message.keep_portraits
@portraits = [] unless $game_message.keep_portraits
ixfuru_port_mess_vx_win_mess_term_mess
end
end
#===============================================================================
# SCENE MAP
#===============================================================================
class Scene_Map < Scene_Base
attr_accessor :message_window
#-----------------------------------------------------------------------------
# Terminate (Aliased)
#-----------------------------------------------------------------------------
alias ixfuru_port_mess_vx_sc_m_term terminate unless $@
def terminate
@message_window.dispose_portraits
@message_window.dispose_portrait_viewport
ixfuru_port_mess_vx_sc_m_term
end
end
#===============================================================================
# GAME INTERPRETER
#===============================================================================
class Game_Interpreter
#-----------------------------------------------------------------------------
# Collect Portraits
#-----------------------------------------------------------------------------
def collect_portraits
return unless $scene.is_a?(Scene_Map)
$scene.message_window.collect_portraits
end
#-----------------------------------------------------------------------------
# Release Portraits
#-----------------------------------------------------------------------------
def release_portraits
return unless $scene.is_a?(Scene_Map)
$scene.message_window.release_portraits
end
end
Instructions
PORTRAITS:
You must create a new folder in your project folder's 'Graphics' directory, and name it 'Portraits'.
SETTINGS:
Use the settings in the module to link the portraits to the given actor, or create NPC portrait links that can be called through the event script call. Also, use the module settings to set the actual portrait default size and the switch you will use to call it.
SCRIPT CALLS:
Finally, in game you can use the following script calls to use the system:
Content Hidden
Calling a Portrait
To call a portrait, place this in your message text box (include the arrows '<>' and the 'msgport' part)
You replace 'portrait_base' with either a zero or a one. If you use zero, the system will find the portrait from the
actor portraits settings. If you use one, it will get the portrait from the NPC portraits settings.
You replace 'portrait_id' with the id of the portrait in the settings base. In other words, to call actor 3, you would say 3, and if
you wanted NPC number 71, you would say 71.
You replace 'alignment' with where you want the portrait to appear. 0 for left, 1 for center, 2 for right.
Finally, replace 'mirror' with a zero or a one. If it's one, the image will be flipped so that it faces the opposite direction. While zero displays the image as is.
This may seem complex, but look at the following example:
The first value, '1', says that the portrait is from the NPC portrait base. The value, '15', says that it's NPC number 15 in the
settings. The third value, '2', says that it should display on the right, and the '1' says to flip (or mirror) the image.
Multiple Portraits
Multiple Portraits can be used by using the following two script calls:
This will trigger the system to start leaving the portraits on the screen, even if the text box is updated to a new page.
This will signal that all portraits should be removed!
To call a portrait, place this in your message text box (include the arrows '<>' and the 'msgport' part)
Code:
<msgport portrait_base, portrait_id, alignment, mirror>
actor portraits settings. If you use one, it will get the portrait from the NPC portraits settings.
You replace 'portrait_id' with the id of the portrait in the settings base. In other words, to call actor 3, you would say 3, and if
you wanted NPC number 71, you would say 71.
You replace 'alignment' with where you want the portrait to appear. 0 for left, 1 for center, 2 for right.
Finally, replace 'mirror' with a zero or a one. If it's one, the image will be flipped so that it faces the opposite direction. While zero displays the image as is.
This may seem complex, but look at the following example:
Code:
<msgport 1, 15, 2, 1>
settings. The third value, '2', says that it should display on the right, and the '1' says to flip (or mirror) the image.
Multiple Portraits
Multiple Portraits can be used by using the following two script calls:
Code:
collect_portraits
Code:
release_portraits
FAQ
Q: What if I want to use faces and portraits?
A: Then toggle switch accordingly.
Q: What if I place a face in a text box with the portrait switch ON?
A: Then the face draw will be ignored and it will resort to drawing portraits!
Compatibility
I'm not really sure about this. I believe I didn't overwrite any methods in this script, so it should be pretty darn compatible. I really haven't heard of a lot of folks using it, except for me, that is. But if you find an issue, tell me about it.
Author's Notes
I was inspired to create this script because of my fondness for games like Agarest War and Spectral Force to name a few. The downside to this script is that it uses portraits And there is no really great generator of portrait images that I know of. But it can bring some real snazz to a game using the default VX characters.
Terms and Conditions
You must credit me if you use this script even if it is modified by you or someone else.
In non-commercial games, it's free to use. For commercial projects, I would just like a free copy and the credit!
Don't claim this is your script because it isn't!
And lastly, if you want to post the script on another site, you must have my permission first.