/***************************************************************************
 * plugin_ejl_sank_dice.sma                               Date: 10/26/2002
 * See Below for the real credits: thanks once again to Luke Sankey
 *  Modified to be even more fun by:
 *   Eric Lidman           ejlmozart@hotmail.com
 *   Alias: Ludwig van     Upgrade: http://lidmanmusic.com/cs/plugins.html 
 *
 * Eric's changes are as follows:
 * 
 * Added "ZeusMode" (godmode and noclip combined)
 * Winners of ZeusMode, GodMode, and Noclip will now glow too 
 * Replaced Slay with human time-bomb -- need   admin_fx 1   in adminmod.cfg
 *  Timebomb player can kill bystanders
 * Replaced Slap with slap disease  -- possibly fatal
 * Enhanced Glow by having it potentially affect health  
 * To Stuck I added a slap at the beginning -- looks funnier
 * Dead players cant gamble.
 *
 * Rolls have changed from below, no need to go into detail.
 *
 * Modified by Eric to be sensitive to the friendlyfire cvar. This way if
 *  FF is off, you dont blow up your teamates. This plugin was designed for
 *  Counter-Strike. With the change to use the CS specific mp_friendlyfire
 *  cvar, I dont know if this will work with mods like TFC or others now.
 *  If it does, let me know. I already know that the C4 timer sound and
 *  part of the explosion sound will only be heard in CS.
 * 
 * Modified 3-30-02 by author to have a delay at round start for kamikazi
 *  runs. Also, within the first 10 seconds of roun start, the bomb will 
 *  only kill the bomber and no bystanders. LOGD is required to make these
 *  changes work. http://logd.sourceforge.net/
 *  Once you get LogD, find and change this one line in my script:
 *
 *   #define use_logd 1 // 0=no  1=yes
 *
 *  By default use_logd is set to 0 to make it comapatible for all users.
 *
 * Make sure you have these in your adminmod.cfg:
 *  admin_fx 1
 *  allow_client_exec 1
 * Adminmod has them both set to 0 by default, just change them to 1
 *
 **************************************************************************/
 
/***************************************************************************
 * plugin_sank_dice.sma
 * Author: Luke Sankey
 * Date November 27, 2001
 * Last Modified: December 4, 2001
 *
 * Fuctionality of this plugin:
 * It is a fun plugin to play dice. Users may gamble when admin_dice is set.
 * The sum of the numbers rolled determines what their fate is. The rewards
 * are as follows:
 *  2 or 12 Godmode
 *  3 or 11 Noclip
 *  4 or 10 Stuck
 *  5 or 9  Glow
 *  6 or 8  Slap
 *  7       Death
 *
 * My most deepest thanks goes to [SCR]Lightfoot-TA- (lightfoot_sf@yahoo.ca)
 * for he was the one who wrote the original, however buggy it may have been.
 ***************************************************************************/
 
 
/* If you have the metamod plugin LogD, this plugin takes advantage of it. */
#define use_logd 0 // 0=no  1=yes
 
 
// Functions included in this plugin
//  admin_dice <on|off>
//  say "roll the dice" or "I feel lucky"
 
// Access required to enable gambling
#define ACCESS_DICE 512
 
// Time of rewards, in seconds
#define GODMODE_TIME 15
#define NOCLIP_TIME 10
#define STUCK_TIME 10
#define GLOW_TIME 10
#define DISEASE1_TIME 6
#define DISEASE2_TIME 3
#define DISEASE3_TIME 12
#define TIMEBOMB_TIME 15
#define ZEUSMODE_TIME 20
 
// Delay required between gambling, in seconds
#define GAMBLE_DELAY 40
 
// For those with logd, time after a round start to wait before kamikaze 
#define ROUND_START_TIME 15
 
/****************************************************************************/
/****************************************************************************/
/************** DO NOT MODIFY CONTENTS BELOW THIS LINE !!! ******************/
/************** DO NOT MODIFY CONTENTS BELOW THIS LINE !!! ******************/
/************** DO NOT MODIFY CONTENTS BELOW THIS LINE !!! ******************/
/****************************************************************************/
/****************************************************************************/
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
#include <sound>
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.51";
 
// Global variables indicating if dice games are enabled or not
new bool:bGamesEnabled = true;
new bool:bIsGambling = false;
new LastGambleTime[MAX_PLAYERS+1];
 
new round_start = 0;
#define ACCESS_CONSOLE 131072
 
new iTimebomb_Timer = 0;
new BlowUpEarly = 0;
new BombCorrectGuy;
new BombGuysTeam;
new BOMBKILL_RANGE = 500;
 
/****************************************************************************/
/************************** Plugin Entry Point ******************************/
/****************************************************************************/
 
public plugin_init() 
{
	plugin_registerinfo("Roll The Dice Plugin", "Roll to win!.", STRING_VERSION);
 
	plugin_registercmd("say", "HandleSay", ACCESS_ALL);
	plugin_registercmd("admin_dice", "admin_dice", ACCESS_DICE, "admin_dice <on|off>: Turns dice games on or off.");
#if use_logd==1
	plugin_registercmd("pre_world_start_d", "pre_world_start_d", ACCESS_CONSOLE);
	plugin_registercmd("world_start_d", "world_start_d", ACCESS_CONSOLE);
	exec( "logd_reg 61 admin_command pre_world_start_d" );
	exec( "logd_reg 62 admin_command world_start_d" );
#endif
	return PLUGIN_CONTINUE;
}
 
public plugin_connect(HLUserName, HLIP, UserIndex)
{
	if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS)
		LastGambleTime[UserIndex] = 0;
 
	return PLUGIN_CONTINUE;
}
 
public plugin_disconnect(HLUserName, UserIndex) 
{
	if (UserIndex >= 1 && UserIndex <= MAX_PLAYERS)
		LastGambleTime[UserIndex] = 0;
 
	return PLUGIN_CONTINUE;
}
 
public world_start_d(HLCommand,HLData,HLUserName,UserIndex){
   if(round_start == 1){
      return PLUGIN_HANDLED;
   }  
   new Params[MAX_DATA_LENGTH];
   convert_string(HLData,Params,MAX_DATA_LENGTH);
   if(Params[6]=='S') {
      round_start = 1;
      set_timer("roundstartover", ROUND_START_TIME, 0);
   }
   return PLUGIN_HANDLED;
}
 
public pre_world_start_d(HLCommand,HLData,HLUserName,UserIndex){
   round_start = 1;
   set_timer("roundstartover", ROUND_START_TIME, 0);
   return PLUGIN_HANDLED;
}
 
public roundstartover() {
   round_start = 0;
}
 
/****************************************************************************/
/************************** User called functions ***************************/
/****************************************************************************/
 
public admin_dice(HLCommand, HLData, HLUserName, UserIndex) 
{
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	convert_string(HLData, Data, MAX_COMMAND_LENGTH);
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (check_param(Data) == 1)
	{
		bGamesEnabled = true;
		snprintf(Text, MAX_TEXT_LENGTH, "Let the games begin!");
		centersay(Text, 5, Red, Green, Blue);
	}
	else 
	{
		bGamesEnabled = false;
		snprintf(Text, MAX_TEXT_LENGTH, "The casino is now closed.");
		centersay(Text, 5, Red, Green, Blue);
	}
 
	snprintf(Text, MAX_TEXT_LENGTH, "admin_dice %d", bGamesEnabled);
	selfmessage(Text);
 
	return PLUGIN_HANDLED;
}
 
public HandleSay(HLCommand, HLData, HLUserName, UserIndex) 
{
	new Data[MAX_DATA_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new Roll;
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	new X;
	new Y;
	new Z;
 
	convert_string(HLData, Data, MAX_DATA_LENGTH);
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	// Remove quotes, if there are any
	strstripquotes(Data);
 
	if ( ((strcasecmp(Data, "roll the dice") == 0) || (strcasecmp(Data, "i feel lucky") == 0))
		&& (bGamesEnabled == true) )
	{
		new Name[MAX_NAME_LENGTH];
		new SessionID;
		new WONID;
		new AUTHID[MAX_AUTHID_LENGTH];
		new UserTeam, UserDead;
		if (playerinfo(UserIndex, Name, MAX_NAME_LENGTH, SessionID, WONID, UserTeam, UserDead, AUTHID)){
		// check to see if player is trying to gamble while dead
		if (UserDead != 0){
			messageex(User, "<Dice Dealer> Dead men roll no dice.", print_chat);
			return PLUGIN_CONTINUE;
				}
		else if (UserDead !=1){
		new CurTime = systemtime();
 
		// Limit gambling frequency
		if (CurTime < (LastGambleTime[UserIndex] + GAMBLE_DELAY))
		{
			messageex(User, "<Dice Dealer> Try later. You gambled recently, give someone else a chance.", print_chat);
			return PLUGIN_CONTINUE;
		}
		else if (bIsGambling == true)
		{
			messageex(User, "<Dice Dealer> I'm busy with someone else; please wait.", print_chat);
			return PLUGIN_CONTINUE;
		}
		else
		{
			// Roll the dice
			new Dieone = random(6);
			Dieone++;
			new Dietwo = random(6);
			Dietwo++;
 
			// Calculate the total roll
			Roll = Dieone + Dietwo;
 
			snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer> %s rolled [%d] [%d]", User, Dieone, Dietwo);
			messageex(User,Text, print_chat);
 
			if (Roll == 2) 
			{
				bIsGambling = true;
 
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer> Congratulations, %s won Godmode!", User);
				godmode(User, 1);
				glow(User, Red, Green, Blue);
				set_timer("Godmode_Timer", 1, GODMODE_TIME);
				snprintf(Text, MAX_TEXT_LENGTH, "Godmode Winner:^n%s!!", User);
				centersay(Text, 3, Red, Green, Blue);
			}
			else if (Roll == 12)
			{
			// ZeusMode is noclip, godmode, and glow all rolled into one. Loads of fun.
				bIsGambling = true;
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer> Whoa, %s won ZeusMode!!  (Godmode and Noclip together)", User);
				godmode(User, 1);
				noclip(User, 1);
				glow(User, Red, Green, Blue);
				set_timer("Zeusmode_Timer", 1, ZEUSMODE_TIME);
				snprintf(Text, MAX_TEXT_LENGTH, "ZeusMode Winner:^n%s!!", User);
				centersay(Text, 3, Red, Green, Blue);
			}
			else if (Roll == 4)
			{
				bIsGambling = true;
 
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer> Congratulations, %s won Noclip!", User);
				noclip(User, 1);
				glow(User, Red, Green, Blue);
				set_timer("Noclip_Timer", 1, NOCLIP_TIME);
				snprintf(Text, MAX_TEXT_LENGTH, "Noclip Winner:^n%s!!", User);
				centersay(Text, 3, Red, Green, Blue);
			}
			else if ((Roll == 10) || (Roll == 3))
			{
				bIsGambling = true;
 
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer> %s lost, and is stuck!", User);
				slap(User);
				get_userorigin(User, X, Y, Z);
				Z -= 40;
				teleport(User, X, Y, Z);
				set_timer("Stuck_Timer", 1, STUCK_TIME);
			}
			else if ((Roll == 5) || (Roll == 8))
			{
			// Glowing isnt enough, we need an edge to it. Its gotta be dangerous to be fun.
				bIsGambling = true;
 
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer> Nice, %s is glowing! But is glowing healthy?", User);
				glow(User, Red, Green, Blue);
				set_timer("Glow_Timer", 1, GLOW_TIME);
			}
			else if (Roll == 9)
			{
			// Slap disease. LOL. 3 different varieties
				bIsGambling = true;
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer>  %s has contracted the deadly slap disease!", User);
				slap(User);
				set_timer("Disease1_Timer", 1, DISEASE1_TIME);
			}
			else if (Roll == 6)
			{
				bIsGambling = true;
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer>  %s has contracted the deadly slap disease!", User);
				slap(User);
				set_timer("Disease2_Timer", 1, DISEASE2_TIME);
			}
			else if (Roll == 11)
			{
				bIsGambling = true;
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer>  %s has contracted the deadly slap disease!", User);
				slap(User);
				set_timer("Disease3_Timer", 1, DISEASE3_TIME);
			}
			else if (Roll == 7)
			{
			// Ahh, the timebomb.
				BombGuysTeam = UserTeam;
				BombCorrectGuy = UserIndex;
				bIsGambling = true;
				snprintf(Text, MAX_TEXT_LENGTH, "<Dice Dealer>  %s is now a human time-bomb!  Everyone RUN for cover", User);
				// set up a loop to tell all players about the bomb with half-life sounds
				new i;
				new iMaxPlayers = maxplayercount();
				for (i = 1; i <= iMaxPlayers; i++) {
					if (playerinfo(i,Name,MAX_NAME_LENGTH, SessionID, WONID, UserTeam, UserDead, AUTHID) == 1) {
   						execclient(Name, "speak ^"warning _comma detonation device activated^"");
					}
				}
				glow(User, Red, Green, Blue);
				iTimebomb_Timer = set_timer("Timebomb_Timer", 1, TIMEBOMB_TIME);	
			}
			LastGambleTime[UserIndex] = CurTime;
			say(Text);
			}
		}
		return PLUGIN_CONTINUE;
	}
}
	return PLUGIN_CONTINUE;
}
 
/****************************************************************************/
/*************************** Timer Functions ********************************/
/****************************************************************************/
 
 
public Glow_Timer(Timer, Repeat, HLUserName, HLParam)
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
	// gowing itself can be a gamble -- 9 percent chance of death
		glow(User, 0, 0, 0);
		new rand = random(11);
		switch(rand)
		{
			case 0: say ("Safely exited glow mode.");
			case 1: say ("Safely exited glow mode.");
			case 2: {
				slap(User);
				say("Ouch, glowing hurts.");
				}
			case 3: say ("Safely exited glow mode.");
			case 4: say ("Safely exited glow mode.");
			case 5: {
				slay(User);
				say("Glowing is not healthy.");
				}
			case 6: say ("Safely exited glow mode.");
			case 7: {
				slap(User);
				say("Ouch, glowing hurts.");
				}
			case 8: say ("Safely exited glow mode.");
			case 9: say ("Safely exited glow mode.");
			case 10: say ("Safely exited glow mode.");
		}
		snprintf(Text, MAX_TEXT_LENGTH, "%s is no longer glowing", User);
		bIsGambling = false;
	}
	else
	{
		glow(User, Red, Green, Blue);
		snprintf(Text, MAX_TEXT_LENGTH, "%s is glowing for %d", User, Repeat-1);
	}
 
	typesay(Text, 1, Red, Green, Blue);
}
 
public Godmode_Timer(Timer, Repeat, HLUserName, HLParam)
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
		glow(User, 0, 0, 0);
		godmode(User, 0);
		snprintf(Text, MAX_TEXT_LENGTH, "%s no longer has Godmode", User);
		bIsGambling = false;
	}
	else
	{
		glow(User, Red, Green, Blue);
		snprintf(Text, MAX_TEXT_LENGTH, "%s has Godmode for %d", User, Repeat-1);
	}
 
	typesay(Text, 1, Red, Green, Blue);
}
 
public Zeusmode_Timer(Timer, Repeat, HLUserName, HLParam)
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
		godmode(User, 0);
		noclip(User, 0);
		glow(User, 0, 0, 0);
		snprintf(Text, MAX_TEXT_LENGTH, "%s no longer has ZeusMode", User);
		bIsGambling = false;
	}
	else
	{
		glow(User, Red, Green, Blue);
		snprintf(Text, MAX_TEXT_LENGTH, "%s has ZeusMode for %d", User, Repeat-1);
	}
 
	typesay(Text, 1, Red, Green, Blue);
}
 
public Noclip_Timer(Timer, Repeat, HLUserName, HLParam) 
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
		noclip(User, 0);
		glow(User, 0, 0, 0);
		snprintf(Text, MAX_TEXT_LENGTH, "%s no longer has Noclip", User);
		bIsGambling = false;
	}
	else
	{
		glow(User, Red, Green, Blue);
		snprintf(Text, MAX_TEXT_LENGTH, "%s has Noclip for %d", User, Repeat-1);
	}
 
	typesay(Text, 1, Red, Green, Blue);
}
 
public Stuck_Timer(Timer, Repeat, HLUserName, HLParam) 
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	new X;
	new Y;
	new Z;
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
		get_userorigin(User, X, Y, Z);
		Z += 50;
		teleport(User, X, Y, Z);
		snprintf(Text, MAX_TEXT_LENGTH, "%s has been unstuck", User);
		bIsGambling = false;
	}
	else
	{
		snprintf(Text, MAX_TEXT_LENGTH, "%s has been stuck for %d", User, Repeat-1);
	}
 
	typesay(Text, 1, Red, Green, Blue);
}
 
public Disease1_Timer(Timer, Repeat, HLUserName, HLParam) 
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
		// set up the random possibility of being slayed after being slapped around
		new rand = random(2);
		switch(rand)
		{
			case 0: {
				snprintf(Text, MAX_TEXT_LENGTH, "Slap disease has left %s.", User);
				typesay(Text, 1, Red, Green, Blue);				
				say("Slap disease can be fatal sometimes.");
				bIsGambling = false;
				}
			case 1: {
				slay(User);
				snprintf(Text, MAX_TEXT_LENGTH, "Slap disease has killed %s", User);
				typesay(Text, 1, Red, Green, Blue);				
				say("Slap disease has claimed another victim.");
				bIsGambling = false;
				}
		}
	}
	else
	{
		slap(User);
		snprintf(Text, MAX_TEXT_LENGTH, "%s has slap disease for %d", User, Repeat-1);
		typesay(Text, 1, Red, Green, Blue);
	}
}
 
public Disease2_Timer(Timer, Repeat, HLUserName, HLParam) 
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
		snprintf(Text, MAX_TEXT_LENGTH, "Slap disease has left %s.", User);
		typesay(Text, 1, Red, Green, Blue);				
		say("Slap disease can be fatal sometimes.");
		bIsGambling = false;
	}
	else
	{
		slap(User);
		snprintf(Text, MAX_TEXT_LENGTH, "%s has slap disease for %d", User, Repeat-1);
		typesay(Text, 1, Red, Green, Blue);
	}
}
 
public Disease3_Timer(Timer, Repeat, HLUserName, HLParam) 
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	if (Repeat-1 == 0)
	{
		snprintf(Text, MAX_TEXT_LENGTH, "Slap disease has left %s.", User);
		typesay(Text, 1, Red, Green, Blue);				
		say("Slap disease can be fatal sometimes.");
		bIsGambling = false;
	}
	else
	{
		slap(User);
		snprintf(Text, MAX_TEXT_LENGTH, "%s has slap disease for %d", User, Repeat-1);
		typesay(Text, 1, Red, Green, Blue);
	}
}
 
 
public Timebomb_Timer(Timer, Repeat, HLUserName, HLParam) 
{
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
	new Countdown[MAX_TEXT_LENGTH];
	new i;
	new iMaxPlayers = maxplayercount();
	new Name[MAX_NAME_LENGTH];
	new COUNTSPEAK[MAX_TEXT_LENGTH];
	new C4_SOUND[MAX_TEXT_LENGTH];
	new C4_BEEP[MAX_TEXT_LENGTH];
 
	new Dead;
	new maxplayers = maxplayercount();
	new SessionID;
	new WONID;
	new Team;
	new AUTHID[MAX_AUTHID_LENGTH];
	new x,y,z;
	new X,Y,Z;
 
	new Red = random(256);
	new Green = random(256);
	new Blue = random(256);
 
	convert_string(HLUserName, User, MAX_NAME_LENGTH);
 
	// go right to the blowup part if player is dead (blowupearly=1)
	if (BlowUpEarly == 1){
		Repeat = 1;
	}
 
	if (Repeat-1 == 0){
		if (round_start == 0){
		// set up a loop to find out where everyone is. Too close to the bomb and we kill them.
			for (i=1; i<=maxplayers; i++) {
				if( playerinfo(i,Name,MAX_NAME_LENGTH,SessionID,WONID,Team,Dead,AUTHID)!=0){
					// we ignore dead players
					if(i == BombCorrectGuy){
						User = Name;
					}
					// find em --- X is bomb   x is all other players 1 at a time
					get_userorigin(User, X, Y, Z);
					get_userorigin(Name,x,y,z);
					if( ! (X-x > BOMBKILL_RANGE || X-x < - BOMBKILL_RANGE || 
					       Y-y > BOMBKILL_RANGE || Y-y < - BOMBKILL_RANGE ||
					       Z-z > BOMBKILL_RANGE || Z-z < - BOMBKILL_RANGE) ){
						if(getvar("mp_friendlyfire")==0){
							if((Dead==0) && (Team != BombGuysTeam)){
								messageex(Name, "<Server>  Sorry, the bomb killed you.", print_chat);			 
								slay(Name);
							}
						}
						if(getvar("mp_friendlyfire")==1){
							if(Dead==0){
								messageex(Name, "<Server>  Sorry, the bomb killed you.", print_chat);			 
								slay(Name);
							}
						}
					}
				}
			}
			if(getvar("mp_friendlyfire")==0){			
				slay(User);
			}
		} else {
			slay(User);
		}
		snprintf(Text, MAX_TEXT_LENGTH, "%s has exploded.", User);
		playsoundall("weapons/c4_explode1.wav");
		playsoundall("weapons/awp1.wav");
		BombCorrectGuy = 0;
		glow(User, 0, 0, 0);
		bIsGambling = false;
		BlowUpEarly = 0;
		kill_timer(iTimebomb_Timer);
	}
	else
	{
		// gotta love this countdown
		// find out if the bomb guy is dead and set blowupearly to 1 if he is dead
		// if timer is higer than 13, them only one beep per second from c4 timer 
		if (Repeat >= 13){
			for (i = 1; i <= iMaxPlayers; i++) {
				if (playerinfo(i,Name,MAX_NAME_LENGTH, SessionID, WONID, Team, Dead, AUTHID) == 1) {
					if (!strcmp(User, Name)){
						if (Dead != 0){
							BlowUpEarly = 1;
						}
					}
					// find everyone X is bomb, x is everyone else (one at a time)
					// tells who should hear the c4 timer and then makes them hear it
					get_userorigin(User, X, Y, Z);
					get_userorigin(Name,x,y,z);
					if( ! (X-x > BOMBKILL_RANGE || X-x < - BOMBKILL_RANGE || 
				   		 Y-y > BOMBKILL_RANGE || Y-y < - BOMBKILL_RANGE ||
				 	  	 Z-z > BOMBKILL_RANGE || Z-z < - BOMBKILL_RANGE) ){
						playsound(Name, "weapons/c4_beep1.wav");
					}
				}
			}
			snprintf(Text, MAX_TEXT_LENGTH, "%s will explode in %d", User, Repeat-1);
			glow(User, Red, Green, Blue);
			typesay(Text, 1, Red, Green, Blue);	
			return PLUGIN_CONTINUE;
		}
		// tell what words to say during countdown
		// set the c4 beep sound to get more intense as timer progresses
		if (Repeat == 12){
			strcpy(Countdown, "remaining", 20);
			strcpy(C4_BEEP, "weapons/c4_beep1.wav", 30);
		}
		if (Repeat == 11){
			strcpy(Countdown, "ten", 10);
			strcpy(C4_BEEP, "weapons/c4_beep1.wav", 30);
		}
		if (Repeat == 10){
			strcpy(Countdown, "nine", 10);
			strcpy(C4_BEEP, "weapons/c4_beep1.wav", 30);
		}
		if (Repeat == 9){
			strcpy(Countdown, "eight", 10);
			strcpy(C4_BEEP, "weapons/c4_beep1.wav", 30);
		}
		if (Repeat == 8){
			strcpy(Countdown, "seven", 10);
			strcpy(C4_BEEP, "weapons/c4_beep2.wav", 30);
		}
		if (Repeat == 7){
			strcpy(Countdown, "six", 10);
			strcpy(C4_BEEP, "weapons/c4_beep2.wav", 30);
		}
		if (Repeat == 6){
			strcpy(Countdown, "five", 10);
			strcpy(C4_BEEP, "weapons/c4_beep4.wav", 30);
		}
		if (Repeat == 5){
			strcpy(Countdown, "four", 10);
			strcpy(C4_BEEP, "weapons/c4_beep4.wav", 30);
		}
		if (Repeat == 4){
			strcpy(Countdown, "three", 10);
			strcpy(C4_BEEP, "weapons/c4_beep4.wav", 30);
		}
		if (Repeat == 3){
			strcpy(Countdown, "two", 10);
			strcpy(C4_BEEP, "weapons/c4_beep5.wav", 30);
		}
		if (Repeat == 2){
			strcpy(Countdown, "one", 10);
			strcpy(C4_BEEP, "weapons/c4_beep5.wav", 30);
		}
		if (Repeat == 1){
			return PLUGIN_CONTINUE;
		}
 
		snprintf(COUNTSPEAK, MAX_DATA_LENGTH, "speak ^"fvox/%s^"", Countdown);
		snprintf(C4_SOUND, MAX_DATA_LENGTH, "^"%s^"", C4_BEEP);
		// two birds with one stone in this loop
		// we speak the words to all the clients, and find out if our bomb is dead so we can
		// blow him up early and skip the rest of the countdown
		for (i = 1; i <= iMaxPlayers; i++) {
			if (playerinfo(i,Name,MAX_NAME_LENGTH, SessionID, WONID, Team, Dead, AUTHID) == 1) {
				if(i == BombCorrectGuy){
					User = Name;
				}
				if (!strcmp(User, Name)){
					if (Dead != 0){
						BlowUpEarly = 1;
					}
				}
				// find everyone X is bomb, x is everyone else (one at a time)
				// find out who should hear the c4 timer sound then make them hear it
				get_userorigin(User, X, Y, Z);
				get_userorigin(Name,x,y,z);
				if( ! (X-x > BOMBKILL_RANGE || X-x < - BOMBKILL_RANGE || 
				   Y-y > BOMBKILL_RANGE || Y-y < - BOMBKILL_RANGE ||
				   Z-z > BOMBKILL_RANGE || Z-z < - BOMBKILL_RANGE) ){
					playsound(Name, C4_SOUND);
				}
				execclient(Name, COUNTSPEAK);
			}
		}
		snprintf(Text, MAX_TEXT_LENGTH, "%s will explode in %d", User, Repeat-1);
		glow(User, Red, Green, Blue);
		typesay(Text, 1, Red, Green, Blue);	
	}
	return PLUGIN_CONTINUE;
}