#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <jailbreak>
#include <colorchat>
#include <hamsandwich>

#define PLUGIN "[Jail] KillDay"
#define VERSION "1.0.6"
#define AUTHOR "Cypis +jb as"

native get_user_jbpack(id) //zwraca ilosc jb packow gracza
native set_user_jbpack(id, wartosc) //ustawia ilosc jb packow graczowi
	
new wyborow[3] 

new const maxAmmo[31] = {0,52,0,90,1,31,1,100,90,1,120,100,100,90,90,90,100,120,30,120,200,31,90,120,90,2,35,90,90,0,100};
new const idWeapons[] = {3,5,7,8,12,13,14,15,18,19,20,21,22,23,27,28,30};

new id_killday;

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	id_killday = jail_register_game("KillDay");
	
	RegisterHam( Ham_Spawn, "player", "fwSpawn1", 1 );
}

public plugin_precache()
{
	precache_sound("jailbreakice/kd.mp3");
}

public OnRemoveData(day)
{
	if(day == id_killday)
	{
		for(new id=1; id<=MAX; id++)
			client_cmd(0, "mp3 stop");
		set_user_hitzones(0, 0, 255);
		set_user_hitzones(0, 0, 255);
	}
}

public OnDayStartPre(day, szInfo[256], szInfo2[512], setting[10], gTimeRound)
{	
	static szTime[12];
	if(day == PIATEK || day == id_killday)
	{
		static szTimes[12];
		format_time(szTime, 11, "%M:%S", gTimeRound-30);
		format_time(szTimes, 11, "%M:%S", gTimeRound-60);
		formatex(szInfo2, 511, "Zasady:^n%s - wiezniowie dostaja bron^n%s - walka wiezniow miedzy soba^nGrupy moga byc maksymalnie 2 osobowe!^nOstatni wiezien ma zyczenie", szTime, szTimes);
		szInfo = "Dzisiaj jest KillDay";
		
		jail_set_prisoners_micro(true, true);
		jail_set_ct_hit_tt(true);
		jail_set_god_ct(true);
		
		setting[0] = 1;
		setting[1] = 1;
		setting[2] = 1;
		setting[4] = 1;
		setting[6] = 0;
		setting[7] = 1;
	}
}

public OnDayStartPost(day)
{
	if(day == PIATEK || day == id_killday)
	{
		jail_open_cele();
		jail_set_game_hud(60, "Rozpoczecie zabawy za");
		client_cmd(0, "mp3 play sound/jailbreakice/kd.mp3");
	}
}

public OnGameHudTick(day, count)
{
	if(count != 30)
		return;
	
	if(day != PIATEK && day != id_killday)
		return;
	
	new nameweapon[24], wid = idWeapons[random(charsmax(idWeapons))];
	get_weaponname(wid, nameweapon, 23);
	
	for(new i=1; i<=MAX; i++)
	{
		if(!is_user_alive(i) || !is_user_connected(i) || cs_get_user_team(i) != CS_TEAM_T)
			continue;
		
		strip_user_weapons(i);
		give_item(i, "weapon_knife");
		give_item(i, "weapon_glock18");
		give_item(i, nameweapon);
		start_glosu(i);
		
		cs_set_user_bpammo(i, wid, maxAmmo[wid]);
		cs_set_user_bpammo(i, CSW_GLOCK18, maxAmmo[CSW_GLOCK18]);
	}
}

public OnGameHudEnd(day)
{
	if(day == PIATEK || day == id_killday)
	{
		set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 5.0);
		show_hudmessage(0, "== WIEZNIOWIE VS WIEZNIOWIE ==");
		
		jail_set_prisoners_fight(true, false, false);
	}
}

public OnLastPrisonerShowWish(id)
{
	if(jail_get_play_game_id() == id_killday){
		OnRemoveData(id_killday);
		set_user_hitzones(0, 0, 255);
	}
	new random_pack = random_num(1,5);
	set_user_hitzones(0, 0, 255);
	set_user_jbpack(id, get_user_jbpack(id)+random_pack);
	ColorChat(id, GREEN, "[SZLUGI]^x01 Za bycie ostatnim wiezniem otrzymujesz %d szlugow.", random_pack);
}

public start_glosu(id) 
{     
	new menu = menu_create("Only HS KillDay", "menu_handler") 
	menu_additem(menu, "Tak, Only HS", "1", 0) 
	menu_additem(menu, "Nie, gramy normalnie", "2", 0) 
	
	menu_addblank(menu, 0) 
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL) 
	
	new players[32], inum 
	get_players(players, inum, "ch") 
	for(new i = 0; i < inum; i++) 
	{ 
		menu_display(players[i], menu, 0) 
	} 
	
	set_task(15.0, "vote_hs") 
	
	wyborow[1] = wyborow[2] 
	
	return 1 
} 

public menu_handler(id, menu, item) 
{ 
	if (item == MENU_EXIT) 
	{ 
		menu_cancel(id) 
		return PLUGIN_HANDLED 
	} 
	
	new data[6], name[32] 
	new access, callback 
	
	menu_item_getinfo(menu, item, access, data, 5, _, _, callback) 
	
	new key = str_to_num(data) 
	get_user_name(id, name, 31) 
	
	switch (key)  
	{ 
		case 1:  
		{ 
			ColorChat(0, GREEN, "^x03[^x01 Only HS KD ^x03]^x01: ^x04%s ^x01zaglosowal na ^x04tak^x01.",name);
		} 
		case 2: 
		{ 
			ColorChat(0, GREEN, "^x03[^x01 Only HS KD ^x03]^x01: ^x04%s ^x01zaglosowal na ^x04nie^x01.", name);
		} 
	} 
	
	++wyborow[key] 
	
	menu_cancel(id) 
	return PLUGIN_HANDLED 
} 

public vote_hs() 
{ 
	
	if(wyborow[1] >= wyborow[2]) 
	{ 
		set_user_hitzones(0, 0, 2);
		
		ColorChat(0, GREY, "^x03[^x01 Only HS KD ^x03]^x01: zostal^x04 wlaczony ^x01zadecydowaly o tym glosy ^x04%d ^x01osob.", wyborow[1]);
	} 
	
	else if(wyborow[2] > wyborow[1]) 
	{ 
		ColorChat(0, GREEN, "^x03[^x01 Only HS KD ^x03]^x01: zostal^x04 wylaczony ^x01zadecydowaly o tym glosy ^x04%d ^x01osob.", wyborow[2]);	
		set_user_hitzones(0, 0, 255);
	} 
}

public fwSpawn1(id)
{	
	set_user_hitzones(0, 0, 255);
}