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

#define PLUGIN "Headshot day"
#define VERSION "1.0.6"
#define AUTHOR "Wielkie Jol"
#define HITGROUP_HEAD (1 << 1)

new jakie_bronie[] = {CSW_M4A1};
new pcvar;

new id_zabawa;
public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	pcvar = register_cvar("amx_onlyhs", "0");
	register_forward(FM_TraceLine, "Fwd_TraceLine");
	id_zabawa = jail_register_game("M4A1 HS DAY");
}

public OnLastPrisonerShowWish(id)
{
	OnRemoveData(id_zabawa);
}

public OnRemoveData(day)
{
	if(day == id_zabawa)
	{
		server_cmd("amx_onlyhs 0");
		jail_set_ct_hit_tt(false);
		jail_set_god_ct(false);
	}
}

public OnDayStartPre(day, szInfo[256], szInfo2[512], setting[10], gTimeRound)
{
	static szTime[12];
	if(day == id_zabawa)
	{
		format_time(szTime, 11, "%M:%S", gTimeRound-30);
		formatex(szInfo2, 511, "Zasady:^n%s - wojna miedzy wiezniami na m4a1^n Liczy sie tylko GLOWA! ^n Graj z glowa!", szTime);
		szInfo = "Headshot Day";
		
		jail_set_prisoners_micro(true, true);
		jail_set_ct_hit_tt(true);
		jail_set_god_ct(true);
		server_cmd("amx_onlyhs 1");
		
		setting[0] = 1;
		setting[1] = 1;
		setting[2] = 1;
		setting[4] = 1;
		setting[6] = 1;
		setting[7] = 1;
	}
}

public OnDayStartPost(day)
{
	if(day == id_zabawa)
	{
		jail_open_cele();
		jail_set_game_hud(30, "Rozpoczecie zabawy za");
		for(new i=1; i<=32; i++){
			if(!is_user_alive(i) || cs_get_user_team(i) != CS_TEAM_T)
				continue;
			for(new j=0; j<sizeof(jakie_bronie); j++)
			{
				new weaponname[24];
				get_weaponname(jakie_bronie[j], weaponname, 23);
				give_item(i, weaponname);
				
				cs_set_user_bpammo(i, jakie_bronie[j], 100);
			}
		}
	}
}

public OnGameHudEnd(day)
{
	if(day == id_zabawa)
	{
		set_hudmessage(255, 0, 0, -1.0, -1.0, 0, 6.0, 5.0);
		show_hudmessage(0, "== M4A1 HeadshotDay ==");
		
		jail_set_prisoners_fight(true, false, false);
	}
}


public Fwd_TraceLine(Float:StartPos[3],Float:EndPos[3], SkipMonsters, id, Trace)
{
	if(!is_user_connected(id) || !is_user_alive(id))
		return FMRES_IGNORED;
	if(!get_pcvar_num(pcvar))
		return FMRES_IGNORED;
	new Hited = get_tr2(Trace, TR_pHit);
	new HitGroup = (1 << get_tr2(Trace, TR_iHitgroup));
	
	if(!is_user_alive(Hited))
		return FMRES_IGNORED;
	
	if(!(HitGroup & HITGROUP_HEAD))
	{
		set_tr2(Trace, TR_flFraction, 1.0);
		return FMRES_SUPERCEDE;
	}
	return FMRES_IGNORED;
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1045\\ f0\\ fs16 \n\\ par }
*/
