Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Actor's Face in the Message Window

Hey people!  Before I begin, I would like you to know that if I am not clear about something in my request, please let me know, and I'll do my best to specify!

I need a script that will allow me to make a different face appear in the message box based on actor ID.  Don't understand?  I'll elaborate.  First off, I'm using Slipknot's message system (to make a face appear you must insert \face[file]).  That's good for NPC's, but I would like to make the player's character's face appear when they are talking.  I really don't want to have to make basically 6 seperate games (one for each class/ gender combo). 

Now, allow me to explain what I want done.  I would like this script to check the actor's ID, and change the image displayed in the message box (when I type \af) based on that.  So, let's say the actor ID is 1; this script should recognize that and change the image displayed when \af is typed to a certain file.

I probably just confused a lot of people, so here are some examples:

***All images will be stored in the pictures folder

if actor id = {insert number}  then \af displays {insert file}
That's the basic formula...here's another example.

if actor id = 1  file = 'mage1'
which should result in: \af displays the image 'mage1' in the text box

if actor id = 2  file = 'warrior4'
which should result in: \af displays the image 'warrior4'

I hope that made it clear for everyone.  Also, if you can't use \af, feel free to use anything you see fit.  Just let me know!  Thanks in advance for the help!
 
I assume you mean you want the 'face' of the actor in the first position in the party?

How about we do this?  In the section of the refresh method that looks for "[Ff]ace",
let's check to see if the face_name is a number.
If it's 0, we'll use the name of the first actor in the party
If it's >0, we'll use the name of that actor in the database.

Code:
    if @text[/\\[Ff]ace/]
      # Left
      if @text.sub!(/\\[Ff]ace{(.+?)}/, '')
        face, face_name = 1, $1
      # Right
      elsif @text.sub!(/\\[Ff]ace\[(.+?)\]/, '')
        face, face_name = 2, $1
      end
      if !face_name[/[^0-9]/]   # is all digits
        if face_name == "0"
          # change face_name to the name of the actor in position 1 in the party
          face_name = $game_party.actors[0].name
        else
          # change the face_name to actor[n] name (from database)
          face_name = $game_actors[face_name.to_i].name
        end
      end
    end

A little more than you asked for, but it should be useful to others as well.

So, for your example, just enter "\face[0]"
And make sure there is a corresponding faceset in the Pictures folder.
ie, if the first actor in the party is "George", there should be a George.png file.

Be well
 
Brewmesiter, thanks a lot for the script, but there is only one issue.  Every time I try to call an actor's image from a name in the database, I get an error message:

Screen 'text_options' line 207: NoMethodError occurred.
undefned method 'name' for nil:nil class

How can I fix this?  Thanks again for the help!

EDIT: Nevermind...it works now.
 
[sarcasm]Sorry, I missed the part where you had custom names....[/sarcasm]

Well then, that won't work, will it?  :scruff:

If we do it this way...

Code:
    if @text[/\\[Ff]ace/]
      # Left
      if @text.sub!(/\\[Ff]ace{(.+?)}/, '')
        face, face_name = 1, $1
      # Right
      elsif @text.sub!(/\\[Ff]ace\[(.+?)\]/, '')
        face, face_name = 2, $1
      end
      if !face_name[/[^0-9]/]   # is all digits
        if face_name == "0"
          # change face_name to the name of the actor in position 1 in the party
          face_name = "Actor" + $game_party.actors[0].actor_id.to_s
        else
          # change the face_name to actor[n] name (from database)
          face_name = "Actor" + face_name
        end
      end
    end

and add the line:
Code:
    attr_reader   :actor_id
to the top of Game_Actor  (with the other 'attr_reader' statements) 

\face[3] will display Actor3.png
\face[0]  will display the file named "Actor<n>.png, for the first actor in the party.

So, for each actor in your database, make a faceset name ActorN.png,  where N is the actor number.

Then the names don't matter.
 
Hey, Brewmeister.

I keep getting a Name Error on line 226 when I add this in. It says "undefined local variable or method 'event' for #<Window_Message:0x1d6e218>"

This only happens with your addition to Slipknot's message script.

EDIT: Forget about it. Turns out I was accidentally deleting a crucial piece of the script.
 
Are you sure you did not make a mistake because it works fine for me?  (I wouldn't really know if you did, I'm not a scripter!  But it is a possibility...)

EDIT: Upon further use of the script, I encountered the same error, so I guess you did not make a mistake.  Could someone fix this please?

EDIT EDIT: Ok, I just realized what was wrong.  You must have forgotten to put  attr_reader  :actor_id under Game_Actors.... now I have to fix errors in Slipknot's original script, hehe
 
Ok, I'd like to add something to this post.  Now that I added this script to my game, using \n[1] to display my character's name does not seem to be working anymore?  Any ideas?

EDIT:  Ok, nevermind.  I found the problem.  It's a pretty simple little bug, but I'm gonna keep it in my game because I can use it probably.  Go figure!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top