/***************************************************************
	Stealth Crowbar
	Author: TaRgEt*TuRkEy - Vaughn Royko
	Version: 1.0.1
	Mod: Half-Life Deathmatch (Valve)
	Requires: AMX Mod X v1.0 
	Description:
		This plugin was originally designed for counter-
		strike by myself.
 
		This plugin allows players to enter "stealth" when
		using the crowbar. Players gain the ability to lose
		visibility, have no footstep sounds, and have third 
		person view. Most of these abilities are configurable 
		with the cvars.
	
	Thanks:
		Thanks to MMX for the invisibility code. Thanks to
		AssKicR for no footstep sounds.
		
		One Hit Knife Kills by Rabid Baboon: 
		http://amxmodx.org/forums/viewtopic.php?t=8257

		Weapon Cloak by MMX (AMX): 
		http://amxmod.net/showplugin.php?id=167518

	Cvars:
	amx_stealthvalue <0-255>
		Changes how visible you are when stealthing.
	amx_stealth3rdperson <0 or 1>
		Set to 0 if you don't want players turning to
		third person view when using crowbar.

	Commands:

	amx_stealthmatch <0 or 1>
		Switches all players to their crowbars, sets to
		darker lighting, and doesn't allow guns if users 
		try to switch to them.
	
***************************************************************/

#include  
#include  
#include 
#include 
#include 

new Title[32] = "Stealth Crowbar"
new Version[32] = "1.0.1"
new Author[16] = "TaRgEt*TuRkEy"
new stealthmode = 0

public SetVisibility(id)
{ 
	new wepi = read_data(2)
	
	BackToNorm(id)

	if(stealthmode==1)
	{
		client_cmd(id,"weapon_crowbar")
	}

	if(wepi == 1) 
	{
		if(is_user_alive(id))
		AlterAlpha(id,get_cvar_num("amx_stealthvalue"))
	} else {
		BackToNorm(id)
	}
	return PLUGIN_HANDLED
}

public BackToNorm(id)
{
	set_user_footsteps(id,0)
	set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,255)
	set_hudmessage(200, 100, 0, -2.0, 0.20, 0, 6.0, 6.0, 0.5, 0.15, 10)
	show_hudmessage(id,"")
	set_view(id, CAMERA_NONE)
}

public AlterAlpha(id,alphaVal)
{
	set_user_rendering(id,kRenderFxGlowShell,0,0,0,kRenderTransAlpha,alphaVal)
	set_hudmessage(200, 100, 0, -2.0, 0.20, 0, 6.0, 99999.0, 0.5, 0.15, 10)
	show_hudmessage(id,"      CROWBAR STEALTH MODE!")
	set_user_footsteps(id,1)
	if(get_cvar_num("amx_stealth3rdperson")==1)
	{
		set_view(id, CAMERA_3RDPERSON)
	}
}

public stealthmatch(id)
{
   	new arg[2]
   	read_argv(1,arg,1)
   	set_hudmessage(100, 125, 250, -1.0, 0.25, 0, 1.0, 5.0, 0.1, 0.2, 7)
   	if(equal(arg,"1"))
	{
   		client_cmd(id,"weapon_crowbar")
		stealthmode = 1
   		show_hudmessage(0,"Stealth Mode Engaged!")
		set_lights("e")
   	} else if(equal(arg,"0")){
		stealthmode = 0
   		show_hudmessage(0,"Stealth Mode Off!")
		set_lights("m")
   	} else {
   		console_print(id,"Usage: amx_stealthmatch 1 = 0n 0 = off")
   	}
   	return PLUGIN_CONTINUE
}


public plugin_init() 
{ 
	register_plugin(Title,Version,Author)
	register_event("CurWeapon","SetVisibility","b","1=1")
	register_concmd("amx_stealthmatch","stealthmatch",ADMIN_LEVEL_A,"- disable and enable stealth match 1 = on 0 = off")
	register_cvar("amx_stealthvalue","80")
	register_cvar("amx_stealth3rdperson","1")
	return PLUGIN_HANDLED 
}

public plugin_precache() 
{	
	//Fixes set_view bug that needs this model on map change
	precache_model("models/rpgrocket.mdl")
   	return PLUGIN_CONTINUE
}