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.

Control Characters Everywhere

Control Characters Everywhere - Version: 1.0
By: Brewmeister

Introduction

Extends the use of Control Characters (\v[n], \N[n], \C[n]) to descriptions, names, pretty much anything in the database...
Developed for RMXP, but should work in RMVX as well.

Screenshots

Color_Text4.png
Color_Text3.png
Color_Text5.png
Color_Text2.png
Color_Text1.png

Demo

N/A

Script

Code:
#---------------------------------------------------------------------------

#

# Control Characters work for object descriptions & names.

# Actor, Class, Items, Weapons, Armors, Skills, Enemies

# Valid Control Characters: \V[n], \N[n], \C[n]

#

# 12Feb09 - Brew  (ref: RRR_supt)

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

 

class Bitmap

  alias draw_parsed_text draw_text

  def draw_text(*args) 

    #parse the text

    if args[0].is_a?(Rect)

      x = args[0].x

      y = args[0].y

      width = args[0].width

      height = args[0].height

      str = args[1]

      align = args[2] != nil ? args[2] : 0

    else

      x = args[0]

      y = args[1]

      width = args[2]

      height = args[3]

      str = args[4]

      align = args[5] != nil ? args[5] : 0

    end

    # If waiting for a message to be displayed

    if str != nil

      if str.is_a?(String)

        text = str.clone

      else

        text = str.to_s

      end

      # Control text processing

      begin

        last_text = text.clone

        text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }

      end until text == last_text

      text.gsub!(/\\[Nn]\[([0-9]+)\]/) do

        $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""

      end

      # Change "\\C" to "\001" and "\\G" to "\002"

      text.sub!(/\\[Cc]\[([0-9]+)\]/, "")

      if $1 != nil

        color = $1.to_i

        font.color = text_color(color)

      end

    end

    draw_parsed_text(x, y, width, height, text, align)

  end

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

  # * Get Text Color

  #     n : text color number (0-7)

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

  def text_color(n)

    case n

    when 0

      return Color.new(255, 255, 255, 255)

    when 1

      return Color.new(128, 128, 255, 255)

    when 2

      return Color.new(255, 128, 128, 255)

    when 3

      return Color.new(128, 255, 128, 255)

    when 4

      return Color.new(128, 255, 255, 255)

    when 5

      return Color.new(255, 128, 255, 255)

    when 6

      return Color.new(255, 255, 128, 255)

    when 7

      return Color.new(192, 192, 192, 255)

    else

      return Color.new(255, 255, 255, 255)

    end

  end

end

Instructions

Paste Above Main

FAQ

Can I add colors?

Sure, to add "Bright Red" for example... after line 70 insert:

when 8
return Color.new(255, 0, 0, 255)


Can I have more than one color in a name or description?

No. Not with this script. This script sets the color before drawing the string.
Unlike the message script, that draws the characters one at a time.

Compatibility

Incompatible with Ccoa's UMS. (\name[#] won't convert the control characters correctly.)

Extends the Bitmap.draw_text method & supports both draw_text(x, y, width, height, str[, align]) and draw_text(rect, str[, align]) formats

Author's Notes

In response to several requests to display item names in different colors.

Terms and Conditions

Please link to this thread instead of posting the script elsewhere. (even though I've posted it elsewhere) :scruff:
Feel free use for any legal purpose you can think of. Feel free to edit, modify, bend, spindle mutilate.
If you make edits or additions, please post them here so I can either include them, or link to them as enhancements.
 
Very nice script.

I did the exact same thing for VX a few years ago but I don't know why, I have never released it. And that's awesome, we did it the exact same way.

Major kudos Brew!
 
Thanks Darg.

yeh, I expect there are a finite # of ways of doing it, and adding the code from Window_Message to draw_text seemed the most logical.

I saw several requests for colored item names, and thought this would be more robust for other users.

Be Well
 
I found some compatibility issues when using with XAS v3.9. XAS v3.9 has an active hud script which require a face graphic: hero_HFace.png, where hero is the name of an actor in the database. Since this script requires the color code \c[n] and file formats cannot start with '\' character, it poses some issues.
 
Souloux":1h9bxjwx said:
I found some compatibility issues when using with XAS v3.9. XAS v3.9 has an active hud script which require a face graphic: hero_HFace.png, where hero is the name of an actor in the database. Since this script requires the color code \c[n] and file formats cannot start with '\' character, it poses some issues.

Actually, this wouldn't work with that even if it used a different format. This script modifies the game so that text that gets drawn to the screen will be affected, which means that other things, like your example, would not be affected at all.
 

Atoa

Member

@Souloux
The problem isn't with this script, but with the hud (using the actor's name isn't the best way to add faces on a hud). It wouldn't be hard to make the hud consider another parameter, like the actor.character_name instead of the actor.name.

It's an great script, i made something similar that only for the help window, but it had some other features like drawing icons and items/skill/equips names. I was planning to make it work for everywhere but i got my hands full with another scripts XD
 
Souloux, If you want colored actor names & use the actor name for the faces, you could modify the hud script to remove the escape sequence from the name before assembling the file name.. (using the same .sub! method from this script)

Atoa, I started with the idea of making it work just for items, but then a lightbulb went on & I realized I could just implement it in draw_text & it would work everywhere.

Glad you guys like it. I hope some people find it useful.

Funny thing, I have almost 200 projects with scripts I wrote from requests. I need to take the time to clean up & document some of the more useful ones & get them posted.

Be Well
 
I find this script to be rather useful, so I tried pairing it with Ccoa's UMS. I add the color code to the actor and tried using the name window feature in Ccoa's UMS.

Database_Works.jpg


This is how it appears when using the text command in RMXP.
Error1_Name_Window.jpg


However it works fine in the menu screens.
Menu_Works.jpg
 

Star

Sponsor

Soooo simple, yet efficient for anyone who is using the standard menus. It's probably still useful for CMS as well. Thanks Brew for this cool script, Ima save it to my collections incase I ever actually finish a game.
 
@Souloux: Obviously, scripts that draw text different than the default will output it differently. What you got simply looks like you could switch the positions of this script and the UMS around and it should work fine.

@Brew: It's indeed a little and cool snippet to put into projects if you're too lazy to script custom color outputs for all your scenes... or simply can't. Personally, I prefer the 'direct' way for no special reason... but then again, I'm not exactly the "yay coloured text" person really :p
I'm personally not 100% about VX compatibility... did anyone check that by now?
 
Souloux, let me know if Bluescope's suggestion fixes it. Otherwise, I'll take a look at UMS & see if I can make them compatible.

I just tested in VX, and it error'd. Apparently, draw_text in VX converts non-strings so they call it with numbers as well. Fixed script to work in both.

Star, thanks.
 

Atoa

Member

Code:
#       if str.is_a?(String)

#         text = str.clone

#       else

#         text = str.to_s

#       end
Why do you clone the string here?
text = str.to_s.dup
would do the same thing, regardless of the value of the str.
 

Atoa

Member

i do this a lot when not sure if the variable will be always the way it's expected to be, so to ensure that it will be always of the type i expect i do something like this xD if the text is as string, no problem nothing changes, but if it's not, it will be converted.
 

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