summaryrefslogtreecommitdiff
path: root/mods/counters/zombieCounter.gsc
blob: 3ea75579423182a96f322f577c6b1d70e23cde04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include common_scripts/utility;
#include maps/mp/gametypes_zm/_hud_util;
#include maps/mp/zombies/_zm_utility;

init()
{
	level thread onPlayerConnect();
}

onPlayerConnect()
{
	while(1)
	{
		level waittill("connected", player);
		player thread onPlayerSpawned();
	}
}

onPlayerSpawned()
{
	self endon("disconnect");
	level endon("game_ended");
	while(1)
	{
		self waittill("spawned_player");

		// Waits for the black preload screen to pass so it can load the mods
		flag_wait( "initial_blackscreen_passed" );

		// Mod that adds a zombie counter to the bottom of the screen
		self thread zombieCounter(self, level, 0, 190);
	}
}

/*
 * Function that draws a zombie counter
 */
zombieCounter(p, l, x, y)
{
	p.zombiecounter = drawCounter(p.zombiecounter, x, y);

	while(1)
	{
		p.zombiecounter.alpha = checkAfterlife(p);

		zombies = l.zombie_total + get_current_zombie_count();
		if ( zombies > 0 )
		{
			p.zombiecounter.label = &"Zombies Left: ^1";
		}
		else
		{
			p.zombiecounter.label = &"Zombies Left: ^6";
		}

		p.zombiecounter setvalue(zombies);
		wait 0.05;
	}
}


// Aux Functions

/*
 * Draws the counter in desired position
 */
drawCounter(counterVar, x, y)
{
	counterVar = createfontstring( "Objective", 1.7 );
	counterVar setpoint( "CENTER", "CENTER", x, y);
	counterVar.alpha = 1;
	counterVar.hidewheninmenu = 1;
	counterVar.hidewhendead = 1;
	return counterVar;
}

/*
 * Checks if the player has entered afterlife
 */
checkAfterlife(p)
{
	if(isdefined(p.afterlife) && p.afterlife)
	{
		return 0.2;
	}
	return 1;
}