
/* AMX Mod script.
*
* [SN*INFO] RoundCount Plugin for AMX 0.5 by sonic (sonic@codet.de)
*
* (c) Copyright 2002, sonic
* This file is provided as is (no warranties).
*
*/

/*  put in server.cfg:
*
*   sn_rcount_mode < flags >
*   "a" - show roundcount/map restart in hud
*   "b" - show roundcount/map restart in chat
*   "c" - show map restart
*	"d" - play sound on roundstart
*
*	set sn_rcount_mode "" to disable roundcount plugin
*
*   default sn_rcount_mode is "bcd"
*/

#include <amxmod>

new rounds = 0

public new_round() {
	new roundtime = floatround(get_cvar_float("mp_roundtime") * 60.0)
	if (roundtime == read_data(1)) {
		rounds++
		new currentmap[64]
		get_mapname(currentmap,64)
		new max_rounds = get_cvar_num("mp_maxrounds")
		new msg[128]
		if (max_rounds == 0){
			format(msg,128,"[SN*INFO] Round %i on %s",rounds,currentmap)
		} else {
			format(msg,128,"[SN*INFO] Round %i of %i on %s",rounds,max_rounds,currentmap)
		}
		new rcmode[8]
		get_cvar_string("sn_rcount_mode",rcmode,8)
		new rcmode_bit = read_flags(rcmode)

		if (rcmode_bit & 1) {
			set_hudmessage(220,80,0,0.05,0.15,0, 6.0, 12.0, 1.0, 2.0, 1)
			show_hudmessage(0,msg)
		}
		if (rcmode_bit & 2) {
			client_print(0,print_chat,msg)
		}
		if (rcmode_bit&8) {
			client_cmd(0,"spk misc/prepare")
			if (rcmode_bit&1) {
				set_hudmessage(220,80,0,-1.0,0.30,0, 6.0, 5.0, 1.0, 2.0, 2)
				show_hudmessage(0,"Prepare to FIGHT!")
			}
			if (rcmode_bit&2) {
				client_print(0,print_chat,"[SN*INFO] Prepare to FIGHT!")
			}
		}
	}
	return PLUGIN_CONTINUE
}

public new_map() {
	rounds = 0
	new currentmap[64]
	get_mapname(currentmap,64)
	new msg[128]
	format(msg,128,"[SN*INFO] Restart map %s",currentmap)

	new rcmode[8]
	get_cvar_string("sn_rcount_mode",rcmode,8)
	new rcmode_bit = read_flags(rcmode)

   	if (rcmode_bit&4 && rcmode_bit&1) {
		client_print(0,print_chat,msg)
	}
	if (rcmode_bit&4 && rcmode_bit&2) {
		set_hudmessage(220,80,0,0.05,0.15,0, 6.0, 12.0, 1.0, 2.0, 1)
		show_hudmessage(0,msg)
	}
	return PLUGIN_CONTINUE
}

public plugin_init() {
	register_plugin("SN*RoundCount","0.51","Sonic (sonic@codet.de)")
	register_event("TextMsg","new_map","ac","2&#Game_C","2&#Game_w")
	register_event("RoundTime", "new_round", "bc")
	register_cvar("sn_rcount_mode","bcd")
	return PLUGIN_CONTINUE
}

