/*  Copyright (C) 2003 Aaron J. Drabeck                                                
                                                                                   
This program is free software; you can redistribute it and/or                      
modify it under the terms of the GNU General Public License                        
as published by the Free Software Foundation.                                      
                                                                                   
This program is distributed in the hope that it will be useful,                    
but WITHOUT ANY WARRANTY; without even the implied warranty of                     
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                      
GNU General Public License for more details.                                       
                                                                                   
You should have received a copy of the GNU General Public License                  
along with this program; if not, write to the Free Software                        
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */                       
                                              
#include <amxmod>
#include <amxmisc>

/* ADMIN_IMMUNITY Flag (amxconst.inc for more info) */
#define ATAC_IMMUNITY_LEVEL 	(1<<0)	 /* flag "a" */

//LANGUAGES 0=English(Default), 1=Francais, 2=Deutsch
#define LANGUAGE 0
#define MAX_LANGUAGES 3

/* Player Flags */
#define SETTODIE 	(1<<0) // 1
#define JAILED 		(1<<1) // 2
#define CHICKEN 	(1<<2) // 4
#define GLOWING 	(1<<3) // 8
#define BLIND 		(1<<4) // 16
#define TIMEBOMB	(1<<5) // 32
#define FIRE		(1<<6) // 64
#define DRUG		(1<<7) // 128

/* Menu Option Flags */
#define OPTION_SLAP		(1<<0)
#define OPTION_SLAPTO1		(1<<1)
#define OPTION_SLAYNR		(1<<2)
#define OPTION_JAIL		(1<<3)
#define OPTION_CHICKEN		(1<<4)
#define OPTION_BURY		(1<<5)
#define OPTION_GLOW		(1<<6)
#define OPTION_BOMB		(1<<7)
#define OPTION_BLIND		(1<<8)
#define OPTION_ROCKET		(1<<9)
#define OPTION_DROP		(1<<10)
#define OPTION_FIRE		(1<<11)
#define OPTION_DRUG		(1<<12)

/* Format: killer/victim (For use with Victim Menu) */
new TK[33][33]

/* Format: killer/victim (For use with /whotkedme) */
new TKHistory[33][33]

new PlayerFlags[33]
new TA[33]
new KickMe[33]
new r_origin[33]
new bool:taAllowed = true
new MenuPage[33]
new StoredName[33][32]

/* Chicken Variables */
new ChickenCount

/* Jail Variables */
new JailedCount
new PreJailOrigin[33][3]
new map_cors_pre
new map_cors_origin[3]

/* Time Variable */
new countdown[33]

/* Game Messages */
new gmsgHealth
new gmsgBattery
new gmsgShake
new gmsgFade
new gmsgDeathMsg
new gmsgStatusText 
new gmsgDamage
new gmsgSetFOV
new atac_tacontrol = 1

/* Saved TeamKills */
new savedtks[300][35]
new savedtkcount 
new authids[33][32]
new atac_status_off[33]

/* Sprites */
new light
new white
new smoke
new fire
new m_fireball
new mflash
new r_trail

/***********************************  LANGUAGES *********************************/
/* MESSAGE LANGUAGES */
new mg1[MAX_LANGUAGES][] = {
"[ATAC] TEAM ATTACK WARNING IMMUNE^n(Damage Inflicted: %i)",
"[ATAC] ALERTE AU ATTAQUE D'EQUIPE IMMUNISE^n(Dommage Inflige: %i)",
"[ATAC] TEAM ATTACK WARNUNG IMMUN^n(Zugefuegter Schaden: %i)"
}

new mg2[MAX_LANGUAGES][] = {
"[ATAC] %s is slayed for attacking a teammate within %i secs of a new round",
"[ATAC] %s est foudroye pour avoir TK dans les %i premieres secondes",
"[ATAC] %s wurde fuer Teamattack innerhalb der ersten %i Sek. erschlagen"
}

new mg3[MAX_LANGUAGES][] = {
"[ATAC] TEAM ATTACK WARNING: %i/%i^n(Damage Inflicted: %i)",
"[ATAC] ALERTE AU ATTAQUE D'EQUIPE: %i/%i^n(Dommage Inflige: %i)",
"[ATAC] TEAM ATTACK WARNUNG: %i/%i^n(Zugefuegter Schaden: %i)"
}

new mg4[MAX_LANGUAGES][] = {
"* [ATAC] %s has neutralized the time bomber!",
"* [ATAC] %s a neutralise le compte a rebourd!",
"* [ATAC] %s hat die Zeitbombe neutralisiert!"
}

new mg5[MAX_LANGUAGES][] = {
"* [ATAC] Sorry, you can't punish admins",
"* [ATAC] Desole, on ne peut pas punir un admin",
"* [ATAC] Entschuldige, du kannst keine Admins bestrafen"
}

new mg6[MAX_LANGUAGES][] = {
"[ATAC] You have been banned for %i mins for Team Kill Violations",
"[ATAC] Vous etes banni pour %i minutes pour TK abusif",
"[ATAC] Du wurdest wegen zu vielen TKs/TAs fuer %i min gebannt"
}

new mg7[MAX_LANGUAGES][] = {
"[ATAC] TEAM KILL VIOLATION: %i/%i for %s.^nBanning for %i mins...",
"[ATAC] TK ABUSIF: %i/%i pour %s.^nBanni pour %i minutes...",
"[ATAC] TEAM KILL VIOLATION: %i/%i von %s.^nGebannt fuer %i min..."
}

new mg8[MAX_LANGUAGES][] = {
"* [ATAC] You have been banned permanently for Team Kill Violations",
"* [ATAC] Vous etes definitivement banni pour TK abusif",
"* [ATAC] Du wurdest wegen zu vielen TKs/TAs dauerhaft gebannt"
}

new mg9[MAX_LANGUAGES][] = {
"[ATAC] TEAM KILL VIOLATION: %i/%i for %s.^nBanning permanently...",
"[ATAC] TK ABUSIF: %i/%i sur %s.^nBan definitif...",
"[ATAC] TEAM KILL VIOLATION: %i/%i von %s.^nDauerhaft gebannt..."
}

new mg10[MAX_LANGUAGES][] = {
"* [ATAC] You have been kicked for Team Kill Violations",
"* [ATAC] Vous avez ete kicke pour TK abusif",
"* [ATAC] Du wurdest wegen zu vielen TKs/TAs gekickt"
}

new mg11[MAX_LANGUAGES][] = {
"[ATAC] TEAM KILL VIOLATION: %i/%i for %s.^nKicking...",
"[ATAC] TK ABUSIF: %i/%i pour %s.^nKicke...",
"[ATAC] TEAM KILL VIOLATION: %i/%i von %s.^nKicking..."
}

new mg12[MAX_LANGUAGES][] = {
"[ATAC] TEAM KILL VIOLATION: %i/%i for %s.^nOn %i you will be banned for %i mins",
"[ATAC] ATTENTION, TK ABUSIF: %i/%i pour %s.^nA %i vous serez banni pour %i minutes",
"[ATAC] TEAM KILL VIOLATION: %i/%i von %s.^nBei %i wirst du fuer %i min gebannt"
}

new mg13[MAX_LANGUAGES][] = {
"[ATAC] TEAM KILL VIOLATION: %i/%i for %s.^nOn %i you will be banned permanently",
"[ATAC] ATTENTION, TK ABUSIF: %i/%i pour %s.^nA %i vous serez banni definitivement",
"[ATAC] TEAM KILL VIOLATION: %i/%i von %s.^nBei %i wirst du dauerhaft gebannt"
}

new mg14[MAX_LANGUAGES][] = {
"[ATAC] TEAM KILL VIOLATION: %i/%i for %s.^nOn %i you will be kicked",
"[ATAC] ATTENTION, TK ABUSIF: %i/%i pour %s.^nA %i vous serez kicke",
"[ATAC] TEAM KILL VIOLATION: %i/%i von %s.^nBei %i wirst du gekickt"
}

new mg15[MAX_LANGUAGES][] = {
"* [ATAC] %s has been turned back into a human", 
"* [ATAC] %s a repris forme humaine", 
"* [ATAC] %s wurde in eine menschliche Gestalt zurueck verwandelt"
}

new mg16[MAX_LANGUAGES][] = {
"* [ATAC] %s has served his jail sentence",
"* [ATAC] %s a purge sa peine",
"* [ATAC] %s hat seine Gefaengnisstrafe abgesessen"
}

new mg17[MAX_LANGUAGES][] = {
"* [ATAC] %s has forgiven %s",
"* [ATAC] %s a pardonne a %s",
"* [ATAC] %s hat %s vergeben"
}

new mg18[MAX_LANGUAGES][] = {
"* [ATAC] %s is a ticking Time Bomb for TKing %s",
"* [ATAC] %s est une bombe pour TKing %s",
"* [ATAC] %s wird wegen TKing %s in eine tickende Zeitbombe verwandelt"
}

new mg19[MAX_LANGUAGES][] = {
"* [ATAC] %s is being Slapped %i times for TKing %s",
"* [ATAC] %s est pris %i baffes pour TKing %s",
"* [ATAC] %s wird wegen TK an %s %i mal geschlagen"
}

new mg20[MAX_LANGUAGES][] = {
"* [ATAC] %s is blind for TKing %s",
"* [ATAC] %s est rendu aveugle pour TKing %s",
"* [ATAC] %s ist wegen TKing %s blind geworden"
}

new mg21[MAX_LANGUAGES][] = {
"* [ATAC] %s is Slapped to 1 hp for TKing %s",
"* [ATAC] %s est colle une baffe a de 1 HP pour TKing %s",
"* [ATAC] %s wird wegen TKing %s auf 1 HP geschlagen"
}

new mg22[MAX_LANGUAGES][] = {
"* [ATAC] %s is a human Rocket for TKing %s",
"* [ATAC] %s est place sur orbite pour TKing %s",
"* [ATAC] %s wird wegen TKing %s zu einer Rakete verwandelt"
}

new mg23[MAX_LANGUAGES][] = {
"* [ATAC] %s will die next round for TKing %s",
"* [ATAC] %s ne fera pas le prochain round pour TKing %s",
"* [ATAC] %s wird wegen TKing %s naechste Runde sterben"
}

new mg24[MAX_LANGUAGES][] = {
"* [ATAC] %s is being Repeatedly Dropped for TKing %s",
"* [ATAC] %s est change en yoyo pour TKing %s",
"* [ATAC] %s wird wegen TKing %s mehrmals fallen gelassen"
}

new mg25[MAX_LANGUAGES][] = {
"* [ATAC] %s is in Jail for %i secs for TKing %s",
"* [ATAC] %s est emprisonne pour %i secondes pour TKing %s",
"* [ATAC] %s ist wegen TKing %s fuer %i sec im Gefaengnis"
}

new mg26[MAX_LANGUAGES][] = {
"* [ATAC] %s is set on Fire for TKing %s",
"* [ATAC] %s est mis le feu a pour TKing %s",
"* [ATAC] %s wird wegen TKing %s in Brand gesetzt"
}

new mg27[MAX_LANGUAGES][] = {
"* [ATAC] %s is turned into a Chicken for TKing %s",
"* [ATAC] %s est change en poulet pour TKing %s",
"* [ATAC] %s wird wegen TKing %s in ein Huhn verwandelt"
}

new mg28[MAX_LANGUAGES][] = {
"* [ATAC] %s is Buried for TKing %s",
"* [ATAC] %s est enterre pour TKing %s",
"* [ATAC] %s wird wegen TKing %s begraben"
}

new mg29[MAX_LANGUAGES][] = {
"* [ATAC] %s is Glowing Pink for TKing %s",
"* [ATAC] %s est teint en rose pour TKing %s",
"* [ATAC] %s glueht wegen TKing %s rosa"
}

new mg30[MAX_LANGUAGES][] = {
"%s will explode in %i",
"%s explosera dans %i",
"%s explodiert in %i"
}

new mg31[MAX_LANGUAGES][] = {
"* [ATAC] OH! NO! %s has caught %s on fire!",
"* [ATAC] OH! NON! %s a mis le feu a %s!",
"* [ATAC] OH! NEIN! %s haelt %s ins Feuer!"
}

new mg32[MAX_LANGUAGES][] = {
"[ATAC] Team Kills: %i/%i Team Attacks: %i/%i",
"[ATAC] TK abusif: %i/%i Alerte au Attaque D'Equipe: %i/%i",
"[ATAC] Team Kills: %i/%i Team Attacks: %i/%i"
}

new mg33[MAX_LANGUAGES][] = {
"* [ATAC] Live Status is now enabled",
"* [ATAC] Live Status active",
"* [ATAC] Live Status ist jetzt eingeschaltet"
}

new mg34[MAX_LANGUAGES][] = {
"* [ATAC] Live Status is now disabled (always off use, setinfo atac_status_off 1 ) ",
"* [ATAC] Live Status desactive (pour l'avoir toujours off, utilisez, setinfo atac_status_off 1 ) ",
"* [ATAC] Live Status ist jetzt ausgeschaltet (immer aus, benutze, setinfo atac_status_off 1 )"
}

new mg35[MAX_LANGUAGES][] = {
"* [ATAC] %s is druged for TKing %s",
"* [ATAC] %s est druged pour TKing %s",
"* [ATAC] %s ist druged fur TKing %s"
}

/* MENU LANGUAGES */
new bk[MAX_LANGUAGES][] = {
"Back",
"Revenir",
"Zurueck"
}

new mo[MAX_LANGUAGES][] = {
"More",
"Plus",
"Mehr"
}

new mo1[MAX_LANGUAGES][] = {
"1. Forgive him",
"1. Lui pardonner",
"1. Vergib ihm"
}

new mo2[MAX_LANGUAGES][] = {
"2. Slap him \y%i\w times",
"2. Lui coller \y%i\w baffes",
"2. Schlage ihn \y%i\w mal"
}

new mo3[MAX_LANGUAGES][] = {
"3. Slap him to \y1\w health",
"3. Lui coller une baffe de \y1\w HP",
"3. Schlage ihn auf \y1\w HP"
}

new mo4[MAX_LANGUAGES][] = {
"4. Slay him next round",
"4. Le foudroyer au prochain round",
"4. Erschlage ihn naechste Runde"
}

new mo5[MAX_LANGUAGES][] = {
"5. Put him in Jail for \y%i\w seconds",
"5. L'emprisonner pour \y%i\w secondes",
"5. Bring ihn fuer \y%i\w Sek. ins Gefaengnis"
}

new mo6[MAX_LANGUAGES][] = {
"6. Turn him into a Chicken",
"6. Le changer en Poulet",
"6. Verwandle ihn in ein Huhn"
}

new mo7[MAX_LANGUAGES][] = {
"7. Bury him",
"7. L'enterrer",
"7. Begrabe ihn"
}
new mo8[MAX_LANGUAGES][] = {
"8. Make him Glow Pink",
"8. Le teindre en rose",
"8. Lass ihn rosa gluehen"
}

new mo11[MAX_LANGUAGES][] = {
"9. Make him a ticking Time Bomb",
"9. Lui accrocher une bombe",
"9. Verwandle ihn in eine tickende Zeitbombe"
}

new mo12[MAX_LANGUAGES][] = {
"1. Make him Blind",
"1. Le rendre aveugle",
"1. Mach ihn blind"
}

new mo13[MAX_LANGUAGES][] = {
"2. Make him a Rocket",
"2. Le placer sur orbite",
"2. Verwandle ihn in eine Rakete"
}

new mo14[MAX_LANGUAGES][] = {
"3. Drop him Repeatedly",
"3. En faire un yoyo",
"3. Lass ihn mehrmals fallen"
}

new mo15[MAX_LANGUAGES][] = {
"4. Set him on fire",
"4. Lui mettre le feu",
"4. Setze ihn in Brand"
}

new mo16[MAX_LANGUAGES][] = {
"5. Drug him",
"5. Drogue il",
"5. Droge er"
}

new mo22a[MAX_LANGUAGES][] = {
"2. Ban him for \y%i\w minutes",
"2. Le bannir pour \y%i\w minutes",
"2. Banne ihn fuer \y%i\w Minuten"
}

new mo22b[MAX_LANGUAGES][] = {
"2. Ban him permanently",
"2. Le bannir definitivement",
"2. Banne ihn dauerhaft"
}


new mo22c[MAX_LANGUAGES][] = {
"2. Kick him",
"2. kicke",
"2. Kicke ihn"
}


new cpf[MAX_LANGUAGES][] = {
"Choose Punishment for",
"Choix de la punission de",
"Waehle Bestrafung fuer"
}

/************************* PRECACHE & INIT FUNCTIONS ******************************/

public plugin_init()   
{
	register_plugin("ATAC", "2.5.3.1", "sQuad|Reset4ik")
	register_cvar("atac_version", "2.5.3.1", FCVAR_SERVER) /* For GameSpy/HLSW and such */
	server_cmd("localinfo atac_version 2.5.3.1") /* For Statsme/AMX Welcome */
	
	register_clcmd("amx_addmetk", "addmetk", ADMIN_LEVEL_A, "- lets you punish yourself")
	register_clcmd("amx_fuck", "fuck", ADMIN_LEVEL_A, "- lets you punish anybody")
	register_clcmd("say /livestatus", "say_livestatus", 0, "- toggles ATAC Live Status (lower,right corner)")
	register_clcmd("say /atacstatus", "say_atacstatus", 0, "- shows your TK/TA Violation Count")
	register_clcmd("say /whotkedme", "say_whotkedme", 0, "- shows who has tked you")
	
	register_menucmd(register_menuid("[ATAC] Menu"), 1023, "action_atac_menu")	
	
	gmsgStatusText = get_user_msgid("StatusText")
	gmsgDamage = get_user_msgid("Damage")
	gmsgDeathMsg = get_user_msgid("DeathMsg")
	gmsgHealth = get_user_msgid("Health")  
	gmsgBattery = get_user_msgid("Battery")  
	gmsgShake = get_user_msgid("ScreenShake") 
	gmsgFade = get_user_msgid("ScreenFade") 
	gmsgSetFOV = get_user_msgid("SetFOV") 
	
	register_event("ScreenFade", "event_screen_fade", "b")
	register_event("ResetHUD", "update_stat_text", "b")
	register_event("DeathMsg", "event_Death", "a")
	register_event("Damage", "event_Damage", "b", "2!0", "3=0", "4!0")
	register_event("RoundTime", "event_RoundTime", "bc")
	register_event("SetFOV", "event_SetFOV", "be", "1<91")
	
	register_cvar("atac_menu", "1")
	register_cvar("atac_options", "8191")	
	register_cvar("atac_slap_freq", "0.25")
	register_cvar("atac_slap_amount", "10")
	register_cvar("atac_slap_power", "5")
	register_cvar("atac_jail_time", "45.0")
	register_cvar("atac_bomb_mode", "1")
	register_cvar("atac_bomb_range", "1000")
	register_cvar("atac_fire_mode", "1")
	
	register_cvar("atac_ta_slap", "1")
	register_cvar("atac_bantime", "120")
	register_cvar("atac_banvia", "1")
	register_cvar("atac_tk_before_ban", "3")
	register_cvar("atac_handlenames", "1")
	register_cvar("atac_tacontrol", "1")
	register_cvar("atac_tanotallowedfor", "5")
	register_cvar("atac_slayonmaxtas", "1")
	register_cvar("atac_ta_equal_v", "5")		
	register_cvar("atac_ta_mirrordmg", "1")
	register_cvar("atac_ta_restore", "1")
	register_cvar("atac_tkcontrol", "1")
	register_cvar("atac_admins_immune", "1")
	register_cvar("atac_savetks", "1")
	register_cvar("atac_status", "1")
	
	server_cmd("exec addons/amx/plugins/atac/atac.cfg")
	server_cmd("mp_tkpunish 0")
	server_cmd("mp_autokick 0")
		
	map_cors_pre = map_cors_present(map_cors_origin) /* check if that map has coordinates */	
}

public plugin_precache()   
{
	m_fireball = precache_model("sprites/zerogxplode.spr")
	mflash = precache_model("sprites/muzzleflash.spr")
	r_trail = precache_model("sprites/smoke.spr")
	light = precache_model("sprites/lgtning.spr")
	smoke = precache_model("sprites/steam1.spr")
	white = precache_model("sprites/white.spr")
	fire = precache_model("sprites/xfireball3.spr")

	precache_sound("ambience/thunder_clap.wav")
	precache_sound("misc/chicken0.wav")
	precache_sound("ambience/flameburst1.wav")
	precache_sound("scientist/scream21.wav")
	precache_sound("scientist/scream07.wav")
	precache_sound("weapons/rocketfire1.wav")
	precache_sound("weapons/rocket1.wav")		
}

/***********************************  TA FUNCTION *********************************/
public event_Damage(vIndex)
{
	if(!atac_tacontrol) 
		return PLUGIN_CONTINUE

	new aIndex = get_user_attacker(vIndex)

	if(!aIndex) 
		return PLUGIN_CONTINUE

	new aTeam = get_user_team(aIndex)
	new vTeam = get_user_team(vIndex)

	if(aTeam != vTeam || vIndex == aIndex) 
		return PLUGIN_CONTINUE

	new damage = read_data(2)

	// Set TA hud msg format
	if(aTeam == 1) 
		set_hudmessage(140, 0, 0, 0.75, 0.50, 2, 0.1, 4.0, 0.02, 0.02, 9)
	else if(aTeam == 2) 
		set_hudmessage(0, 100, 200, 0.75, 0.50, 2, 0.1, 4.0, 0.02, 0.02, 9)

	// Immunity Check
	if((get_user_flags(aIndex) & ATAC_IMMUNITY_LEVEL) && get_cvar_num("atac_admins_immune"))
	{
		show_hudmessage(aIndex, mg1[LANGUAGE], damage)
		return PLUGIN_CONTINUE
	}
	if(!taAllowed) 
	{
		if(get_cvar_num("atac_tanotallowedfor"))
		{
			new aName[32]
			get_user_name(aIndex, aName, 31)
			
			// Set TK hud msg format
			if(aTeam == 1) 
				set_hudmessage(140, 0, 0, 0.05, 0.50, 2, 0.1, 4.0, 0.02, 0.02, 10)
			else if(aTeam == 2) 
				set_hudmessage(0, 100, 200, 0.05, 0.50, 2, 0.1, 4.0, 0.02, 0.02, 10)
			show_hudmessage(0, mg2[LANGUAGE], aName, get_cvar_num("atac_tanotallowedfor"))
			slay(aIndex, 1)
		}
	}
	else
	{
		// Increase attackers TA by index
		TA[aIndex]++	
				
		new atac_ta_equal_v = get_cvar_num("atac_ta_equal_v")

		show_hudmessage(aIndex, mg3[LANGUAGE], TA[aIndex], atac_ta_equal_v, damage)
		// Slap bit 
		if(get_cvar_num("atac_ta_slap")) 
			user_slap(aIndex, 0)
		// Mirror Damage bit 
		if(get_cvar_num("atac_ta_mirrordmg"))   
		{
			new aHeath = get_user_health(aIndex)
			if(damage >= aHeath) 
				set_user_health(aIndex, 1)
			else 
				set_user_health(aIndex, aHeath - damage)
		}
		// Restore bit 
		if(get_cvar_num("atac_ta_restore") && is_user_alive(vIndex)) 
			set_user_health(vIndex, get_user_health(vIndex) + damage)	
		// Check for last warning 
		if(TA[aIndex] == atac_ta_equal_v)   
		{ 
			// If TA is equal to get_cvar_num("atac_ta_equal_v") then treat it as tk (add 1 TK point)
			KickMe[aIndex]++
			check_v(aIndex)
			// Reset TA count
			TA[aIndex] = 0					
			if(get_cvar_num("atac_slayonmaxtas")) 
				slay(aIndex, 1)
		}
		update_stat_text(aIndex)
	}
	return PLUGIN_CONTINUE
}

/**********************************  TK FUNCTIONS *********************************/
public event_Death(id)
{		
	if(get_cvar_num("atac_tkcontrol"))   
	{
		new kIndex = read_data(1)
		new vIndex = read_data(2)
		if(PlayerFlags[vIndex] & TIMEBOMB)   
		{
			new users[32], inum, kName[32]
			get_players(users, inum, "c")
			get_user_name(kIndex, kName, 31)			
			client_print(0, 3, mg4[LANGUAGE], kName)
			PlayerFlags[vIndex] -= TIMEBOMB
		}
		if(PlayerFlags[vIndex] & FIRE)   
		{
			emit_sound(kIndex, CHAN_AUTO, "scientist/scream21.wav", 1.0, ATTN_NORM, 0, PITCH_HIGH)
			PlayerFlags[vIndex] -= FIRE
		}
		if(kIndex && kIndex != vIndex)
		{
			if(get_user_team(kIndex) == get_user_team(vIndex)) // Check indexes of teams
			{
				if( get_cvar_num("atac_admins_immune") && (get_user_flags(kIndex) & ATAC_IMMUNITY_LEVEL))
				{
					// If you can't punish admins display this
					client_print(vIndex, 3, mg5[LANGUAGE])
				}
				else
				{
					// Store who killed who for history
					TKHistory[kIndex][vIndex]++
					if(get_cvar_num("atac_menu"))  
					{
						TK[kIndex][vIndex]++ 
						// Check to see if someone needs the menu sent to them
						if(KickMe[kIndex] >= get_cvar_num("atac_tk_before_ban") - 1)  {
							MenuPage[vIndex] = 3 //Ban Menu
							show_atac_menu(kIndex, vIndex)				
						}			
						else   { 
							MenuPage[vIndex] = 1 
							show_atac_menu(kIndex, vIndex)
						}
					}
					else
					{
						KickMe[kIndex]++
						check_v(kIndex)
					}						
					update_stat_text(kIndex)						
				}
			}
		}
	}
	return PLUGIN_CONTINUE
}

find_killer(vIndex)
{
	// Get Killer (if more than one killer, handle last one in array order first)
	new kIndex = 0, maxplayers = get_maxplayers()
	for(new k = 1; k <= maxplayers; ++k)   {
		if(TK[k][vIndex] > 0) 
			kIndex = k
	}
	return kIndex
}

/********************************  CHECK TK FUNCTION *******************************/
check_v(kIndex) 
{
	if(!is_user_connected(kIndex)) 
		return PLUGIN_CONTINUE

	// Check to see if player has any TK's left then ban or warn
	new kName[32]
	new kAuthid[32]
	new kIP[32]
	new Date[64]
	new BanInfo[256]
	get_user_name(kIndex, kName, 31)
	get_user_authid(kIndex, kAuthid, 31)
	get_user_ip(kIndex, kIP, 31, 1)
	get_time("%m/%d/%y %H:%M:%S", Date, 63)

	// Set TK hud msg format 
	if(get_user_team(kIndex) == 1) 
		set_hudmessage(140, 0, 0, 0.05, 0.50, 2, 0.1, 4.0, 0.02, 0.02, 10)
	else if(get_user_team(kIndex) == 2) 
		set_hudmessage(0, 100, 200, 0.05, 0.50, 2, 0.1, 4.0, 0.02, 0.02, 10)

	new atac_tk_before_ban = get_cvar_num("atac_tk_before_ban")
	new atac_banvia = get_cvar_num("atac_banvia")
	new atac_bantime = get_cvar_num("atac_bantime")
	
	update_stat_text(kIndex)
		
	// Check if user needs to be banned
	if(KickMe[kIndex] >= atac_tk_before_ban) 
	{
		new userid = get_user_userid(kIndex) 		
		if( atac_banvia == 1 || atac_banvia == 2 ) 
		{
			if(atac_bantime)
			{
				client_print(kIndex, 1, mg6[LANGUAGE], atac_bantime)	
				show_hudmessage(0, mg7[LANGUAGE], KickMe[kIndex], atac_tk_before_ban, kName, atac_bantime)
				format(BanInfo, 255, "L %s - ^"%s<%s><%s>^" ^"Team Kill Violations: %i of %i banned for %i min^"", Date, kName, kIP, kAuthid,KickMe[kIndex], atac_tk_before_ban, atac_bantime)
			}
			else
			{
				client_print(kIndex, 1, mg8[LANGUAGE])	
				show_hudmessage(0, mg9[LANGUAGE], KickMe[kIndex], atac_tk_before_ban, kName)
				format(BanInfo, 255, "L %s - ^"%s<%s><%s>^" ^"Team Kill Violations: %i of %i banned permanently^"", Date, kName, kIP, kAuthid,KickMe[kIndex], atac_tk_before_ban)	
			}
			//Reomved due to steam equal("4294967295", kAuthid) 
			if( atac_banvia == 2 ) // If LAN or IP ban via IP
				server_cmd("addip %i %s;writeip;kick #%d", atac_bantime, kIP, userid)
			else 	
				server_cmd("banid %i #%d kick;writeid", atac_bantime, userid)
		} 
		else if( atac_banvia == 3 )
		{
			client_print(kIndex, 1, mg10[LANGUAGE])	
			show_hudmessage(0, mg11[LANGUAGE], KickMe[kIndex], atac_tk_before_ban, kName)
			format(BanInfo, 255, "L %s - ^"%s<%s><%s>^" ^"Team Kill Violations: %i of %i kicked from server^"", Date, kName, kIP, kAuthid, KickMe[kIndex], atac_tk_before_ban)
			server_cmd("kick #%d", userid)
		}
		write_file("addons/amx/plugins/atac/atacban.log", BanInfo, -1)
	} 
	else
	{
		if( atac_banvia == 1 || atac_banvia == 2)
		{
			if(atac_bantime)  	
				show_hudmessage(0, mg12[LANGUAGE], KickMe[kIndex], atac_tk_before_ban, kName, atac_tk_before_ban, atac_bantime)
			else 
				show_hudmessage(0, mg13[LANGUAGE], KickMe[kIndex], atac_tk_before_ban, kName, atac_tk_before_ban)
		}
		else if(atac_banvia == 3) 
			show_hudmessage(0, mg14[LANGUAGE], KickMe[kIndex], atac_tk_before_ban, kName, atac_tk_before_ban)	
		
	}
	
	return PLUGIN_CONTINUE
}

/*******************************  START ROUND FUNCTIONS ****************************/
public preround_start()
{
	new atac_handlenames = get_cvar_num("atac_handlenames")
	new maxplayers = get_maxplayers()
	for(new j = 1; j <= maxplayers; ++j)
	{
		if(PlayerFlags[j] & SETTODIE)
		{
			slay(j, 1)
			PlayerFlags[j] -= SETTODIE
		} 
		if(PlayerFlags[j] & CHICKEN) 
		{
			if( atac_handlenames ) 
				set_user_info(j, "name", StoredName[j])
			server_cmd("c_unchicken # %i", j)
			new name[32]
			get_user_info(j, "name",name, 31)
			client_print(0, 3, mg15[LANGUAGE], name) 
			PlayerFlags[j] -= CHICKEN
			ChickenCount--
		}
		if(PlayerFlags[j] & JAILED) 
		{
			if( atac_handlenames ) 
				set_user_info(j, "name", StoredName[j])
			new name[32]
			get_user_info(j, "name",name, 31)
			client_print(0, 3, mg16[LANGUAGE], name) 
			PlayerFlags[j] -= JAILED
			JailedCount--
		}
		if(PlayerFlags[j] & GLOWING)
		{
			set_user_rendering(j, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 255)
			PlayerFlags[j] -= GLOWING
		}
		if(PlayerFlags[j] & BLIND) 
			PlayerFlags[j] -= BLIND
		if((PlayerFlags[j] & DRUG)) 
		{
			PlayerFlags[j] -= DRUG
			message_begin(MSG_ONE, gmsgSetFOV, {0,0,0}, j)
			write_byte(90)
			message_end()
		}
	}
}

public event_RoundTime()
{
	new Float:roundtime = get_cvar_float("mp_roundtime") * 60.0
	new rtime = read_data(1) 
	
	// Round Start at start of freeze time
	if(get_cvar_num("mp_freezetime") == rtime)   
	{
		set_task(0.3, "preround_start")
		new maxplayers = get_maxplayers()
		for(new i = 1; i <= maxplayers; ++i) 
			TA[i] = 0
	}
	// Round Start after freezetime
	else if(roundtime == rtime)
	{
		new Float:tanot = get_cvar_float("atac_tanotallowedfor")
		if(tanot)
		{
			// Set timer for TA within x seconds get slayed
			taAllowed = false
			set_task(tanot, "ta_NA_timer")	
		}
		atac_tacontrol = get_cvar_num("atac_tacontrol")
	}
}

public ta_NA_timer() 
	taAllowed = true


/********************************  MENU FUNCTIONS *********************************/
show_atac_menu(kIndex, vIndex)   
{
	new menuoption[10][64]
	new menu[8]
	new keys = (1<<0)
	new atac_options = get_cvar_num("atac_options")
	// Clear string
	for(new z = 0; z < 10; ++z) 
		menuoption[z][0] = 0

	switch(MenuPage[vIndex])  
	{
		case 1:		/* PAGE 1*/
		{
			copy(menu, 7, "1/2")
			format(menuoption[0], 63, mo1[LANGUAGE])
			if(atac_options & OPTION_SLAP)
			{
				keys |= (1<<1)	
				format(menuoption[1], 63, mo2[LANGUAGE], get_cvar_num("atac_slap_amount"))
			}
			if(atac_options & OPTION_SLAPTO1)
			{
				keys |= (1<<2)
				format(menuoption[2], 63, mo3[LANGUAGE])
			}
			if(atac_options & OPTION_SLAYNR)
			{
				keys |= (1<<3)
				format(menuoption[3], 63, mo4[LANGUAGE])
			}
			if(atac_options & OPTION_JAIL  && map_cors_pre)
			{
				keys |= (1<<4)
				format(menuoption[4], 63, mo5[LANGUAGE], get_cvar_num("atac_jail_time"))
			}
			if(atac_options & OPTION_CHICKEN && cvar_exists("chicken_version"))
			{
				keys |= (1<<5)
				format(menuoption[5], 63, mo6[LANGUAGE])   
			}
			if(atac_options & OPTION_BURY )
			{
				keys |= (1<<6)
				format(menuoption[6], 63, mo7[LANGUAGE])
			}
			if(atac_options & OPTION_GLOW)   
			{
				keys |= (1<<7)
				format(menuoption[7], 63, mo8[LANGUAGE])
			}
			if(atac_options & OPTION_BOMB)
			{
				keys |= (1<<8)
				format(menuoption[8], 63, mo11[LANGUAGE])
			}
			keys |= (1<<9)
			format(menuoption[9], 63, "0. %s", mo[LANGUAGE])
		}
		case 2:		/* PAGE 2*/
		{
			copy(menu, 7, "2/2")
			if(atac_options & OPTION_BLIND)
			{
				keys |= (1<<0)
				format(menuoption[0], 63, mo12[LANGUAGE])
			}
			if(atac_options & OPTION_ROCKET)
			{
				keys |= (1<<1)
				format(menuoption[1], 63, mo13[LANGUAGE])
			}	
			if(atac_options & OPTION_DROP)
			{
				keys |= (1<<2)	
				format(menuoption[2], 63, mo14[LANGUAGE])
			}
			if(atac_options & OPTION_FIRE)
			{
				keys |= (1<<3)
				format(menuoption[3], 63, mo15[LANGUAGE])
			}
			if(atac_options & OPTION_DRUG)
			{
				keys |= (1<<4)
				format(menuoption[4], 63, mo16[LANGUAGE])
			}
			keys |= (1<<9)
			format(menuoption[9], 63, "0. %s", bk[LANGUAGE])
		}
		case 3:		/* PAGE 3 BAN/KICK MENU */
		{
			new atac_bantime = get_cvar_num("atac_bantime")	
			keys |= (1<<1)
			copy(menu, 7, "Final")
			format(menuoption[0], 63, mo1[LANGUAGE])
			if(get_cvar_num("atac_banvia") == 1 || get_cvar_num("atac_banvia") == 2)   
				atac_bantime ? format(menuoption[1], 63, mo22a[LANGUAGE], atac_bantime) : format(menuoption[1], 63, "2. %s", mo22b[LANGUAGE])		
			else 
				format(menuoption[1], 63, "2. %s", mo22c[LANGUAGE])
		}
	}
	new kName[32], menubody[512]
	get_user_name(kIndex, kName, 31)
	format(menubody, 511, "\d[ATAC] Menu %s:\w^n%s \r%s^n^n\w%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n%s^n^n%s",
		menu, cpf[LANGUAGE], kName, menuoption[0], menuoption[1], menuoption[2], menuoption[3], menuoption[4], menuoption[5], menuoption[6], menuoption[7], menuoption[8], menuoption[9])
	
	show_menu(vIndex, keys, menubody)
	return PLUGIN_HANDLED
}

menu_check(vIndex)
{
	new maxplayers = get_maxplayers()
	for(new k = 1; k <= maxplayers; ++k)   
	{
		if(TK[k][vIndex] > 0)   
		{
			MenuPage[vIndex] = 1
			show_atac_menu(k, vIndex)
			return PLUGIN_CONTINUE
		}
	}
	return PLUGIN_CONTINUE
}

public action_atac_menu(vIndex, key)   
{
	new kIndex = find_killer(vIndex)
	
	new vName[32], kName[32]
	get_user_name(vIndex, vName, 31)
	get_user_name(kIndex, kName, 31)
		
	if(MenuPage[vIndex] == 1)
	{
		switch(key)  
		{
			case 0: /* Option Forgive */
			{
				TK[kIndex][vIndex]--
				menu_check(vIndex)
				client_print(0, 3, mg17[LANGUAGE], vName, kName)
				return PLUGIN_HANDLED
			}
			case 1: /* Option Slap */
			{
				client_print(0, 3, mg19[LANGUAGE], kName, get_cvar_num("atac_slap_amount"), vName)
				SlapXTimes(kIndex)
			}
			case 2: /* Option Slap to 1hp */
			{
				client_print(0, 3, mg21[LANGUAGE], kName, vName)
				SlapTo1(kIndex)
			}
			case 3: /* Option Slay Next Round */
			{
				client_print(0, 3, mg23[LANGUAGE], kName, vName)
				SlayNextRound(kIndex)
			}
			case 4: /* Option Jail */
			{
				client_print(0, 3, mg25[LANGUAGE], kName, get_cvar_num("atac_jail_time"), vName)
				Jail(kIndex)
			}
			case 5: /* Option Chicken */
			{
				client_print(0, 3, mg27[LANGUAGE], kName, vName)
				Chicken(kIndex)							
			}
			case 6: /* Option Bury */
			{
				client_print(0, 3, mg28[LANGUAGE],  kName, vName)
				Bury(kIndex)
			}
			case 7: /* Option Glow */
			{
				client_print(0, 3, mg29[LANGUAGE], kName, vName)
				Glow(kIndex)
			}	
			case 8: /* Option Bomb */
			{
				client_print(0, 3, mg18[LANGUAGE], kName, vName)
				TimeBomb(kIndex)
			}
			case 9: /* Option More...*/
			{
				MenuPage[vIndex]++
				show_atac_menu(kIndex, vIndex) 
				return PLUGIN_HANDLED
			}
		}
	}
	else if(MenuPage[vIndex] == 2)
	{
		switch(key)  
		{
			case 0: /* Option Blind */
			{
				client_print(0, 3, mg20[LANGUAGE], kName, vName)  				
				Blind(kIndex)
			}
			case 1: /* Option Rocket */
			{
				client_print(0, 3, mg22[LANGUAGE], kName, vName)			
				Rocket(kIndex)
			}
			case 2: /* Option Drop */
			{
				client_print(0, 3, mg24[LANGUAGE], kName, vName)			
				Raise(kIndex)
			}
			case 3: /* Option Fire */
			{
				client_print(0, 3, mg26[LANGUAGE], kName, vName)
				Fire(kIndex)
			}
			case 4: /* Option Drug */
			{
				client_print(0, 3, mg35[LANGUAGE], kName, vName)
				Drug(kIndex)
			}
			case 9: /* Option Back... */
			{
				MenuPage[vIndex]--
				show_atac_menu(kIndex, vIndex) 
				return PLUGIN_HANDLED
			}
		}
	}
	else if(MenuPage[vIndex] == 3)
	{
		switch(key)  
		{
			case 0: /* Option Forgive */
			{
				TK[kIndex][vIndex]--
				menu_check(vIndex)
				client_print(0, 3, mg17[LANGUAGE], vName, kName)
				return PLUGIN_HANDLED
			}
			/* case 1: Option BAN/KICK */
			
		}
	}
	TK[kIndex][vIndex]--
	menu_check(vIndex)
	KickMe[kIndex]++
	check_v(kIndex)
	return PLUGIN_HANDLED
}

/**********************************  PUNISHMENTS  ********************************/

public slap(skIndex[])
{
	new kIndex = skIndex[0]
	new atac_slap_power = get_cvar_num("atac_slap_power")
	
	if(!is_user_alive(kIndex)) 
		return PLUGIN_CONTINUE 
		
	if(get_user_health(kIndex) <= atac_slap_power) 
		user_slap(kIndex, 0)
	else 
		user_slap(kIndex, atac_slap_power)
	return PLUGIN_CONTINUE
}

SlapXTimes(player)
{
	new splayer[2]
	splayer[0] = player
	
	if(is_user_alive(player))   
		set_task(get_cvar_float("atac_slap_freq"), "slap", 0, splayer, 2, "a", get_cvar_num("atac_slap_amount") - 1)
}

SlapTo1(player)
{
	if(is_user_alive(player))   
	{
		new user_heath = get_user_health(player)
		user_slap(player, user_heath - 1)
	}
}

SlayNextRound(player)
{
	if(!(PlayerFlags[player] & SETTODIE)) 
		PlayerFlags[player] += SETTODIE
}

/********************************** JAIL  *****************************/
Jail(player)
{
	if( is_user_alive(player) && !(PlayerFlags[player] & JAILED) )   
	{				
		JailedCount++
		if( get_cvar_num("atac_handlenames") ) 
		{			 
			new name[32]
			get_user_name(player, name, 31)
			StoredName[player] = name
			client_cmd(player, "name ^"Inmate #00%i^"", JailedCount)
		}
		PlayerFlags[player] += JAILED					
		DropWeapons(player)
		//Teleport
		get_user_origin(player, PreJailOrigin[player])
		PreJailOrigin[player][2] += 5
		set_user_origin(player, map_cors_origin)
		set_task(get_cvar_float("atac_jail_time"), "un_jail" ,player)
		// client_print(0, 1, "DEBUG: x:%i, y:%i, z:%i", map_cors_origin[0], map_cors_origin[1], map_cors_origin[2]) 
		
	}
}

map_cors_present(maporigin[3])
{
	if(file_exists("addons/amx/plugins/atac/atac.cor"))   
	{
		new readdata[64]
		new currentmap[32]
		get_mapname(currentmap, 31)
		new map[32], x[16], y[16], z[16], len
		for(new i = 0; i < 100 && read_file("addons/amx/plugins/atac/atac.cor", i, readdata, 63, len); ++i)
		{
			parse(readdata, map, 31, x, 15, y, 15, z, 15)
			if(equal(map, currentmap))
			{
				maporigin[0] = strtonum(x)
				maporigin[1] = strtonum(y)
				maporigin[2] = strtonum(z)
				return 1
			}
		}	
	}				
	return 0
}

public un_jail(player) 
{
	if(is_user_alive(player) && PlayerFlags[player] & JAILED)  
	{
		if(get_cvar_num("atac_handlenames")) 
			set_user_info(player, "name", StoredName[player])
		new name[32]
		get_user_info(player, "name",name, 31)
		client_print(0, 3, mg16[LANGUAGE], name) 
		set_user_origin(player, PreJailOrigin[player])
		PlayerFlags[player] -= JAILED
		JailedCount--
	}
	return PLUGIN_CONTINUE 
}

/********************************** CHICKEN  *****************************/
Chicken(player)
{
	if(is_user_alive(player)) 
	{
		if(!(PlayerFlags[player] & CHICKEN))
		{
			ChickenCount++
			emit_sound(player, CHAN_VOICE, "misc/chicken0.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
			server_cmd("c_chicken # %i", player)			
			if( get_cvar_num("atac_handlenames") ) 
			{
				new name[32]
				get_user_name(player, name, 31)
				StoredName[player] = name
				client_cmd(player, "name ^"Chicken #00%i^"", ChickenCount)
			}
			PlayerFlags[player] += CHICKEN									
		}
	}
}

/********************************** BURY  *****************************/
Bury(player)
{
	if(is_user_alive(player)) 
	{
		DropWeapons(player) 
		new origin[3]
		get_user_origin(player, origin)
		origin[2] -= 30
		set_user_origin(player, origin)
	}
}

DropWeapons(player) 
{
	//Drop Weapons
	new iwpn, iwpns[32], nwpn[32]
	get_user_weapons(player, iwpns, iwpn)
	for(new a = 0; a < iwpn; ++a)   
	{
		get_weaponname(iwpns[a], nwpn, 31)
		engclient_cmd(player, "drop", nwpn)
	}
}	

/********************************** GLOW  *****************************/
Glow(player)
{
	if(is_user_alive(player)) 
	{
		if(!(PlayerFlags[player] & GLOWING)) 
			PlayerFlags[player] += GLOWING
		set_user_rendering(player, kRenderFxGlowShell, 255, 0, 255, kRenderTransAlpha, 255)
	}
}

/********************************** TIME BOMB *****************************/
TimeBomb(player)
{
	if(!(PlayerFlags[player] & TIMEBOMB)) 
		PlayerFlags[player] += TIMEBOMB
	countdown[player] = 10
	set_task(1.0, "TimeBombLoop", player)
}

public TimeBombLoop(player)
{
	new speak[11][] = {"fire!", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"} 
	new red = random_num(0, 255)
	new green = random_num(0, 255)
	new blue = random_num(0, 255)
	new alpha = random_num(100, 255)
	new kName[32]
	new players[32], inum
	get_user_name(player, kName, 31)

	if(is_user_alive(player))   
	{
		set_hudmessage(red, green, blue, -1.0, 0.25, 0, 1.2, 1.2, 0.5, 0.15, 5)	
		if(countdown[player] > 0)   
		{
			// Glow Me 
			set_user_rendering(player, kRenderFxGlowShell, red, green, blue, kRenderTransAlpha, alpha)
			// Annouce Me
			get_players(players, inum, "c")
			for(new i = 0; i < inum; ++i)
			{
				client_cmd(players[i], "speak ^"fvox/%s^"", speak[countdown[player]])
				show_hudmessage(0, mg30[LANGUAGE], kName, countdown[player])
			}
			message_begin(MSG_ONE, gmsgHealth, {0,0,0}, player) 
			write_byte(countdown[player])
			message_end() 			
			message_begin(MSG_ONE, gmsgBattery, {0,0,0}, player) 
			write_short(countdown[player])
			message_end()
			countdown[player]--
			// Call Again
			set_task(1.0, "TimeBombLoop", player)
		}
		else   //explode
		{
			if(PlayerFlags[player] & TIMEBOMB) 
				PlayerFlags[player] -= TIMEBOMB
			set_user_rendering(player, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 255)
			get_players(players, inum, "c")
			for(new i = 0; i < inum; ++i)   
			{
				client_cmd(players[i], "speak ^"hgrunt/%s^"", speak[countdown[player]])	
				message_begin(MSG_ONE, gmsgShake, {0,0,0}, players[i]) 
				write_short(1<<14) // shake amount
				write_short(1<<14) // shake lasts this long
				write_short(1<<14) // shake noise frequency
				message_end()
			}
			// FIRE!
			show_hudmessage(0, "FIRE!", kName)
			slay(player, 3)

			// Fade to red, for bomber
			message_begin(MSG_ONE, gmsgFade, {0,0,0}, player)
			write_short(1<<15)
			write_short(1<<10)
			write_short(1<<1)  
			write_byte(100) 
			write_byte(0)
			write_byte(0)
			write_byte(255)  
			message_end()
			
			if( get_cvar_num("atac_bomb_mode") )   
			{				
				get_players(players, inum, "a")
				for(new i = 0; i < inum; ++i)   
				{
					new pOrigin[3]					
					new kOrigin[3]
					get_user_origin(players[i], pOrigin)
					get_user_origin(player, kOrigin)				
					if(get_cvar_num("atac_bomb_range") > get_distance(kOrigin, pOrigin))   
					{ 
						// Death Msg
						message_begin(MSG_ALL, gmsgDeathMsg, {0,0,0}, 0)
						write_byte(player)
						write_byte(players[i])
						write_byte(0)
						write_string("ATAC Timebomb")
						message_end()
						slay(players[i], 0)
						
						// Fade to red, for everyone within bomb explosion  
						message_begin(MSG_ONE, gmsgFade, {0,0,0}, player)
						write_short(1<<15) 
						write_short(1<<10) 
						write_short(1<<1)
						write_byte(100)
						write_byte(0) 
						write_byte(0)
						write_byte(255)
						message_end()
					}
				}
			}
		}
	}
	else
		 set_user_rendering(player, kRenderFxGlowShell, 0, 0, 0, kRenderTransAlpha, 255)
}

/********************************** BLIND  *****************************/
Blind(player)
{
	if(is_user_alive(player) && !(PlayerFlags[player] & BLIND))
	{
		message_begin(MSG_ONE, gmsgFade, {0,0,0}, player) 
		write_short(1<<12) 
		write_short(1<<8)   
		write_short(1<<0) 
		write_byte(0) 
		write_byte(0)
		write_byte(0)   
		write_byte(255)   
		message_end() 
		set_task(1.0, "dely_screen_fade", player)				
		PlayerFlags[player] += BLIND
	}
}

public event_screen_fade(id) 
	set_task(0.6, "dely_screen_fade", id)

public dely_screen_fade(id) 
{
	if(PlayerFlags[id] & BLIND)   
	{
		// Blind Bit  
		message_begin(MSG_ONE, gmsgFade, {0,0,0}, id)
		write_short(1<<0)
		write_short(1<<0)
		write_short(1<<2)
		write_byte(0)
		write_byte(0)
		write_byte(0) 
		write_byte(255)  
		message_end() 
	}
}

/********************************** ROCKET  *****************************/
Rocket(player)
{
	if(is_user_alive(player))
	{
		emit_sound(player, CHAN_VOICE, "weapons/rocketfire1.wav", 1.0, 0.5, 0, PITCH_NORM)
		set_user_maxspeed(player, 1.2)
		set_task(0.7, "rocket_sfx", player)
	}
}

public rocket_sfx(player)   
{
	set_user_gravity(player, -0.50)
	client_cmd(player, "+jump;wait;wait;-jump")
	emit_sound(player, CHAN_VOICE, "weapons/rocket1.wav", 1.0, 0.5, 0, PITCH_NORM)
	rocket_rise(player)
	
	message_begin(MSG_ONE,gmsgShake, {0,0,0}, player) 
	write_short(1<<15) // shake amount
	write_short(1<<15) // shake lasts this long
	write_short(1<<15) // shake noise frequency
	message_end()
	
	// Rocket Trail
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(22) // TE_BEAMFOLLOW
	write_short(player)
	write_short(r_trail)
	write_byte(30)
	write_byte(2)
	write_byte(250)
	write_byte(250)
	write_byte(250)
	write_byte(250)
	message_end()

	return PLUGIN_CONTINUE
}

public rocket_rise(player)   
{
	new origin[3] 
	get_user_origin(player, origin)	
	draw_fire(origin)
		
	message_begin(MSG_ONE, gmsgDamage, {0,0,0}, player) 
	write_byte(30) // dmg_save
	write_byte(30) // dmg_take 
	write_long(1<<16) // visibleDamageBits 
	write_coord(origin[0]) // damageOrigin.x 
	write_coord(origin[1]) // damageOrigin.y
	write_coord(origin[2]) // damageOrigin.z 
	message_end()	

	if(r_origin[player] == origin[2])
	{
		rocket_explode(player)
		return PLUGIN_HANDLED
	}
	r_origin[player] = origin[2]
	set_task(0.2, "rocket_rise",player)
	return PLUGIN_CONTINUE
}

public rocket_explode(player)   
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(99) // TE_KILLBEAM
	write_short(player)
	message_end()
	
	if(is_user_alive(player))
		slay(player, 2)

	emit_sound(player, CHAN_VOICE, "weapons/rocket1.wav", 0.0, 0.0, (1<<5), PITCH_NORM)
	set_user_maxspeed(player, 1.0)	
	set_user_gravity(player, 1.00)

	return PLUGIN_CONTINUE
}

/********************************** DROP  *****************************/
public Raise(player)
{
	if(is_user_alive(player))   
	{
		set_user_gravity(player, -2.0)
		client_cmd(player, "+jump;wait;wait;-jump")
		set_task(0.2, "Drop", player)
	}
	else set_user_gravity(player, 1.0)
}

public Drop(player) 
{
	if(is_user_alive(player))   
	{
		set_user_gravity(player, 3.0)
		set_task(0.5, "Raise",player)
	}
	else 
		set_user_gravity(player, 1.0)
}

/********************************** FIRE  *****************************/
Fire(player)
{
	if(!(PlayerFlags[player] & FIRE))
	{
		PlayerFlags[player] += FIRE
		ignite_effects(player)
		ignite_player(player)								
	}
}

public ignite_effects(player)
{
	if(is_user_alive(player) && PlayerFlags[player] & FIRE)
	{
		new korigin[3] 
		get_user_origin(player, korigin)
		draw_fire(korigin) 
		set_task(0.2, "ignite_effects", player)	
	}
}

public ignite_player(player)   
{
	if(is_user_alive(player) && PlayerFlags[player] & FIRE)    
	{
		new korigin[3] 
		new players[32], inum = 0
		new pOrigin[3]		
		new kHeath = get_user_health(player)
		get_user_origin(player, korigin)
		
		// Create some damage
		set_user_health(player, kHeath - 5)
		message_begin(MSG_ONE, gmsgDamage, {0,0,0}, player) 
		write_byte(30) // dmg_save
		write_byte(30) // dmg_take 
		write_long(1<<21) // visibleDamageBits 
		write_coord(korigin[0]) // damageOrigin.x 
		write_coord(korigin[1]) // damageOrigin.y
		write_coord(korigin[2]) // damageOrigin.z 
		message_end()
				
		// Create some sound
		emit_sound(player, CHAN_ITEM, "ambience/flameburst1.wav", 0.6, ATTN_NORM, 0, PITCH_NORM)
				
		// Ignite Others
		if( get_cvar_num("atac_fire_mode") )    
		{		
			get_players(players, inum, "a")
			for(new i = 0; i < inum; ++i)
			{									
				get_user_origin(players[i], pOrigin)				
				if(get_distance(korigin, pOrigin) < 100)   
				{
					if(!(PlayerFlags[players[i]] & FIRE))   
					{
						new spIndex[2] 
						spIndex[0] = players[i]
						new pName[32], kName[32]					
						get_user_name(players[i], pName, 31)
						get_user_name(player, kName, 31)
						emit_sound(players[i], CHAN_WEAPON, "scientist/scream07.wav", 1.0, ATTN_NORM, 0, PITCH_HIGH)
						PlayerFlags[players[i]] += FIRE
						ignite_player(players[i])
						ignite_effects(players[i])
						get_players(players, inum, "c")
						client_print(players[i], 3, mg31[LANGUAGE], kName, pName)
					}					
				}
			}			
			players[0] = 0
			pOrigin[0] = 0					
			korigin[0] = 0		
		}
		// Call again in 1 second		
		set_task(1.0, "ignite_player", player)		
	}
}

/* FIRE SPECIAL EFFECTS */
draw_fire(vec1[3])
{
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY) 
	write_byte(17) // TE_SPRITE
	write_coord(vec1[0])
	write_coord(vec1[1])  
	write_coord(vec1[2]) 
	write_short(mflash)
	write_byte(20) 
	write_byte(200)
	message_end()
	
	// Smoke
	message_begin(MSG_BROADCAST,SVC_TEMPENTITY,vec1)
	write_byte(5) // TE_SMOKE
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_short(smoke)
	write_byte(20)
	write_byte(15)
	message_end()
	
	return PLUGIN_CONTINUE
}

/********************************  DRUG FUNCTION *********************************/
Drug(player)
{
	if(is_user_alive(player))    
	{
		if(!(PlayerFlags[player] & DRUG)) 
			PlayerFlags[player] += DRUG
	
		message_begin(MSG_ONE, gmsgSetFOV, {0,0,0}, player)
		write_byte(170)
		message_end()
	}
}

public event_SetFOV(id)
{	
	if((PlayerFlags[id] & DRUG)) 
	{
		message_begin(MSG_ONE, gmsgSetFOV, {0,0,0}, id)
		write_byte(170)
		message_end()
	}
}
	

/********************************  SLAY FUNCTIONS *********************************/
slay(player,type)
{
	if(is_user_alive(player)) 	
	{
		new origin[3]
		get_user_origin(player, origin)
		origin[2] = origin[2] - 26
		switch(type)
		{
			case 1:   
			{
				lightning(origin)
				emit_sound(player, CHAN_ITEM, "ambience/thunder_clap.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
			}
			case 2: 
				explode(origin)
			case 3: 
				fireball(origin)
		}			
		user_kill(player, 1)
	}
	return PLUGIN_CONTINUE 
}

/* SLAYING SPECIAL EFFECTS */
lightning(vec1[3])
{
	// Lightning
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(0) // TE_BEAMPOINTS
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_coord(vec1[0] + 150)
	write_coord(vec1[1] + 150)
	write_coord(vec1[2] + 400)
	write_short(light)
	write_byte(1)
	write_byte(5)
	write_byte(2)
	write_byte(20)
	write_byte(30)
	write_byte(200)
	write_byte(200)
	write_byte(200)
	write_byte(200)
	write_byte(200)
	message_end()
	
	// Sparks
	message_begin(MSG_PVS, SVC_TEMPENTITY, vec1)
	write_byte(9) // TE_SPARKS
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	message_end()
	
	// Smoke	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY, vec1)
	write_byte(5) // TE_SMOKE
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_short(smoke)
	write_byte(10) 
	write_byte(10) 
	message_end()
	
	return PLUGIN_CONTINUE
}

explode(vec1[3])   
{
	// Blast Circles
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY, vec1)
	write_byte(21) // TE_BEAMCYLINDER
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2] + 16)
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2] + 1936)
	write_short(white)
	write_byte(0)
	write_byte(0)
	write_byte(2)
	write_byte(16)
	write_byte(0)
	write_byte(188)
	write_byte(220)
	write_byte(255)
	write_byte(255)
	write_byte(0)
	message_end()

	// Explosion2
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(12) // TE_EXPLOSION2
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_byte(188)
	write_byte(10)
	message_end()
	
	// Smoke
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY, vec1)
	write_byte(5) // TE_SMOKE
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_short(smoke)
	write_byte(2) 
	write_byte(10) 
	message_end()
	
	return PLUGIN_CONTINUE
}

fireball(vec1[3])   
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY, vec1)
	write_byte(17) // TE_BEAMSPRITE
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2] +256)
	write_short(fire)
	write_byte(120)
	write_byte(255)
	message_end()

	// Implosion
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(14) // TE_IMPLOSION
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_byte(100)
	write_byte(20)
	write_byte(5)
	message_end()

	// Random Explosions
	message_begin(MSG_PVS, SVC_TEMPENTITY, vec1)
	write_byte(3) // TE_EXPLOSION
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_short(m_fireball)
	write_byte(30) 
	write_byte(12) 
	write_byte(0) // TE_EXPLFLAG_NONE
	message_end()

	// Lots of Smoke
	message_begin(MSG_PVS, SVC_TEMPENTITY, vec1)
	write_byte(5) // TE_SMOKE
	write_coord(vec1[0])
	write_coord(vec1[1])
	write_coord(vec1[2])
	write_short(smoke)
	write_byte(60) 
	write_byte(10)
	message_end()
	
	return PLUGIN_CONTINUE
}

/**********************************  STATUS FUNCTION ********************************/
public update_stat_text(id) 
{
	#if !defined NO_STEAM
	return PLUGIN_CONTINUE
	#endif
	// WarCraft 3 XP Compatibility
	if(get_cvar_num("sv_warcraft3") || !get_cvar_num("atac_status"))
		 return PLUGIN_CONTINUE
	if(is_user_bot(id) || id == 0) 
		return PLUGIN_CONTINUE
	if(atac_status_off[id]) 
		return PLUGIN_CONTINUE
			
	new status[64]
	new atac_ta_equal_v = get_cvar_num("atac_ta_equal_v")
	new atac_tk_before_ban = get_cvar_num("atac_tk_before_ban")
	format(status, 63, mg32[LANGUAGE], KickMe[id], atac_tk_before_ban, TA[id], atac_ta_equal_v)
	message_begin(MSG_ONE, gmsgStatusText, {0,0,0}, id)
	write_byte(0)
	write_string(status)
	message_end()
	
	return PLUGIN_CONTINUE
}

/***************************** CONNECTION FUNCTIONS ******************************/
#if !defined NO_STEAM
public client_authorized(id)
#else
public client_connect(id)
#endif
{
	if(!is_user_bot(id) && get_cvar_num("atac_savetks"))   
	{
		new storedauthid[32]
		new storedtk[3]
		new authid[32]
		get_user_authid(id, authid, 31)
		authids[id] = authid

		for(new x = 0; x <= savedtkcount; ++x)	
		{
			parse(savedtks[x], storedauthid, 31, storedtk, 2)
			if(equal(storedauthid, authid)) KickMe[id] = strtonum(storedtk)
		}
	}
	//Check client setinfo "atac_status_off" "value"
	new satac_status_off[3]
	get_user_info(id,"atac_status_off",satac_status_off,2)
	atac_status_off[id] = str_to_num(satac_status_off)

	return PLUGIN_CONTINUE
}
	
public client_disconnect(id)   
{
	if(!is_user_bot(id) && get_cvar_num("atac_savetks"))
	{
		new string[35] 
		new storedauthid[32]
		new storedtk[3]
		new authid[32]
		new bool:found 
		get_user_authid(id, authid, 31)
				
		// Check for auth id already stored
		for(new x = 0; x <= savedtkcount; ++x)   
		{
			parse(savedtks[x], storedauthid, 31, storedtk, 2)
			if(equal(storedauthid, authid))   
			{
				if(KickMe[id] >= get_cvar_num("atac_tk_before_ban"))   
				{
					// In Case of ban, unban and reconnect on same map
					format(string, 34, "%s 0", authids[id])
					savedtks[x] = string
				} 
				else   
				{
					format(string, 34, "%s %i", authids[id], KickMe[id])
					savedtks[x] = string
					found = true
				}
			}
			storedauthid[0] = 0
			storedtk[0] = 0
		}
		// If not stored, store
		if(!found || savedtkcount < 300)
		{
			format(string, 34, "%s %i", authids[id], KickMe[id])
			savedtks[savedtkcount] = string
			savedtkcount++			
		}
	}
	for(new i = 1; i < 33; ++i)
	{
		// If disconnecting player has been killed by anyone erase history of it
		TK[i][id] = 0
		TKHistory[i][id] = 0
		// If disconnecting player has killed anyone erase history of it
		TK[id][i] = 0
		TKHistory[id][i] = 0
	}
	StoredName[id][0] = 0
	PlayerFlags[id] = 0
	KickMe[id] = 0
	authids[id][0] = 0
	return PLUGIN_CONTINUE
}

/****************************** CLIENT/ADMIN FUNCTIONS *****************************/
public say_atacstatus(id, level, cid)
{
	client_print(id, 3, mg32[LANGUAGE], KickMe[id], get_cvar_num("atac_tk_before_ban"), TA[id], get_cvar_num("atac_ta_equal_v"))	
	return PLUGIN_HANDLED
}

public say_livestatus(id, level, cid)
{
	if(atac_status_off[id]) 
	{
		atac_status_off[id] = 0
		update_stat_text(id)
		//On
		client_print(id, 3, mg33[LANGUAGE] )			
	}
	else  
	{
		atac_status_off[id] = 1
		// Reset atac_status_off	
		message_begin(MSG_ONE, gmsgStatusText, {0,0,0}, id)
		write_byte(0)
		write_string("")
		message_end()
		
		//OFF
		client_print(id, 3, mg34[LANGUAGE] )		
	}	
	return PLUGIN_HANDLED	
}	

public say_whotkedme(id, level, cid)
{	
	// Look at all killers see if Victims Match
	new maxplayers = get_maxplayers()
	new kName[32], message[1024], entry[256]
	
	message[0] = 0
	new len = copy( message, 1023, "<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN><html><head><meta http-equiv=Content-Type content=text/html; charset=iso-8859-1></head><body><table width=100% border=1 cellpadding=0 cellspacing=0 bgcolor=#000000>      <tr>           <td><div align=center><font color=#FFFFFF><strong>TKed You</strong></font></div></td>          <td><div align=center><font color=#FFFFFF><strong>X Times</strong></font></div></td>        </tr>" )

	for(new k = 1; k <= maxplayers; ++k)
	{
		if(TKHistory[k][id] > 0) 
		{
			get_user_name(k, kName, 31)
			format(entry, 255, "<tr>       <td><div align=center><font color=#FFFFFF>%s</font></div></td>        <td><div align=center><font color=#FFFFFF>%i</font></div></td>        </tr>", kName, TKHistory[k][id])	
			len += copy( message[len], 1023 - len, entry  ) 
		}
	}
	len += copy( message[len], 1023 - len, "</table></body></html>"  ) 
	
	show_motd(id, message, "[ATAC] Who TKed Me:")
	return PLUGIN_HANDLED
}

public addmetk(id, level, cid)
{
	if(!cmd_access(id, level, cid, 1)) 	
		return PLUGIN_HANDLED 
	
	TK[id][id]++
	TKHistory[id][id]++
	
	if(KickMe[id] >= get_cvar_num("atac_tk_before_ban") - 1)    {
		MenuPage[id] = 3
		show_atac_menu(id, id)				
	}			
	else   { 
		MenuPage[id] = 1
		show_atac_menu(id, id)	
	}
		
	client_print(id, 3, "Your Flags: %i", PlayerFlags[id])
	return PLUGIN_HANDLED
}
public fuck(id, level, cid)
{
	if(!cmd_access(id, level, cid, 1)) 	
		return PLUGIN_HANDLED 
  new cmd[32] 
  read_argv(0,cmd,31)
  new voteban = equal(cmd,"amx_fuck")
  new arg[32] 
  read_argv(1,arg,31)
  new kid = cmd_target(id,arg,1)
  if (!kid) return PLUGIN_HANDLED

	TK[kid][id]++
	TKHistory[kid][id]++

	if(KickMe[id] >= get_cvar_num("atac_tk_before_ban") - 1)    {
		MenuPage[id] = 3
		show_atac_menu(kid, id)				
	}			
	else   { 
		MenuPage[id] = 1
		show_atac_menu(kid, id)	
	}
		
	client_print(id, 3, "Your Flags: %i", PlayerFlags[id])
	return PLUGIN_HANDLED
}
