When writing a plugin many of us (or maybe just me) would like to be able to define their own colors with which messages from their plugins are displayed. However, the current messaging system is not very conducive to this so I discovered a workaround by figuring out how control/consolecolors.txt was parsed and its values handled. Below is how to accomplish custom domains and add colors to them.
Before we get started here is a list of acceptable colors (from control/consolecolors.txt):
Code: Select all
black, darkgrey, grey, white, red, darkred, yellow, brown, green, darkgreen, cyan, darkcyan, blue, darkblue, magenta, darkmagenta, default
Code: Select all
$consoleColors{<type>}{<custom domain>} = <color>;
<type> is the type of call you are using (ie message error warning debug) and
<custom domain> is the name of your custom domain (don't reuse domains already listed in colorconsole.txt).
<color> is a color from the list of colors above.
An Example:
Code: Select all
package customDomainTest;
use strict;
use Globals;
use Plugins;
use Log qw(message);
Plugins::register("colorDomainTest", "Custom Domain Test", \&on_unload, \&on_reload);
my $aiHook = Plugins::addHook('in_game', \&on_load, undef);
sub on_load {
#This will print the message in the darkmagenta color.
$consoleColors{'message'}{'Example'} = 'darkmagenta';
message "\n[Custom Domain Test] : This is a test.\n", "Example";
}
sub on_unload {
Plugins::delHook("AI_pre", $aiHook);
}
sub on_reload {
&on_unload;
}
1;
Note: this will break if someone reloads consolecolors.txt