#include <amxmodx>
#include <fun>
#include <fakemeta>
#include <zombieplague>
#include <hamsandwich>
#include <dhudmessage>

#define PLUGIN "Zp Addon: New Score"
#define VERSION "1.5"
#define AUTHOR "kiryxapro"

new g_winhuman , g_winzombie , g_roundhud 
new cvar_zp_cs_restartround;
new g_maxplayers

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	register_event("HLTV", "event_roundstart", "a", "1=0", "2=0")
	
	register_dictionary("zp_score.txt") 
	
	cvar_zp_cs_restartround = get_cvar_pointer("sv_restartround")
	 
	set_task (0.6,"showhud",_,_,_,"b")
	
	g_maxplayers = get_maxplayers()
	g_roundhud = 0
}

public event_roundstart()
{
	g_roundhud += 1 
	
	if (g_roundhud == 1)
	{
	g_winhuman = 0
	}
	 
}

public showhud()
{
	set_dhudmessage(255, 255, 20, -1.0, 0.0, 0, 0.0, 0.01)
	show_dhudmessage(0, "%L", LANG_PLAYER, "ZP_SCORE", fn_get_humans(),g_roundhud,fn_get_zombies(),g_winhuman,g_winzombie)  
}

public zp_round_ended(winteam)
{
	if(get_pcvar_num(cvar_zp_cs_restartround))
	{
		for(new id=1;id<=g_maxplayers;id++)
		{
			g_roundhud = 0
			g_winzombie = 0
			g_winhuman = 0
			return PLUGIN_CONTINUE
		}
	}
	if(winteam == WIN_ZOMBIES)
	{
		g_winzombie += 1 
	}else{
		g_winhuman += 1
	}
	
	return PLUGIN_CONTINUE	
}

fn_get_humans()
{
	static iAlive, id
	iAlive = 0
	
	for (id = 1; id <= 32; id++)
	{
		if (is_user_alive(id) && !zp_get_user_zombie(id))
			iAlive++
	}
	
	return iAlive;
}

fn_get_zombies()
{
	static iAlive, id
	iAlive = 0
	
	for (id = 1; id <= 32; id++)
	{
		if (is_user_alive(id) && zp_get_user_zombie(id))
			iAlive++
	}
	
	return iAlive;
}