#include <amxmodx>
#include <dhudmessage>
#include <zombieplague>
#include <fakemeta>
 
#define PLUGIN "ZP Round Results"
#define VERSION "1.0"
#define AUTHOR "MonsteR"
 
const OFFSET_LINUX = 5
const OFFSET_DEATHS = 444
const OFFSET_TEAM = 114
 
new cvar_zp_cs_restartround;
 
new g_maxplayers
new g_msgScoreInfo
new PlayerOldName[33][32]
 
new cvar_zp_human_win
new cvar_zp_human_lose
new cvar_zp_human_draw
new cvar_zp_zombie_win
new cvar_zp_zombie_lose
new cvar_zp_zombie_draw
 
public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
 
	register_dictionary("zp_round_results.txt")
	
	cvar_zp_cs_restartround = get_cvar_pointer("sv_restartround")
		
	cvar_zp_human_win = register_cvar("zp_human_win", "6");
	cvar_zp_human_lose = register_cvar("zp_human_lose", "2");
	cvar_zp_human_draw = register_cvar("zp_human_draw", "4");
	cvar_zp_zombie_win = register_cvar("zp_zombie_win", "5");
	cvar_zp_zombie_lose = register_cvar("zp_zombie_lose", "2");
	cvar_zp_zombie_draw = register_cvar("zp_zombie_draw", "4");
       
	g_maxplayers = get_maxplayers();
}

public fw_ClientConnect_Post(id)
{
 	get_user_name(id,PlayerOldName[id],31)
	if (zp_get_user_ammo_packs(id))
	{
		zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + 0)
	}
	return FMRES_IGNORED;
}

 public zp_round_ended(winteam)
{	
	if(get_pcvar_num(cvar_zp_cs_restartround))
	{
		for(new id=1;id<=g_maxplayers;id++)
		{
			zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + 0)

			return PLUGIN_CONTINUE
		}
	}

	new color[3]	
	for(new i = 0; i < 3; i++)
	{
		color[i] = 255 * winteam
	}	
	set_task(1.0, "round_results", 300+winteam)
	
	return PLUGIN_CONTINUE;
}
 
public round_results(taskid)
{
        new strtemp1[16]
        new color[3]
        new winteam = taskid-300
 
        for (new id=1;id<=g_maxplayers;id++)
        {
                if (!is_user_connected(id)) continue;
 
                new AmmoBonus;
                if (zp_get_user_zombie(id)||(zp_get_user_nemesis(id)))
                {
                        switch(winteam)
                        {
                                case 0:
                                {
                                        color[2]=255;
                                        strtemp1="NOONE"
                                        AmmoBonus=get_pcvar_num(cvar_zp_zombie_draw)
                                }
                                case 1:
                                {
                                        color[1]=255;
                                        strtemp1="WIN"
                                        AmmoBonus=get_pcvar_num(cvar_zp_zombie_win)
                                }
                                case 2:
                                {
                                        color[0]=255;
                                        strtemp1="FAIL"
                                        AmmoBonus=get_pcvar_num(cvar_zp_zombie_lose)
                                }
                        }
                }
                else
                {
                        switch(winteam)
                        {
                                case 0:
                                {
                                        color[2]=255;
                                        strtemp1="NOONE"
                                        AmmoBonus=get_pcvar_num(cvar_zp_human_draw)
                                }
                                case 1:
                                {
                                        color[0]=255;
                                        strtemp1="FAIL"
                                        AmmoBonus=get_pcvar_num(cvar_zp_human_lose)
                                }
                                case 2:
                                {
                                        color[1]=255;
                                        strtemp1="WIN"
                                        AmmoBonus=get_pcvar_num(cvar_zp_human_win)
                                }
                        }
                }
               
                zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + AmmoBonus)
               
                set_dhudmessage(color[0], color[1], color[2], 0.05, 0.63, 2, 1.0, 3.5,0.05,0.05)               
                show_dhudmessage(id, "%L", LANG_PLAYER, strtemp1, AmmoBonus)
               
                set_task(0.1,"update_scoreboard",id)
        }
}
 
public update_scoreboard(id)
{
        message_begin(MSG_BROADCAST, g_msgScoreInfo)
        write_byte(id)
        write_short(pev(id, pev_frags))
        write_short(get_pdata_int(id, OFFSET_DEATHS, OFFSET_LINUX))
        write_short(0)
        write_short(get_pdata_int(id, OFFSET_TEAM, OFFSET_LINUX))
        message_end()
}