
/* AMX Mod script.
*
* (c) Copyright 2002, OLO
* This file is provided as is (no warranties).
*
*/

/*  cvar:
*   amx_bomb_events < flags >
*   "a" - exploded
*   "b" - planting
*   "c" - defusing
*   "d" - planted
*   "e" - defused
*   "f" - failed to defuse
*   "g" - pickup
*   "h" - droped
*/

#include <amxmod>

new planter
new defuser
new c4timer
new defusing
new Float:last_omg
new Float:last_plan

get_bemode() {
	new bemode[10]
	get_cvar_string("amx_bomb_events",bemode,10)
	return read_flags(bemode)
}
public got_bomb(id){
	new bemode = get_bemode()
	if (bemode&1){
		planter = id
		defuser = defusing = 0
		if ((read_data(1)==2) && (last_omg < get_gametime())){
			last_omg = get_gametime() + 15.0
			new name[32]
			get_user_name(planter, name , 32)
			set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
			show_hudmessage(0,"Omg! %s reached the target!",name)
		}
	}
}
public bdef_g(id){
	new bemode = get_bemode()
	if (read_data(1) == 3){
		if (last_plan < get_gametime()){
			if (bemode&2){
				last_plan = get_gametime() + 15.0
				new name[32]
				set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
				get_user_name(planter, name , 32)
				show_hudmessage(0,"%s is planting the bomb!",name)
			}
		}
	}
	else {
		defuser = defusing = id	
		if (last_plan < get_gametime()){
			if (bemode&4){
				last_plan = get_gametime() + 15.0
				new name[32]
				set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
				get_user_name(defusing, name , 32)
				show_hudmessage(0,"%s is defusing the bomb :D",name)
			}
		}
	}
}
public bdef_l(id)
	defusing = 0
public disable_c4(){
	c4timer = 0
	last_plan = 0.0
	last_omg = 0.0
	remove_task(8038)
}
public bomb_planted(){
	new bemode = get_bemode()
	if (bemode&8){
		new name[32]
		get_user_name(planter, name , 32)
		set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
		show_hudmessage(0,"%s set us up the bomb!!!",name)
		c4timer = get_cvar_num("mp_c4timer") - 2
		set_task(1.0,"bomb_c",8038,"",0,"b")
		last_plan = 0.0
	}
}
public bomb_c(){
	if (--c4timer > 0){
		if (c4timer == 30 || c4timer == 20){
			new temp[48]
			num_to_word(c4timer,temp,48)
			client_cmd(0,"spk ^"vox/%s seconds until explosion^"",temp)
		}
		else if (c4timer < 11){
			new temp[48]
			num_to_word(c4timer,temp,48)
			client_cmd(0,"spk ^"vox/%s^"",temp)
		}
		if (defusing)
			client_print(defusing,print_center,"%d",c4timer)
	}
	else{
		remove_task(8038)
	}
}
public bomb_defused(){
	new bemode = get_bemode()
	if (bemode&16){
		new name[32]
		get_user_name(defuser, name , 32)
		set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
		show_hudmessage(0,"%s defused the bomb!",name)
		disable_c4()
	}
}
public bomb_failure(){
	new bemode = get_bemode()
	if (bemode&32){
		if (defuser){
			new name[32]
			get_user_name(defuser, name , 32)
			set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
			show_hudmessage(0,"%s  failed to defuse the bomb...",name)
		}
	}
}
public bomb_pickup(id){
	new bemode = get_bemode()
	if (bemode&64){
		new name[32]
		get_user_name(id, name , 32)
		set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
		show_hudmessage(0,"%s pick up the bomb...",name)
	}
}
public bomb_drop(){
	new bemode = get_bemode()
	if (bemode&128){
		new name[32]
		get_user_name(planter, name , 32)
		set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
		show_hudmessage(0,"%s dropped the bomb!!!",name)
	}
}
public plugin_init(){
	register_plugin("Bomb Events","0.61b","default")
	register_event("StatusIcon", "got_bomb", "be", "1=1", "1=2", "2=c4")
	register_event("SendAudio", "bomb_planted", "a", "2&%!MRAD_BOMBPL")
	register_event("SendAudio", "bomb_defused", "a", "2&%!MRAD_BOMBDEF")
	register_event("TextMsg", "bomb_failure", "a", "2&#Target_B")
	register_event("BarTime", "bdef_g", "be", "1=10", "1=5","1=3")
	register_event("BarTime", "bdef_l", "be", "1=0")
	register_event("TextMsg", "bomb_pickup", "bc", "2&#Got_bomb")
	register_event("TextMsg", "bomb_drop", "bc", "2&#Game_bomb_d")
	register_event("SendAudio", "disable_c4", "a", "2&%!MRAD_terwin","2&%!MRAD_ctwin","2&%!MRAD_rounddraw")
	register_event("TextMsg","disable_c4","a","2&#Game_C","2&#Game_w") 
	register_cvar("amx_bomb_events","abcdefgh")
	return PLUGIN_CONTINUE
}

