#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <engine>
#include <jailbreak>

#define PLUGIN "[JB] Kaczki"
#define VERSION "1.0.6"
#define AUTHOR "Cypis"

native cs_set_player_model(id, newmodel[]);
new id_zabawa;

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)

	id_zabawa = jail_register_game("Kaczki z AWP");
}

public plugin_precache()
{
	precache_model("models/rpgrocket.mdl"); //wymagane do poprawnego działania set_view
	
	precache_model("models/player/kaczki/kaczki.mdl");
	precache_sound("jb_cypis/kaczki.mp3");
}

public OnLastPrisonerShowWish(id)
{
	if(jail_get_play_game_id() == id_zabawa){
		OnRemoveData(id_zabawa);
		cs_set_player_model(id, "wiezien_cypis");
	}
}

public OnRemoveData(day)
{
	if(day == id_zabawa)
	{
		client_cmd(0, "mp3 stop");
		for(new i=1; i<=MAX; i++)
		{
			if(!is_user_connected(i))
				continue;
				
			set_view(i, CAMERA_NONE);
		}
	}
}

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 - Wiezniowie maja czas na schownie sie^n%s - CT szuka i zabija uciekajace kaczki", szTime, szTime);
		szInfo = "Dzisiaj jest Kaczki";
		
		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] = 3;
		setting[7] = 2;
	}
}

public OnDayStartPost(day)
{
	if(day == id_zabawa)
	{
		jail_open_cele();
		jail_set_game_hud(30, "Rozpoczecie zabawy za");
		
		jail_set_users_speed(0.1);
	}
}

public OnGameHudEnd(day)
{
	if(day == id_zabawa)
	{
		jail_set_ct_hit_tt(false);
		
		jail_set_users_speed(250.0);
		client_cmd(0, "mp3 play sound/jb_cypis/kaczki.mp3");
	}
}

//stock
stock jail_set_users_speed(Float:speed)
{
	for(new i=1; i<=MAX; i++)
	{
		if(!is_user_alive(i) || !is_user_connected(i))
			continue;
			
		if(get_user_team(i) == 1)
		{
			strip_user_weapons(i);
			cs_set_player_model(i, "kaczki");

			set_view(i, CAMERA_3RDPERSON);
		}
		else
		{
			if(speed == 250.0)
			{
				strip_user_weapons(i);
				give_item(i, "weapon_knife");
				give_item(i, "weapon_awp");
			}
			jail_set_user_speed(i, speed);
		}
	}
}
