/*================================================================================





Credits To PRoSToTeM@(Idea), ZETA [M|E|N](Small Bug FIX), Am[D]em(Some bug with showing hud Msg)





=================================================================================*/





#include <amxmodx>
#include <amxmisc>
#include <zombieplague>

#define PLUGIN "[ZP] Count zombies, humans, wins informer"
#define VERSION "1.0"
#define AUTHOR "PRoSToTeM@ / ZETA [M|E|N] / Am[D]eM"

new g_MsgSync, iWinNoOne, iWinHumans, iWinZombies, human, g_maxplayers

enum (+= 100)
{
	TASK_INFORMER
}

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("HLTV", "NewRound", "a", "1=0", "2=0")
	register_event("TextMsg", "RoundRestart", "a", "2&#Game_C", "2&#Game_w")
	
	g_MsgSync = CreateHudSyncObj()
	
	g_maxplayers = get_maxplayers()
	
	set_task(1.0, "get_informer", 1, "", 0, "b")
}

public zp_round_started()
{
	remove_task(TASK_INFORMER)

	set_task(0.1, "fixerbug2", TASK_INFORMER, _, _, "b")
}

public fixerbug2()
{
	human = zp_get_human_count()
}

public zp_round_ended(winteam)
{
	if (winteam == WIN_NO_ONE)
	{
		iWinNoOne++
	}
	else if (winteam == WIN_HUMANS)
	{
		iWinHumans++
	}
	else if (winteam == WIN_ZOMBIES)
	{
		iWinZombies++
	}
}

public NewRound()
{
	remove_task(TASK_INFORMER)

	set_task(0.1, "fixerbug", TASK_INFORMER, _, _, "b")
}

public fixerbug()
{
	static iHumans, id
	iHumans = 0
	
	for (id = 1; id <= g_maxplayers; id++)
	{
		if (is_user_alive(id))
			iHumans++
	}
	
	human = iHumans
}

public RoundRestart()
{
	iWinNoOne = 0
	iWinHumans = 0
	iWinZombies = 0
}

public get_informer()
{
	new zombie
	zombie = zp_get_zombie_count()
	
	set_hudmessage(255, 255, 255, -1.0, 0.01, 0, 0.0, 3.0, 2.0, 1.0, -1)
	ShowSyncHudMsg(0, g_MsgSync, "[Люди %s%i [%s%i] | [%s%i] %s%i Зомби]", human < 10 ? "0":"", human, iWinHumans + iWinNoOne < 10 ? "0":"", iWinHumans + iWinNoOne, iWinZombies < 10 ? "0":"", iWinZombies, zombie < 10 ? "0":"", zombie)
}