/*================================================================================
			[ZP] EXTRA ITEM : SNIPER PACK + LASER SIGHT
				( Weapon for human, of course. )
				
				
				
Description :
Give you 4 snipers and a laser sight after you buy it.

Cvars :
zp_line 1 - If 0 it's a dot, if 1 - a line
zp_pvis 0 - If 1 only you can see your laser, if 0 everyone can see your laser.
zp_laser_red	- Red, color of laser.(default "255")
zp_laser_green	- green, color of laser.(default "0")
zp_laser_blue	- blue, color of laser.(default "0")

if you change above cvar in-game, write zp_refresh in console and push enter.
Credit :
Toaster v2.1 ( For laser sight plugin. )
MeRcyLeZZ ( For zp_extra_items_example.sma file. )
================================================================================*/

#include <amxmodx>
#include <fakemeta_util>
#include <zombieplague>

new sprite;
new ls_line, ls_pvis;
new g_sniperid;
new g_hassnipergun[33];

public plugin_init()
{
	register_plugin("[ZP] Sniper pack + Laser sight", "1.2", "Anggara_nothing");
	register_event("HLTV","new_round", "a","1=0", "2=0");
	register_forward(FM_PlayerPreThink, "show_laser");
	register_forward(FM_ClientConnect, "client_connect");
	register_forward(FM_ClientDisconnect, "client_disconnect");
	register_cvar("zp_laser_red", "255");
	register_cvar("zp_laser_green", "0");
	register_cvar("zp_laser_blue", "0");
	
	g_sniperid = zp_register_extra_item("Снайпер pack+Лазер(1 round)", 5, ZP_TEAM_HUMAN)
	ls_line = register_cvar("zp_line", "1")
	ls_pvis = register_cvar("zp_pvis", "0")
}

public plugin_precache()
{
	sprite = precache_model("sprites/white.spr")
}

// Item Selected forward
public zp_extra_item_selected(player, itemid)
{
	if (itemid == g_sniperid){
		
		g_hassnipergun[player] = 1
		
		fm_give_item(player, "weapon_scout")
		fm_give_item(player, "ammo_762nato")
		
		fm_give_item(player, "weapon_awp")
		fm_give_item(player, "ammo_338magnum")
		
		fm_give_item(player, "weapon_g3sg1")
		fm_give_item(player, "ammo_762nato")
		
		fm_give_item(player, "weapon_sg550")
		fm_give_item(player, "ammo_556nato")
	}
}

// Show laser sight
public show_laser(id)
{
	new rgb1 = get_cvar_num("zp_laser_red");
	new rgb2 = get_cvar_num("zp_laser_green");
	new rgb3 = get_cvar_num("zp_laser_blue");
	
	if(!is_user_alive(id)) 
		return PLUGIN_CONTINUE;
	
	if(!g_hassnipergun[id]) 
		return PLUGIN_CONTINUE;
		
	if(zp_get_user_zombie(id) || zp_get_user_first_zombie(id) || zp_get_user_last_zombie(id) || zp_get_user_nemesis(id))
		return PLUGIN_CONTINUE;
	
	new e[3]
	
	get_user_origin(id, e, 3)
	
	if(get_pcvar_num(ls_pvis) == 0)message_begin( MSG_BROADCAST,SVC_TEMPENTITY)
	else message_begin( MSG_ONE_UNRELIABLE,SVC_TEMPENTITY, _, id)
	
	if(get_pcvar_num(ls_line) != 0)
	{
	  write_byte (1)
	  write_short(id | 0x1000)
	  write_coord (e[0]) // write_coord = position
	  write_coord (e[1])
	  write_coord (e[2])
	}
	else
	{
	  write_byte (0)
	  write_coord (e[0] + 1)
	  write_coord (e[1] + 1)
	  write_coord (e[2] + 1)
	  write_coord (e[0] - 1)
	  write_coord (e[1] - 1)
	  write_coord (e[2] - 1)
	}
	
	write_short(sprite) // using what (sprite = .spr), (model = .mdl) and need to precache.
	write_byte (0)
	write_byte (10)     						
	write_byte (1)
	write_byte (5)   						
	write_byte (0)    
	
	write_byte (rgb1) 		// Red   | R,G,B
	write_byte (rgb2)		// Green | R,G,B
	write_byte (rgb3)		// BLUE  | R,G,B
	
	write_byte (255)     						
	write_byte (10)      						
	message_end()
	
	return PLUGIN_CONTINUE;
}

public new_round()
{
	for(new i = 0; i < 32; i++)
	{
		g_hassnipergun[i] = 0
	}
}

public client_connect(id)
{
	g_hassnipergun[id] = 0
}

public client_disconnect(id)
{
	g_hassnipergun[id] = 0
}

/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
