#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <engine>
#include <jailbreak>
#include <fakemeta>
#include <hamsandwich>
#define IsPlayer(%1) (1<=%1<=maxPlayers)
#define PLUGIN "[JB] Szybki jak blyskawica"
#define VERSION "1.0.6"
#define AUTHOR "Wielkie Jol"

native cs_set_player_model(id, newmodel[]);
new id_zabawa;
new HamHook: hDmg, HamHook:hBron, HamHook:hBron2;
new maxPlayers;

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	id_zabawa = jail_register_game("Szybki jak blyskawica");
}

public plugin_cfg() maxPlayers=get_maxplayers();

public OnLastPrisonerShowWish(id)
{
	if(jail_get_play_game_id() == id_zabawa){
		OnRemoveData(id_zabawa);
	}
}

public OnRemoveData(day)
{
	if(day == id_zabawa)
	{
		for(new i=1; i<=32; i++){
			if(is_user_alive(i) & get_user_team(i) == 2){
				jail_set_user_speed(i, 250.0);
				jail_set_user_speed(i, 250.0);
			}
			for(new i=1; i<=32; i++){
				if(is_user_connected(i) & get_user_team(i) == 1){
					cs_set_user_zoom(i, CS_RESET_ZOOM, 1);
				}
			}
			
		}
		if(hDmg)
			DisableHamForward(hDmg);
		if(hBron)
			DisableHamForward(hBron);
		if(hBron2)
			DisableHamForward(hBron2);
	}
}

public OnDayStartPre(day, szInfo[256], szInfo2[512], setting[10], gTimeRound)
{	
	static szTime[12];
	if(day == id_zabawa)
	{
		format_time(szTime, 11, "%M:%S", gTimeRound-15);
		formatex(szInfo2, 511, "Zasady:^n%s - Klawisze maja bardzo malo hp, sa bardzo szybcy i zabijaja na raz^n Wiezniowie maja tylko scouta bez zooma ^n", szTime, szTime);
		szInfo = "Dzien blyskawicy";
		
		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[7] = 2;
	}
}

public OnDayStartPost(day)
{
	if(day == id_zabawa)
	{
		jail_open_cele();
		jail_set_game_hud(15, "Rozpoczecie zabawy za");
		for(new i=1; i<=32; i++){
			if(is_user_alive(i) && get_user_team(i) == 2 ){
				strip_user_weapons(i);
				give_item(i, "weapon_knife");
				jail_set_user_speed(i, 1500.0);
				set_user_maxspeed(i, 1500.0);
				set_user_health(i, 5);
			}
			for(new i=1; i<=32; i++){
				if(is_user_alive(i) && get_user_team(i) == 1 ){
					strip_user_weapons(i);
					give_item(i, "weapon_scout");
					cs_set_user_bpammo(i, CSW_SCOUT, 90);
					cs_set_user_zoom(i, CS_SET_NO_ZOOM, 0);
				}
				
			}
		}
		if(!hDmg)
			hDmg = RegisterHam(Ham_TakeDamage, "player", "fwTakeDamage_JedenCios");
		else
			EnableHamForward(hDmg);
		if(!hBron)
			hBron = RegisterHam(Ham_Touch, "weaponbox", "HamTouchPre", 0);
		else
			EnableHamForward(hBron);
		if(!hBron2)
			hBron2 = RegisterHam(Ham_Touch, "armoury_entity", "HamTouchPre", 0);
		else
			EnableHamForward(hBron2);
	}
}

public HamTouchPre(weapon, id){
	if(!pev_valid(weapon) || !IsPlayer(id) || !is_user_alive(id)){
		return HAM_IGNORED;
	}
	new name[20];
	pev(weapon, pev_model, name, 19);
	if(containi(name, "w_backpack")!=-1){
		return HAM_IGNORED;
	}
	return HAM_SUPERCEDE;
}

public fwTakeDamage_JedenCios(id, ent, attacker){
	if(is_user_alive(attacker) && get_user_team(attacker) == 2 && get_user_weapon(attacker) == CSW_KNIFE)
	{
		cs_set_user_armor(id, 0, CS_ARMOR_NONE);
		SetHamParamFloat(4, float(get_user_health(id) + 1));
		return HAM_HANDLED;
	}
	return HAM_IGNORED;
}

public TakeDamage(id, this, idinflictor, idattacker, Float:damage, damagebits){
	
	if(!is_user_alive(idattacker))
		return HAM_IGNORED;
		
	if(get_user_weapon(idattacker) == CSW_KNIFE){
		cs_set_user_armor(id, 0, CS_ARMOR_NONE);
		SetHamParamFloat(4, float(get_user_health(id) + 1));
		return HAM_HANDLED;
	}
	return HAM_IGNORED;
}

public OnGameHudEnd(day)
{
	if(day == id_zabawa)
	{
		jail_set_ct_hit_tt(false);
		jail_set_god_ct(false);
	}
}

