Modme Forums
Menu:

[Tutorial] On_Or_Off_Zombie_Counter

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: CT8918


This script was requested by: Scorpiolo

I took DuaLVII's zombie counter script and modified it to allow the zombie counter to be turned on and off by a Trigger.

Test Footage: On_Or_Off_Zombie_Counter_Test_Footage

Instructions:
1. Create a use trigger. Give the trigger the targetname of "toggle_zombie_counter"

2. Open your maps .gsc file.
C:\Program Files (x86)\Steam\steamapps\common\Call of Duty Black Ops III\usermaps\your_map\scripts\zm\your_map.gsc

3. Add the following code at the top of your main() function:

_INIT_ZCOUNTER();


4. Add the following functions at the bottom of your gsc. If you already have a version of the zombie counter, make sure you delete it.
/*
FUNCTION: On_Or_Off_Zombie_Counter 
Original Author: DuaLVII
On_Or_Off_Zombie_Counter Author: CT8918
Modified Date: 3/19/2017
Current Project: Mortuus_Arena
Function to display the amount of zombies there currently are. Added the ability to turn off and on.
*/ 
//*************************************************************************************************************************************************************************************
//START ZOMBIE COUNTER
//*************************************************************************************************************************************************************************************
function _INIT_ZCOUNTER()
{
	ZombieCounterHuds = [];
	ZombieCounterHuds["LastZombieText"] 	= "One Zombie Left";
	ZombieCounterHuds["ZombieText"]			= "Zombies Left";
	ZombieCounterHuds["LastDogText"]		= "Dog Left";
	ZombieCounterHuds["DogText"]			= "Dog's Left";
	ZombieCounterHuds["NoText"]				= "";
	ZombieCounterHuds["DefaultColor"]		= (1,1,1);
	ZombieCounterHuds["HighlightColor"]		= (1, 0.55, 0);
	ZombieCounterHuds["FontScale"]			= 1.5;
	ZombieCounterHuds["DisplayType"]		= 0; // 0 = Shows Total Zombies and Counts down, 1 = Shows Currently spawned zombie count

	ZombieCounterHuds["counter"] = createNewHudElement("left", "top", 2, 10, 1, 1.5);
	ZombieCounterHuds["text"] = createNewHudElement("left", "top", 2, 10, 1, 1.5);

	ZombieCounterHuds["counter"] hudRGBA(ZombieCounterHuds["DefaultColor"], 0);
	ZombieCounterHuds["text"] hudRGBA(ZombieCounterHuds["DefaultColor"], 0);

	level thread _THINK_ZCOUNTER(ZombieCounterHuds);
	level thread zombie_counter_flip_flop(); //Added by CT8918. This is what allows the user to turn the counter on or off.
}

function _THINK_ZCOUNTER(hudArray)
{
	level endon("end_game");
	for(;;)
	{
		level waittill("start_of_round");
		level _ROUND_COUNTER(hudArray);
		hudArray["counter"] SetValue(0);
		hudArray["text"] thread hudMoveTo((2, 10, 0), 4);
		hudArray["counter"] thread hudRGBA(hudArray["DefaultColor"], 0, 1);
		
		//Added by CT8918. Only displays "End of round" if zombie counter is on.
		if(level.run_zombie_counter == true)
		{
			hudArray["text"] SetText("End of round"); hudArray["text"] thread hudRGBA(hudArray["DefaultColor"], 0, 3);
		}
	}
}

//Added by CT8918. Function that allows user input to flip counter on and off.
function zombie_counter_flip_flop()
{
	zombie_counter_off = true;
	toggle_zombie_counter = GetEnt("toggle_zombie_counter", "targetname");	
	toggle_zombie_counter SetCursorHint("HINT_NOICON");
	level.run_zombie_counter = false;

	while(1)
	{
		if(zombie_counter_off == true)
		{
			toggle_zombie_counter SetHintString("^7Press ^3&&1 ^7to turn ^2on ^7the zombie counter."); //Added by CT8918
			while(1)
			{
				toggle_zombie_counter waittill("trigger", player); //Added by CT8918
				zombie_counter_off = false;
				level.run_zombie_counter = true;
				break;
			}
		}
		else
		{
			toggle_zombie_counter SetHintString("^7Press ^3&&1 ^7to turn ^2off ^7the zombie counter."); //Added by CT8918
			while(1)
			{
				toggle_zombie_counter waittill("trigger", player); //Added by CT8918
				zombie_counter_off = true;
				level.run_zombie_counter = false;
				break;
			}
		}
	}
}
function _ROUND_COUNTER(hudArray)
{
	level endon("end_of_round");
	lastCount = 0;
	numberToString = "";
	
	hudArray["counter"] thread hudRGBA(hudArray["DefaultColor"], 1.0, 1);
	hudArray["text"] thread hudRGBA(hudArray["DefaultColor"], 1.0, 1);
	
	if(level flag::get("dog_round"))
		hudArray["text"] SetText(hudArray["DogText"]);

	for(;;)
	{
		zm_count = (zombie_utility::get_current_zombie_count() + level.zombie_total);
		if(hudArray["DisplayType"] == 1) zm_count = zombie_utility::get_current_zombie_count();
		if(zm_count == 0) {wait(1); continue;}
		
		//If / else if statements added by CT8918. Allows the distinction between on and off.
		if(level.run_zombie_counter == true)
		{
			hudArray["counter"] thread hudRGBA(hudArray["DefaultColor"], 1.0, 1);
			hudArray["counter"].fontscale = 1.5; 
			hudArray["text"] SetText(hudArray["ZombieText"]);
			hudArray["counter"] SetValue(zm_count);
			if(lastCount != zm_count && level.run_zombie_counter == true)
			{
				lastCount = zm_count;
				numberToString = "" + zm_count;
				hudArray["text"] thread hudMoveTo((10 + (4 * numberToString.Size), 10, 0), 4);
				if(zm_count == 1 && !level flag::get("dog_round")) hudArray["text"] SetText(hudArray["LastZombieText"]);
				else if(zm_count == 1 && level flag::get("dog_round")) hudArray["text"] SetText(hudArray["LastDogText"]);

				hudArray["counter"].color = hudArray["HighlightColor"]; hudArray["counter"].fontscale = (hudArray["FontScale"] + 0.5);
				hudArray["text"].color = hudArray["HighlightColor"]; hudArray["text"].fontscale = (hudArray["FontScale"] + 0.5);
				hudArray["counter"] thread hudRGBA(hudArray["DefaultColor"], 1, 0.5); hudArray["counter"] thread hudFontScale(hudArray["FontScale"], 0.5);
				hudArray["text"] thread hudRGBA(hudArray["DefaultColor"], 1, 0.5); hudArray["text"] thread hudFontScale(hudArray["FontScale"], 0.5);
			}
		}
		else if (level.run_zombie_counter == false)
		{
			hudArray["counter"] thread hudRGBA(hudArray["DefaultColor"], 0, 1); //Added by CT8918. Hides the counter number.
			hudArray["text"] SetText(hudArray["NoText"]); //Added by CT8918. Hides the counter text.
		}
		wait(0.1);
	}
}

function createNewHudElement(xAlign, yAlign, posX, posY, foreground, fontScale)
{
	hud = newHudElem();
	hud.horzAlign = xAlign; hud.alignX = xAlign;
	hud.vertAlign = yAlign; hug.alignY = yAlign;
	hud.x = posX; hud.y = posY;
	hud.foreground = foreground;
	hud.fontscale = fontScale;
	return hud;
}

function hudRGBA(newColor, newAlpha, fadeTime)
{
	if(isDefined(fadeTime))
		self FadeOverTime(fadeTime);

	self.color = newColor;
	self.alpha = newAlpha;
}

function hudFontScale(newScale, fadeTime)
{
	if(isDefined(fadeTime))
		self ChangeFontScaleOverTime(fadeTime);

	self.fontscale = newScale;
}

function hudMoveTo(posVector, fadeTime) // Just because MoveOverTime doesn't always work as wanted
{
	initTime = GetTime();
	hudX = self.x;
	hudY = self.y;
	hudVector = (hudX, hudY, 0);
	while(hudVector != posVector)
	{
		time = GetTime();
		hudVector = VectorLerp(hudVector, posVector, (time - initTime) / (fadeTime * 1000));
		self.x = hudVector[0];
		self.y = hudVector[1];
		wait(0.0001);
	}
}
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//END ZOMBIE COUNTER
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Feel free to ask any questions regarding the installation and any other modifications you may like.


ModmeBot:

Reply By: Ping998
Nice tutorial but your Test Footage doesn't link to the correct page. Sorry :/


ModmeBot:

Reply By: CT8918

Ping998
Nice tutorial but your Test Footage doesn't link to the correct page. Sorry :/

Oops. Should work now


ModmeBot:

Reply By: Fil he Modder
i'm constantly getting an error saying that 'undefined is not a field object line 353, and the line is hud.vertAlign = yAlign; hug.alignY = yAlign;

please help :/


ModmeBot:

Reply By: mathfag

Fil he Modder
i'm constantly getting an error saying that 'undefined is not a field object line 353, and the line is hud.vertAlign = yAlign; hug.alignY = yAlign; please help :/


hug.alignY -->  hud.alignY


ModmeBot:

Reply By: Fil he Modder
aren't i retarded?! xDDD