• 0
Myriad

Set font color in message box?

Question

Hello again Hercules,

 

I want to set a variable so when it is 1, it can appear in a message box next to writing in a 'mes' box. But I can't figure out how to make it work.

 

E.g.

I set my variable to 1.

set @color, 1;

And then whenever 

if (.color == 1) {
^00ff00;
}
else {
^ff0000;
}

 

It will appear in a message box like so:

 

if color is set to 1,

mes "" + @color + "This text is bright green^000000.";

This text is bright green.

 

if color is set to 0 (or anything else),
mes "" + @color + "This text is bright green^000000.";

This text is bright green.

 

Hope I explained it well enough. Any suggestions appreciated. Thank you.

Edited by True Zeal

Share this post


Link to post
Share on other sites

6 answers to this question

  • 0


mes (@color?"^00ff00":"^ff0000") + "This text will change color depending if @color is set!^000000";

 

Edited by Garr

Share this post


Link to post
Share on other sites
  • 0

Thank you for the quick response, really appreciate it.

Share this post


Link to post
Share on other sites
  • 0

there is function for this
 
https://github.com/HerculesWS/Hercules/blob/master/npc/other/Global_Functions.txt#L360" class="bbc_url" title="External link" rel="nofollow external">https://github.com/HerculesWS/Hercules/blob/master/npc/other/Global_Functions.txt#L360

//== Function F_MesColor ===================================
// Function to colorize npc dialog without having to memorize the color code
// Examples:
//    mes callfunc("F_MesColor", C_BLUE) +"This message is now in BLUE";
function	script	F_MesColor	{
	return sprintf("^X", min(getarg(0), 0xFFFFFF));
}

Share this post


Link to post
Share on other sites
  • 0

Sorry I should have explained what I'm trying to do better. I'm trying to make an npc which you can choose which buffs it gives and the buffs it will give you depends on what is active. The activity will be shown in red or green on a menu.

Error log says I am missing a parenthesis/bracket '(' ')' somewhere in this line.

 

 

[email protected] = select("^777777Return^000000:(@agicolor?"^cc0000":"^cc0000") +Increase Agility^000000:(@blessingcolor?"^cc0000":"^cc0000") +Blessing^000000");

Share this post


Link to post
Share on other sites
  • 0

Because ternary is an operator, and should be outside quotes :3

[email protected] = select("^777777Return^000000:" +(@agicolor?"^cc0000":"^cc0000") + "Increase Agility^000000:" +(@blessingcolor?"^cc0000":"^cc0000") + "Blessing^000000");

Share this post


Link to post
Share on other sites
  • 0

Thank god, I can finally see the light. Thanks for all the replies and taking your time to help me so far. I think I'm almost there.

 

Edit: Figured it out. 

Edited by True Zeal

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