How to make HUD text change color

I’m making a mode where the players have a limited number of lives and there is some HUD text displaying how many lives each player has. Currently the color is static, but I want it to change depending on how many lives you have left (e.g. 5 is blue, 4 is green, 3 is yellow, etc.). Does anyone know how to do something like that?

variables
{
	player:
		0: LivesRemaining
}

rule("Life HUD Team 1")
{
	event
	{
		Ongoing - Global;
	}

	actions
	{
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(0,
			Team 1))), Players In Slot(0, Team 1).LivesRemaining, Players In Slot(0, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(1,
			Team 1))), Players In Slot(1, Team 1).LivesRemaining, Players In Slot(1, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(2,
			Team 1))), Players In Slot(2, Team 1).LivesRemaining, Players In Slot(2, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(3,
			Team 1))), Players In Slot(3, Team 1).LivesRemaining, Players In Slot(3, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(4,
			Team 1))), Players In Slot(4, Team 1).LivesRemaining, Players In Slot(4, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
	}
}

rule("Life HUD Team 2")
{
	event
	{
		Ongoing - Global;
	}

	actions
	{
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(0,
			Team 2))), Players In Slot(0, Team 2).LivesRemaining, Players In Slot(0, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(1,
			Team 2))), Players In Slot(1, Team 2).LivesRemaining, Players In Slot(1, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(2,
			Team 2))), Players In Slot(2, Team 2).LivesRemaining, Players In Slot(2, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(3,
			Team 2))), Players In Slot(3, Team 2).LivesRemaining, Players In Slot(3, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(4,
			Team 2))), Players In Slot(4, Team 2).LivesRemaining, Players In Slot(4, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
	}
}

You need to store the desired color in a variable and put that variable as an argument input of color in your HUDS, make sure you allow color to be reevaluated so it updates as the variable mutate its value, then you need 2 furthermore rules, one that initialize your lives and first color and lastly a rule that triggers on a players death, that decrease the lives by 1 and set a new color depending on a player’s life count.

variables
{
	player:
		0: LivesRemaining
		1: Color
}

rule("Life HUD Team 1")
{
	event
	{
		Ongoing - Global;
	}

	actions
	{
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(0,
			Team 1))), Players In Slot(0, Team 1).LivesRemaining, Players In Slot(0, Team 1)), Null, Null, Left, 0, Players In Slot(0,
			Team 1).Color, Color(White), Color(Blue), Visible To String and Color, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(1,
			Team 1))), Players In Slot(1, Team 1).LivesRemaining, Players In Slot(1, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(2,
			Team 1))), Players In Slot(2, Team 1).LivesRemaining, Players In Slot(2, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(3,
			Team 1))), Players In Slot(3, Team 1).LivesRemaining, Players In Slot(3, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 1), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(4,
			Team 1))), Players In Slot(4, Team 1).LivesRemaining, Players In Slot(4, Team 1)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
	}
}

rule("Life HUD Team 2")
{
	event
	{
		Ongoing - Global;
	}

	actions
	{
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(0,
			Team 2))), Players In Slot(0, Team 2).LivesRemaining, Players In Slot(0, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(1,
			Team 2))), Players In Slot(1, Team 2).LivesRemaining, Players In Slot(1, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(2,
			Team 2))), Players In Slot(2, Team 2).LivesRemaining, Players In Slot(2, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(3,
			Team 2))), Players In Slot(3, Team 2).LivesRemaining, Players In Slot(3, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
		Create HUD Text(All Players(Team 2), Custom String("{2} {0} Lives Remaining: {1}", Hero Icon String(Hero Of(Players In Slot(4,
			Team 2))), Players In Slot(4, Team 2).LivesRemaining, Players In Slot(4, Team 2)), Null, Null, Left, 0, Color(Blue), Color(
			White), Color(Blue), Visible To and String, Default Visibility);
	}
}

rule("Player Init")
{
	event
	{
		Ongoing - Each Player;
		All;
		All;
	}

	actions
	{
		Event Player.LivesRemaining = 5;
		Event Player.Color = Color(Blue);
	}
}

rule("Change Color")
{
	event
	{
		Player Died;
		All;
		All;
	}

	actions
	{
		Event Player.LivesRemaining -= 1;
		If(Event Player.LivesRemaining == 4);
			Event Player.Color = Color(Green);
		Else If(Event Player.LivesRemaining == 3);
			Event Player.Color = Color(Yellow);
		Else If(Event Player.LivesRemaining == 2);
			Event Player.Color = Color(Orange);
		Else If(Event Player.LivesRemaining == 1);
			Event Player.Color = Color(Red);
		Else If(Event Player.LivesRemaining == 0);
			Event Player.Color = Color(Black);
		End;
	}
}

Note i only modified the first HUD (which is you when testing solo, you need to update the other huds accordingly), also note you can only colorize full Headers, Subheaders and Texts only, colorizing individual string letters is not possible even with markup language codes like html etc. they will fail.

3 Likes