/*
[WHO]Them's bomb countdown timer.
Ripped and stripped from bud-froggy's bombsay code to expedite release.
 
Edited by Kndroc to be complient with LogD 1.0
*/
 
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
#define ACCESS_CONSOLE 131072
new ADDON_WORDS[] = "seconds until explosion";
 
new STRING_VERSION[MAX_DATA_LENGTH] = "v1.2";
new bombdefused = 1;
 
public bt_checkplant(HLCommand,HLData,HLUserName,UserIndex)
{
	new Data[MAX_DATA_LENGTH];
	new sID[MAX_DATA_LENGTH];
 
	convert_string(HLData, Data, MAX_DATA_LENGTH);
	strbreak(Data, sID, Data, MAX_DATA_LENGTH);
 
	if(strcmp(Data, "Planted_The_Bomb") == 0)
	{
		new c4time = 45;
		new numstring[MAX_DATA_LENGTH];
		getstrvar("mp_c4timer",numstring, MAX_DATA_LENGTH);
		c4time = strtonum(numstring);
		set_timer("thirtysecstillboom", c4time - 30, 0);
		set_timer("twentysecstillboom", c4time - 20, 0);
		set_timer("tensecstillboom", c4time - 10, 0);
		set_timer("fivesecstillboom", c4time - 5, 0);
		set_timer("foursecstillboom", c4time - 4, 0);
		set_timer("threesecstillboom", c4time - 3, 0);
		set_timer("twosecstillboom", c4time - 2, 0);
		set_timer("onesecstillboom", c4time - 1, 0);
		bombdefused = 0;
 
	}
	return PLUGIN_CONTINUE;
}
 
public bt_checkdone(HLCommand,HLData,HLUserName,UserIndex)
{
	new Params[MAX_DATA_LENGTH];
	convert_string(HLData,Params,MAX_DATA_LENGTH);
	switch( Params[ 6 ] )
	{
		case 'S':
		{
			bombdefused = 1;
			return PLUGIN_CONTINUE;
		}
		case 'E':
		{
			bombdefused = 1;
			return PLUGIN_CONTINUE;
		}
	}
 
	return PLUGIN_CONTINUE;
}
 
public thirtysecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new messageout[MAX_DATA_LENGTH];
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		strcpy(messageout, "speak ^"thirty ", MAX_DATA_LENGTH);
		strcat(messageout, ADDON_WORDS, MAX_DATA_LENGTH);
		strcat(messageout, "^"", MAX_DATA_LENGTH);
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,messageout);
			}
		}
	}
}
 
public twentysecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new messageout[MAX_DATA_LENGTH];
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		strcpy(messageout, "speak ^"twenty ", MAX_DATA_LENGTH);
		strcat(messageout, ADDON_WORDS, MAX_DATA_LENGTH);
		strcat(messageout, "^"", MAX_DATA_LENGTH);
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,messageout);
			}
		}
	}
}
 
public tensecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new messageout[MAX_DATA_LENGTH];
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		strcpy(messageout, "speak ^"ten ", MAX_DATA_LENGTH);
		strcat(messageout, ADDON_WORDS, MAX_DATA_LENGTH);
		strcat(messageout, "^"", MAX_DATA_LENGTH);
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,messageout);
			}
		}
	}
}
 
public fivesecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,"speak ^"five^"");
			}
		}
	}
}
 
public foursecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,"speak ^"four^"");
			}
		}
	}
}
 
public threesecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,"speak ^"three^"");
			}
		}
	}
}
 
public twosecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,"speak ^"two^"");
			}
		}
	}
}
 
public onesecstillboom() {
	if(bombdefused == 0) {
		new i;
		new SessionID;
		new WONID;
		new Team;
		new Target[MAX_NAME_LENGTH];
		new maxplayers = maxplayercount();
		for(i=1; i<=maxplayers; i++) {
			strinit(Target);
			if(playerinfo(i,Target,MAX_NAME_LENGTH,SessionID,WONID,Team)==1) {
				execclient(Target,"speak ^"one^"");
			}
		}
		bombdefused = 1;
	}
}
 
 
public plugin_init() {
	plugin_registerinfo("Bomb Planting Timer","Just a countdown until the bomb explodes.",STRING_VERSION);
	plugin_registercmd("bt_checkplant", "bt_checkplant", ACCESS_CONSOLE);
	plugin_registercmd("bt_checkdone", "bt_checkdone", ACCESS_CONSOLE);
 
	exec( "logd_reg 60 admin_command bt_checkplant" );
	exec( "logd_reg 62 admin_command bt_checkdone" );
 
	return PLUGIN_CONTINUE;
}