#include <amxmodx>
#include <fun>

new Cvar[4], hud, los = 0, kolorek[33], nick[32]

public plugin_init() {
	register_plugin("Losowanie", "1.0", "AztekHQS")
	
	register_clcmd("say /losuj", "Losuj")

	Cvar[0] = register_cvar("jb_los_dzwiek", "1")
	Cvar[1] = register_cvar("jb_los_powloka", "1")
	Cvar[2] = register_cvar("jb_los_hud", "1")
	Cvar[3] = register_cvar("jb_los_czas", "10")

	register_logevent("KoniecRundy", 2, "1=Round_End")

	hud = CreateHudSyncObj()
}

public KoniecRundy() los = 0

public Losuj(id) {
	if(!is_user_alive(id) || get_user_team(id) != 2) return 1

	new ids[33], ktory_gracz = 0

	for(new i = 1; i <= get_maxplayers(); i++) {
		if(get_user_team(i) == 1 && is_user_alive(i)) {
			ids[ktory_gracz] = i
			ktory_gracz++
		}
		los = ids[random_num(0, ktory_gracz-1)]
	}
	if(get_pcvar_num(Cvar[0]) == 1) client_cmd(los, "spk fvox/blip")
	if(get_pcvar_num(Cvar[0]) == 2) client_cmd(0, "spk fvox/blip")
	if(get_pcvar_num(Cvar[1]) == 1) {
		set_user_rendering(los, kRenderFxGlowShell, 255, 212, 85, kRenderNormal, 8)
		set_task(get_pcvar_float(Cvar[3]), "Usun", los)
		kolorek[los] = true
	}
	get_user_name(los, nick, 31)
	set_hudmessage(255, 255, 255, 0.01, 0.37, 0, 6.0, 5.0)
	switch(get_pcvar_num(Cvar[2])) {
		case 1: ShowSyncHudMsg(id, hud, "Wylosowany wiezien: %s", nick)
		case 2: ShowSyncHudMsg(los, hud, "Wylosowany wiezien: %s", nick)
		case 3: ShowSyncHudMsg(0, hud, "Wylosowany wiezien: %s", nick)
	}
	return 1
}

public Usun(id) {
	if(!(get_pcvar_num(Cvar[1]) != 1) || !is_user_alive(id)) return 1

	set_user_rendering(id)
	kolorek[id] = false
	return 0
}