/* AMX Mod script. 
* 
* (c) Copyright 2002, OLO, Adapted by Rav
* This file is provided as is (no warranties).
*
* MENU OPTIONS AFTER TK:
*
* 1. Kill Now
* 2. Slap with 50hp
* 3. Punish Next Round
* 4. Reduce Health to 35hp
* 5. Bury Killer
* 6. Glow Killer
* 7. Make Timebomb
* 8. Give bad aim
*
* 9. Forgive TK
*
*
* Changelog: 
*
* V 1.11 - Changed glow effect
* V 1.12 - Added Timebomb
* V 1.13 - Added hud message format changed
* V 1.14 - Added Give Bad aim (option 8)
*
* Credits: 
*       
*    OLO - For writing origional tkrevenge
*    Ludwig van - For writing timebomb & slim version for this plugin
*    My dog - For needing a walk when I got stressed
* 
*/ 

#include <amxmod> 

new BOMB_FUSE = 10        // fuse time (can be changed)
new BOMBKILL_RANGE = 250  // killing radius of bomb. (96 is playerheight) 
new gMenu 
new gKillers[33] 
new gPunishMe[33] 
new light  
new smoke  
new white
new fire
new Float:ejl_ff 
new IsBomb[33]
new IsKamik[33] 
new bool:rs = false 

explode(vec1[3]){ 
   // blast circles 
   message_begin( MSG_BROADCAST,SVC_TEMPENTITY,vec1) 
   write_byte( 21 ) 
   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 ) // startframe 
   write_byte( 0 ) // framerate 
   write_byte( 2 ) // life 2
   write_byte( 20 ) // width 16 
   write_byte( 0 ) // noise 
   write_byte( 188 ) // r 
   write_byte( 220 ) // g 
   write_byte( 255 ) // b 
   write_byte( 255 ) //brightness 
   write_byte( 0 ) // speed 
   message_end() 
    
   //Explosion2 
   message_begin( MSG_BROADCAST,SVC_TEMPENTITY) 
   write_byte( 12 ) 
   write_coord(vec1[0]) 
   write_coord(vec1[1]) 
   write_coord(vec1[2])
   write_byte( 188 ) // byte (scale in 0.1's) 188 
   write_byte( 10 ) // byte (framerate) 
   message_end() 

   //TE_Explosion 
   message_begin( MSG_BROADCAST,SVC_TEMPENTITY,vec1) 
   write_byte( 3 ) 
   write_coord(vec1[0]) 
   write_coord(vec1[1]) 
   write_coord(vec1[2])
   write_short( fire ) 
   write_byte( 60 ) // byte (scale in 0.1's) 188 
   write_byte( 10 ) // byte (framerate) 
   write_byte( 0 ) // byte flags 
   message_end() 


   //Smoke 
   message_begin( MSG_BROADCAST,SVC_TEMPENTITY,vec1) 
   write_byte( 5 ) // 5
   write_coord(vec1[0]) 
   write_coord(vec1[1]) 
   write_coord(vec1[2]) 
   write_short( smoke )
   write_byte( 10 )  // 2
   write_byte( 10 )  // 10
   message_end()
 
} 

blood(vec1[3])  
{  
   //LAVASPLASH 
   message_begin( MSG_BROADCAST,SVC_TEMPENTITY)  
   write_byte( 10 )  
   write_coord(vec1[0])  
   write_coord(vec1[1])  
   write_coord(vec1[2])  
   message_end()  
}

lightning(vec1[3],vec2[3])  
{  
   //Lightning 
   message_begin( MSG_BROADCAST,SVC_TEMPENTITY)  
   write_byte( 0 )  
   write_coord(vec1[0])  
   write_coord(vec1[1])  
   write_coord(vec1[2])  
   write_coord(vec2[0])  
   write_coord(vec2[1])  
   write_coord(vec2[2])  
   write_short( light )  
   write_byte( 1 ) // framestart 
   write_byte( 5 ) // framerate 
   write_byte( 2 ) // life 
   write_byte( 20 ) // width 
   write_byte( 30 ) // noise 
   write_byte( 200 ) // r, g, b 
   write_byte( 200 ) // r, g, b 
   write_byte( 200 ) // r, g, b 
   write_byte( 200 ) // brightness 
   write_byte( 200 ) // speed 
   message_end()  

   //Sparks 
   message_begin( MSG_PVS, SVC_TEMPENTITY,vec2)  
   write_byte( 9 )  
   write_coord( vec2[0] )  
   write_coord( vec2[1] )  
   write_coord( vec2[2] )  
   message_end()  
     
}  

public timebomb_timer(){

	new hibomb = 100
	new maxpl = get_maxplayers()
	new a
	for(a = 0; a < maxpl; a++) {
		if ((IsBomb[a] != 0) && (IsBomb[a] < hibomb)){
			hibomb = a   		
		}
	}

	for(a = 1; a < maxpl; a++) {
		if (IsBomb[a] > 0){
			emit_sound(a,CHAN_ITEM, "buttons/blip2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
			if (IsBomb[a] == 1){
				blowem_up(a)   		
			}else{
				IsBomb[a] -= 1
				if (a == hibomb){ 
					new name[32]
					get_user_name(a,name,32)
					set_hudmessage(0, 100, 200, 0.05, 0.65, 2, 0.02, 1.0, 0.01, 0.1, 2)
					show_hudmessage(0,"%s will explode in %d seconds.",name,IsBomb[a])
					if (IsBomb[a] == 11){
						client_cmd(0,"spk ^"fvox/remaining^"")
					}
					if (IsBomb[a] < 11){
						new temp[48]
						num_to_word(IsBomb[a],temp,48)
						client_cmd(0,"spk ^"fvox/%s^"",temp)
					}
				}
				if(is_user_alive(a) == 0){
					blowem_up(a)
				}
			}
		}
	}
}

public blowem_up(id){ 

   new bombguyfrags 

   if(id == 100){ 
      new maxpl = get_maxplayers() 
      for(new a = 0; a < maxpl; a++) { 
         if ((IsBomb[a] > 0) || (IsKamik[a] == 1)){ 
            IsKamik[a] = 0 
            IsBomb[a] = 0 
            new name[32] 
            get_user_name(a,name,32) 
            set_user_rendering(a,kRenderFxNone,255,255,255, kRenderNormal,16); 
            set_hudmessage(0, 100, 200, 0.05, 0.65, 2, 0.02, 1.0, 0.01, 0.1, 2) 
            show_hudmessage(0,"%s has exploded.",name) 
            new origin[3]    
            get_user_origin(a,origin)  
            origin[2] = origin[2] - 26  
            user_kill(a,1) 
            explode(origin) 
         } 
      } 
   }else{ 
      if (IsBomb[id] > 0){ 
         IsBomb[id] = 0 
         IsKamik[id] = 0 
         new name[32] 
         new team[32] 
         get_user_name(id,name,32) 
         set_user_rendering(id,kRenderFxNone,255,255,255, kRenderNormal,16); 
         set_hudmessage(0, 100, 200, 0.05, 0.65, 2, 0.02, 1.0, 0.01, 0.1, 2) 
         show_hudmessage(0,"%s has exploded.",name) 
         ejl_ff = get_cvar_float("mp_friendlyfire") 
         new origin[3]    
         get_user_origin(id,origin) 
         get_user_team(id, team , 32); 
         new maxpl = get_maxplayers() 
         for(new a = 1; a < maxpl; a++) { 
            new origin1[3] 
            new team1[32]          
            get_user_origin(a,origin1) 
            get_user_team(a, team1 , 32) 
            if(is_user_alive(a) != 0){ 
               if( ! (origin[0]-origin1[0] > BOMBKILL_RANGE || origin[0]-origin1[0] < - BOMBKILL_RANGE ||  
                         origin[1]-origin1[1] > BOMBKILL_RANGE || origin[1]-origin1[1] < - BOMBKILL_RANGE || 
                         origin[2]-origin1[2] > BOMBKILL_RANGE || origin[2]-origin1[2] < - BOMBKILL_RANGE) ){ 
                  if(ejl_ff == 0){ 
                     if(!equal(team, team1, 1)){ 
                        client_print(a,print_chat,"  You were to close to the walking timebimb.") 
                        user_kill(a,1) 
                        if(a != id){ 
                           bombguyfrags = get_user_frags(id) 
                           bombguyfrags +=1 
                           set_user_frags(id,bombguyfrags) 
                        } 
                        explode(origin1)        
                     } 
                  } 
                  if(ejl_ff == 1){ 
                     if(rs == false){ 
                        client_print(a,print_chat,"  Sorry, the bomb killed you.")                          
                        user_kill(a,1) 
                        if(!equal(team, team1, 1)){ 
                           bombguyfrags = get_user_frags(id) 
                           bombguyfrags +=1 
                           set_user_frags(id,bombguyfrags) 
                        } 
                        if(a != id){ 
                           explode(origin1) 
                        } 
                     }else{ 
                        client_print(a,print_chat,"  Sorry, the bomb killed you.") 
                        if(a == id){ 
                           user_kill(a,1) 
                        } 
                     }     
                  }                      
               } 
            } 
         } 
         if(ejl_ff == 0){ 
            client_print(id,print_chat,"  Sorry, the bomb killed you.") 
            user_kill(id,1) 
         } 
         origin[2] = origin[2] - 26   
         explode(origin) 
      } 
   } 
} 


public menu_option1(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0 
		new name1[32], name2[32] 
		get_user_name(id,name1,32) 
		get_user_name(gKillers[id],name2,32)         
		client_print(0,print_chat,"%s was punished by %s for team killing",name2,name1) 
		user_kill(gKillers[id])
		new origin[3]
		get_user_origin(gKillers[id],origin)
		origin[2] = origin[2] - 26
		new sorigin[3]
		sorigin[0] = origin[0] + 150
		sorigin[1] = origin[1] + 150
		sorigin[2] = origin[2] + 400
		blood(origin)  
		explode(origin)
		emit_sound(gKillers[id],CHAN_ITEM, "weapons/headshot2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
		} 
			else 
			client_print(id,print_chat,"Too late for any action") 
	return PLUGIN_HANDLED 
} 

public menu_option2(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0     
		new name1[32], name2[32] 
		get_user_name(id,name1,32) 
		get_user_name(gKillers[id],name2,32) 
		user_slap(gKillers[id],50) 
		client_print(0,print_chat," %s slaped %s with 50hp for teamkilling",name1,name2) 
		} 
			else 
			client_print(id,print_chat," Too late for any action") 
	return PLUGIN_HANDLED 
} 

public menu_option3(id,keys){ 
	if (gPunishMe[gKillers[id]]){ 
		new name[32] 
		get_user_name(gKillers[id],name,32)         
		client_print(0,print_chat,"%s will be punished on nextround for team killing",name) 
		} 
			else 
			client_print(id,print_chat,"Too late for any action") 
	return PLUGIN_HANDLED 
} 


public menu_option4(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0     
		new name1[32], name2[32] 
		get_user_name(id,name1,32) 
		get_user_name(gKillers[id],name2,32) 
		client_print(0,print_chat,"%s reduced %s 's health for team killing",name1,name2) 
		set_user_health(gKillers[id],35)
		new origin[3]
		get_user_origin(gKillers[id],origin)
		origin[2] = origin[2] - 26
		new sorigin[3]
		sorigin[0] = origin[0] + 150
		sorigin[1] = origin[1] + 150
		sorigin[2] = origin[2] + 400
		lightning(sorigin,origin)
		emit_sound(gKillers[id],CHAN_ITEM, "ambience/thunder_clap.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
		} 
			else 
			client_print(id,print_chat,"Too late for any action") 
	return PLUGIN_HANDLED 
} 

public menu_option5(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0     
		new name1[32], name2[32] 
		get_user_name(id,name1,32) 
		get_user_name(gKillers[id],name2,32) 
		new origin[3]
		get_user_origin(gKillers[id], origin)
		origin[2] -= 30
		set_user_origin(gKillers[id], origin)
		client_print(0,print_chat,"%s burried %s for team killing",name1,name2) 
		} 
			else 
			client_print(id,print_chat,"Too late for any action") 
	return PLUGIN_HANDLED 
} 

public menu_option6(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0     
		new name1[32], name2[32] 
		get_user_name(id,name1,32) 
		get_user_name(gKillers[id],name2,32) 
		new red = random_num(50,255)  
		new green = random_num(50,255)  
		new blue = random_num(50,255)  
		set_user_rendering(gKillers[id],kRenderFxGlowShell,red,green,blue,kRenderNormal,16)
		client_print(0,print_chat,"%s has set %s glowing for team killing",name1,name2) 
	} 
			else 
			client_print(id,print_chat,"Too late for any action") 
	return PLUGIN_HANDLED 
} 

public menu_option7(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0     
		new arg[32]
		read_argv(1,arg,32)
		new player = gKillers[id]
		if (player){
		if(is_user_alive(player) == 0){
		client_print(id,print_console,"The player is dead and cannot be bombed")
		return PLUGIN_HANDLED
	}
		IsBomb[player] = BOMB_FUSE
		new name2[32]
		get_user_name(player,name2,32)
		set_user_rendering(player,kRenderFxGlowShell, 255,0,0, kRenderNormal,16)
		client_cmd(0,"spk ^"vox/warning _comma _comma detonation device activated^"")	
		client_print(0,print_chat,"%s has become a human timebomb, run for cover!!!", name2)
	}
			else{
			client_print(id,print_console,"Too late client has left the game!")
		}
	}

	return PLUGIN_HANDLED
}

public menu_option8(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0     
		new name[32] 
		get_user_name(gKillers[id],name,32) 
		set_user_hitzones(gKillers[id],0,192) 
		client_print(0,print_chat,"%s now has bad aim, punishment for teamkilling",name)
		set_hudmessage(200, 100, 0, -1.0, 0.30, 0, 6.0, 6.0, 0.5, 0.15, 1)
		show_hudmessage(gKillers[id],"You will have to shoot low, GOOD LUCK!")
	} 
	return PLUGIN_HANDLED
}

public menu_option9(id,keys){ 
	if (gPunishMe[gKillers[id]]) { 
		gPunishMe[gKillers[id]]=0     
		new name1[32], name2[32] 
		get_user_name(id,name1,32) 
		get_user_name(gKillers[id],name2,32) 
		client_print(0,print_chat,"%s forgave %s isn't that nice!",name1,name2) 
	} 
			else 
			client_print(id,print_chat,"Too late for any action") 
	return PLUGIN_HANDLED 
} 

public show_tkmenu(param[]){ 
	new szmenu[256], name[32] 
	get_user_name(param[1],name,32) 
	format(szmenu,256,"\yTK Revenge on %s^n^n\w1. Kill now!^n2. Slap with 50hp^n3. Punish Next round^n4. Reduce Health to 35hp^n5. Bury Now^n6. Glow Now^n7. Make TimeBomb (EVIL)^n8. Give bad aim^n^n9. \yForgive TK ",name) 
	show_menu(param[0],((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)),szmenu) 
} 

public death_msg(id){ 
	new killer = read_data(1) 
	new victim = read_data(2) 
	if ( killer && (killer!=victim) ) { 
	if (get_user_team(killer)==get_user_team(victim)) { 
		gKillers[victim] = killer         
		gPunishMe[killer] = 1 
		new param[2] 
		param[0] = victim 
		param[1] = killer 
		set_task(0.25,"show_tkmenu",0,param,2) 
		} 
	}
	return PLUGIN_CONTINUE 
} 

public delayed_kill(param[]){ 
	client_print(param[0],print_chat," You have been punished for killing the teammate(s)") 
	user_kill(param[0]) 
	return PLUGIN_CONTINUE 
    
} 

public damage_event()  
{ 
	new victim = read_data(0); 
	new damage = read_data(2); 
	new weapon; 
	new attacker = get_user_attacker(victim,weapon); 
	if ( attacker && (attacker!=victim) ) { 
	if (get_user_team(attacker)==get_user_team(victim)) { 
		set_user_flags(attacker,(1<<0),31) 
		gKillers[victim] = attacker 
		new name[32] 
		get_user_name(attacker,name,32) 
		set_hudmessage(140, 0, 0, 0.75, 0.50, 0, 3.0, 3.0, 0.5, 0.15, 4)  
		show_hudmessage(attacker,"STOP ATTACKING TEAMMATES^nYou might be punished!^nLast hit caused %i damage",damage) 
		show_hudmessage(victim,"TEAM ATTACK DAMAGE^n You lost %i Health",damage) 
		} 
	} 
	return PLUGIN_CONTINUE 
} 

public reset_hud(id){ 
	if (gPunishMe[id]){ 
		gPunishMe[id] = 0 
		new param[2] 
		param[0] = id 
		set_task(0.25,"delayed_kill",0,param,2) 
	} 
	return PLUGIN_CONTINUE 
} 


public client_connect(id){ 
	gPunishMe[id] = 0 
	IsBomb[id] = 0
	return PLUGIN_CONTINUE 
} 

public client_disconnect(id){ 
	gPunishMe[id] = 0 
	IsBomb[id] = 0
	return PLUGIN_CONTINUE 
} 

public reset_punishment(){ 
	for(new id=0;id<33;++id)  
        gPunishMe[id] = 0 
	return PLUGIN_CONTINUE         
}

public plugin_precache()
{
	light = precache_model("sprites/lgtning.spr")
	precache_sound( "ambience/thunder_clap.wav")
	precache_sound( "weapons/headshot2.wav")
	smoke = precache_model("sprites/steam1.spr") 
        white = precache_model("sprites/white.spr")
        fire = precache_model("sprites/explode1.spr")
        precache_sound( "buttons/blip2.wav")
	return PLUGIN_CONTINUE
}

public plugin_init(){ 
	register_plugin("tkrevenge extra","1.14","RVS") 
	gMenu = register_menuid("TK Revenge") 
	register_menucmd(gMenu,(1<<0),"menu_option1") 
	register_menucmd(gMenu,(1<<1),"menu_option2") 
	register_menucmd(gMenu,(1<<2),"menu_option3")     
	register_menucmd(gMenu,(1<<3),"menu_option4") 
	register_menucmd(gMenu,(1<<4),"menu_option5") 
	register_menucmd(gMenu,(1<<5),"menu_option6")
	register_menucmd(gMenu,(1<<6),"menu_option7")
	register_menucmd(gMenu,(1<<7),"menu_option8")
	register_menucmd(gMenu,(1<<8),"menu_option9")
	register_event("TextMsg","reset_punishment","a","2&#Game_C","2&#Game_w") 
	register_event("Damage", "damage_event", "b", "2!0");
	register_event("ResetHUD","reset_hud","b") 
	register_event("DeathMsg","death_msg","a")
	set_task(1.0,"timebomb_timer",0,"",0,"a", 9999)
	set_cvar_float("mp_t",0.0) 
	register_cvar("RVS_TKRevenge", "1.14",FCVAR_SERVER)
	return PLUGIN_CONTINUE
} 


