CSO SHOP V0.2 (BETA) - UPDATE (MUTAT PE NATIVE!)

Pluginuri pentru modul AmxModX.

Moderators: Moderatori ajutatori, Moderatori

User avatar
dragonCSX
Membru, skill +1
Membru, skill +1
Posts: 189
Joined: 04 Feb 2017, 17:36
Detinator Steam: Da
CS Status: Web Developer / Scripting AMXX.
Detinator server CS: da
SteamID: weedakadulceata
Fond eXtream: 0
Location: Ploiesti
Contact:

06 Jan 2019, 22:52

Descriere: O tentativa de al cincelea plugin pe care il fac , este un shop cu arme CSO. Deoarece am vazut unul la rusi si era aiurea configurat , am zis sa fac ceva strict romanesc , nu vreau sa inceapa lumea ca hua , nu esti tu autor sau astea , eu doar am incercat sa il fac pentru serverul pe care il detin si zic eu a iesit destul de frumos . Am si ascuns comenzile , atunci cand cumperi o arma , nu apare si comanda in chat !

Descarcare: Resurse + Sursa


UPDATE CSO SHOP V0.2 (BETA) , a fost mutat pe native !
csx_shopcso.sma (optimizata) | Afiseaza codul
#include < amxmodx >
#include < amxmisc >
#include < cstrike >

// Declarand o constanta cu tag-ul e doar o pierdere de memorie
#define CHAT_TAG	"^x04[CSDM NEW]^x01"

// Declaram nativele
native give_dualuzi ( Player );
native give_dartpistol ( Player );
native give_ethereal ( Player );
native give_thanatos ( Player );
native give_spear ( Player );
native give_lightsaber ( Player );
native give_thunderbolt ( Player );

public plugin_init ( )
{
	register_plugin ( "CSO Shop", "0.2", "dragonCSX" );
	register_clcmd ( "say", "PlayerMenu" );
	register_clcmd ( "say_team", "PlayerMenu" );
}

public PlayerMenu ( Player )
{
	new szArg [ 32 ];
	read_args ( szArg, charsmax ( szArg ) );
	remove_quotes ( szArg );

	if ( containi ( szArg, "/shop" ) != -1 || equal ( szArg, "/shop" ) && is_user_alive ( Player ) )
		ShowPlayerWeapons ( Player );

	return szArg [ 0 ] == '/' ? PLUGIN_HANDLED : PLUGIN_CONTINUE;
}

public ShowPlayerWeapons ( Player )
{
	new szName [ 32 ], szTitle [ 128 ];
	get_user_name ( Player, szName, charsmax ( szName ) );
	formatex ( szTitle, charsmax ( szTitle ), "\w[\rCSO NST\w] Magazin Arme \rCSO^n\wBun venit [\r%s\w]", szName );

	new MenuID = menu_create ( szTitle, "MenuHandler" );

	menu_additem ( MenuID, "\wLightsaber \r[800$]" );
	menu_additem ( MenuID, "\wDart Pistol \r[1500$]" );
	menu_additem ( MenuID, "\wThanatos-11 \r[4500$]" );
	menu_additem ( MenuID, "\wEhereal Gun \r[6500$]" );
	menu_additem ( MenuID, "\wDual Uzi \r[8500$]" );
	menu_additem ( MenuID, "\wSpear Gun \r[12500$]" );
	menu_additem ( MenuID, "\wThunderbolt \r[16000$]" );

	menu_setprop ( MenuID, MPROP_EXITNAME, "\wIesire" );
	menu_setprop ( MenuID, MPROP_EXIT, MEXIT_ALL );
	menu_display ( Player, MenuID, 0 );
}

public MenuHandler ( Player, MenuID, ITEM )
{
	if ( !( ITEM == MENU_EXIT ) )
	{
		static Money;	Money = cs_get_user_money ( Player );

		switch ( ITEM )
		{
			case 0:		
			{
				if ( Money < 800 )
					ErrorShow ( Player, 800 );

				cs_set_user_money ( Player, Money - 800 );
				give_lightsaber ( Player );
				chat_color ( Player, "Ai cumparat^x04 Light Saber" );
			}

			case 1:
			{
				if ( Money < 2500 )
					ErrorShow ( Player, 2500 );

				cs_set_user_money ( Player, Money - 2500 );
				give_dartpistol ( Player );
				chat_color ( Player, "Ai cumparat^x04 Dart Pistol" );
			}

			case 2:
			{
				if ( Money < 4500 )
					ErrorShow ( Player, 4500 );
			
				cs_set_user_money ( Player, Money - 4500 );
				give_thanatos ( Player );
				chat_color ( Player, "Ai cumparat^x04 Thanatos-11" );
			}

			case 3:
			{
				if ( Money < 6500 )
					ErrorShow ( Player, 6500 );	
				
				cs_set_user_money ( Player, Money - 6500 );
				give_ethereal ( Player );
				chat_color ( Player, "Ai cumparat^x04 Ethereal" );
			}

			case 4:
			{
				if ( Money < 8500 )
					ErrorShow ( Player, 8500 );

				cs_set_user_money ( Player, Money - 8500 );
				give_dualuzi ( Player );
				chat_color ( Player, "Ai cumparat^x04 Dual U.Z.I" );
			}

			case 5:
			{
				if ( Money < 12500 )
					ErrorShow ( Player, 12500 );

				cs_set_user_money ( Player, Money - 12500 );
				give_spear ( Player );
				chat_color ( Player, "Ai cumparat^x04 Spear Gun" );
			}

			case 6:
			{
				if ( Money < 16000 )
					ErrorShow ( Player, 16000 );

				cs_set_user_money ( Player, Money - 16000 );
				give_thunderbolt ( Player );
				chat_color ( Player, "Ai cumparat^x04 Thunder Bolt" );
			}
		}
	}

	menu_destroy ( MenuID );
	return PLUGIN_HANDLED;
}

public ErrorShow ( Player, Money )
{
	chat_color ( Player, "Ai nevoie de^x04 %d $^x01 pentru a cumpara acest item", Money );
	return PLUGIN_HANDLED;
}

stock chat_color ( const Player, const Text [ ], any:... )
{
	static Message [ 191 ];
	new Players [ 32 ], Count = 1;
	vformat ( Message, charsmax ( Message ), Text, 3 );

	formatex ( Message, charsmax ( Message ), "%s %s", CHAT_TAG, Message );

	static SayText;

	if ( !SayText )
		SayText = get_user_msgid ( "SayText" );

	if ( Player )	Players [ 0 ] = Player; else get_players ( Players, Count, "ch" )
	{
		for ( new i = 0; i < Count; i++ )
		{
			if ( !is_user_connected ( Players [ i ] ) )
				continue;
			
			message_begin ( MSG_ONE_UNRELIABLE, SayText, _, Players [ i ] );
			write_byte ( Players [ i ] );
			write_string ( Message );
			message_end ( );
		}
	}
}
csx_shopcso.sma | Afiseaza codul
#include <amxmodx>
#include <amxmisc> 
#include <cstrike> 
#include <colorchat>

// NATIVE (UPDATE CSO SHOP 0.2 RAMAS IN BETA)
native give_dualuzi ( Player );
native give_dartpistol ( Player );
native give_ethereal ( Player );
native give_thanatos ( Player );
native give_spear ( Player );
native give_lightsaber ( Player );
native give_thunderbolt ( Player );

//tag cand cumperi bro
new const prefixCSO [ ] 		=	 "CSDM NEW";

public plugin_init() {
	register_plugin("CSO Shop", "0.2", "dragonCSX");
	register_clcmd("say /csoshop", "player");
        register_clcmd("say_team /csoshop", "player");
        register_clcmd("say", "CmdSay");
        register_clcmd("say_team", "CmdSay" );
}

public handled(id) { 
	if ( cs_get_user_team(id) == CS_TEAM_UNASSIGNED ) 
		return PLUGIN_CONTINUE 
	
	player(id) 
	return PLUGIN_HANDLED 
}

public player( id ) 
{ 
	new Name [ 32 ];
	get_user_name ( id, Name, charsmax ( Name ) );

	new Title [ 256 ];
	formatex ( Title, charsmax ( Title ), "\w[\rCSO NST\w] \wMagazin Arme \rCSO ^n\wBun venit \w[ \r%s \w] !", Name );
	new menu = menu_create ( Title, "menu_handler" );

	menu_additem( menu, "\wLightsaber \y[ \r800$ \y]", "0", 0); 
	menu_additem( menu, "\wDart Pistol \y[ \r1500$ \y]", "1", 0); 
        menu_additem( menu, "\wThanatos-11 \y[ \r4500 \y]", "2", 0);
        menu_additem( menu, "\wEthereal Gun \y[ \r6500$ \y]", "3", 0);
        menu_additem( menu, "\wDual Uzi \y[ \r8500$ \y]", "4", 0);
        menu_additem( menu, "\wSpear Gun \y[ \r12500$ \y]", "5", 0);
        menu_additem( menu, "\wThunderbolt \y[ \r16000$ \y]^n", "6", 0);
	
	menu_setprop( menu, MPROP_EXITNAME, "\wIesire"); 
	
	menu_display( id, menu, 0 ); 
	
} 

public menu_handler( id, menu, item ) 
{
	if(item == MENU_EXIT)
	{
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}

	switch( item ) 
	{ 

		case 0: 
		{ 
			if(cs_get_user_money(id) >= 800)
			{
				cs_set_user_money(id, cs_get_user_money(id) - 800);
                                give_lightsaber( id );
				chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!yLightsaber!g) !", prefixCSO );
				chat_color( id, "!g[!y%s!g] !yEu sunt !gTATAL TAU !", prefixCSO );
			}
			else
			{
				chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
				return 1;
			}
		}
		case 1: 
		{ 
			if(cs_get_user_money(id) >= 2500)
			{
				cs_set_user_money(id, cs_get_user_money(id) - 2500);
				give_dartpistol( id );
				chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!yDart Pistol!g) !", prefixCSO );
				chat_color( id, "!g[!y%s!g] !yAm jurat pe !g6 GLOANTE !", prefixCSO );
			}
			else
			{
				chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
				return 1;
			}
		}
		case 2: 
		{ 
			if(cs_get_user_money(id) >= 4500)
			{
				cs_set_user_money(id, cs_get_user_money(id) - 4500);
                                give_thanatos( id );
				chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!yThanatos-11!g) !", prefixCSO );
				chat_color( id, "!g[!y%s!g] !yTe vanez ca in !gCSGO !", prefixCSO );
			}
			else
			{
				chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
				return 1;
			}
		}
		case 3: 
		{ 
			if(cs_get_user_money(id) >= 6500)
			{
				cs_set_user_money(id, cs_get_user_money(id) - 6500);
                                give_ethereal( id );
				chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!yEthereal Gun!g) !", prefixCSO );
				chat_color( id, "!g[!y%s!g] !yAcum le-ai dat de i-ai !gJULIT !", prefixCSO );
			}
			else
			{
				chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
				return 1;
			}
		}
		case 4: 
		{ 
			if(cs_get_user_money(id) >= 8500)
			{
				cs_set_user_money(id, cs_get_user_money(id) - 8500);
                                give_dualuzi( id );
				chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!yDual Uzi!g) !", prefixCSO );
				chat_color( id, "!g[!y%s!g] !yEsti un !gGANGSTAR ADEVARAT !", prefixCSO );
			}
			else
			{
				chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
				return 1;
			}
		}
		case 5: 
		{ 
			if(cs_get_user_money(id) >= 12500)
			{
				cs_set_user_money(id, cs_get_user_money(id) - 12500);
                                give_spear( id );
				chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!ySpear Gun!g) !", prefixCSO );
				chat_color( id, "!g[!y%s!g] !ySpor la !gALLAHU AKBAR MODE !", prefixCSO );
			}
			else
			{
				chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
				return 1;
			}
		}
		case 6: 
		{ 
			if(cs_get_user_money(id) >= 16000)
			{
				cs_set_user_money(id, cs_get_user_money(id) - 16000);
                                give_thunderbolt( id );
				chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!yThunderbolt!g) !", prefixCSO );
				chat_color( id, "!g[!y%s!g] !yBine ai venit !gHITMAN !", prefixCSO );
			}
			else
			{
				chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
				return 1;
			}
		}
	} 
	menu_destroy( menu ); 
	return PLUGIN_HANDLED; 
}

public CmdSay( id )
{
new szArg[4];
read_args( szArg, charsmax( szArg ) );
remove_quotes( szArg );

return szArg[0] == '/' ? PLUGIN_HANDLED_MAIN : PLUGIN_CONTINUE;
}

stock chat_color(const id, const input[], any:...)
{
	new count = 1, players[32]
	static msg[191]
	vformat(msg, 190, input, 3)
	
	replace_all(msg, 190, "!g", "^4")
	replace_all(msg, 190, "!y", "^1")
	replace_all(msg, 190, "!team", "^3")
	
	if (id) players[0] = id; else get_players(players, count, "ch")
	{
	for (new i = 0; i < count; i++)
	{
		if (is_user_connected(players))
		{
			message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players)
			write_byte(players);
			write_string(msg);
			message_end();
		}
	}
}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ ansicpg1252\\ deff0\\ deflang1033{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ f0\\ fs16 \n\\ par }
*/
extraitem_dartpistol.sma | Afiseaza codul
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <xs>
#include <fun>

#define PLUGIN "[CSO] Dart Pistol"
#define VERSION "1.0"
#define AUTHOR "Dias"

#define DAMAGE 35
#define CLIP 5
#define BPAMMO 50
#define TIME_RELOAD 4.0
#define TIME_SHOOT 4.0

#define DART_SPEED 1000
#define DART_SHOCKTIME 1.0
#define DART_LIVETIME 5.0
#define DART_SHOCKRADIUS 64.0

#define MODEL_V "models/v_dartpistol.mdl"
#define MODEL_P "models/p_dartpistol.mdl"
#define MODEL_W "models/w_dartpistol.mdl"
#define MODEL_S "models/dart.mdl"

#define DARTPISTOL_OLDMODEL "models/w_deagle.mdl"
#define DART_CLASSNAME "dart"

new const WeaponSounds[10][] =
{
	"weapons/dartpistol-1.wav",
	"weapons/dartpistol_shoot_empty.wav",
	"weapons/dartpistol_explosion1.wav",
	"weapons/dartpistol_explosion2.wav",
	"weapons/dartpistol_draw.wav",
	"weapons/dartpistol_clipin1.wav",
	"weapons/dartpistol_clipin2.wav",
	"weapons/dartpistol_clipin3.wav",
	"weapons/dartpistol_clipout1.wav",
	"weapons/dartpistol_clipout2.wav"
}

new const Electric_Sprite[] = "sprites/dart_explosion.spr"

enum
{
	ANIME_IDLE = 0,
	ANIME_SHOOT,
	ANIME_SHOOT2,
	ANIME_RELOAD,
	ANIME_DRAW,
	ANIME_SHOOT_EMPTY
}

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

const pev_user = pev_iuser1
const pev_touched = pev_iuser2
const pev_attached = pev_iuser3
const pev_hitgroup = pev_iuser4
const pev_time = pev_fuser1
const pev_time2 = pev_fuser2
const pev_time3 = pev_fuser4

const m_iLastHitGroup = 75

// Vars
new g_Had_DartPistol, g_Clip[33]
new g_SprID, g_Event_DartPistol, g_SprId_LaserBeam
new g_CvarFriendlyFire, g_MaxPlayers

// Safety
new g_IsConnected, g_IsAlive, g_PlayerWeapon[33], g_HamBot

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Safety
	Register_SafetyFunc()
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_SetModel, "fw_SetModel")	
	
	register_think(DART_CLASSNAME, "fw_SpearThink")
	register_touch(DART_CLASSNAME, "*", "fw_SpearTouch")
	
	// Ham
	RegisterHam(Ham_Item_Deploy, "weapon_deagle", "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, "weapon_deagle", "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle, "weapon_deagle", "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Item_PostFrame, "weapon_deagle", "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, "weapon_deagle", "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, "weapon_deagle", "fw_Weapon_Reload_Post", 1)	
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	g_CvarFriendlyFire = get_cvar_pointer("mp_friendlyfire")
	g_MaxPlayers = get_maxplayers()

	
}

public plugin_precache()
{
	precache_model(MODEL_V)
	precache_model(MODEL_P)
	precache_model(MODEL_W)
	precache_model(MODEL_S)

	for(new i = 0; i < sizeof(WeaponSounds); i++)
		precache_sound(WeaponSounds)
		
	g_SprID = precache_model(Electric_Sprite)
	g_SprId_LaserBeam = engfunc(EngFunc_PrecacheModel, "sprites/laserbeam.spr")
	
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
}

public fw_PrecacheEvent_Post(type, const name[])
{
	if(equal("events/deagle.sc", name)) g_Event_DartPistol = get_orig_retval()		
}

public client_putinserver(id)
{
	Safety_Connected(id)
	
	if(!g_HamBot && is_user_bot(id))
	{
		g_HamBot = 1
		set_task(0.1, "Do_Register_HamBot", id)
	}
}

public Do_Register_HamBot(id) 
{
	Register_SafetyFuncBot(id)
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")	
}

public client_disconnect(id)
{
	Safety_Disconnected(id)
}

public plugin_natives ()
{
	register_native("give_dartpistol", "give_weapon", 1)
}
public give_weapon(id)
{
	Get_DartPistol(id)
}
public Get_DartPistol(id)
{
	Set_BitVar(g_Had_DartPistol, id)
	give_item(id, "weapon_deagle")
	
	// Clip & Ammo
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_DEAGLE)
	if(!pev_valid(Ent)) return
	
	cs_set_weapon_ammo(Ent, CLIP)
	cs_set_user_bpammo(id, CSW_DEAGLE, BPAMMO)
	
}

public Remove_DartPistol(id)
{
	UnSet_BitVar(g_Had_DartPistol, id)
}

public Event_CurWeapon(id)
{
	static CSW; CSW = read_data(2)
	if(CSW != CSW_DEAGLE)
		return
	if(!Get_BitVar(g_Had_DartPistol, id))	
		return

	static Float:Delay, Float:Delay2
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_DEAGLE)
	if(!pev_valid(Ent)) return
	
	Delay = get_pdata_float(Ent, 46, 4) * TIME_SHOOT
	Delay2 = get_pdata_float(Ent, 47, 4) * TIME_SHOOT
	
	if(Delay > 0.0)
	{
		set_pdata_float(Ent, 46, Delay, 4)
		set_pdata_float(Ent, 47, Delay2, 4)
	}
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_DEAGLE && Get_BitVar(g_Had_DartPistol, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_connected(invoker))
		return FMRES_IGNORED	
	if(get_player_weapon(invoker) != CSW_DEAGLE || !Get_BitVar(g_Had_DartPistol, invoker))
		return FMRES_IGNORED
	if(eventid != g_Event_DartPistol)
		return FMRES_IGNORED
	
	engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)

	Set_WeaponAnim(invoker, ANIME_SHOOT)
	emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	Create_Dart(invoker)
	
	return FMRES_SUPERCEDE
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[32]
	pev(entity, pev_classname, Classname, sizeof(Classname))
	
	if(!equal(Classname, "weaponbox"))
		return FMRES_IGNORED
	
	static iOwner
	iOwner = pev(entity, pev_owner)
	
	if(equal(model, DARTPISTOL_OLDMODEL))
	{
		static weapon; weapon = find_ent_by_owner(-1, "weapon_deagle", entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED;
		
		if(Get_BitVar(g_Had_DartPistol, iOwner))
		{
			set_pev(weapon, pev_impulse, 1372015)
			engfunc(EngFunc_SetModel, entity, MODEL_W)
		
			Remove_DartPistol(iOwner)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_alive(id))
		return FMRES_IGNORED
	if(get_user_weapon(id) != CSW_DEAGLE || !Get_BitVar(g_Had_DartPistol, id))
		return FMRES_IGNORED
		
	
	
	return FMRES_HANDLED
}


public fw_Item_Deploy_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return
	if(!Get_BitVar(g_Had_DartPistol, Id))
		return
	
	set_pev(Id, pev_viewmodel2, MODEL_V)
	set_pev(Id, pev_weaponmodel2, MODEL_P)
	
	Set_WeaponAnim(Id, ANIME_DRAW)
}

public fw_Item_AddToPlayer_Post(Ent, id)
{
	if(!pev_valid(Ent))
		return HAM_IGNORED
		
	if(pev(Ent, pev_impulse) == 1372015)
	{
		Set_BitVar(g_Had_DartPistol, id)
		set_pev(Ent, pev_impulse, 0)
	}
	
	return HAM_HANDLED	
}

public fw_Item_PostFrame(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_DartPistol, id))
		return HAM_IGNORED	
	
	static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
	static bpammo; bpammo = cs_get_user_bpammo(id, CSW_DEAGLE)
	
	static iClip; iClip = get_pdata_int(ent, 51, 4)
	static fInReload; fInReload = get_pdata_int(ent, 54, 4)
	
	if(fInReload && flNextAttack <= 0.0)
	{
		static temp1
		temp1 = min(CLIP - iClip, bpammo)

		set_pdata_int(ent, 51, iClip + temp1, 4)
		cs_set_user_bpammo(id, CSW_DEAGLE, bpammo - temp1)		
		
		set_pdata_int(ent, 54, 0, 4)
		
		fInReload = 0
	}		
	
	return HAM_IGNORED
}

public fw_Weapon_Reload(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_DartPistol, id))
		return HAM_IGNORED	

	g_Clip[id] = -1
		
	static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_DEAGLE)
	static iClip; iClip = get_pdata_int(ent, 51, 4)
		
	if(BPAmmo <= 0)
		return HAM_SUPERCEDE
	if(iClip >= CLIP)
		return HAM_SUPERCEDE		
			
	g_Clip[id] = iClip	
	
	return HAM_HANDLED
}

public fw_Weapon_Reload_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_DartPistol, id))
		return HAM_IGNORED	
	
	if((get_pdata_int(ent, 54, 4) == 1))
	{ // Reload
		if(g_Clip[id] == -1)
			return HAM_IGNORED
		
		set_pdata_int(ent, 51, g_Clip[id], 4)
		Set_WeaponAnim(id, ANIME_RELOAD)
		
		Set_PlayerNextAttack(id, TIME_RELOAD)
	}
	
	return HAM_HANDLED
}

public fw_Weapon_WeaponIdle_Post( iEnt )
{
	if(pev_valid(iEnt) != 2)
		return
	static Id; Id = get_pdata_cbase(iEnt, 41, 4)
	if(get_pdata_cbase(Id, 373) != iEnt)
		return
	if(!Get_BitVar(g_Had_DartPistol, Id))
		return
		
	//if(get_pdata_float(iEnt, 48, 4) <= 0.25)
	//{
		//Set_WeaponAnim(Id, g_Ammo[Id] > 0 ? ANIME_IDLE : ANIME_IDLE_EMPTY)
		//set_pdata_float(iEnt, 48, 20.0, 4)
	//}	
}


public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_connected(Attacker))
		return HAM_IGNORED	
	if(get_player_weapon(Attacker) != CSW_DEAGLE || !Get_BitVar(g_Had_DartPistol, Attacker))
		return HAM_IGNORED
		
	set_tr2(pentru, TR_vecEndPos, {4960.0, 4960.0, 4960.0})
	
	return HAM_SUPERCEDE
}

public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_connected(Attacker))
		return HAM_IGNORED	
	if(get_player_weapon(Attacker) != CSW_DEAGLE || !Get_BitVar(g_Had_DartPistol, Attacker))
		return HAM_IGNORED

	set_tr2(pentru, TR_vecEndPos, {4960.0, 4960.0, 4960.0})
	
	return HAM_SUPERCEDE
}

public Create_Dart(id)
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	if(!pev_valid(Ent)) return
	
	static Float:Origin[3], Float:Target[3], Float:Angles[3], Float:Velocity[3]
	
	Get_Position(id, 12.0, 6.0, -3.0, Origin)
	Get_Position(id, 1024.0, 0.0, 0.0, Target)
	
	pev(id, pev_v_angle, Angles); 
	
	//Angles[0] *= -1.0
	Angles[1] += 180.0
	
	// Set info for ent
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	
	set_pev(Ent, pev_classname, DART_CLASSNAME)
	engfunc(EngFunc_SetModel, Ent, MODEL_S)
	
	set_pev(Ent, pev_mins, Float:{-1.0, -1.0, -1.0})
	set_pev(Ent, pev_maxs, Float:{1.0, 1.0, 1.0})
	
	set_pev(Ent, pev_origin, Origin)
	set_pev(Ent, pev_angles, Angles)
	set_pev(Ent, pev_gravity, 0.01)
	
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	
	set_pev(Ent, pev_user, id)
	set_pev(Ent, pev_touched, 0)
	set_pev(Ent, pev_time, 0.0)
	set_pev(Ent, pev_time2, get_gametime() + 15.0)
	set_pev(Ent, pev_hitgroup, -1)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
	
	get_speed_vector(Origin, Target, float(DART_SPEED), Velocity)
	set_pev(Ent, pev_velocity, Velocity)
	
	// Create Beam
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMFOLLOW)
	write_short(Ent)
	write_short(g_SprId_LaserBeam)
	write_byte(5)
	write_byte(1)
	write_byte(0)
	write_byte(127)
	write_byte(255)
	write_byte(150)
	message_end()
}

public fw_SpearThink(Ent)
{
	if(!pev_valid(Ent))
		return
	if(pev(Ent, pev_flags) == FL_KILLME)
		return
		
	static Victim; Victim = pev(Ent, pev_attached)
	static Owner; Owner = pev(Ent, pev_user)
	if(is_alive(Victim))
	{
		static Float:Origin[3]; pev(Victim, pev_origin, Origin)
		engfunc(EngFunc_SetOrigin, Ent, Origin)
	} else {
		
	}
	
	if(is_connected(Owner) && pev(Ent, pev_touched))
	{
		static Float:Time; pev(Ent, pev_fuser4, Time)
		if(get_gametime() - DART_SHOCKTIME > Time)
		{
			static Float:Origin[3]; pev(Ent, pev_origin, Origin)
			
			message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
			write_byte(TE_EXPLOSION)
			engfunc(EngFunc_WriteCoord, Origin[0])
			engfunc(EngFunc_WriteCoord, Origin[1])
			engfunc(EngFunc_WriteCoord, Origin[2])
			write_short(g_SprID)
			write_byte(6)
			write_byte(15)
			write_byte(TE_EXPLFLAG_NODLIGHTS | TE_EXPLFLAG_NOPARTICLES | TE_EXPLFLAG_NOSOUND)
			message_end()
			
			emit_sound(Ent, CHAN_BODY, WeaponSounds[random_num(2, 3)], VOL_NORM, ATTN_NONE, 0, PITCH_NORM)
			
			Check_Damage(Ent, Owner, Origin, Owner)
			
			Time = get_gametime()
			set_pev(Ent, pev_fuser4, Time)
		}
	}
	
	if(pev(Ent, pev_touched) && pev(Ent, pev_time) <= get_gametime())
		set_pev(Ent, pev_flags, FL_KILLME)
	
	if(pev(Ent, pev_time2) <= get_gametime())
		set_pev(Ent, pev_flags, FL_KILLME)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}

public Check_Damage(Ent, id, Float:Origin[3], Except)
{
	for(new i = 0; i < g_MaxPlayers; i++)
	{
		if(!is_alive(i))
			continue
		if(entity_range(Ent, i) > DART_SHOCKRADIUS)
			continue
		if(Except == i)
			continue
			
		if(id != i) ExecuteHamB(Ham_TakeDamage, i, 0, id, float(DAMAGE), DMG_BURN)
	}
}

public fw_SpearTouch(Ent, Touched)
{
	if(!pev_valid(Ent))
		return
	
	static id; id = pev(Ent, pev_user)
	if(!is_user_connected(id))
	{
		remove_entity(Ent)
		return
	}
	if(pev(Ent, pev_touched))
		return
	
	if(is_user_alive(Touched))
	{
		if(id == Touched)
			return
		if(!get_pcvar_num(g_CvarFriendlyFire))
		{
			if(cs_get_user_team(id) == cs_get_user_team(Touched))
				return
		}
		
		// Check hitgroup
		static Float:HeadOrigin[3], Float:HeadAngles[3];
		engfunc(EngFunc_GetBonePosition, Touched, 8, HeadOrigin, HeadAngles);
			
		static Float:EntOrigin[3]
		pev(Ent, pev_origin, EntOrigin)

		if(get_distance_f(EntOrigin, HeadOrigin) <= 10.0) set_pev(Ent, pev_hitgroup, HIT_HEAD)
		else set_pev(Ent, pev_hitgroup, HIT_CHEST)
		
		// Handle
		set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
		
		set_pev(Ent, pev_touched, 1)
		set_pev(Ent, pev_time, get_gametime() + DART_LIVETIME)
		set_pev(Ent, pev_attached, Touched)
	} else {
		set_pev(Ent, pev_movetype, MOVETYPE_NONE)
		
		set_pev(Ent, pev_touched, 1)
		set_pev(Ent, pev_time, get_gametime() + DART_LIVETIME)
	}
}

/* ===============================
------------- SAFETY -------------
=================================*/
public Register_SafetyFunc()
{
	register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
	
	RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
	RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
}

public Register_SafetyFuncBot(id)
{
	RegisterHamFromEntity(Ham_Spawn, id, "fw_Safety_Spawn_Post", 1)
	RegisterHamFromEntity(Ham_Killed, id, "fw_Safety_Killed_Post", 1)
}

public Safety_Connected(id)
{
	Set_BitVar(g_IsConnected, id)
	UnSet_BitVar(g_IsAlive, id)
	
	g_PlayerWeapon[id] = 0
}

public Safety_Disconnected(id)
{
	UnSet_BitVar(g_IsConnected, id)
	UnSet_BitVar(g_IsAlive, id)
	
	g_PlayerWeapon[id] = 0
}

public Safety_CurWeapon(id)
{
	if(!is_alive(id))
		return
		
	static CSW; CSW = read_data(2)
	if(g_PlayerWeapon[id] != CSW) g_PlayerWeapon[id] = CSW
}

public fw_Safety_Spawn_Post(id)
{
	if(!is_user_alive(id))
		return
		
	Set_BitVar(g_IsAlive, id)
}

public fw_Safety_Killed_Post(id)
{
	UnSet_BitVar(g_IsAlive, id)
}

public is_alive(id)
{
	if(!(1 <= id <= 32))
		return 0
	if(!Get_BitVar(g_IsConnected, id))
		return 0
	if(!Get_BitVar(g_IsAlive, id)) 
		return 0
	
	return 1
}

public is_connected(id)
{
	if(!(1 <= id <= 32))
		return 0
	if(!Get_BitVar(g_IsConnected, id))
		return 0
	
	return 1
}

public get_player_weapon(id)
{
	if(!is_alive(id))
		return 0
	
	return g_PlayerWeapon[id]
}

/* ===============================
--------- End of SAFETY ----------
=================================*/

stock Set_WeaponAnim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
{
	// Find target
	static Decal; Decal = random_num(41, 45)
	static LoopTime; 
	
	if(Damage > 100.0) LoopTime = 2
	else LoopTime = 1
	
	for(new i = 0; i < LoopTime; i++)
	{
		// Put decal on "world" (a wall)
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_WORLDDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_byte(Decal)
		message_end()
		
		// Show sparcles
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_GUNSHOTDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_short(id)
		write_byte(Decal)
		message_end()
	}
}

stock Make_BulletSmoke(id, TrResult)
{
	static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
	
	get_weapon_attachment(id, vecSrc)
	global_get(glb_v_forward, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)

	get_tr2(TrResult, TR_vecEndPos, vecSrc)
	get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)
    
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, vecEnd[0])
	engfunc(EngFunc_WriteCoord, vecEnd[1])
	engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
	write_short(g_SmokePuff_SprId)
	write_byte(2)
	write_byte(50)
	write_byte(TE_FLAG)
	message_end()
}

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{ 
	static Float:vfEnd[3], viEnd[3] 
	get_user_origin(id, viEnd, 3)  
	IVecFVec(viEnd, vfEnd) 
	
	static Float:fOrigin[3], Float:fAngle[3]
	
	pev(id, pev_origin, fOrigin) 
	pev(id, pev_view_ofs, fAngle)
	
	xs_vec_add(fOrigin, fAngle, fOrigin) 
	
	static Float:fAttack[3]
	
	xs_vec_sub(vfEnd, fOrigin, fAttack)
	xs_vec_sub(vfEnd, fOrigin, fAttack) 
	
	static Float:fRate
	
	fRate = fDis / vector_length(fAttack)
	xs_vec_mul_scalar(fAttack, fRate, fAttack)
	
	xs_vec_add(fOrigin, fAttack, output)
}

stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
{
	new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}

stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
{
	new_velocity[0] = origin2[0] - origin1[0]
	new_velocity[1] = origin2[1] - origin1[1]
	new_velocity[2] = origin2[2] - origin1[2]
	new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
	new_velocity[0] *= num
	new_velocity[1] *= num
	new_velocity[2] *= num
	
	return 1;
}

stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle)
{
	static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
	if(!pev_valid(entwpn)) 
		return
		
	set_pdata_float(entwpn, 46, TimeIdle, 4)
	set_pdata_float(entwpn, 47, TimeIdle, 4)
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
}

stock Set_PlayerNextAttack(id, Float:nexttime)
{
	set_pdata_float(id, 83, nexttime, 5)
}


stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[])
{
	static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1042\\ f0\\ fs16 \n\\ par }
*/
extraitem_dualuzi.sma | Afiseaza codul
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <xs>
#include <fun>

#define PLUGIN "[CSO] Dual Uzi"
#define VERSION "1.0"
#define AUTHOR "Dias Pendragon"

// Data Config
#define MODEL_V "models/v_dualuzi.mdl"
#define MODEL_P "models/p_dualuzi.mdl"
#define MODEL_W "models/w_dualuzi.mdl"
#define MODEL_W_OLD "models/w_mp5.mdl"

#define CSW_BASE CSW_MP5NAVY
#define weapon_base "weapon_mp5navy"

#define SUBMODEL -1 // can -1
#define WEAPON_CODE 2102015
#define WEAPON_EVENT "events/mp5n.sc"
#define ANIM_EXT "dualpistols"

#define ANIME_SHOOT 3
#define ANIME_RELOAD 15 // can -1
#define ANIME_DRAW 16 // can -1
#define ANIME_IDLE random_num(0, 1) // can -1

new const WeaponSounds[10][] =
{
	"weapons/dualuzi-1.wav",
	"weapons/dualuzi_draw.wav",
	"weapons/dualuzi_idle2_1.wav",
	"weapons/dualuzi_idle2_2.wav",
	"weapons/dualuzi_clipin1.wav",
	"weapons/dualuzi_clipout1.wav",
	"weapons/dualuzi_off_shoulder.wav",
	"weapons/dualuzi_on_shoulder.wav",
	"weapons/dualuzi_on_shoulder_reload1.wav",
	"weapons/dualuzi_on_shoulder_reload2.wav"
}

enum
{
	ANIME_IDLEX = 0,
	ANIME_IDLE2,
	ANIME_LEFT_EMPTY,
	ANIME_SHOOT_L1,
	ANIME_SHOOT_L2,
	ANIME_SHOOT_L3,
	ANIME_SHOOT_L4,
	ANIME_SHOOT_L5,
	ANIME_SHOOT_LLAST,
	ANIME_SHOOT_R1,
	ANIME_SHOOT_R2,
	ANIME_SHOOT_R3,
	ANIME_SHOOT_R4,
	ANIME_SHOOT_R5,
	ANIME_SHOOT_RLAST,
	ANIME_RELOADX,
	ANIME_DRAWX,
	ANIME_CHANGE_TO_B,
	ANIME_B_IDLE,
	ANIME_B_SHOOT_L,
	ANIME_B_SHOOT_LLAST,
	ANIME_B_LEFT_EMPTY,
	ANIME_B_SHOOT_R,
	ANIME_B_SHOOT_RLAST,
	ANIME_B_RELOAD,
	ANIME_CHANGE_TO_A
}

// Weapon Config
#define DAMAGE 26 // 52 for Zombie
#define ACCURACY 70 // 0 - 100 ; -1 Default
#define CLIP 80
#define BPAMMO 240
#define SPEED 0.05
#define RECOIL 0.5
#define RELOAD_TIME 3.0

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

//new g_Base
new g_Had_Base, g_Clip[33], g_OldWeapon[33], Float:g_Recoil[33][3]
new g_Event_Base, g_SmokePuff_SprId, g_MsgCurWeapon, g_ShellId

// Safety
new g_HamBot
new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Safety
	Register_SafetyFunc()
	
	// Event
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	register_forward(FM_SetModel, "fw_SetModel")	
	register_forward(FM_CmdStart, "fw_CmdStart")

	// Ham
	RegisterHam(Ham_Item_Deploy, weapon_base, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_base, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_base, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_base, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload_Post", 1)	
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack_Post", 1)
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	// Cache
	g_MsgCurWeapon = get_user_msgid("CurWeapon")
}

public plugin_precache()
{
	precache_model(MODEL_V)
	precache_model(MODEL_P)
	precache_model(MODEL_W)
	
	for(new i = 0; i < sizeof(WeaponSounds); i++)
		precache_sound(WeaponSounds)
	
	g_ShellId = engfunc(EngFunc_PrecacheModel, "models/pshell.mdl")
	g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
}

public fw_PrecacheEvent_Post(type, const name[])
{
	if(equal(WEAPON_EVENT, name)) g_Event_Base = get_orig_retval()		
}

public client_putinserver(id)
{
        Safety_Connected(id)
	
	if(!g_HamBot && is_user_bot(id))
	{
		g_HamBot = 1
		set_task(0.1, "Register_HamBot", id)
	}
}
 
public Register_HamBot(id)
{
	Register_SafetyFuncBot(id)
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")	
}
 
public client_disconnect(id)
{
        Safety_Disconnected(id)
}
/*
public Mileage_WeaponGet(id, ItemID)
{
	if(ItemID == g_Base) Get_Base(id)
}

public Mileage_WeaponRefillAmmo(id, ItemID)
{
	if(ItemID == g_Base) cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
}

public Mileage_WeaponRemove(id, ItemID)
{
	if(ItemID == g_Base) Remove_Base(id)
}*/
public plugin_natives ()
{
	register_native("give_dualuzi", "give_weaponuzi", 1)
}
public give_weaponuzi(id)
{
	Get_Base(id)
}
public Get_Base(id)
{
	Set_BitVar(g_Had_Base, id)
	give_item(id, weapon_base)
	
	// Clip & Ammo
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
	if(!pev_valid(Ent)) return
	
	cs_set_weapon_ammo(Ent, CLIP)
	cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
	
	message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
	write_byte(1)
	write_byte(CSW_BASE)
	write_byte(CLIP)
	message_end()
	
	cs_set_weapon_silen(Ent, 0, 0)
}

public Remove_Base(id)
{
	UnSet_BitVar(g_Had_Base, id)
}

public Event_CurWeapon(id)
{
	static CSWID; CSWID = read_data(2)
	static SubModel; SubModel = SUBMODEL
	
	if((CSWID == CSW_BASE && g_OldWeapon[id] != CSW_BASE) && Get_BitVar(g_Had_Base, id))
	{
		if(SubModel != -1) Draw_NewWeapon(id, CSWID)
	} else if((CSWID == CSW_BASE && g_OldWeapon[id] == CSW_BASE) && Get_BitVar(g_Had_Base, id)) {
		static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
		if(!pev_valid(Ent))
		{
			g_OldWeapon[id] = get_user_weapon(id)
			return
		}
		
		set_pdata_float(Ent, 46, SPEED, 4)
		set_pdata_float(Ent, 47, SPEED, 4)
	} else if(CSWID != CSW_BASE && g_OldWeapon[id] == CSW_BASE) {
		if(SubModel != -1) Draw_NewWeapon(id, CSWID)
	}
	
	g_OldWeapon[id] = get_user_weapon(id)
}

public Draw_NewWeapon(id, CSW_ID)
{
	if(CSW_ID == CSW_BASE)
	{
		static ent
		ent = fm_get_user_weapon_entity(id, CSW_BASE)
		
		if(pev_valid(ent) && Get_BitVar(g_Had_Base, id))
		{
			set_pev(ent, pev_effects, pev(ent, pev_effects) &~ EF_NODRAW) 
			engfunc(EngFunc_SetModel, ent, MODEL_P)	
			set_pev(ent, pev_body, SUBMODEL)
		}
	} else {
		static ent
		ent = fm_get_user_weapon_entity(id, CSW_BASE)
		
		if(pev_valid(ent)) set_pev(ent, pev_effects, pev(ent, pev_effects) | EF_NODRAW) 			
	}
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_BASE && Get_BitVar(g_Had_Base, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_connected(invoker))
		return FMRES_IGNORED	
	if(get_player_weapon(invoker) != CSW_BASE || !Get_BitVar(g_Had_Base, invoker))
		return FMRES_IGNORED
	if(eventid != g_Event_Base)
		return FMRES_IGNORED
	
	engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
	DualAttack(invoker)
	
	return FMRES_SUPERCEDE
}
public DualAttack(id)
{
	static iFlags, iAnimDesired, iWeaponState, iItem, szAnimation[64]
	
	#define WEAPONSTATE_ELITE_LEFT (1 << 3)
	
	iItem = fm_get_user_weapon_entity(id, CSW_BASE)
	if(!pev_valid(iItem)) return
	
	iFlags = pev(id, pev_flags);
	iWeaponState = get_pdata_int(iItem, 74, 4)
	
	if(iWeaponState & WEAPONSTATE_ELITE_LEFT)
	{	
		iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
	
		Set_WeaponAnim(id, ANIME_SHOOT_L1)
		Make_Shell(id, 1)
		
		formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot_%s" : "ref_shoot_%s", ANIM_EXT);
	} else {
		iWeaponState |= WEAPONSTATE_ELITE_LEFT;
		
		Set_WeaponAnim(id, ANIME_SHOOT_R1)
		Make_Shell(id, 0)
		
		formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot2_%s" : "ref_shoot2_%s", ANIM_EXT);
	}
	
	if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
		iAnimDesired = 0;
	
	set_pev(id, pev_sequence, iAnimDesired)
	set_pdata_int(iItem, 74, iWeaponState, 4)
	
	emit_sound(id, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
}

public Make_Shell(id, Right)
{
	static Float:player_origin[3], Float:origin[3], Float:origin2[3], Float:gunorigin[3], Float:oldangles[3], Float:v_forward[3], Float:v_forward2[3], Float:v_up[3], Float:v_up2[3], Float:v_right[3], Float:v_right2[3], Float:viewoffsets[3];
	
	pev(id, pev_v_angle, oldangles); pev(id,pev_origin,player_origin); pev(id, pev_view_ofs, viewoffsets);

	engfunc(EngFunc_MakeVectors, oldangles)
	
	global_get(glb_v_forward, v_forward); global_get(glb_v_up, v_up); global_get(glb_v_right, v_right);
	global_get(glb_v_forward, v_forward2); global_get(glb_v_up, v_up2); global_get(glb_v_right, v_right2);
	
	xs_vec_add(player_origin, viewoffsets, gunorigin);
	
	if(!Right)
	{
		xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, 2.0, v_right);
		xs_vec_mul_scalar(v_up, -2.7, v_up);
		xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 4.0, v_right2);
		xs_vec_mul_scalar(v_up2, -3.0, v_up2);
	} else {
		xs_vec_mul_scalar(v_forward, 10.3, v_forward); xs_vec_mul_scalar(v_right, -4.0, v_right);
		xs_vec_mul_scalar(v_up, -3.7, v_up);
		xs_vec_mul_scalar(v_forward2, 10.0, v_forward2); xs_vec_mul_scalar(v_right2, 2.0, v_right2);
		xs_vec_mul_scalar(v_up2, -4.0, v_up2);
	}
	
	xs_vec_add(gunorigin, v_forward, origin);
	xs_vec_add(gunorigin, v_forward2, origin2);
	xs_vec_add(origin, v_right, origin);
	xs_vec_add(origin2, v_right2, origin2);
	xs_vec_add(origin, v_up, origin);
	xs_vec_add(origin2, v_up2, origin2);

	static Float:velocity[3]
	get_speed_vector(origin2, origin, random_float(140.0, 160.0), velocity)

	static angle; angle = random_num(0, 360)

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_MODEL)
	engfunc(EngFunc_WriteCoord, origin[0])
	engfunc(EngFunc_WriteCoord,origin[1])
	engfunc(EngFunc_WriteCoord,origin[2])
	engfunc(EngFunc_WriteCoord,velocity[0])
	engfunc(EngFunc_WriteCoord,velocity[1])
	engfunc(EngFunc_WriteCoord,velocity[2])
	write_angle(angle)
	write_short(g_ShellId)
	write_byte(1)
	write_byte(20)
	message_end()
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[32]
	pev(entity, pev_classname, Classname, sizeof(Classname))
	
	if(!equal(Classname, "weaponbox"))
		return FMRES_IGNORED
	
	static iOwner
	iOwner = pev(entity, pev_owner)
	
	if(equal(model, MODEL_W_OLD))
	{
		static weapon; weapon = find_ent_by_owner(-1, weapon_base, entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED;
		
		if(Get_BitVar(g_Had_Base, iOwner))
		{
			set_pev(weapon, pev_impulse, WEAPON_CODE)
			engfunc(EngFunc_SetModel, entity, MODEL_W)
			set_pev(entity, pev_body, SUBMODEL)
		
			Remove_Base(iOwner)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if (!is_alive(id))
		return FMRES_IGNORED	
	if(get_player_weapon(id) != CSW_BASE || !Get_BitVar(g_Had_Base, id))
		return FMRES_IGNORED
		
	static Button; Button = get_uc(uc_handle, UC_Buttons)	
	
	if(Button & IN_ATTACK2)
	{
		static Float:Time; Time = get_pdata_float(id, 83, 5)
		if(Time > 0.0) return FMRES_IGNORED
		
		if(cs_get_user_zoom(id) != CS_SET_AUGSG552_ZOOM) cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 1)
		else cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
		
		Time = 0.25
		set_pdata_float(id, 83, Time, 5)
	}
	
	return FMRES_IGNORED
}

public fw_Item_Deploy_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return
	if(!Get_BitVar(g_Had_Base, Id))
		return
		
	static SubModel; SubModel = SUBMODEL
	
	set_pev(Id, pev_viewmodel2, MODEL_V)
	set_pev(Id, pev_weaponmodel2, SubModel != -1 ? "" : MODEL_P)
	
	static Draw; Draw = ANIME_DRAW
	if(Draw != -1) Set_WeaponAnim(Id, ANIME_DRAW)
	
	set_pdata_string(Id, (492) * 4, ANIM_EXT, -1 , 20)
}

public fw_Item_AddToPlayer_Post(Ent, id)
{
	if(!pev_valid(Ent))
		return HAM_IGNORED
		
	if(pev(Ent, pev_impulse) == WEAPON_CODE)
	{
		Set_BitVar(g_Had_Base, id)
		set_pev(Ent, pev_impulse, 0)
	}
	
	return HAM_HANDLED	
}

public fw_Item_PostFrame(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Base, id))
		return HAM_IGNORED	
	
	static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
	static bpammo; bpammo = cs_get_user_bpammo(id, CSW_BASE)
	
	static iClip; iClip = get_pdata_int(ent, 51, 4)
	static fInReload; fInReload = get_pdata_int(ent, 54, 4)
	
	if(fInReload && flNextAttack <= 0.0)
	{
		static temp1
		temp1 = min(CLIP - iClip, bpammo)

		set_pdata_int(ent, 51, iClip + temp1, 4)
		cs_set_user_bpammo(id, CSW_BASE, bpammo - temp1)		
		
		set_pdata_int(ent, 54, 0, 4)
		
		fInReload = 0
	}		
	
	return HAM_IGNORED
}

public fw_Weapon_Reload(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Base, id))
		return HAM_IGNORED	

	g_Clip[id] = -1
		
	static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_BASE)
	static iClip; iClip = get_pdata_int(ent, 51, 4)
		
	if(BPAmmo <= 0)
		return HAM_SUPERCEDE
	if(iClip >= CLIP)
		return HAM_SUPERCEDE		
			
	g_Clip[id] = iClip	
	
	return HAM_HANDLED
}

public fw_Weapon_Reload_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Base, id))
		return HAM_IGNORED	
	
	if((get_pdata_int(ent, 54, 4) == 1))
	{ // Reload
		if(g_Clip[id] == -1)
			return HAM_IGNORED
		
		set_pdata_int(ent, 51, g_Clip[id], 4)
		
		static Reload; Reload = ANIME_RELOAD
		if(Reload != -1) Set_WeaponAnim(id, ANIME_RELOAD)
		Set_PlayerNextAttack(id, RELOAD_TIME)
	}
	
	return HAM_HANDLED
}

public fw_Weapon_WeaponIdle_Post( iEnt )
{
	if(pev_valid(iEnt) != 2)
		return
	static Id; Id = get_pdata_cbase(iEnt, 41, 4)
	if(get_pdata_cbase(Id, 373) != iEnt)
		return
	if(!Get_BitVar(g_Had_Base, Id))
		return
		
	static Idle; Idle = ANIME_IDLE
	
	if(Idle != -1 && get_pdata_float(iEnt, 48, 4) <= 0.25)
	{
		Set_WeaponAnim(Id, ANIME_IDLE)
		set_pdata_float(iEnt, 48, 20.0, 4)
	}	
}

public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_connected(Attacker))
		return HAM_IGNORED	
	if(get_player_weapon(Attacker) != CSW_BASE || !Get_BitVar(g_Had_Base, Attacker))
		return HAM_IGNORED
		
	static Float:flEnd[3], Float:vecPlane[3]
		
	get_tr2(pentru, TR_vecEndPos, flEnd)
	get_tr2(pentru, TR_vecPlaneNormal, vecPlane)		
			
	Make_BulletHole(Attacker, flEnd, Damage)
	Make_BulletSmoke(Attacker, pentru)

	SetHamParamFloat(3, float(DAMAGE))
	
	return HAM_HANDLED
}

public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_connected(Attacker))
		return HAM_IGNORED	
	if(get_player_weapon(Attacker) != CSW_BASE || !Get_BitVar(g_Had_Base, Attacker))
		return HAM_IGNORED

	static Float:flEnd[3]
	get_tr2(pentru, TR_vecEndPos, flEnd)	
		
	SetHamParamFloat(3, float(DAMAGE))
	
	return HAM_HANDLED
}

public fw_Weapon_PrimaryAttack(Ent)
{
	static id; id = pev(Ent, pev_owner)
	if(!is_alive(id))
		return
	if(!Get_BitVar(g_Had_Base, id))
		return

	pev(id, pev_punchangle, g_Recoil[id])
}

public fw_Weapon_PrimaryAttack_Post(Ent)
{
	static id; id = pev(Ent, pev_owner)
	if(!is_alive(id))
		return
	if(!Get_BitVar(g_Had_Base, id))
		return

	static Float:Push[3]
	pev(id, pev_punchangle, Push)
	xs_vec_sub(Push, g_Recoil[id], Push)
	
	xs_vec_mul_scalar(Push, RECOIL, Push)
	xs_vec_add(Push, g_Recoil[id], Push)
	
	set_pev(id, pev_punchangle, Push)

	// Acc
	static Accena; Accena = ACCURACY
	if(Accena != -1)
	{
		static Float:Accuracy
		Accuracy = (float(100 - ACCURACY) * 1.5) / 100.0

		set_pdata_float(Ent, 62, Accuracy, 4);
	}
}

/* ===============================
------------- SAFETY -------------
=================================*/
public Register_SafetyFunc()
{
	register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
	
	RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
	RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
}

public Register_SafetyFuncBot(id)
{
	RegisterHamFromEntity(Ham_Spawn, id, "fw_Safety_Spawn_Post", 1)
	RegisterHamFromEntity(Ham_Killed, id, "fw_Safety_Killed_Post", 1)
}

public Safety_Connected(id)
{
	Set_BitVar(g_IsConnected, id)
	UnSet_BitVar(g_IsAlive, id)
	
	g_PlayerWeapon[id] = 0
}

public Safety_Disconnected(id)
{
	UnSet_BitVar(g_IsConnected, id)
	UnSet_BitVar(g_IsAlive, id)
	
	g_PlayerWeapon[id] = 0
}

public Safety_CurWeapon(id)
{
	if(!is_alive(id))
		return
		
	static CSW; CSW = read_data(2)
	if(g_PlayerWeapon[id] != CSW) g_PlayerWeapon[id] = CSW
}

public fw_Safety_Spawn_Post(id)
{
	if(!is_user_alive(id))
		return
		
	Set_BitVar(g_IsAlive, id)
}

public fw_Safety_Killed_Post(id)
{
	UnSet_BitVar(g_IsAlive, id)
}

public is_connected(id)
{
	if(!(1 <= id <= 32))
		return 0
	if(!Get_BitVar(g_IsConnected, id))
		return 0

	return 1
}

public is_alive(id)
{
	if(!is_connected(id))
		return 0
	if(!Get_BitVar(g_IsAlive, id))
		return 0
		
	return 1
}

public get_player_weapon(id)
{
	if(!is_alive(id))
		return 0
	
	return g_PlayerWeapon[id]
}

/* ===============================
--------- END OF SAFETY  ---------
=================================*/

stock Set_WeaponAnim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
{
	// Find target
	static Decal; Decal = random_num(41, 45)
	static LoopTime; 
	
	if(Damage > 100.0) LoopTime = 2
	else LoopTime = 1
	
	for(new i = 0; i < LoopTime; i++)
	{
		// Put decal on "world" (a wall)
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_WORLDDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_byte(Decal)
		message_end()
		
		// Show sparcles
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_GUNSHOTDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_short(id)
		write_byte(Decal)
		message_end()
	}
}

stock Make_BulletSmoke(id, TrResult)
{
	static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
	
	get_weapon_attachment(id, vecSrc)
	global_get(glb_v_forward, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)

	get_tr2(TrResult, TR_vecEndPos, vecSrc)
	get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)
    
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, vecEnd[0])
	engfunc(EngFunc_WriteCoord, vecEnd[1])
	engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
	write_short(g_SmokePuff_SprId)
	write_byte(2)
	write_byte(50)
	write_byte(TE_FLAG)
	message_end()
}

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{ 
	static Float:vfEnd[3], viEnd[3] 
	get_user_origin(id, viEnd, 3)  
	IVecFVec(viEnd, vfEnd) 
	
	static Float:fOrigin[3], Float:fAngle[3]
	
	pev(id, pev_origin, fOrigin) 
	pev(id, pev_view_ofs, fAngle)
	
	xs_vec_add(fOrigin, fAngle, fOrigin) 
	
	static Float:fAttack[3]
	
	xs_vec_sub(vfEnd, fOrigin, fAttack)
	xs_vec_sub(vfEnd, fOrigin, fAttack) 
	
	static Float:fRate
	
	fRate = fDis / vector_length(fAttack)
	xs_vec_mul_scalar(fAttack, fRate, fAttack)
	
	xs_vec_add(fOrigin, fAttack, output)
}

stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
{
	new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}

stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
{
	new_velocity[0] = origin2[0] - origin1[0]
	new_velocity[1] = origin2[1] - origin1[1]
	new_velocity[2] = origin2[2] - origin1[2]
	new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
	new_velocity[0] *= num
	new_velocity[1] *= num
	new_velocity[2] *= num
	
	return 1;
}

stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle)
{
	static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
	if(!pev_valid(entwpn)) 
		return
		
	set_pdata_float(entwpn, 46, TimeIdle, 4)
	set_pdata_float(entwpn, 47, TimeIdle, 4)
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
}

stock Set_PlayerNextAttack(id, Float:nexttime)
{
	set_pdata_float(id, 83, nexttime, 5)
}

stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[])
{
	static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1042\\ f0\\ fs16 \n\\ par }
*/
extraitem_ethereal.sma | Afiseaza codul
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>

#define PLUGIN "[CSO] Ethereal"
#define VERSION "1.0"
#define AUTHOR "Dias Pendragon"

#define DAMAGE 26
#define CLIP 30
#define SPEED 1.0
#define RECOIL 0.75

#define CSW_ETHEREAL CSW_M4A1
#define weapon_ethereal "weapon_m4a1"
#define PLAYER_ANIMEXT "carbine"
#define ETHEREAL_OLDMODEL "models/w_m4a1.mdl"

#define V_MODEL "models/v_ethereal2.mdl"
#define P_MODEL "models/p_ethereal.mdl"
#define W_MODEL "models/w_ethereal.mdl"

new const Ethereal_Sounds[4][] = 
{
	"weapons/ethereal-1.wav",
	"weapons/ethereal_draw.wav",
	"weapons/ethereal_idle1.wav",
	"weapons/ethereal_reload.wav"
}

new const Ethereal_Resources[3][] = 
{
	"sprites/weapon_ethereal.txt",
	"sprites/640hud7_2.spr",
	"sprites/640hud74_2.spr"
}

#define MUZZLE_FLASH "sprites/muzzleflash7.spr"

enum
{
	E_ANIM_IDLE = 0,
	E_ANIM_RELOAD,
	E_ANIM_DRAW,
	E_ANIM_SHOOT1,
	E_ANIM_SHOOT2,
	E_ANIM_SHOOT3
}


// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)

new g_Had_Ethereal, g_Ethereal_Clip[33], Float:g_Recoil[33][3]
new g_Event_Ethereal, g_Msg_WeaponList, g_SmokePuff_SprId, g_ham_bot, g_Beam_SprID
new g_Muzzleflash_Ent, g_Muzzleflash

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	register_forward(FM_UpdateClientData,"fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	register_forward(FM_SetModel, "fw_SetModel")	
	register_forward(FM_CmdStart, "fw_CmdStart")
	
	register_forward(FM_AddToFullPack, "fw_AddToFullPack_post", 1)
	register_forward(FM_CheckVisibility, "fw_CheckVisibility")
	
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_ethereal, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_ethereal, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_ethereal, "fw_Weapon_PrimaryAttack_Post", 1)	
	RegisterHam(Ham_Item_Deploy, weapon_ethereal, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_ethereal, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_ethereal, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_ethereal, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_ethereal, "fw_Weapon_Reload_Post", 1)	
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	g_Msg_WeaponList = get_user_msgid("WeaponList")
	register_clcmd("weapon_ethereal", "Hook_Weapon")
	
}

public plugin_precache()
{
	engfunc(EngFunc_PrecacheModel, V_MODEL)
	engfunc(EngFunc_PrecacheModel, P_MODEL)
	engfunc(EngFunc_PrecacheModel, W_MODEL)
	
	new i
	for(i = 0; i < sizeof(Ethereal_Sounds); i++)
		engfunc(EngFunc_PrecacheSound, Ethereal_Sounds)
	for(i = 0; i < sizeof(Ethereal_Resources); i++)
	{
		if(i == 0) engfunc(EngFunc_PrecacheGeneric, Ethereal_Resources)
		else engfunc(EngFunc_PrecacheModel, Ethereal_Resources)
	}
	
	g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
	g_Beam_SprID = engfunc(EngFunc_PrecacheModel, "sprites/laserbeam.spr")
	
	
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
	
	// Muzzleflash
	g_Muzzleflash_Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	precache_model(MUZZLE_FLASH)
	engfunc(EngFunc_SetModel, g_Muzzleflash_Ent, MUZZLE_FLASH)
	set_pev(g_Muzzleflash_Ent, pev_scale, 0.2)
	
	set_pev(g_Muzzleflash_Ent, pev_rendermode, kRenderTransTexture)
	set_pev(g_Muzzleflash_Ent, pev_renderamt, 0.0)
}

public fw_PrecacheEvent_Post(type, const name[])
{
	if(equal("events/m4a1.sc", name)) g_Event_Ethereal = get_orig_retval()		
}

public client_putinserver(id)
{
	if(!g_ham_bot && is_user_bot(id))
	{
		g_ham_bot = 1
		set_task(0.1, "Do_Register_HamBot", id)
	}
}

public Do_Register_HamBot(id)
{
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")
}

/*
public zd_weapon_bought(id, ItemID)
{
	if(ItemID == g_Ethereal) Get_Ethereal(id)
}

public zd_weapon_remove(id, ItemID)
{
	if(ItemID == g_Ethereal) Remove_Ethereal(id)
}

public zd_weapon_addammo(id, ItemID)
{
	if(ItemID == g_Ethereal) 
	{
		Give_RealAmmo(id, CSW_ETHEREAL)
	}
}*/
public plugin_natives ()
{
	register_native("give_ethereal", "give_weaponethe", 1)
}
public give_weaponethe(id)
{
	Get_Ethereal(id)
}
public Get_Ethereal(id)
{
	Set_BitVar(g_Had_Ethereal, id)
	fm_give_item(id, weapon_ethereal)
	
	Give_RealAmmo(id, CSW_ETHEREAL)
	
	engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, get_user_msgid("CurWeapon"), {0, 0, 0}, id)
	write_byte(1)
	write_byte(CSW_M4A1)
	write_byte(30)
	message_end()
}

public Remove_Ethereal(id)
{
	UnSet_BitVar(g_Had_Ethereal, id)
}

public Hook_Weapon(id)
{
	engclient_cmd(id, weapon_ethereal)
	return PLUGIN_HANDLED
}

public Event_CurWeapon(id)
{
	if(!Get_BitVar(g_Had_Ethereal, id))	
		return

	static Float:Delay, Float:Delay2
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_ETHEREAL)
	if(!pev_valid(Ent)) return
	
	Delay = get_pdata_float(Ent, 46, 4) * SPEED
	Delay2 = get_pdata_float(Ent, 47, 4) * SPEED
	
	if(Delay > 0.0)
	{
		set_pdata_float(Ent, 46, Delay, 4)
		set_pdata_float(Ent, 47, Delay2, 4)
	}
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_user_alive(id) || !is_user_connected(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_ETHEREAL && Get_BitVar(g_Had_Ethereal, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_user_connected(invoker))
		return FMRES_IGNORED	
	if(get_user_weapon(invoker) != CSW_ETHEREAL || !Get_BitVar(g_Had_Ethereal, invoker))
		return FMRES_IGNORED
	if(eventid != g_Event_Ethereal)
		return FMRES_IGNORED
	
	engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
		
	set_weapon_anim(invoker, E_ANIM_SHOOT1)
	
	emit_sound(invoker, CHAN_WEAPON, Ethereal_Sounds[0], 1.0, ATTN_NORM, 0, PITCH_NORM)
	//Eject_Shell(invoker, g_RifleShell_Id, 0.01)
	
	return FMRES_IGNORED
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[32]
	pev(entity, pev_classname, Classname, sizeof(Classname))
	
	if(!equal(Classname, "weaponbox"))
		return FMRES_IGNORED
	
	static iOwner
	iOwner = pev(entity, pev_owner)
	
	if(equal(model, ETHEREAL_OLDMODEL))
	{
		static weapon; weapon = fm_find_ent_by_owner(-1, weapon_ethereal, entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED;
		
		if(Get_BitVar(g_Had_Ethereal, iOwner))
		{
			Remove_Ethereal(iOwner)
			
			set_pev(weapon, pev_impulse, 1712015)
			engfunc(EngFunc_SetModel, entity, W_MODEL)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(!Get_BitVar(g_Had_Ethereal, id) || get_user_weapon(id) != CSW_ETHEREAL)	
		return FMRES_IGNORED
		
	static PressButton; PressButton = get_uc(uc_handle, UC_Buttons)

	if((PressButton & IN_ATTACK2))
	{
		PressButton &= ~IN_ATTACK2
		set_uc(uc_handle, UC_Buttons, PressButton)
	}
	
	return FMRES_IGNORED
}


public fw_AddToFullPack_post(esState, iE, iEnt, iHost, iHostFlags, iPlayer, pSet)
{
	if(iEnt != g_Muzzleflash_Ent)
		return
		
	if(Get_BitVar(g_Muzzleflash, iHost))
	{
		set_es(esState, ES_Frame, float(random_num(0, 2)))
			
		set_es(esState, ES_RenderMode, kRenderTransAdd)
		set_es(esState, ES_RenderAmt, 255.0)
		
		UnSet_BitVar(g_Muzzleflash, iHost)
	}
		
	set_es(esState, ES_Skin, iHost)
	set_es(esState, ES_Body, 1)
	set_es(esState, ES_AimEnt, iHost)
	set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
}

public fw_CheckVisibility(iEntity, pSet)
{
	if (iEntity != g_Muzzleflash_Ent)
		return FMRES_IGNORED
	
	forward_return(FMV_CELL, 1)
	
	return FMRES_SUPERCEDE
}

public fw_Weapon_PrimaryAttack(Ent)
{
	static id; id = pev(Ent, pev_owner)
	pev(id, pev_punchangle, g_Recoil[id])
	
	return HAM_IGNORED
}

public fw_Weapon_PrimaryAttack_Post(Ent)
{
	static id; id = pev(Ent, pev_owner)
	
	if(Get_BitVar(g_Had_Ethereal, id))
	{
		static Float:Push[3]
		pev(id, pev_punchangle, Push)
		xs_vec_sub(Push, g_Recoil[id], Push)
		
		xs_vec_mul_scalar(Push, RECOIL, Push)
		xs_vec_add(Push, g_Recoil[id], Push)
		set_pev(id, pev_punchangle, Push)
		
		Event_CurWeapon(id)
		Set_BitVar(g_Muzzleflash, id)
	}
}

public fw_Weapon_WeaponIdle_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return HAM_IGNORED	
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return HAM_IGNORED	
	if(!Get_BitVar(g_Had_Ethereal, Id))
		return HAM_IGNORED	
		
	if(get_pdata_float(Ent, 48, 4) <= 0.1) 
	{
		set_weapon_anim(Id, E_ANIM_IDLE)
		
		set_pdata_float(Ent, 48, 20.0, 4)
		set_pdata_string(Id, (492) * 4, PLAYER_ANIMEXT, -1 , 20)
	}
	
	return HAM_IGNORED	
}

public fw_Item_Deploy_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return
	if(!Get_BitVar(g_Had_Ethereal, Id))
		return
	
	set_pev(Id, pev_viewmodel2, V_MODEL)
	set_pev(Id, pev_weaponmodel2, P_MODEL)
	
	set_weapon_anim(Id, E_ANIM_DRAW)
}

public fw_Item_AddToPlayer_Post(Ent, id)
{
	if(!pev_valid(Ent))
		return HAM_IGNORED
		
	if(pev(Ent, pev_impulse) == 1712015)
	{
		Set_BitVar(g_Had_Ethereal, id)
		set_pev(Ent, pev_impulse, 0)
	}		
	
	message_begin(MSG_ONE_UNRELIABLE, g_Msg_WeaponList, .player = id)
	write_string(Get_BitVar(g_Had_Ethereal, id) ? "weapon_ethereal" : "weapon_m4a1")
	write_byte(4) // PrimaryAmmoID
	write_byte(90) // PrimaryAmmoMaxAmount
	write_byte(-1) // SecondaryAmmoID
	write_byte(-1) // SecondaryAmmoMaxAmount
	write_byte(0) // SlotID (0...N)
	write_byte(6) // NumberInSlot (1...N)
	write_byte(Get_BitVar(g_Had_Ethereal, id) ? CSW_ETHEREAL : CSW_M4A1) // WeaponID
	write_byte(0) // Flags
	message_end()

	return HAM_HANDLED	
}

public fw_Item_PostFrame(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Ethereal, id))
		return HAM_IGNORED	
	
	static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
	static bpammo; bpammo = cs_get_user_bpammo(id, CSW_ETHEREAL)
	
	static iClip; iClip = get_pdata_int(ent, 51, 4)
	static fInReload; fInReload = get_pdata_int(ent, 54, 4)
	
	if(fInReload && flNextAttack <= 0.0)
	{
		static temp1
		temp1 = min(CLIP - iClip, bpammo)

		set_pdata_int(ent, 51, iClip + temp1, 4)
		cs_set_user_bpammo(id, CSW_ETHEREAL, bpammo - temp1)		
		
		set_pdata_int(ent, 54, 0, 4)
		
		fInReload = 0
	}		
	
	return HAM_IGNORED
}

public fw_Weapon_Reload(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Ethereal, id))
		return HAM_IGNORED	

	g_Ethereal_Clip[id] = -1
		
	static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_ETHEREAL)
	static iClip; iClip = get_pdata_int(ent, 51, 4)
		
	if(BPAmmo <= 0)
		return HAM_SUPERCEDE
	if(iClip >= CLIP)
		return HAM_SUPERCEDE		
			
	g_Ethereal_Clip[id] = iClip	
	
	return HAM_HANDLED
}

public fw_Weapon_Reload_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Ethereal, id))
		return HAM_IGNORED	
		
	if((get_pdata_int(ent, 54, 4) == 1))
	{ // Reload
		if(g_Ethereal_Clip[id] == -1)
			return HAM_IGNORED
		
		set_pdata_int(ent, 51, g_Ethereal_Clip[id], 4)
		set_weapon_anim(id, E_ANIM_RELOAD)
	}
	
	return HAM_HANDLED
}

public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_ETHEREAL || !Get_BitVar(g_Had_Ethereal, Attacker))
		return HAM_IGNORED
		
	static Float:flEnd[3], Float:vecPlane[3]
		
	get_tr2(pentru, TR_vecEndPos, flEnd)
	get_tr2(pentru, TR_vecPlaneNormal, vecPlane)		
			
	//Make_BulletHole(Attacker, flEnd, Damage)
	Make_LaserLine(Attacker, flEnd)
	Make_BulletSmoke(Attacker, pentru)

	SetHamParamFloat(3, float(DAMAGE))
	
	return HAM_IGNORED
}

public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_ETHEREAL || !Get_BitVar(g_Had_Ethereal, Attacker))
		return HAM_IGNORED
		
	SetHamParamFloat(3, float(DAMAGE))
	
	return HAM_IGNORED
}

public Make_LaserLine(id, Float:Origin[3])
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte (TE_BEAMENTPOINT)
	write_short(id | 0x1000)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_Beam_SprID)
	write_byte(1)
	write_byte(5)
	write_byte(1)
	write_byte(2)
	write_byte(0)
	write_byte(0)
	write_byte(125)
	write_byte(255)
	write_byte(200)
	write_byte(200)
	message_end()
}

public Give_RealAmmo(id, CSWID)
{
	static Amount, Max
	switch(CSWID)
	{
		case CSW_P228: {Amount = 10; Max = 104;}
		case CSW_SCOUT: {Amount = 6; Max = 180;}
		case CSW_XM1014: {Amount = 8; Max = 64;}
		case CSW_MAC10: {Amount = 16; Max = 200;}
		case CSW_AUG: {Amount = 6; Max = 180;}
		case CSW_ELITE: {Amount = 16; Max = 200;}
		case CSW_FIVESEVEN: {Amount = 4; Max = 200;}
		case CSW_UMP45: {Amount = 16; Max = 200;}
		case CSW_SG550: {Amount = 6; Max = 180;}
		case CSW_GALIL: {Amount = 6; Max = 180;}
		case CSW_FAMAS: {Amount = 6; Max = 180;}
		case CSW_USP: {Amount = 18; Max = 200;}
		case CSW_GLOCK18: {Amount = 16; Max = 200;}
		case CSW_AWP: {Amount = 6; Max = 60;}
		case CSW_MP5NAVY: {Amount = 16; Max = 200;}
		case CSW_M249: {Amount = 4; Max = 200;}
		case CSW_M3: {Amount = 8; Max = 64;}
		case CSW_M4A1: {Amount = 7; Max = 180;}
		case CSW_TMP: {Amount = 7; Max = 200;}
		case CSW_G3SG1: {Amount = 7; Max = 180;}
		case CSW_DEAGLE: {Amount = 10; Max = 70;}
		case CSW_SG552: {Amount = 7; Max = 180;}
		case CSW_AK47: {Amount = 7; Max = 180;}
		case CSW_P90: {Amount = 4; Max = 200;}
		default: {Amount = 3; Max = 200;}
	}

	for(new i = 0; i < Amount; i++) give_ammo(id, 0, CSWID, Max)
}

public give_ammo(id, silent, CSWID, Max)
{
	static Amount, Name[32]
		
	switch(CSWID)
	{
		case CSW_P228: {Amount = 13; formatex(Name, sizeof(Name), "357sig");}
		case CSW_SCOUT: {Amount = 30; formatex(Name, sizeof(Name), "762nato");}
		case CSW_XM1014: {Amount = 8; formatex(Name, sizeof(Name), "buckshot");}
		case CSW_MAC10: {Amount = 12; formatex(Name, sizeof(Name), "45acp");}
		case CSW_AUG: {Amount = 30; formatex(Name, sizeof(Name), "556nato");}
		case CSW_ELITE: {Amount = 30; formatex(Name, sizeof(Name), "9mm");}
		case CSW_FIVESEVEN: {Amount = 50; formatex(Name, sizeof(Name), "57mm");}
		case CSW_UMP45: {Amount = 12; formatex(Name, sizeof(Name), "45acp");}
		case CSW_SG550: {Amount = 30; formatex(Name, sizeof(Name), "556nato");}
		case CSW_GALIL: {Amount = 30; formatex(Name, sizeof(Name), "556nato");}
		case CSW_FAMAS: {Amount = 30; formatex(Name, sizeof(Name), "556nato");}
		case CSW_USP: {Amount = 12; formatex(Name, sizeof(Name), "45acp");}
		case CSW_GLOCK18: {Amount = 30; formatex(Name, sizeof(Name), "9mm");}
		case CSW_AWP: {Amount = 10; formatex(Name, sizeof(Name), "338magnum");}
		case CSW_MP5NAVY: {Amount = 30; formatex(Name, sizeof(Name), "9mm");}
		case CSW_M249: {Amount = 30; formatex(Name, sizeof(Name), "556natobox");}
		case CSW_M3: {Amount = 8; formatex(Name, sizeof(Name), "buckshot");}
		case CSW_M4A1: {Amount = 30; formatex(Name, sizeof(Name), "556nato");}
		case CSW_TMP: {Amount = 30; formatex(Name, sizeof(Name), "9mm");}
		case CSW_G3SG1: {Amount = 30; formatex(Name, sizeof(Name), "762nato");}
		case CSW_DEAGLE: {Amount = 7; formatex(Name, sizeof(Name), "50ae");}
		case CSW_SG552: {Amount = 30; formatex(Name, sizeof(Name), "556nato");}
		case CSW_AK47: {Amount = 30; formatex(Name, sizeof(Name), "762nato");}
		case CSW_P90: {Amount = 50; formatex(Name, sizeof(Name), "57mm");}
	}
	
	if(!silent) emit_sound(id, CHAN_ITEM, "items/9mmclip1.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	ExecuteHamB(Ham_GiveAmmo, id, Amount, Name, Max)
}

stock Eject_Shell(id, Shell_ModelIndex, Float:Time) // By Dias
{
	static Ent; Ent = get_pdata_cbase(id, 373, 5)
	if(!pev_valid(Ent))
		return

        set_pdata_int(Ent, 57, Shell_ModelIndex, 4)
        set_pdata_float(id, 111, get_gametime() + Time)
}

// Drop primary/secondary weapons
stock drop_weapons(id, dropwhat)
{
	// Get user weapons
	static weapons[32], num, i, weaponid
	num = 0 // reset passed weapons count (bugfix)
	get_user_weapons(id, weapons, num)
	
	// Loop through them and drop primaries or secondaries
	for (i = 0; i < num; i++)
	{
		// Prevent re-indexing the array
		weaponid = weapons
		
		if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
		{
			// Get weapon entity
			static wname[32]; get_weaponname(weaponid, wname, charsmax(wname))
			engclient_cmd(id, "drop", wname)
		}
	}
}

stock set_weapon_anim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
{
	// Find target
	static Decal; Decal = random_num(41, 45)
	static LoopTime; 
	
	if(Damage > 100.0) LoopTime = 2
	else LoopTime = 1
	
	for(new i = 0; i < LoopTime; i++)
	{
		// Put decal on "world" (a wall)
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_WORLDDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_byte(Decal)
		message_end()
		
		// Show sparcles
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_GUNSHOTDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_short(id)
		write_byte(Decal)
		message_end()
	}
}

stock Make_BulletSmoke(id, TrResult)
{
	static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
	
	get_weapon_attachment(id, vecSrc)
	global_get(glb_v_forward, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)

	get_tr2(TrResult, TR_vecEndPos, vecSrc)
	get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)
    
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, vecEnd[0])
	engfunc(EngFunc_WriteCoord, vecEnd[1])
	engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
	write_short(g_SmokePuff_SprId)
	write_byte(2)
	write_byte(50)
	write_byte(TE_FLAG)
	message_end()
}

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{ 
	static Float:vfEnd[3], viEnd[3] 
	get_user_origin(id, viEnd, 3)  
	IVecFVec(viEnd, vfEnd) 
	
	static Float:fOrigin[3], Float:fAngle[3]
	
	pev(id, pev_origin, fOrigin) 
	pev(id, pev_view_ofs, fAngle)
	
	xs_vec_add(fOrigin, fAngle, fOrigin) 
	
	static Float:fAttack[3]
	
	xs_vec_sub(vfEnd, fOrigin, fAttack)
	xs_vec_sub(vfEnd, fOrigin, fAttack) 
	
	static Float:fRate
	
	fRate = fDis / vector_length(fAttack)
	xs_vec_mul_scalar(fAttack, fRate, fAttack)
	
	xs_vec_add(fOrigin, fAttack, output)
}

stock Set_Player_NextAttack(id, CSWID, Float:NextTime)
{
	static Ent; Ent = fm_get_user_weapon_entity(id, CSWID)
	if(!pev_valid(Ent)) return
	
	set_pdata_float(id, 83, NextTime, 5)
	
	set_pdata_float(Ent, 46 , NextTime, 4)
	set_pdata_float(Ent, 47, NextTime, 4)
	set_pdata_float(Ent, 48, NextTime, 4)
}
extraitem_lightsaber.sma | Afiseaza codul
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <xs>

#define PLUGIN "[CSO] LightSaber"
#define VERSION "1.0"
#define AUTHOR "Dias Leon"

/* ===============================
------------ Configs -------------
=================================*/
#define DAMAGE_LIGHTSABER 62
#define DAMAGE_ATTACK 31

#define RADIUS_ON 96
#define RADIUS_OFF 72

#define DRAW_TIME 0.75
#define TURN_TIME 0.5
#define RESET_TIME 1.5

#define ANIMEXT1 "onehanded"
#define ANIMEXT2 "knife"

#define V_MODEL "models/v_sfsword.mdl"
#define P_MODEL_ON "models/p_sfsword_on.mdl"
#define P_MODEL_OFF "models/p_sfsword_off.mdl"

new const LightSaber_Sounds[14][] =
{
	"weapons/sfsword_draw.wav",
	"weapons/sfsword_hit1.wav",
	"weapons/sfsword_hit2.wav",
	"weapons/sfsword_idle.wav",
	"weapons/sfsword_midslash1.wav",
	"weapons/sfsword_midslash2.wav",
	"weapons/sfsword_midslash3.wav",
	"weapons/sfsword_off.wav",
	"weapons/sfsword_off_hit.wav",
	"weapons/sfsword_off_slash1.wav",
	"weapons/sfsword_on.wav", // 10
	"weapons/sfsword_stab.wav",
	"weapons/sfsword_wall1.wav",
	"weapons/sfsword_wall2.wav"
}

enum
{
	LS_ANIM_IDLE_ON = 0,
	LS_ANIM_ON,
	LS_ANIM_OFF,
	LS_ANIM_DRAW,
	LS_ANIM_STAB,
	LS_ANIM_STAB_MISS,
	LS_ANIM_MIDSLASH1,
	LS_ANIM_MIDSLASH2,
	LS_ANIM_MIDSLASH3,
	LS_ANIM_IDLE_OFF,
	LS_ANIM_SLASH_OFF
}

/* ===============================
--------- End of Config ----------
=================================*/

#define CSW_LIGHTSABER CSW_KNIFE
#define weapon_lightsaber "weapon_knife"

#define TASK_TURN 4234234
#define TASK_SLASH 6948638
#define TASK_RESET 54893534

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

enum
{
	HIT_NOTHING = 0,
	HIT_ENEMY,
	HIT_WALL
}

enum
{
	ATTACK_SLASH1 = 0,
	ATTACK_SLASH2,
	ATTACK_SLASH3
}

// Vars
new g_Had_LightSaber, g_IsOnMode, g_TempingAttack, g_InSpecialAttack
new g_OldWeapon[33], g_WillBeHit[33], g_AttackingMode[33]
new g_MaxPlayers, g_Ham_Bot

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_EmitSound, "fw_EmitSound")
	register_forward(FM_TraceLine, "fw_TraceLine")
	register_forward(FM_TraceHull, "fw_TraceHull")			
	
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_lightsaber, "fw_Weapon_WeaponIdle_Post", 1)
	g_MaxPlayers = get_maxplayers()
	
}

public plugin_precache()
{
	engfunc(EngFunc_PrecacheModel, V_MODEL)
	engfunc(EngFunc_PrecacheModel, P_MODEL_ON)
	engfunc(EngFunc_PrecacheModel, P_MODEL_OFF)
	
	for(new i = 0; i < sizeof(LightSaber_Sounds); i++)
		engfunc(EngFunc_PrecacheSound, LightSaber_Sounds)
}

public client_putinserver(id)
{
	Remove_LightSaber(id)

	if(!g_Ham_Bot && is_user_bot(id))
	{
		g_Ham_Bot = 1
		set_task(0.1, "Do_RegisterHam_Bot", id)
	}
}

public Do_RegisterHam_Bot(id)
{
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
}
public plugin_natives ()
{
	register_native("give_lightsaber", "give_weaponlight", 1)
}
public give_weaponlight(id)
{
	Get_LightSaber(id)
}
public Get_LightSaber(id)
{
	if(!is_user_alive(id))
		return
		
	Set_BitVar(g_Had_LightSaber, id)
	Set_BitVar(g_IsOnMode, id)
	UnSet_BitVar(g_TempingAttack, id)
	UnSet_BitVar(g_InSpecialAttack, id)
	g_WillBeHit[id] = HIT_NOTHING
	g_AttackingMode[id] = 0
	
	remove_task(id+TASK_TURN)
	remove_task(id+TASK_SLASH)
	remove_task(id+TASK_RESET)
	
	fm_give_item(id, weapon_lightsaber)
	if(get_user_weapon(id) == CSW_LIGHTSABER)
	{
		set_pev(id, pev_viewmodel2, V_MODEL)
		set_pev(id, pev_weaponmodel2, Get_BitVar(g_IsOnMode, id) ? P_MODEL_ON : P_MODEL_OFF)	

		set_player_nextattack(id, DRAW_TIME)
		set_weapons_timeidle(id, CSW_LIGHTSABER, DRAW_TIME + 0.5)
		
		set_weapon_anim(id, LS_ANIM_DRAW)
	} else {
		engclient_cmd(id, weapon_lightsaber)
	}
}

public Remove_LightSaber(id)
{
	UnSet_BitVar(g_Had_LightSaber, id)
	UnSet_BitVar(g_IsOnMode, id)
	UnSet_BitVar(g_TempingAttack, id)
	UnSet_BitVar(g_InSpecialAttack, id)
	g_WillBeHit[id] = HIT_NOTHING
	g_AttackingMode[id] = 0
	
	remove_task(id+TASK_TURN)
	remove_task(id+TASK_SLASH)
	remove_task(id+TASK_RESET)
}

public Event_CurWeapon(id)
{
	if(!is_user_alive(id))
		return
	static CSWID; CSWID = read_data(2)
	
	if((CSWID == CSW_LIGHTSABER && g_OldWeapon[id] != CSW_LIGHTSABER) && Get_BitVar(g_Had_LightSaber, id))
	{
		set_pev(id, pev_viewmodel2, V_MODEL)
		set_pev(id, pev_weaponmodel2, Get_BitVar(g_IsOnMode, id) ? P_MODEL_ON : P_MODEL_OFF)
		
		set_player_nextattack(id, DRAW_TIME)
		set_weapons_timeidle(id, CSW_LIGHTSABER, DRAW_TIME + 0.5)
		
		set_weapon_anim(id, LS_ANIM_DRAW)
		set_pdata_string(id, (492) * 4, ANIMEXT1, -1 , 20)
	} else if(CSWID != CSW_LIGHTSABER && g_OldWeapon[id] == CSW_LIGHTSABER) {
		g_AttackingMode[id] = 0
		
		Set_BitVar(g_IsOnMode, id)
		UnSet_BitVar(g_InSpecialAttack, id)
		
		remove_task(id+TASK_TURN)
	}
	
	g_OldWeapon[id] = CSWID
}

public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	if(!is_user_connected(id))
		return FMRES_IGNORED
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return FMRES_IGNORED
		
	if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i')
	{
		if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')
		{
			g_WillBeHit[id] = HIT_NOTHING
			return FMRES_SUPERCEDE
		}
		if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't')
		{
			if (sample[17] == 'w') // wall
			{
				g_WillBeHit[id] = HIT_WALL
				return FMRES_SUPERCEDE
			} else {
				g_WillBeHit[id] = HIT_ENEMY
				return FMRES_SUPERCEDE
			}
		}
		if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')
			return FMRES_SUPERCEDE;
	}
	
	return FMRES_IGNORED
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_user_alive(id)) 
		return
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return
	
	static ent; ent = fm_get_user_weapon_entity(id, CSW_LIGHTSABER)
	if(!pev_valid(ent))
		return
	if(get_pdata_float(id, 83, 5) > 0.0) 
		return
	
	static CurButton; CurButton = get_uc(uc_handle, UC_Buttons)
	if(CurButton & IN_ATTACK)
	{
		CurButton &= ~IN_ATTACK
		set_uc(uc_handle, UC_Buttons, CurButton)
		
		if(Get_BitVar(g_IsOnMode, id))
		{
			if(!Get_BitVar(g_InSpecialAttack, id))
			{
				if(g_AttackingMode[id] == 0) g_AttackingMode[id] = 1
				
				g_AttackingMode[id]++
				if(g_AttackingMode[id] > ATTACK_SLASH3) g_AttackingMode[id] = 1
				
				set_pdata_string(id, (492) * 4, ANIMEXT2, -1 , 20)
					
				Set_BitVar(g_TempingAttack, id)
				ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
				UnSet_BitVar(g_TempingAttack, id)
				
				set_weapons_timeidle(id, CSW_LIGHTSABER, 1.0)
				set_player_nextattack(id, 1.0)
				
				if(g_AttackingMode[id] == 1) set_weapon_anim(id, LS_ANIM_MIDSLASH1)
				else if(g_AttackingMode[id] == 2) set_weapon_anim(id, LS_ANIM_MIDSLASH2)
				else if(g_AttackingMode[id] == 3) set_weapon_anim(id, LS_ANIM_MIDSLASH3)
				
				set_task(0.25, "Damage_Slash", id+TASK_SLASH)
				set_task(RESET_TIME, "Reset_Anim", id+TASK_RESET)
				Set_BitVar(g_InSpecialAttack, id)
			} else {
				set_pdata_string(id, (492) * 4, ANIMEXT2, -1 , 20)
					
				Set_BitVar(g_TempingAttack, id)
				ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
				UnSet_BitVar(g_TempingAttack, id)
				
				set_weapons_timeidle(id, CSW_LIGHTSABER, 1.0)
				set_player_nextattack(id, 1.0)
				
				set_weapon_anim(id, LS_ANIM_STAB)
				
				set_task(0.25, "Damage_Stab", id+TASK_SLASH)
				set_task(0.5, "Damage_Stab", id+TASK_SLASH)
				set_task(RESET_TIME, "Reset_Anim", id+TASK_RESET)
				UnSet_BitVar(g_InSpecialAttack, id)
			}
		} else {
			set_pdata_string(id, (492) * 4, ANIMEXT2, -1 , 20)
					
			Set_BitVar(g_TempingAttack, id)
			ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
			UnSet_BitVar(g_TempingAttack, id)
			
			set_weapons_timeidle(id, CSW_LIGHTSABER, 1.0)
			set_player_nextattack(id, 1.0)
			
			set_weapon_anim(id, LS_ANIM_SLASH_OFF)
			set_task(0.25, "Damage_OffStab", id+TASK_SLASH)
			set_task(RESET_TIME, "Reset_Anim", id+TASK_RESET)
			
			UnSet_BitVar(g_InSpecialAttack, id)
		}
	} else if(CurButton & IN_ATTACK2) {
		CurButton &= ~IN_ATTACK2
		set_uc(uc_handle, UC_Buttons, CurButton)
		
		set_weapon_anim(id, !Get_BitVar(g_IsOnMode, id) ? LS_ANIM_ON : LS_ANIM_OFF)
		
		set_player_nextattack(id, TURN_TIME)
		set_weapons_timeidle(id, CSW_LIGHTSABER, TURN_TIME)
		
		set_task(TURN_TIME - 0.1, "Turn_Complete", id+TASK_TURN)
	}
}

public Turn_Complete(id)
{
	id -= TASK_TURN
	if(!is_user_alive(id)) 
		return
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return
		
	if(Get_BitVar(g_IsOnMode, id)) UnSet_BitVar(g_IsOnMode, id)
	else Set_BitVar(g_IsOnMode, id)	
	
	set_pev(id, pev_weaponmodel2, Get_BitVar(g_IsOnMode, id) ? P_MODEL_ON : P_MODEL_OFF)
	set_pdata_string(id, (492) * 4, Get_BitVar(g_IsOnMode, id) ? ANIMEXT1 : ANIMEXT2, -1 , 20)
}

public Reset_Anim(id)
{
	id -= TASK_RESET
	if(!is_user_alive(id)) 
		return
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return
		
	set_pdata_string(id, (492) * 4, Get_BitVar(g_IsOnMode, id) ? ANIMEXT1 : ANIMEXT2, -1 , 20)
}

public Damage_Slash(id)
{
	id -= TASK_SLASH
	if(!is_user_alive(id)) 
		return
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return
		
	static Target; Target = CheckAttack(id, float(RADIUS_ON), 48.0, float(DAMAGE_LIGHTSABER))
	if(Target) emit_sound(id, CHAN_WEAPON, LightSaber_Sounds[random_num(1, 2)], 1.0, ATTN_NORM, 0, PITCH_NORM)
	else if(g_WillBeHit[id] == HIT_WALL) emit_sound(id, CHAN_WEAPON, LightSaber_Sounds[random_num(12, 13)], 1.0, ATTN_NORM, 0, PITCH_NORM)
}

public Damage_Stab(id)
{
	id -= TASK_SLASH
	if(!is_user_alive(id)) 
		return
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return
		
	static Target; Target = CheckAttack(id, float(RADIUS_ON), 48.0, float(DAMAGE_LIGHTSABER))
	if(Target) emit_sound(id, CHAN_WEAPON, LightSaber_Sounds[random_num(1, 2)], 1.0, ATTN_NORM, 0, PITCH_NORM)
	else if(g_WillBeHit[id] == HIT_WALL) emit_sound(id, CHAN_WEAPON, LightSaber_Sounds[random_num(12, 13)], 1.0, ATTN_NORM, 0, PITCH_NORM)
}

public Damage_OffStab(id)
{
	id -= TASK_SLASH
	if(!is_user_alive(id)) 
		return
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return
		
	static Ent; Ent = fm_get_user_weapon_entity(id, get_user_weapon(id))
	if(!pev_valid(Ent)) Ent = 0
	
	static Target; Target = CheckAttack(id, float(RADIUS_OFF), 24.0, float(DAMAGE_ATTACK))
	if(Target) emit_sound(id, CHAN_WEAPON, LightSaber_Sounds[8], 1.0, ATTN_NORM, 0, PITCH_NORM)
}

public CheckAttack(id, Float:Radius, Float:PointDis, Float:Damage)
{
	static Float:Max_Distance, Float:Point[4][3], Float:TB_Distance, Float:Point_Dis
	
	Point_Dis = PointDis
	Max_Distance = Radius
	TB_Distance = Max_Distance / 4.0
	
	static Float:VicOrigin[3], Float:MyOrigin[3]
	pev(id, pev_origin, MyOrigin)
	
	for(new i = 0; i < 4; i++) get_position(id, TB_Distance * (i + 1), 0.0, 0.0, Point[i])
		
	static Have_Victim; Have_Victim = 0
	static ent; ent = fm_get_user_weapon_entity(id, get_user_weapon(id))
		
	if(!pev_valid(ent))
		return 0
		
	for(new i = 0; i < g_MaxPlayers; i++)
	{
		if(!is_user_alive(i))
			continue
		if(id == i)
			continue
		if(entity_range(id, i) > Max_Distance)
			continue
	
		pev(i, pev_origin, VicOrigin)
		if(is_wall_between_points(MyOrigin, VicOrigin, id))
			continue
			
		if(get_distance_f(VicOrigin, Point[0]) <= Point_Dis
		|| get_distance_f(VicOrigin, Point[1]) <= Point_Dis
		|| get_distance_f(VicOrigin, Point[2]) <= Point_Dis
		|| get_distance_f(VicOrigin, Point[3]) <= Point_Dis)
		{
			if(!Have_Victim) Have_Victim = 1
			do_attack(id, i, ent, Damage)
		}
	}	
	
	if(Have_Victim) return 1
	return 0
}	

public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)

	if(Get_BitVar(g_TempingAttack, id)) xs_vec_mul_scalar(v_forward, (Get_BitVar(g_IsOnMode, id) ? float(RADIUS_ON) : float(RADIUS_OFF)), v_forward)
	else xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) != CSW_LIGHTSABER || !Get_BitVar(g_Had_LightSaber, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)
	
	if(Get_BitVar(g_TempingAttack, id)) xs_vec_mul_scalar(v_forward, (Get_BitVar(g_IsOnMode, id) ? float(RADIUS_ON) : float(RADIUS_OFF)), v_forward)
	else xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_TraceAttack(Victim, Attacker, Float:Damage, Float:Direction[3], TraceResult, DamageBits) 
{
	if(!is_user_alive(Attacker))	
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_LightSaber, Attacker) || !Get_BitVar(g_TempingAttack, Attacker))
		return HAM_IGNORED
		
	return HAM_SUPERCEDE
}

public fw_Weapon_WeaponIdle_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_LightSaber, id))
		return HAM_IGNORED
		
	if(get_pdata_float(ent, 48, 4) <= 0.25) 
	{
		set_weapon_anim(id, Get_BitVar(g_IsOnMode, id) ? LS_ANIM_IDLE_ON : LS_ANIM_IDLE_OFF)
		set_pdata_float(ent, 48, 20.0, 4)
	}
	
	return HAM_IGNORED
}

stock is_wall_between_points(Float:start[3], Float:end[3], ignore_ent)
{
	static pentru
	pentru = create_tr2()

	engfunc(EngFunc_TraceLine, start, end, IGNORE_MONSTERS, ignore_ent, pentru)
	
	static Float:EndPos[3]
	get_tr2(pentru, TR_vecEndPos, EndPos)

	free_tr2(pentru)
	return floatround(get_distance_f(end, EndPos))
} 

do_attack(Attacker, Victim, Inflictor, Float:fDamage)
{
	fake_player_trace_attack(Attacker, Victim, fDamage)
	fake_take_damage(Attacker, Victim, fDamage, Inflictor)
}

fake_player_trace_attack(iAttacker, iVictim, &Float:fDamage)
{
	// get fDirection
	static Float:fAngles[3], Float:fDirection[3]
	pev(iAttacker, pev_angles, fAngles)
	angle_vector(fAngles, ANGLEVECTOR_FORWARD, fDirection)
	
	// get fStart
	static Float:fStart[3], Float:fViewOfs[3]
	pev(iAttacker, pev_origin, fStart)
	pev(iAttacker, pev_view_ofs, fViewOfs)
	xs_vec_add(fViewOfs, fStart, fStart)
	
	// get aimOrigin
	static iAimOrigin[3], Float:fAimOrigin[3]
	get_user_origin(iAttacker, iAimOrigin, 3)
	IVecFVec(iAimOrigin, fAimOrigin)
	
	// TraceLine from fStart to AimOrigin
	static pentru; pentru = create_tr2() 
	engfunc(EngFunc_TraceLine, fStart, fAimOrigin, DONT_IGNORE_MONSTERS, iAttacker, pentru)
	static pHit; pHit = get_tr2(pentru, TR_pHit)
	static iHitgroup; iHitgroup = get_tr2(pentru, TR_iHitgroup)
	static Float:fEndPos[3]; get_tr2(pentru, TR_vecEndPos, fEndPos)

	// get target & body at aiming
	static iTarget, iBody
	get_user_aiming(iAttacker, iTarget, iBody)
	
	// if aiming find target is iVictim then update iHitgroup
	if (iTarget == iVictim)
	{
		iHitgroup = iBody
	}
	
	// if pentru find target not is iVictim
	else if (pHit != iVictim)
	{
		// get AimOrigin in iVictim
		static Float:fVicOrigin[3], Float:fVicViewOfs[3], Float:fAimInVictim[3]
		pev(iVictim, pev_origin, fVicOrigin)
		pev(iVictim, pev_view_ofs, fVicViewOfs) 
		xs_vec_add(fVicViewOfs, fVicOrigin, fAimInVictim)
		fAimInVictim[2] = fStart[2]
		fAimInVictim[2] += get_distance_f(fStart, fAimInVictim) * floattan( fAngles[0] * 2.0, degrees )
		
		// check aim in size of iVictim
		static iAngleToVictim; iAngleToVictim = get_angle_to_target(iAttacker, fVicOrigin)
		iAngleToVictim = abs(iAngleToVictim)
		static Float:fDis; fDis = 2.0 * get_distance_f(fStart, fAimInVictim) * floatsin( float(iAngleToVictim) * 0.5, degrees )
		static Float:fVicSize[3]
		pev(iVictim, pev_size , fVicSize)
		if ( fDis <= fVicSize[0] * 0.5 )
		{
			// TraceLine from fStart to aimOrigin in iVictim
			static ptr2; ptr2 = create_tr2() 
			engfunc(EngFunc_TraceLine, fStart, fAimInVictim, DONT_IGNORE_MONSTERS, iAttacker, ptr2)
			static pHit2; pHit2 = get_tr2(ptr2, TR_pHit)
			static iHitgroup2; iHitgroup2 = get_tr2(ptr2, TR_iHitgroup)
			
			// if ptr2 find target is iVictim
			if ( pHit2 == iVictim && (iHitgroup2 != HIT_HEAD || fDis <= fVicSize[0] * 0.25) )
			{
				pHit = iVictim
				iHitgroup = iHitgroup2
				get_tr2(ptr2, TR_vecEndPos, fEndPos)
			}
			
			free_tr2(ptr2)
		}
		
		// if pHit still not is iVictim then set default HitGroup
		if (pHit != iVictim)
		{
			// set default iHitgroup
			iHitgroup = HIT_GENERIC
			
			static ptr3; ptr3 = create_tr2() 
			engfunc(EngFunc_TraceLine, fStart, fVicOrigin, DONT_IGNORE_MONSTERS, iAttacker, ptr3)
			get_tr2(ptr3, TR_vecEndPos, fEndPos)
			
			// free ptr3
			free_tr2(ptr3)
		}
	}
	
	// set new Hit & Hitgroup & EndPos
	set_tr2(pentru, TR_pHit, iVictim)
	set_tr2(pentru, TR_iHitgroup, iHitgroup)
	set_tr2(pentru, TR_vecEndPos, fEndPos)

	// hitgroup multi fDamage
	static Float:fMultifDamage 
	switch(iHitgroup)
	{
		case HIT_HEAD: fMultifDamage  = 4.0
		case HIT_STOMACH: fMultifDamage  = 1.25
		case HIT_LEFTLEG: fMultifDamage  = 0.75
		case HIT_RIGHTLEG: fMultifDamage  = 0.75
		default: fMultifDamage  = 1.0
	}
	
	fDamage *= fMultifDamage
	
	// ExecuteHam
	fake_trake_attack(iAttacker, iVictim, fDamage, fDirection, pentru)
	
	// free pentru
	free_tr2(pentru)
}

stock fake_trake_attack(iAttacker, iVictim, Float:fDamage, Float:fDirection[3], iTraceHandle, iDamageBit = (DMG_NEVERGIB | DMG_BULLET))
{
	ExecuteHamB(Ham_TraceAttack, iVictim, iAttacker, fDamage, fDirection, iTraceHandle, iDamageBit)
}

stock fake_take_damage(iAttacker, iVictim, Float:fDamage, iInflictor = 0, iDamageBit = (DMG_NEVERGIB | DMG_BULLET))
{
	ExecuteHamB(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamage, iDamageBit)
}

stock get_angle_to_target(id, const Float:fTarget[3], Float:TargetSize = 0.0)
{
	static Float:fOrigin[3], iAimOrigin[3], Float:fAimOrigin[3], Float:fV1[3]
	pev(id, pev_origin, fOrigin)
	get_user_origin(id, iAimOrigin, 3) // end position from eyes
	IVecFVec(iAimOrigin, fAimOrigin)
	xs_vec_sub(fAimOrigin, fOrigin, fV1)
	
	static Float:fV2[3]
	xs_vec_sub(fTarget, fOrigin, fV2)
	
	static iResult; iResult = get_angle_between_vectors(fV1, fV2)
	
	if (TargetSize > 0.0)
	{
		static Float:fTan; fTan = TargetSize / get_distance_f(fOrigin, fTarget)
		static fAngleToTargetSize; fAngleToTargetSize = floatround( floatatan(fTan, degrees) )
		iResult -= (iResult > 0) ? fAngleToTargetSize : -fAngleToTargetSize
	}
	
	return iResult
}

stock get_angle_between_vectors(const Float:fV1[3], const Float:fV2[3])
{
	static Float:fA1[3], Float:fA2[3]
	engfunc(EngFunc_VecToAngles, fV1, fA1)
	engfunc(EngFunc_VecToAngles, fV2, fA2)
	
	static iResult; iResult = floatround(fA1[1] - fA2[1])
	iResult = iResult % 360
	iResult = (iResult > 180) ? (iResult - 360) : iResult
	
	return iResult
}

stock get_position(ent, Float:forw, Float:right, Float:up, Float:vStart[])
{
	static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(ent, pev_origin, vOrigin)
	pev(ent, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(ent, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}

stock set_weapons_timeidle(id, WeaponId ,Float:TimeIdle)
{
	static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
	if(!pev_valid(entwpn)) 
		return
		
	set_pdata_float(entwpn, 46, TimeIdle, 4)
	set_pdata_float(entwpn, 47, TimeIdle, 4)
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
}

stock set_weapon_anim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, id)
	write_byte(anim)
	write_byte(0)
	message_end()	
}

stock set_player_nextattack(id, Float:NextTime) set_pdata_float(id, 83, NextTime, 5)
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
extraitem_spear.sma | Afiseaza codul
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <fun>

#define PLUGIN "Speargun"
#define VERSION "1.0"
#define AUTHOR "Dias Pendragon"

#define SPEAR 30
#define SPEAR_SPEED 1500
#define SPEAR_EXP_RADIUS 100
#define SPEAR_DAMAGE 50 // 95: Human | 560: Zombie
#define SPEAR_KNOCK 1000

#define TIME_DRAW 0.75
#define TIME_RELOAD 2.5
#define TIME_EXPLOSION 1.0

#define OLD_WMODEL "models/w_m249.mdl"
#define PLAYER_ANIMEXT "carbine"

#define SPEAR_CLASSNAME "spear"
#define TASK_RELOAD 13320141

#define V_MODEL "models/v_speargun.mdl"
#define P_MODEL "models/p_speargun.mdl"
#define W_MODEL "models/w_speargun.mdl"
#define S_MODEL "models/s_spear.mdl"

new const SpearSounds[4][] = 
{
	"weapons/speargun-1.wav",
	"weapons/speargun_hit.wav",
	"weapons/speargun_draw.wav",
	"weapons/speargun_clipin.wav"
}

new const SpearResources[3][] =
{
	"sprites/weapon_speargun.txt",
	"sprites/640hud12_2.spr",
	"sprites/640hud103_2.spr"
}

new const ExplosionSpr[] = "sprites/spear_exp.spr"
new const ExplosionSpr2[] = "sprites/SpearExp.spr"

enum
{
	SPEAR_ANIM_IDLE = 0, // 30/51
	SPEAR_ANIM_SHOOT, // 30/31
	SPEAR_ANIM_RELOAD, // 30/55
	SPEAR_ANIM_DRAW, // 30/43
	SPEAR_ANIM_DRAW_EMPTY, // 30/43
	SPEAR_ANIM_IDLE_EMPTY // 30/51
}

const pev_user = pev_iuser1
const pev_touched = pev_iuser2
const pev_attached = pev_iuser3
const pev_hitgroup = pev_iuser4
const pev_time = pev_fuser1
const pev_time2 = pev_fuser2

const m_iLastHitGroup = 75

#define CSW_SPEAR CSW_M249
#define weapon_spear "weapon_m249"

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

new g_IsAlive, g_TempAttack, g_HamBot_Register, g_Shoot
new g_Had_Spear, g_Spear[33], Float:CheckDelay[33], g_CurrentSpear[33]
new g_MaxPlayers, g_MsgWeaponList, g_MsgCurWeapon, g_MsgAmmoX, g_CvarFriendlyFire
new g_SprId_LaserBeam, g_SprId_Exp, g_SprId_Exp2

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	register_event("DeathMsg", "Event_Death", "a")
	
	register_think(SPEAR_CLASSNAME, "fw_SpearThink")
	register_touch(SPEAR_CLASSNAME, "*", "fw_SpearTouch")
	
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_SetModel, "fw_SetModel")	
	register_forward(FM_EmitSound, "fw_EmitSound")
	register_forward(FM_TraceLine, "fw_TraceLine")
	register_forward(FM_TraceHull, "fw_TraceHull")	
	
	RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_spear, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Item_Deploy, weapon_spear, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_spear, "fw_Item_AddToPlayer_Post", 1)

	g_MaxPlayers = get_maxplayers()
	g_MsgWeaponList = get_user_msgid("WeaponList")
	g_MsgCurWeapon = get_user_msgid("CurWeapon")
	g_MsgAmmoX = get_user_msgid("AmmoX")
	g_CvarFriendlyFire = get_cvar_pointer("mp_friendlyfire")
	
	register_clcmd("weapon_speargun", "Hook_Weapon")
}

public plugin_precache()
{
	engfunc(EngFunc_PrecacheModel, V_MODEL)
	engfunc(EngFunc_PrecacheModel, P_MODEL)
	engfunc(EngFunc_PrecacheModel, W_MODEL)
	engfunc(EngFunc_PrecacheModel, S_MODEL)
	
	for(new i = 0; i < sizeof(SpearSounds); i++)
		engfunc(EngFunc_PrecacheSound, SpearSounds[i])
		
	for(new i = 0; i < sizeof(SpearResources); i++)
	{
		if(i == 0) engfunc(EngFunc_PrecacheGeneric, SpearResources[i])
		else engfunc(EngFunc_PrecacheModel, SpearResources[i])
	}	
	
	g_SprId_LaserBeam = engfunc(EngFunc_PrecacheModel, "sprites/laserbeam.spr")
	g_SprId_Exp = engfunc(EngFunc_PrecacheModel, ExplosionSpr)
	g_SprId_Exp2 = engfunc(EngFunc_PrecacheModel, ExplosionSpr2)
}

public client_putinserver(id)
{
	if(is_user_bot(id) && !g_HamBot_Register)
	{
		g_HamBot_Register = 1
		set_task(0.1, "Do_RegisterHamBot", id)
	}
	
	UnSet_BitVar(g_TempAttack, id)
	UnSet_BitVar(g_IsAlive, id)
}

public client_disconnect(id)
{
	UnSet_BitVar(g_TempAttack, id)
	UnSet_BitVar(g_IsAlive, id)
}

public Do_RegisterHamBot(id)
{
	RegisterHamFromEntity(Ham_Spawn, id, "fw_PlayerSpawn_Post", 1)
}

public plugin_natives ()
{
	register_native("give_spear", "give_weaponspear", 1)
}
public give_weaponspear(id)
{
	Get_Spear(id)
}

public Get_Spear(id)
{
	Set_BitVar(g_Had_Spear, id)
	UnSet_BitVar(g_Shoot, id)
	g_Spear[id] = SPEAR
	
	give_item(id, weapon_spear)
	
	update_ammo(id, -1, g_Spear[id])
}

public Remove_Spear(id)
{
	UnSet_BitVar(g_Had_Spear, id)
	UnSet_BitVar(g_Shoot, id)
	g_Spear[id] = 0
	
	remove_task(id+TASK_RELOAD)
}

public Hook_Weapon(id)
{
	engclient_cmd(id, weapon_spear)
	return PLUGIN_HANDLED
}

public Event_CurWeapon(id)
{
	if(!Get_BitVar(g_IsAlive, id))
		return
	
	static CSWID; CSWID = read_data(2)
	if(CSWID == CSW_SPEAR && Get_BitVar(g_Had_Spear, id))
		update_ammo(id, -1, g_Spear[id])
}

public Event_Death()
{
	static Victim; Victim = read_data(2)
	UnSet_BitVar(g_IsAlive, Victim)
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_SPEAR && Get_BitVar(g_Had_Spear, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[64]
	pev(entity, pev_classname, Classname, sizeof(Classname))
	
	if(!equal(Classname, "weaponbox"))
		return FMRES_IGNORED
	
	static id
	id = pev(entity, pev_owner)
	
	if(equal(model, OLD_WMODEL))
	{
		static weapon
		weapon = fm_get_user_weapon_entity(entity, CSW_SPEAR)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED
		
		if(Get_BitVar(g_Had_Spear, id))
		{
			UnSet_BitVar(g_Had_Spear, id)
			
			set_pev(weapon, pev_impulse, 1332014)
			set_pev(weapon, pev_iuser4, g_Spear[id])
			
			engfunc(EngFunc_SetModel, entity, W_MODEL)
			Remove_Spear(id)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, UcHandle, Seed)
{
	if(!Get_BitVar(g_IsAlive, id))
		return
	if(get_user_weapon(id) != CSW_SPEAR || !Get_BitVar(g_Had_Spear, id))
		return

	static CurButton; CurButton = get_uc(UcHandle, UC_Buttons)
	if(CurButton & IN_ATTACK)
	{
		if(get_pdata_float(id, 83, 5) > 0.0)
			return
		
		CurButton &= ~IN_ATTACK
		set_uc(UcHandle, UC_Buttons, CurButton)

		if(get_gametime() - TIME_RELOAD > CheckDelay[id])
		{
			Spear_Shooting(id)
			CheckDelay[id] = get_gametime()
		}
	} else if(CurButton & IN_ATTACK2) {
		CurButton &= ~IN_ATTACK2
		set_uc(UcHandle, UC_Buttons, CurButton)
		
		if(!Get_BitVar(g_Shoot, id))
			return
			
		if(pev_valid(g_CurrentSpear[id]))
		{
			SpearExplosion(g_CurrentSpear[id], 1)
			set_pev(g_CurrentSpear[id], pev_flags, FL_KILLME)
			
			UnSet_BitVar(g_Shoot, id)
		}
	}
}

public Spear_Shooting(id)
{
	if(g_Spear[id] <= 0)
		return
		
	Set_BitVar(g_Shoot, id)
		
	Set_BitVar(g_TempAttack, id)
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
	if(pev_valid(Ent)) ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
	UnSet_BitVar(g_TempAttack, id)
	
	g_Spear[id]--
	update_ammo(id, -1, g_Spear[id])
	
	Set_WeaponAnim(id, SPEAR_ANIM_SHOOT)
	emit_sound(id, CHAN_WEAPON, SpearSounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)	
	
	Make_FakePunch(id)
	
	// Set Idle
	Set_Player_NextAttack(id, TIME_RELOAD)
	Set_WeaponIdleTime(id, CSW_SPEAR, TIME_RELOAD)
		
	// Spear
	Create_Spear(id)
	
	// Set Task
	set_task(1.0, "Play_ReloadAnim", id+TASK_RELOAD)
}

public Make_FakePunch(id)
{
	static Float:PunchAngles[3]
	PunchAngles[0] = random_float(-3.5, -7.0)
	
	set_pev(id, pev_punchangle, PunchAngles)
}

public Play_ReloadAnim(id)
{
	id -= TASK_RELOAD
	
	if(!Get_BitVar(g_IsAlive, id))
		return
	if(get_user_weapon(id) != CSW_SPEAR || !Get_BitVar(g_Had_Spear, id))
		return
	if(g_Spear[id] <= 0)
		return
		
	Set_WeaponAnim(id, SPEAR_ANIM_RELOAD)
}

public Create_Spear(id)
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	if(!pev_valid(Ent)) return
	
	static Float:Origin[3], Float:Target[3], Float:Angles[3], Float:Velocity[3]
	
	get_weapon_attachment(id, Origin, 0.0)
	//Get_Position(id, 0.0, 9.0, -8.0, Origin)
	Get_Position(id, 1024.0, 0.0, 0.0, Target)
	
	pev(id, pev_v_angle, Angles); Angles[0] *= -1.0

	// Set info for ent
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	
	set_pev(Ent, pev_classname, SPEAR_CLASSNAME)
	engfunc(EngFunc_SetModel, Ent, S_MODEL)
	
	set_pev(Ent, pev_mins, Float:{-1.0, -1.0, -1.0})
	set_pev(Ent, pev_maxs, Float:{1.0, 1.0, 1.0})
	
	set_pev(Ent, pev_origin, Origin)
	set_pev(Ent, pev_angles, Angles)
	set_pev(Ent, pev_gravity, 0.01)
	
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	
	set_pev(Ent, pev_user, id)
	set_pev(Ent, pev_touched, 0)
	set_pev(Ent, pev_time, 0.0)
	set_pev(Ent, pev_time2, get_gametime() + 5.0)
	set_pev(Ent, pev_hitgroup, -1)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
	
	Get_SpeedVector(Origin, Target, float(SPEAR_SPEED), Velocity)
	set_pev(Ent, pev_velocity, Velocity)
	
	g_CurrentSpear[id] = Ent

	// Create Beam
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMFOLLOW)
	write_short(Ent)
	write_short(g_SprId_LaserBeam)
	write_byte(2)
	write_byte(1)
	write_byte(42)
	write_byte(255)
	write_byte(170)
	write_byte(150)
	message_end()
}

public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_TempAttack, id))
		return FMRES_IGNORED
		
	if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i')
	{
		if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')
			return FMRES_SUPERCEDE
		if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't')
		{
			if (sample[17] == 'w')  return FMRES_SUPERCEDE
			else  return FMRES_SUPERCEDE
		}
		if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')
			return FMRES_SUPERCEDE;
	}
	
	return FMRES_IGNORED
}

public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_TempAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)

	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_TempAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)
	
	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_SpearThink(Ent)
{
	if(!pev_valid(Ent))
		return
	if(pev(Ent, pev_flags) == FL_KILLME)
		return
		
	static Victim; Victim = pev(Ent, pev_attached)
	static Owner; Owner = pev(Ent, pev_user)
	
	if(!pev(Ent, pev_touched) && (is_user_connected(Owner) && Get_BitVar(g_IsAlive, Owner)))
	{
		static i, Target; Target = 0
		for(i = 0; i < g_MaxPlayers; i++)
		{
			if(!is_user_connected(i))
				continue
			if(!Get_BitVar(g_IsAlive, i))
				continue
			if(entity_range(Ent, i) > 24.0)
				continue
			
			Target = i
			
			break
		}
	
		if(Get_BitVar(g_IsAlive, Target) && Target != Owner)
		{
			if(!get_pcvar_num(g_CvarFriendlyFire))
			{
				if(cs_get_user_team(Owner) != cs_get_user_team(Target))
				{
					// Check hitgroup
					static Float:HeadOrigin[3], Float:HeadAngles[3];
					engfunc(EngFunc_GetBonePosition, Target, 8, HeadOrigin, HeadAngles);
						
					static Float:EntOrigin[3]
					pev(Ent, pev_origin, EntOrigin)
			
					if(get_distance_f(EntOrigin, HeadOrigin) <= 10.0) set_pev(Ent, pev_hitgroup, HIT_HEAD)
					else set_pev(Ent, pev_hitgroup, HIT_CHEST)
					
					// Handle
					set_pev(Ent, pev_touched, 1)
					set_pev(Ent, pev_time, get_gametime() + TIME_EXPLOSION)
					set_pev(Ent, pev_attached, Target)
				}
			} else {
				// Check hitgroup
				static Float:HeadOrigin[3], Float:HeadAngles[3];
				engfunc(EngFunc_GetBonePosition, Target, 8, HeadOrigin, HeadAngles);
					
				static Float:EntOrigin[3]
				pev(Ent, pev_origin, EntOrigin)
		
				if(get_distance_f(EntOrigin, HeadOrigin) <= 10.0) set_pev(Ent, pev_hitgroup, HIT_HEAD)
				else set_pev(Ent, pev_hitgroup, HIT_CHEST)
				
				// Handle
				set_pev(Ent, pev_touched, 1)
				set_pev(Ent, pev_time, get_gametime() + TIME_EXPLOSION)
				set_pev(Ent, pev_attached, Target)
			}
		}
	}
		
	if(is_user_connected(Victim) && Get_BitVar(g_IsAlive, Victim))
	{
		static Float:Origin[3]; pev(Victim, pev_origin, Origin)
		engfunc(EngFunc_SetOrigin, Ent, Origin)
		
		if(Get_BitVar(g_IsAlive, Owner))
		{
			static Float:OriginA[3]; pev(Owner, pev_origin, OriginA)
			static Float:Velocity[3]; Get_SpeedVector(OriginA, Origin, float(SPEAR_KNOCK), Velocity)
			
			static i
			for(i = 0; i < g_MaxPlayers; i++)
			{
				if(Victim == i)
					continue
				if(!is_user_connected(i))
					continue
				if(!Get_BitVar(g_IsAlive, i))
					continue
				if(entity_range(Victim, i) > 36.0)
					continue
				
				set_pev(i, pev_velocity, Velocity)
			}
			
			set_pev(Victim, pev_velocity, Velocity)
		}
	}
	
	if(pev(Ent, pev_touched) && pev(Ent, pev_time) <= get_gametime())
	{
		SpearExplosion(Ent, 0)
		set_pev(Ent, pev_flags, FL_KILLME)
		
		static Owner; Owner = pev(Ent, pev_user)
		UnSet_BitVar(g_Shoot, Owner)
	}
	
	if(pev(Ent, pev_time2) <= get_gametime())
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		
		static Owner; Owner = pev(Ent, pev_user)
		UnSet_BitVar(g_Shoot, Owner)
	}
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
}

public fw_SpearTouch(Ent, Touched)
{
	if(!pev_valid(Ent))
		return
		
	static id; id = pev(Ent, pev_user)
	if(!is_user_connected(id))
	{
		remove_entity(Ent)
		return
	}
	if(pev(Ent, pev_touched))
		return
	
	if(!is_user_alive(Touched))
	{
		emit_sound(Ent, CHAN_BODY, SpearSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		
		set_pev(Ent, pev_movetype, MOVETYPE_NONE)
		
		set_pev(Ent, pev_touched, 1)
		set_pev(Ent, pev_time, get_gametime() + TIME_EXPLOSION)
	}
}

public SpearExplosion(Ent, Remote)
{
	static Float:Origin[3]
	pev(Ent, pev_origin, Origin)
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_SprId_Exp)
	write_byte(20)
	write_byte(150)
	write_byte(TE_EXPLFLAG_NOSOUND)
	message_end()

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_SPARKS)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	message_end()

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_TAREXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	message_end()
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_SprId_Exp2)
	write_byte(6)
	write_byte(10)
	write_byte(TE_EXPLFLAG_NODLIGHTS | TE_EXPLFLAG_NOPARTICLES | TE_EXPLFLAG_NOSOUND)
	message_end()
	
	static Id; Id = pev(Ent, pev_user)
	if(is_user_connected(Id)) 
	{
		static Hitgroup; Hitgroup = pev(Ent, pev_hitgroup)
		static Target; Target = pev(Ent, pev_attached)
		
		Check_Damage(Ent, Id, Origin, Target)
		
		if(is_user_alive(Target))
		{
			if(!get_pcvar_flags(g_CvarFriendlyFire))
			{
				if(cs_get_user_team(Id) == cs_get_user_team(Target))
					return
			}
			
			if(Hitgroup == HIT_HEAD) 
			{
				set_pdata_int(Target, m_iLastHitGroup, HIT_HEAD, 5)
				ExecuteHamB(Ham_TakeDamage, Target, 0, Id, float(SPEAR_DAMAGE) * 2.5, DMG_BURN)
			} else {
				set_pdata_int(Target, m_iLastHitGroup, HIT_CHEST, 5)
				ExecuteHamB(Ham_TakeDamage, Target, 0, Id, float(SPEAR_DAMAGE), DMG_BURN)
			}
			
		}
	}
	
	// Extra
	if(Remote) SpearExplosion(Ent, 0)
}

public Check_Damage(Ent, id, Float:Origin[3], Except)
{
	for(new i = 0; i < g_MaxPlayers; i++)
	{
		if(!Get_BitVar(g_IsAlive, i))
			continue
		if(entity_range(Ent, i) > float(SPEAR_EXP_RADIUS))
			continue
		if(Except == i)
			continue
			
		if(id != i) ExecuteHamB(Ham_TakeDamage, i, 0, id, float(SPEAR_DAMAGE) / 3.0, DMG_BURN)
		Check_Knockback(i, Ent, id)
	}
}

public Check_Knockback(id, Ent, Owner)
{
	if(id == Owner)
	{
		static Float:Velocity[3]; pev(id, pev_velocity, Velocity)
		
		Velocity[0] *= 1.0; Velocity[1] *= 1.0; Velocity[2] *= 1.5
		if(Velocity[2] < 0.0) Velocity[2] /= -1.25 
		
		set_pev(id, pev_velocity, Velocity)
	}
}

public fw_PlayerSpawn_Post(id) 
{
	Set_BitVar(g_IsAlive, id)
}

public fw_Weapon_WeaponIdle_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return HAM_IGNORED	
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return HAM_IGNORED	
	if(!Get_BitVar(g_Had_Spear, Id))
		return HAM_IGNORED	
		
	if(get_pdata_float(Ent, 48, 4) <= 0.1) 
	{
		if(g_Spear[Id] > 0) Set_WeaponAnim(Id, SPEAR_ANIM_IDLE)
		else Set_WeaponAnim(Id, SPEAR_ANIM_IDLE_EMPTY)
		
		set_pdata_float(Ent, 48, 20.0, 4)
		set_pdata_string(Id, (492) * 4, PLAYER_ANIMEXT, -1 , 20)
	}
	
	return HAM_IGNORED	
}

public fw_Item_Deploy_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return
	if(!Get_BitVar(g_Had_Spear, Id))
		return
	
	set_pev(Id, pev_viewmodel2, V_MODEL)
	set_pev(Id, pev_weaponmodel2, P_MODEL)
	
	if(g_Spear[Id] > 0) Set_WeaponAnim(Id, SPEAR_ANIM_DRAW)
	else Set_WeaponAnim(Id, SPEAR_ANIM_DRAW_EMPTY)
	
	set_pdata_string(Id, (492) * 4, PLAYER_ANIMEXT, -1 , 20)
	Set_Player_NextAttack(Id, TIME_DRAW)
	
	remove_task(Id+TASK_RELOAD)
}

public fw_Item_AddToPlayer_Post(Ent, id)
{
	if(!pev_valid(Ent))
		return HAM_IGNORED
		
	if(pev(Ent, pev_impulse) == 1332014)
	{
		Set_BitVar(g_Had_Spear, id)
		set_pev(Ent, pev_impulse, 0)
		
		g_Spear[id] = pev(Ent, pev_iuser4)
	}		
	
	message_begin(MSG_ONE_UNRELIABLE, g_MsgWeaponList, .player = id)
	write_string(Get_BitVar(g_Had_Spear, id) ? "weapon_speargun" : weapon_spear)
	write_byte(3) // PrimaryAmmoID
	write_byte(200) // PrimaryAmmoMaxAmount
	write_byte(-1) // SecondaryAmmoID
	write_byte(-1) // SecondaryAmmoMaxAmount
	write_byte(0) // SlotID (0...N)
	write_byte(4) // NumberInSlot (1...N)
	write_byte(CSW_SPEAR) // WeaponID
	write_byte(0) // Flags
	message_end()

	return HAM_HANDLED	
}

public update_ammo(id, Ammo, BpAmmo)
{
	message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
	write_byte(1)
	write_byte(CSW_SPEAR)
	write_byte(Ammo)
	message_end()
	
	message_begin(MSG_ONE_UNRELIABLE, g_MsgAmmoX, _, id)
	write_byte(10)
	write_byte(BpAmmo)
	message_end()
	
	cs_set_user_bpammo(id, CSW_SPEAR, BpAmmo)
}

stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle)
{
	static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
	if(!pev_valid(entwpn)) 
		return
		
	set_pdata_float(entwpn, 46, TimeIdle, 4)
	set_pdata_float(entwpn, 47, TimeIdle, 4)
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
}

stock Set_Player_NextAttack(id, Float:nexttime)
{
	set_pdata_float(id, 83, nexttime, 5)
}

stock Set_WeaponAnim(id, Anim)
{
	set_pev(id, pev_weaponanim, Anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(Anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock Get_Position(id,Float:forw, Float:right, Float:up, Float:vStart[])
{
	static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}

stock Get_SpeedVector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
{
	new_velocity[0] = origin2[0] - origin1[0]
	new_velocity[1] = origin2[1] - origin1[1]
	new_velocity[2] = origin2[2] - origin1[2]
	new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
	new_velocity[0] *= num
	new_velocity[1] *= num
	new_velocity[2] *= num
	
	return 1;
}

stock Get_Yaw(Float:Start[3], Float:End[3])
{
	static Float:Vec[3], Float:Angles[3]
	Vec = Start
	
	Vec[0] = End[0] - Vec[0]
	Vec[1] = End[1] - Vec[1]
	Vec[2] = End[2] - Vec[2]
	engfunc(EngFunc_VecToAngles, Vec, Angles)
	Angles[0] = Angles[2] = 0.0 
	
	return floatround(Angles[1])
}

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{ 
	static Float:vfEnd[3], viEnd[3] 
	get_user_origin(id, viEnd, 3)  
	IVecFVec(viEnd, vfEnd) 
	
	static Float:fOrigin[3], Float:fAngle[3]
	
	pev(id, pev_origin, fOrigin) 
	pev(id, pev_view_ofs, fAngle)
	
	xs_vec_add(fOrigin, fAngle, fOrigin) 
	
	static Float:fAttack[3]
	
	xs_vec_sub(vfEnd, fOrigin, fAttack)
	xs_vec_sub(vfEnd, fOrigin, fAttack) 
	
	static Float:fRate
	
	fRate = fDis / vector_length(fAttack)
	xs_vec_mul_scalar(fAttack, fRate, fAttack)
	
	xs_vec_add(fOrigin, fAttack, output)
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1042\\ f0\\ fs16 \n\\ par }
*/
extraitem_thanatos11 | Afiseaza codul
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <fun>

#define PLUGIN "[CSO] Thanatos-11"
#define VERSION "1.0"
#define AUTHOR "Dias Pendragon"

#define DAMAGE_A 140 // 140 for zombie, 70 for human
#define DAMAGE_B 560 // 560 for zombie, 280 for human

#define CLIP 15
#define BPAMMO 64

#define SPEED 0.85
#define SCYTHE_RELOAD 5.0 // Reload Time per one
#define SCYTHE_MAX 3 // Max Ammo

#define SCYTHE_CLASSNAME "scythe11"

#define V_MODEL "models/v_thanatos11_fix.mdl"
#define P_MODEL "models/p_thanatos11.mdl"
#define W_MODEL "models/w_thanatos11.mdl"
#define S_MODEL "models/thanatos11_scythe.mdl"

new const WeaponSounds[16][] =
{
	"weapons/thanatos11-1.wav",
	"weapons/thanatos11_shootb.wav",
	"weapons/thanatos11_shootb_empty.wav",
	"weapons/thanatos11_shootb_hit.wav",
	"weapons/thanatos11_after_reload.wav",
	"weapons/thanatos11_changea.wav",
	"weapons/thanatos11_changea_empty.wav",
	"weapons/thanatos11_changeb.wav",
	"weapons/thanatos11_changeb_empty.wav",
	"weapons/thanatos11_count.wav",
	"weapons/thanatos11_count_start.wav",
	"weapons/thanatos11_explode.wav",
	"weapons/thanatos11_idleb_reload.wav",
	"weapons/thanatos11_idleb1.wav",
	"weapons/thanatos11_idleb2.wav",
	"weapons/thanatos11_insert_reload.wav"
}

#define SCYTHE_HEAD "sprites/thanatos11_scythe.spr"
#define SCYTHE_CIRCLE "sprites/circle.spr"
#define SCYTHE_DEATH "sprites/thanatos11_fire.spr"

#define CSW_THANATOS11 CSW_M3 
#define weapon_thanatos11 "weapon_m3"

#define WEAPON_SECRETCODE 2122015
#define OLD_W_MODEL "models/w_m3.mdl"
#define OLD_EVENT "events/m3.sc"

#define TASK_CHANGE 23332

enum
{
	T11_ANIM_IDLEA = 0, // 0
	T11_ANIM_IDLEB1,
	T11_ANIM_IDLEB2,
	T11_ANIM_INSERT,
	T11_ANIM_AFTER,
	T11_ANIM_START, // 5
	T11_ANIM_IDLEB_EMPTY,
	T11_ANIM_SHOOTA,
	T11_ANIM_SHOOTB,
	T11_ANIM_SHOOTB_EMPTY,
	T11_ANIM_CHANGEA, // 10
	T11_ANIM_CHANGEA_EMPTY,
	T11_ANIM_CHANGEB,
	T11_ANIM_CHANGEB_EMPTY,
	T11_ANIM_DRAW,
	T11_ANIM_IDLEB_RELOAD // 15
}

enum
{
	T11_MODE_NORMAL = 0,
	T11_MODE_THANATOS
}

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

new g_Had_Thanatos11, g_Thanatos11_Mode[33], g_ChargedAmmo2[33], g_OldWeapon[33], Float:ReloadTime[33]
new g_HamBot, g_MsgCurWeapon, g_Event_Thanatos11, g_SmokePuff_Id, m_spriteTexture
new g_Msg_StatusIcon, g_InTempingAttack, g_ScytheDeath

// Safety
new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]

// ==========================================================
enum _:ShotGuns {
	m3,
	xm1014
}

const NOCLIP_WPN_BS	= ((1<<CSW_HEGRENADE)|(1<<CSW_SMOKEGRENADE)|(1<<CSW_FLASHBANG)|(1<<CSW_KNIFE)|(1<<CSW_C4))
const SHOTGUNS_BS	= ((1<<CSW_M3)|(1<<CSW_XM1014))

// weapons offsets
#define XTRA_OFS_WEAPON			4
#define m_pPlayer				41
#define m_iId					43
#define m_fKnown				44
#define m_flNextPrimaryAttack		46
#define m_flNextSecondaryAttack	47
#define m_flTimeWeaponIdle		48
#define m_iPrimaryAmmoType		49
#define m_iClip				51
#define m_fInReload				54
#define m_fInSpecialReload		55
#define m_fSilent				74

// players offsets
#define XTRA_OFS_PLAYER		5
#define m_flNextAttack		83
#define m_rgAmmo_player_Slot0	376

stock const g_iDftMaxClip[CSW_P90+1] = {
	-1,  13, -1, 10,  1,  7,    1, 30, 30,  1,  30, 
		20, 25, 30, 35, 25,   12, 20, 10, 30, 100, 
		8 , 30, 30, 20,  2,    7, 30, 30, -1,  50}

stock const Float:g_fDelay[CSW_P90+1] = {
	0.00, 2.70, 0.00, 2.00, 0.00, 0.55,   0.00, 3.15, 3.30, 0.00, 4.50, 
		 2.70, 3.50, 3.35, 2.45, 3.30,   2.70, 2.20, 2.50, 2.63, 4.70, 
		 0.55, 3.05, 2.12, 3.50, 0.00,   2.20, 3.00, 2.45, 0.00, 3.40
}

stock const g_iReloadAnims[CSW_P90+1] = {
	-1,  5, -1, 3, -1,  6,   -1, 1, 1, -1, 14, 
		4,  2, 3,  1,  1,   13, 7, 4,  1,  3, 
		6, 11, 1,  3, -1,    4, 1, 1, -1,  1}
		
new Float:g_PostFrame[33]

// Attachment

#define MAX_CHANNEL 4
#define ATTACHMENT_CLASSNAME "hattach"

const pev_user = pev_iuser1
const pev_livetime = pev_fuser1
const pev_totalframe = pev_fuser2

new g_MyAttachment[33][MAX_CHANNEL+1]

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)

	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	register_forward(FM_EmitSound, "fw_EmitSound")
	register_forward(FM_TraceLine, "fw_TraceLine")
	register_forward(FM_TraceHull, "fw_TraceHull")		
	
	register_touch(SCYTHE_CLASSNAME, "*", "fw_Scythe_Touch")
	register_think(SCYTHE_CLASSNAME, "fw_Scythe_Think")
	
	// Safety
	Register_SafetyFunc()
	
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack")		
	
	RegisterHam(Ham_Item_Deploy, weapon_thanatos11, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_thanatos11, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_thanatos11, "fw_Item_PostFrame")
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_thanatos11, "fw_Weapon_WeaponIdle")	
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_thanatos11, "fw_Weapon_WeaponIdle_Post", 1)	
	
	// Cache
	g_Msg_StatusIcon = get_user_msgid("StatusIcon")
	g_MsgCurWeapon = get_user_msgid("CurWeapon")
	
	
	// Attach
	register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
	register_think(ATTACHMENT_CLASSNAME, "fw_Think")
}

public plugin_precache()
{
	precache_model(V_MODEL)
	precache_model(P_MODEL)
	precache_model(W_MODEL)
	precache_model(S_MODEL)
	g_ScytheDeath = precache_model(SCYTHE_DEATH)
	
	precache_model(SCYTHE_HEAD)
	precache_model(SCYTHE_CIRCLE)
	
	for(new i = 0; i < sizeof(WeaponSounds); i++)
		precache_sound(WeaponSounds[i])

	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)	
	
	m_spriteTexture = precache_model("sprites/laserbeam.spr")
	g_SmokePuff_Id = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
}

public fw_PrecacheEvent_Post(type, const name[])
{
	if(equal(OLD_EVENT, name))
		g_Event_Thanatos11 = get_orig_retval()
}

public client_putinserver(id)
{
	Safety_Connected(id)
	
	if(!g_HamBot && is_user_bot(id))
	{
		g_HamBot = 1
		set_task(0.1, "Do_Register_HamBot", id)
	}
}

public Do_Register_HamBot(id) 
{
	Register_SafetyFuncBot(id)
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
}

public client_disconnect(id)
{
	Safety_Disconnected(id)
}


public plugin_natives ()
{
	register_native("give_thanatos", "give_weaponthana", 1)
}
public give_weaponthana(id)
{
	Get_Thanatos11(id)
}


public Get_Thanatos11(id)
{
	Remove_Thanatos11(id)
	
	Set_BitVar(g_Had_Thanatos11, id)
	g_Thanatos11_Mode[id] = T11_MODE_NORMAL
	g_ChargedAmmo2[id] = 0
	
	give_item(id, weapon_thanatos11)
	cs_set_user_bpammo(id, CSW_THANATOS11, BPAMMO)
	
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_THANATOS11)
	if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, CLIP)
	
	engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, g_MsgCurWeapon, {0, 0, 0}, id)
	write_byte(1)
	write_byte(CSW_THANATOS11)
	write_byte(CLIP)
	message_end()
	
	update_specialammo(id, g_ChargedAmmo2[id], 0)
}

public Remove_Thanatos11(id)
{
	update_specialammo(id, g_ChargedAmmo2[id], 0)
	
	UnSet_BitVar(g_Had_Thanatos11, id)
	g_Thanatos11_Mode[id] = T11_MODE_NORMAL
	g_ChargedAmmo2[id] = 0
}

public Hook_Weapon(id)
{
	engclient_cmd(id, weapon_thanatos11)
	return PLUGIN_HANDLED
}

public Event_CurWeapon(id)
{
	if(!is_player(id, 1))
		return
	
	static CSWID; CSWID = read_data(2)

	if((CSWID == CSW_THANATOS11 && g_OldWeapon[id] == CSW_THANATOS11) && Get_BitVar(g_Had_Thanatos11, id)) 
	{
		static Ent; Ent = fm_get_user_weapon_entity(id, CSW_THANATOS11)
		if(pev_valid(Ent)) 
		{
			set_pdata_float(Ent, 46, get_pdata_float(Ent, 46, 4) * SPEED, 4)
			set_pdata_float(Ent, 47, get_pdata_float(Ent, 46, 4) * SPEED, 4)	
		}
	}
	
	g_OldWeapon[id] = CSWID
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[64]
	pev(entity, pev_classname, Classname, sizeof(Classname))
	
	if(!equal(Classname, "weaponbox"))
		return FMRES_IGNORED
	
	static id
	id = pev(entity, pev_owner)
	
	if(equal(model, OLD_W_MODEL))
	{
		static weapon
		weapon = fm_get_user_weapon_entity(entity, CSW_THANATOS11)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED
		
		if(Get_BitVar(g_Had_Thanatos11, id))
		{
			set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
			set_pev(weapon, pev_iuser4, g_ChargedAmmo2[id])
			engfunc(EngFunc_SetModel, entity, W_MODEL)
			
			Remove_Thanatos11(id)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_player(id, 1))
		return
	if(!Get_BitVar(g_Had_Thanatos11, id))
		return
		
	if(get_gametime() - SCYTHE_RELOAD > ReloadTime[id])
	{
		if(g_ChargedAmmo2[id] < SCYTHE_MAX)
		{
			update_specialammo(id, g_ChargedAmmo2[id], 0)
			g_ChargedAmmo2[id]++
			if(g_ChargedAmmo2[id] == 1 && g_Thanatos11_Mode[id] == T11_MODE_THANATOS) 
				Set_WeaponAnim(id, T11_ANIM_IDLEB_RELOAD)
			
			emit_sound(id, CHAN_ITEM, WeaponSounds[9], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
			
			update_specialammo(id, g_ChargedAmmo2[id], 1)
		}
		
		ReloadTime[id] = get_gametime()
	}
	
	if(get_player_weapon(id) != CSW_THANATOS11)
		return
		
	static PressedButton
	PressedButton = get_uc(uc_handle, UC_Buttons)
	
	if(PressedButton & IN_RELOAD)
	{
		if(get_pdata_float(id, 83, 5) > 0.0)
			return 
	
		if(g_Thanatos11_Mode[id] == T11_MODE_THANATOS)
		{
			PressedButton &= ~IN_RELOAD
			set_uc(uc_handle, UC_Buttons, PressedButton)
		}
	}
	
	if(PressedButton & IN_ATTACK)
	{
		if(get_pdata_float(id, 83, 5) > 0.0)
			return 
	
		if(g_Thanatos11_Mode[id] == T11_MODE_THANATOS)
		{
			PressedButton &= ~IN_ATTACK
			set_uc(uc_handle, UC_Buttons, PressedButton)
			
			Shoot_Scythe(id)
		}
	}
	
	if(PressedButton & IN_ATTACK2)
	{
		if(get_pdata_float(id, 83, 5) > 0.0)
			return 
	
		switch(g_Thanatos11_Mode[id])
		{
			case T11_MODE_NORMAL:
			{
				if(g_ChargedAmmo2[id] > 0) Set_WeaponAnim(id, T11_ANIM_CHANGEA)
				else Set_WeaponAnim(id, T11_ANIM_CHANGEA_EMPTY)
				
				set_pdata_float(id, 83, 2.5, 5)
				
				remove_task(id+TASK_CHANGE)
				set_task(2.35, "Complete_Reload", id+TASK_CHANGE)
			}
			case T11_MODE_THANATOS:
			{
				if(g_ChargedAmmo2[id] > 0) Set_WeaponAnim(id, T11_ANIM_CHANGEB)
				else Set_WeaponAnim(id, T11_ANIM_CHANGEB_EMPTY)
				
				set_pdata_float(id, 83, 2.5, 5)
				
				remove_task(id+TASK_CHANGE)
				set_task(2.35, "Complete_Reload", id+TASK_CHANGE)
			}
		}
	}
}

public Complete_Reload(id)
{
	id -= TASK_CHANGE
	
	if(!is_user_alive(id))
		return
	if(get_user_weapon(id) != CSW_THANATOS11 || !Get_BitVar(g_Had_Thanatos11, id))
		return
		
	switch(g_Thanatos11_Mode[id])
	{
		case T11_MODE_NORMAL:
		{
			g_Thanatos11_Mode[id] = T11_MODE_THANATOS
		}
		case T11_MODE_THANATOS:
		{
			g_Thanatos11_Mode[id] = T11_MODE_NORMAL
		}
	}
}

public Shoot_Scythe(id)
{
	if(g_ChargedAmmo2[id] <= 0)
		return

	Create_FakeAttackAnim(id)
	update_specialammo(id, g_ChargedAmmo2[id], 0)
	g_ChargedAmmo2[id]--
	
	if(g_ChargedAmmo2[id]) 
	{	
		Set_WeaponAnim(id, T11_ANIM_SHOOTB)
		update_specialammo(id, g_ChargedAmmo2[id], 1)
		
		emit_sound(id, CHAN_WEAPON, WeaponSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	} else {
		Set_WeaponAnim(id, T11_ANIM_SHOOTB_EMPTY)
		
		emit_sound(id, CHAN_WEAPON, WeaponSounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	}
	
	set_pdata_float(id, 83, 1.0, 5)
	
	// Fake Punch
	static Float:Origin[3]
	Origin[0] = random_float(-2.5, -5.0)
	
	set_pev(id, pev_punchangle, Origin)
	
	// Scythe
	Create_Scythe(id)
}

public Create_Scythe(id)
{
	new iEnt = create_entity("info_target")
	
	static Float:Origin[3], Float:Angles[3], Float:TargetOrigin[3], Float:Velocity[3]
	
	get_weapon_attachment(id, Origin, 40.0)
	get_position(id, 1024.0, 0.0, 0.0, TargetOrigin)
	
	pev(id, pev_v_angle, Angles)
	Angles[0] *= -1.0

	// set info for ent
	set_pev(iEnt, pev_movetype, MOVETYPE_FLY)
	entity_set_string(iEnt, EV_SZ_classname, SCYTHE_CLASSNAME)
	engfunc(EngFunc_SetModel, iEnt, S_MODEL)
	
	set_pev(iEnt, pev_mins, Float:{-6.0, -6.0, -6.0})
	set_pev(iEnt, pev_maxs, Float:{6.0, 6.0, 6.0})
	set_pev(iEnt, pev_origin, Origin)
	set_pev(iEnt, pev_gravity, 0.01)
	set_pev(iEnt, pev_angles, Angles)
	set_pev(iEnt, pev_solid, SOLID_TRIGGER)
	set_pev(iEnt, pev_owner, id)	
	set_pev(iEnt, pev_iuser1, get_user_team(id))
	set_pev(iEnt, pev_iuser2, 0)
	set_pev(iEnt, pev_fuser1, get_gametime() + 10.0)
	
	get_speed_vector(Origin, TargetOrigin, 1600.0, Velocity)
	set_pev(iEnt, pev_velocity, Velocity)	
	
	set_pev(iEnt, pev_nextthink, get_gametime() + 0.1)
	
	// Animation
	set_pev(iEnt, pev_animtime, get_gametime())
	set_pev(iEnt, pev_framerate, 2.0)
	set_pev(iEnt, pev_sequence, 0)
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMFOLLOW)
	write_short(iEnt)
	write_short(m_spriteTexture)
	write_byte(10)
	write_byte(3)
	write_byte(0)
	write_byte(85)
	write_byte(255)
	write_byte(255)
	message_end()
}

public fw_Scythe_Touch(Ent, id)
{
	if(!pev_valid(Ent))
		return
		
	if(is_user_alive(id))
	{
		static Owner; Owner = pev(Ent, pev_owner)
		if(!is_user_connected(Owner) || (get_user_team(id) == pev(Ent, pev_iuser1)))
			return
			
		ThanatosBladeSystem(id, Owner)
			
		set_pev(Ent, pev_movetype, MOVETYPE_NONE)
		set_pev(Ent, pev_velocity, {0.0, 0.0, 0.0})
		
		set_pev(Ent, pev_flags, FL_KILLME)
		set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
	} else {
		set_pev(Ent, pev_movetype, MOVETYPE_NONE)
		set_pev(Ent, pev_velocity, {0.0, 0.0, 0.0})
		
		set_pev(Ent, pev_flags, FL_KILLME)
		set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
		
		return
	}
}

public ThanatosBladeSystem(id, attacker)
{
	Show_Attachment(id, SCYTHE_HEAD, 3.0, 1.0, 1.0, 6)
	Show_Attachment(id, SCYTHE_CIRCLE, 3.0, 1.0, 0.1, 10)
	
	emit_sound(id, CHAN_ITEM, WeaponSounds[3], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	static ArraySuck[2]
	ArraySuck[0] = id
	ArraySuck[1] = attacker
	
	set_task(3.0, "Explosion", id+2122, ArraySuck, 2)
}

public Explosion(ArraySuck[], taskid)
{
	static id, attacker;
	id = ArraySuck[0]
	attacker = ArraySuck[1]
	
	if(!is_user_alive(id) || !is_user_connected(attacker))
		return
	if(get_user_team(id) == get_user_team(attacker))
		return
		
	emit_sound(id, CHAN_ITEM, WeaponSounds[11], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	static Float:Origin[3];
	pev(id, pev_origin, Origin)
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_ScytheDeath)
	write_byte(10)
	write_byte(15)
	write_byte(TE_EXPLFLAG_NOSOUND)  
	message_end()
	
	ExecuteHamB(Ham_TakeDamage, id, fm_get_user_weapon_entity(attacker, CSW_THANATOS11), attacker, float(DAMAGE_B), DMG_BULLET)
}

public fw_Scythe_Think(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Float:Time; pev(Ent, pev_fuser1, Time)
	
	if(Time <= get_gametime())
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
		
		return
	}
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
}


public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_player(id, 1))
		return FMRES_IGNORED	
	if(get_player_weapon(id) == CSW_THANATOS11 && Get_BitVar(g_Had_Thanatos11, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_player(invoker, 0))
		return FMRES_IGNORED		
	if(get_player_weapon(invoker) == CSW_THANATOS11 && Get_BitVar(g_Had_Thanatos11, invoker) && eventid == g_Event_Thanatos11)
	{
		engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
		Set_WeaponAnim(invoker, T11_ANIM_SHOOTA)

		emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], 1.0, ATTN_NORM, 0, PITCH_LOW)	
			
		return FMRES_SUPERCEDE
	}
	
	return FMRES_HANDLED
}

public fw_TraceAttack(Ent, Attacker, Float:Damage, Float:Dir[3], pentru, DamageType)
{
	if(!is_player(Attacker, 0))
		return HAM_IGNORED	
	if(get_player_weapon(Attacker) != CSW_THANATOS11 || !Get_BitVar(g_Had_Thanatos11, Attacker))
		return HAM_IGNORED
		
	static Float:flEnd[3], Float:vecPlane[3]
	
	get_tr2(pentru, TR_vecEndPos, flEnd)
	get_tr2(pentru, TR_vecPlaneNormal, vecPlane)		
		
	if(!is_player(Ent, 0))
	{
		make_bullet(Attacker, flEnd)
		fake_smoke(Attacker, pentru)
	}
	
	SetHamParamFloat(3, float(DAMAGE_A) / 6.0)
	
	return HAM_HANDLED	
}

public fw_Item_Deploy_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return
	if(!Get_BitVar(g_Had_Thanatos11, Id))
		return

	g_Thanatos11_Mode[Id] = T11_MODE_NORMAL
		
	set_pev(Id, pev_viewmodel2, V_MODEL)
	set_pev(Id, pev_weaponmodel2, P_MODEL)
	
	Set_WeaponAnim(Id, T11_ANIM_DRAW)
}

public fw_Item_AddToPlayer_Post(ent, id)
{
	if(pev(ent, pev_impulse) == WEAPON_SECRETCODE)
	{
		Set_BitVar(g_Had_Thanatos11, id)
		
		set_pev(ent, pev_impulse, 0)
		g_ChargedAmmo2[id] = pev(ent, pev_iuser4)
		
		update_specialammo(id, g_ChargedAmmo2[id], 1)
	}			
}

public update_specialammo(id, Ammo, On)
{
	static AmmoSprites[33]
	format(AmmoSprites, sizeof(AmmoSprites), "number_%d", Ammo)
  	
	message_begin(MSG_ONE_UNRELIABLE, g_Msg_StatusIcon, {0,0,0}, id)
	write_byte(On)
	write_string(AmmoSprites)
	write_byte(0) // red
	write_byte(85) // green
	write_byte(255) // blue
	message_end()	
}

public fw_Weapon_WeaponIdle( iEnt )
{
	if(pev_valid(iEnt) != 2)
		return 
	static id; id = get_pdata_cbase(iEnt, m_pPlayer, XTRA_OFS_WEAPON)
	if(get_pdata_cbase(id, 373) != iEnt)
		return
	if(!Get_BitVar(g_Had_Thanatos11, id))
		return
	
	if( get_pdata_float(iEnt, m_flTimeWeaponIdle, XTRA_OFS_WEAPON) > 0.0 )
	{
		return
	}
	
	static iId ; iId = get_pdata_int(iEnt, m_iId, XTRA_OFS_WEAPON)
	static iMaxClip ; iMaxClip = CLIP

	static iClip ; iClip = get_pdata_int(iEnt, m_iClip, XTRA_OFS_WEAPON)
	static fInSpecialReload ; fInSpecialReload = get_pdata_int(iEnt, m_fInSpecialReload, XTRA_OFS_WEAPON)

	if( !iClip && !fInSpecialReload )
	{
		return
	}

	if( fInSpecialReload )
	{
		static iBpAmmo ; iBpAmmo = get_pdata_int(id, 381, XTRA_OFS_PLAYER)
		static iDftMaxClip ; iDftMaxClip = g_iDftMaxClip[iId]

		if( iClip < iMaxClip && iClip == iDftMaxClip && iBpAmmo )
		{
			Shotgun_Reload(iEnt, iId, iMaxClip, iClip, iBpAmmo, id)
			return
		}
		else if( iClip == iMaxClip && iClip != iDftMaxClip )
		{
			Set_WeaponAnim(id, T11_ANIM_AFTER)
			
			set_pdata_int(iEnt, m_fInSpecialReload, 0, XTRA_OFS_WEAPON)
			set_pdata_float(iEnt, m_flTimeWeaponIdle, 1.5, XTRA_OFS_WEAPON)
		}
	}
	
	return
}

public fw_Weapon_WeaponIdle_Post( iEnt )
{
	if(pev_valid(iEnt) != 2)
		return 
	static id; id = get_pdata_cbase(iEnt, m_pPlayer, XTRA_OFS_WEAPON)
	if(get_pdata_cbase(id, 373) != iEnt)
		return
	if(!Get_BitVar(g_Had_Thanatos11, id))
		return
		
	static SpecialReload; SpecialReload = get_pdata_int(iEnt, 55, 4)
	if(!SpecialReload && get_pdata_float(iEnt, 48, 4) <= 0.25)
	{
		switch(g_Thanatos11_Mode[id])
		{
			case T11_MODE_NORMAL: Set_WeaponAnim(id, T11_ANIM_IDLEA)
			case T11_MODE_THANATOS: 
			{
				if(g_ChargedAmmo2[id] > 0) Set_WeaponAnim(id, T11_ANIM_IDLEB1)
				else Set_WeaponAnim(id, T11_ANIM_IDLEB_EMPTY)
			}
		}
		
		set_pdata_float(iEnt, 48, 20.0, 4)
	}	
}

public fw_Item_PostFrame( iEnt )
{
	static id ; id = get_pdata_cbase(iEnt, m_pPlayer, XTRA_OFS_WEAPON)	

	static iBpAmmo ; iBpAmmo = get_pdata_int(id, 381, XTRA_OFS_PLAYER)
	static iClip ; iClip = get_pdata_int(iEnt, m_iClip, XTRA_OFS_WEAPON)
	static iId ; iId = get_pdata_int(iEnt, m_iId, XTRA_OFS_WEAPON)
	static iMaxClip ; iMaxClip = CLIP

	// Support for instant reload (used for example in my plugin "Reloaded Weapons On New Round")
	// It's possible in default cs
	if( get_pdata_int(iEnt, m_fInReload, XTRA_OFS_WEAPON) && get_pdata_float(id, m_flNextAttack, 5) <= 0.0 )
	{
		new j = min(iMaxClip - iClip, iBpAmmo)
		set_pdata_int(iEnt, m_iClip, iClip + j, XTRA_OFS_WEAPON)
		set_pdata_int(id, 381, iBpAmmo-j, XTRA_OFS_PLAYER)
		
		set_pdata_int(iEnt, m_fInReload, 0, XTRA_OFS_WEAPON)
		return
	}

	static iButton ; iButton = pev(id, pev_button)
	if( iButton & IN_ATTACK && get_pdata_float(iEnt, m_flNextPrimaryAttack, XTRA_OFS_WEAPON) <= 0.0 )
	{
		return
	}
	
	if( iButton & IN_RELOAD  )
	{
		if( iClip >= iMaxClip )
		{
			set_pev(id, pev_button, iButton & ~IN_RELOAD) // still this fucking animation
			set_pdata_float(iEnt, m_flNextPrimaryAttack, 0.5, XTRA_OFS_WEAPON)  // Tip ?
		}

		else if( iClip == g_iDftMaxClip[iId] )
		{
			if( iBpAmmo )
			{
				Shotgun_Reload(iEnt, iId, iMaxClip, iClip, iBpAmmo, id)
			}
		}
	}
	
	if(get_pdata_int(iEnt, 55, 4) == 1)
	{
		static Float:CurTime
		CurTime = get_gametime()
		
		if(CurTime - 0.35 > g_PostFrame[id])
		{
			Set_WeaponAnim(id, T11_ANIM_INSERT)
			g_PostFrame[id] = CurTime
		}
	}
}

Shotgun_Reload(iEnt, iId, iMaxClip, iClip, iBpAmmo, id)
{
	if(iBpAmmo <= 0 || iClip == iMaxClip)
		return

	if(get_pdata_int(iEnt, m_flNextPrimaryAttack, XTRA_OFS_WEAPON) > 0.0)
		return

	switch( get_pdata_int(iEnt, m_fInSpecialReload, XTRA_OFS_WEAPON) )
	{
		case 0:
		{
			Set_WeaponAnim(id, T11_ANIM_START)
		
			set_pdata_int(iEnt, m_fInSpecialReload, 1, XTRA_OFS_WEAPON)
			set_pdata_float(id, m_flNextAttack, 0.55, 5)
			set_pdata_float(iEnt, m_flTimeWeaponIdle, 0.55, XTRA_OFS_WEAPON)
			set_pdata_float(iEnt, m_flNextPrimaryAttack, 0.55, XTRA_OFS_WEAPON)
			set_pdata_float(iEnt, m_flNextSecondaryAttack, 0.55, XTRA_OFS_WEAPON)
			return
		}
		case 1:
		{
			if( get_pdata_float(iEnt, m_flTimeWeaponIdle, XTRA_OFS_WEAPON) > 0.0 )
			{
				return
			}
			set_pdata_int(iEnt, m_fInSpecialReload, 2, XTRA_OFS_WEAPON)
			set_pdata_float(iEnt, m_flTimeWeaponIdle, iId == CSW_XM1014 ? 0.30 : 0.45, XTRA_OFS_WEAPON)
		}
		default:
		{
			set_pdata_int(iEnt, m_iClip, iClip + 1, XTRA_OFS_WEAPON)
			set_pdata_int(id, 381, iBpAmmo-1, XTRA_OFS_PLAYER)
			set_pdata_int(iEnt, m_fInSpecialReload, 1, XTRA_OFS_WEAPON)
		}
	}
}

public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	if(!is_user_connected(id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_InTempingAttack, id))
		return FMRES_IGNORED
		
	if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i')
	{
		if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')
			return FMRES_SUPERCEDE
		if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't')
		{
			if (sample[17] == 'w')  return FMRES_SUPERCEDE
			else  return FMRES_SUPERCEDE
		}
		if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')
			return FMRES_SUPERCEDE;
	}
	
	return FMRES_IGNORED
}

public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(!Get_BitVar(g_InTempingAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)

	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(!Get_BitVar(g_InTempingAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)
	
	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
	
	return FMRES_SUPERCEDE
}

public Create_FakeAttackAnim(id)
{
	Set_BitVar(g_InTempingAttack, id)
	
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
	if(pev_valid(Ent)) ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
	
	UnSet_BitVar(g_InTempingAttack, id)
}

public Event_NewRound() remove_entity_name(ATTACHMENT_CLASSNAME)
public Show_Attachment(id, const Sprite[],  Float:Time, Float:Scale, Float:FrameRate, TotalFrame)
{
	if(!is_user_alive(id))
		return

	static channel; channel = 0
	for(new i = 0; i < MAX_CHANNEL; i++)
	{
		if(pev_valid(g_MyAttachment[id][i])) channel++
		else {
			channel = i
			break
		}
	}
	if(channel >= MAX_CHANNEL) return
	if(!pev_valid(g_MyAttachment[id][channel]))
		g_MyAttachment[id][channel] = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
	if(!pev_valid(g_MyAttachment[id][channel]))
		return
	
	// Set Properties
	set_pev(g_MyAttachment[id][channel], pev_takedamage, DAMAGE_NO)
	set_pev(g_MyAttachment[id][channel], pev_solid, SOLID_NOT)
	set_pev(g_MyAttachment[id][channel], pev_movetype, MOVETYPE_FOLLOW)
	
	// Set Sprite
	set_pev(g_MyAttachment[id][channel], pev_classname, ATTACHMENT_CLASSNAME)
	engfunc(EngFunc_SetModel, g_MyAttachment[id][channel], Sprite)
	
	// Set Rendering
	set_pev(g_MyAttachment[id][channel], pev_renderfx, kRenderFxNone)
	set_pev(g_MyAttachment[id][channel], pev_rendermode, kRenderTransAdd)
	set_pev(g_MyAttachment[id][channel], pev_renderamt, 200.0)
	
	// Set other
	set_pev(g_MyAttachment[id][channel], pev_user, id)
	set_pev(g_MyAttachment[id][channel], pev_scale, Scale)
	set_pev(g_MyAttachment[id][channel], pev_livetime, get_gametime() + Time)
	set_pev(g_MyAttachment[id][channel], pev_totalframe, float(TotalFrame))
	
	// Set Origin
	static Float:Origin[3]; pev(id, pev_origin, Origin)
	if(!(pev(id, pev_flags) & FL_DUCKING)) Origin[2] += 25.0
	else Origin[2] += 20.0
	
	engfunc(EngFunc_SetOrigin, g_MyAttachment[id][channel], Origin)
	
	// Allow animation of sprite ?
	if(TotalFrame && FrameRate > 0.0)
	{
		set_pev(g_MyAttachment[id][channel], pev_animtime, get_gametime())
		set_pev(g_MyAttachment[id][channel], pev_framerate, FrameRate + 9.0)
		
		set_pev(g_MyAttachment[id][channel], pev_spawnflags, SF_SPRITE_STARTON)
		dllfunc(DLLFunc_Spawn, g_MyAttachment[id][channel])
	}	
	
	// Force Think
	set_pev(g_MyAttachment[id][channel], pev_nextthink, get_gametime() + 0.05)
}

public fw_Think(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Owner; Owner = pev(Ent, pev_user)
	if(!is_user_alive(Owner))
	{
		engfunc(EngFunc_RemoveEntity, Ent)
		return
	}
	if(get_gametime() >= pev(Ent, pev_livetime))
	{
		if(pev(Ent, pev_renderamt) > 0.0)
		{
			static Float:AMT; pev(Ent, pev_renderamt, AMT)
			static Float:RealAMT; 
			
			AMT -= 10.0
			RealAMT = float(max(floatround(AMT), 0))
			
			set_pev(Ent, pev_renderamt, RealAMT)
		} else {
			engfunc(EngFunc_RemoveEntity, Ent)
			return
		}
	}
	if(pev(Ent, pev_frame) >= pev(Ent, pev_totalframe)) 
		set_pev(Ent, pev_frame, 0.0)
	
	// Set Attachment
	static Float:Origin[3]; pev(Owner, pev_origin, Origin)
	
	if(!(pev(Owner, pev_flags) & FL_DUCKING)) Origin[2] += 36.0
	else Origin[2] += 26.0
	
	engfunc(EngFunc_SetOrigin, Ent, Origin)
	
	// Force Think
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}

stock Set_WeaponAnim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock Set_Weapon_Idle(id, WeaponId ,Float:TimeIdle)
{
	static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
	if(!pev_valid(entwpn)) 
		return
		
	set_pdata_float(entwpn, 46, TimeIdle, 4)
	set_pdata_float(entwpn, 47, TimeIdle, 4)
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
}

stock Set_Player_NextAttack(id, Float:NextTime) set_pdata_float(id, 83, NextTime, 5)
stock make_bullet(id, Float:Origin[3])
{
	// Find target
	new decal = random_num(41, 45)
	const loop_time = 2
	
	static Body, Target
	get_user_aiming(id, Target, Body, 999999)
	
	if(is_user_connected(Target))
		return
	
	for(new i = 0; i < loop_time; i++)
	{
		// Put decal on "world" (a wall)
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_WORLDDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_byte(decal)
		message_end()
		
		// Show sparcles
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_GUNSHOTDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_short(id)
		write_byte(decal)
		message_end()
	}
}

stock fake_smoke(id, trace_result)
{
	static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
	
	get_weapon_attachment(id, vecSrc)
	global_get(glb_v_forward, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)

	get_tr2(trace_result, TR_vecEndPos, vecSrc)
	get_tr2(trace_result, TR_vecPlaneNormal, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)
    
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, vecEnd[0])
	engfunc(EngFunc_WriteCoord, vecEnd[1])
	engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
	write_short(g_SmokePuff_Id)
	write_byte(2)
	write_byte(50)
	write_byte(TE_FLAG)
	message_end()
}

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{ 
	new Float:vfEnd[3], viEnd[3] 
	get_user_origin(id, viEnd, 3)  
	IVecFVec(viEnd, vfEnd) 
	
	new Float:fOrigin[3], Float:fAngle[3]
	
	pev(id, pev_origin, fOrigin) 
	pev(id, pev_view_ofs, fAngle)
	
	xs_vec_add(fOrigin, fAngle, fOrigin) 
	
	new Float:fAttack[3]
	
	xs_vec_sub(vfEnd, fOrigin, fAttack)
	xs_vec_sub(vfEnd, fOrigin, fAttack) 
	
	new Float:fRate
	
	fRate = fDis / vector_length(fAttack)
	xs_vec_mul_scalar(fAttack, fRate, fAttack)
	
	xs_vec_add(fOrigin, fAttack, output)
}

stock get_position(ent, Float:forw, Float:right, Float:up, Float:vStart[])
{
	static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(ent, pev_origin, vOrigin)
	pev(ent, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(ent, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}

stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
{
	new_velocity[0] = origin2[0] - origin1[0]
	new_velocity[1] = origin2[1] - origin1[1]
	new_velocity[2] = origin2[2] - origin1[2]
	new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
	new_velocity[0] *= num
	new_velocity[1] *= num
	new_velocity[2] *= num
	
	return 1;
}

/* ===============================
------------- SAFETY -------------
=================================*/
public Register_SafetyFunc()
{
	register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
	
	RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
	RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
}

public Register_SafetyFuncBot(id)
{
	RegisterHamFromEntity(Ham_Spawn, id, "fw_Safety_Spawn_Post", 1)
	RegisterHamFromEntity(Ham_Killed, id, "fw_Safety_Killed_Post", 1)
}

public Safety_Connected(id)
{
	Set_BitVar(g_IsConnected, id)
	UnSet_BitVar(g_IsAlive, id)
	
	g_PlayerWeapon[id] = 0
}

public Safety_Disconnected(id)
{
	UnSet_BitVar(g_IsConnected, id)
	UnSet_BitVar(g_IsAlive, id)
	
	g_PlayerWeapon[id] = 0
}

public Safety_CurWeapon(id)
{
	if(!is_player(id, 1))
		return
		
	static CSW; CSW = read_data(2)
	if(g_PlayerWeapon[id] != CSW) g_PlayerWeapon[id] = CSW
}

public fw_Safety_Spawn_Post(id)
{
	if(!is_user_alive(id))
		return
		
	Set_BitVar(g_IsAlive, id)
}

public fw_Safety_Killed_Post(id)
{
	UnSet_BitVar(g_IsAlive, id)
}

public is_player(id, IsAliveCheck)
{
	if(!(1 <= id <= 32))
		return 0
	if(!Get_BitVar(g_IsConnected, id))
		return 0
	if(IsAliveCheck)
	{
		if(Get_BitVar(g_IsAlive, id)) return 1
		else return 0
	}
	
	return 1
}

public get_player_weapon(id)
{
	if(!is_player(id, 1))
		return 0
	
	return g_PlayerWeapon[id]
}

/* ===============================
--------- End of SAFETY ----------
=================================*/
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1042\\ f0\\ fs16 \n\\ par }
*/
extraitem_thunder.sma | Afiseaza codul
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <fun>

#define PLUGIN "Thunderbolt"
#define VERSION "2014"
#define AUTHOR "Dias"

#define DAMAGE 250
#define DEFAULT_AMMO 20
#define RELOAD_TIME 2.67

#define CSW_THUNDERBOLT CSW_AWP
#define weapon_thunderbolt "weapon_awp"
#define old_event "events/awp.sc"
#define old_w_model "models/w_awp.mdl"
#define WEAPON_SECRETCODE 4234234

#define V_MODEL "models/v_sfsniperF.mdl"
#define P_MODEL "models/p_sfsniper.mdl"
#define W_MODEL "models/w_sfsniper.mdl"

#define SNIP_MODEL_R "models/v_sfsightR.mdl"
#define SNIP_MODEL_B "models/v_sfsightB.mdl"

new const WeaponSounds[5][] = 
{
	"weapons/sfsniper-1.wav",
	"weapons/sfsniper_insight1.wav",
	"weapons/sfsniper_zoom.wav",
	"weapons/sfsniper_idle.wav",
	"weapons/sfsniper_draw.wav"
}

new const WeaponResources[4][] = 
{
	"sprites/weapon_sfsniperF.txt",
	"sprites/640hud2_2.spr",
	"sprites/640hud10_2.spr",
	"sprites/640hud81_2.spr"
}

enum
{
	TB_ANIM_IDLE = 0,
	TB_ANIM_SHOOT,
	TB_ANIM_DRAW
}

enum
{
	ZOOM_NONE = 0,
	ZOOM_ACT
}

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

new g_Had_Thunderbolt, g_Zoom[33]
new g_IsAlive
new Float:CheckDelay[33], Float:CheckDelay2[33], Float:CheckDelay3[33], g_TempAttack
new g_Msg_CurWeapon, g_Msg_AmmoX, g_Msg_WeaponList
new g_Beam_SprId, g_HamBot_Register, g_Event_Thunderbolt

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	register_event("DeathMsg", "Event_Death", "a")
	
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")		
	register_forward(FM_SetModel, "fw_SetModel")	
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_EmitSound, "fw_EmitSound")
	register_forward(FM_TraceLine, "fw_TraceLine")
	register_forward(FM_TraceHull, "fw_TraceHull")
	
	RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
	RegisterHam(Ham_Item_AddToPlayer, weapon_thunderbolt, "fw_AddToPlayer_Post", 1)
	RegisterHam(Ham_Item_Deploy, weapon_thunderbolt, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_thunderbolt, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_awp", "fw_Weapon_SecondaryAttack")
	
	g_Msg_CurWeapon = get_user_msgid("CurWeapon")
	g_Msg_AmmoX = get_user_msgid("AmmoX")	
	g_Msg_WeaponList = get_user_msgid("WeaponList")
	
	register_clcmd("weapon_sfsniperF", "CLCMD_HookWeapon")
}

public plugin_precache()
{
	precache_model(V_MODEL)
	precache_model(P_MODEL)
	precache_model(W_MODEL)
	
	precache_model(SNIP_MODEL_R)
	precache_model(SNIP_MODEL_B)
	
	for(new i = 0; i < sizeof(WeaponSounds); i++) 
		engfunc(EngFunc_PrecacheSound, WeaponSounds[i])
	for(new i = 0; i < sizeof(WeaponResources); i++)
	{
		if(i == 0) engfunc(EngFunc_PrecacheGeneric, WeaponResources[0])
		else engfunc(EngFunc_PrecacheModel, WeaponResources[i])
	}
	
	g_Beam_SprId =  engfunc(EngFunc_PrecacheModel, "sprites/laserbeam.spr")
}

public client_putinserver(id)
{
	if(is_user_bot(id) && !g_HamBot_Register)
	{
		g_HamBot_Register = 1
		set_task(0.1, "Do_RegisterHamBot", id)
	}
	
	UnSet_BitVar(g_TempAttack, id)
	UnSet_BitVar(g_IsAlive, id)
}

public Do_RegisterHamBot(id)
{
	RegisterHamFromEntity(Ham_Spawn, id, "fw_PlayerSpawn_Post", 1)
}

public fw_PrecacheEvent_Post(type, const name[])
{
	if(equal(old_event, name)) g_Event_Thunderbolt = get_orig_retval()
}

public plugin_natives ()
{
	register_native("give_thunderbolt", "give_weaponbolt", 1)
}
public give_weaponbolt(id)
{
	Get_Thunderbolt(id)
}


public Get_Thunderbolt(id)
{
	g_Zoom[id] = ZOOM_NONE
	Set_BitVar(g_Had_Thunderbolt, id)
	
	give_item(id, weapon_thunderbolt)
	
	static weapon_ent; weapon_ent = fm_find_ent_by_owner(-1, weapon_thunderbolt, id)
	if(pev_valid(weapon_ent)) cs_set_weapon_ammo(weapon_ent, 10)
	
	cs_set_user_bpammo(id, CSW_THUNDERBOLT, DEFAULT_AMMO)
}

public Remove_Thunderbolt(id)
{
	g_Zoom[id] = ZOOM_NONE
	UnSet_BitVar(g_Had_Thunderbolt, id)
}

public Event_CurWeapon(id)
{
	static CSWID; CSWID = read_data(2)
	if(CSWID != CSW_THUNDERBOLT || !Get_BitVar(g_Had_Thunderbolt, id))
		return
		
	/*
	if(cs_get_user_zoom(id) > 1) // Zoom
	{
		emit_sound(id, CHAN_WEAPON, WeaponSounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		if(!Get_BitVar(g_Zoomed, id))
		{
			//set_pev(id, pev_viewmodel2, SNIP_MODEL
			Set_BitVar(g_Zoomed, id)
		}
	} else { // Not Zoom
		emit_sound(id, CHAN_WEAPON, WeaponSounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		set_pev(id, pev_viewmodel2, V_MODEL)
		UnSet_BitVar(g_Zoomed, id)
	}*/
	
	UpdateAmmo(id, -1, cs_get_user_bpammo(id, CSW_THUNDERBOLT))
}

public Event_Death()
{
	static Victim; Victim = read_data(2)
	UnSet_BitVar(g_IsAlive, Victim)
}

public CLCMD_HookWeapon(id)
{
	engclient_cmd(id, weapon_thunderbolt)
	return
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_THUNDERBOLT && Get_BitVar(g_Had_Thunderbolt, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if(eventid != g_Event_Thunderbolt)
		return FMRES_IGNORED
	if(!Get_BitVar(g_IsAlive, invoker))
		return FMRES_IGNORED		
	if(get_user_weapon(invoker) != CSW_THUNDERBOLT || !Get_BitVar(g_Had_Thunderbolt, invoker))
		return FMRES_IGNORED
	
	engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)

	return FMRES_SUPERCEDE
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[64]
	pev(entity, pev_classname, Classname, sizeof(Classname))
	
	if(!equal(Classname, "weaponbox"))
		return FMRES_IGNORED
	
	static id
	id = pev(entity, pev_owner)
	
	if(equal(model, old_w_model))
	{
		static weapon
		weapon = fm_get_user_weapon_entity(entity, CSW_THUNDERBOLT)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED
		
		if(Get_BitVar(g_Had_Thunderbolt, id))
		{
			UnSet_BitVar(g_Had_Thunderbolt, id)
			
			set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
			set_pev(weapon, pev_iuser4, cs_get_user_bpammo(id, CSW_THUNDERBOLT))
			
			engfunc(EngFunc_SetModel, entity, W_MODEL)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, UcHandle, Seed)
{
	if(!Get_BitVar(g_IsAlive, id))
		return
	if(get_user_weapon(id) != CSW_THUNDERBOLT || !Get_BitVar(g_Had_Thunderbolt, id))
		return
	if(get_pdata_float(id, 83, 5) > 0.0)
		return
	
	static CurButton; CurButton = get_uc(UcHandle, UC_Buttons)
	if(CurButton & IN_ATTACK)
	{
		CurButton &= ~IN_ATTACK
		set_uc(UcHandle, UC_Buttons, CurButton)
		
		if(get_gametime() - RELOAD_TIME > CheckDelay[id])
		{
			Thunderbolt_Shooting(id)
			
			CheckDelay[id] = get_gametime()
		}
	}
	
	if(CurButton & IN_ATTACK2)
	{
		//CurButton &= ~IN_ATTACK2
		//set_uc(UcHandle, UC_Buttons, CurButton)
		//cs_set_user_
		//cs_set_user_zoom(id, CS_SET_NO_ZOOM, 1)
		
		if(get_gametime() - 0.5 > CheckDelay3[id])
		{
			switch(g_Zoom[id])
			{
				case ZOOM_NONE: Activate_Zoom(id, ZOOM_ACT)
				case ZOOM_ACT: Activate_Zoom(id, ZOOM_NONE)
				default: Activate_Zoom(id, ZOOM_NONE)
			}
			
			CheckDelay3[id] = get_gametime()
		}
	}
	
	if(get_gametime() - 0.25 > CheckDelay2[id])
	{
		static Body, Target; get_user_aiming(id, Target, Body, 99999)
		
		if(g_Zoom[id] == ZOOM_ACT)
		{
			if(Get_BitVar(g_IsAlive, Target))  
			{
				emit_sound(id, CHAN_WEAPON, WeaponSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
				set_pev(id, pev_viewmodel2, SNIP_MODEL_R)
			} else {
				set_pev(id, pev_viewmodel2, SNIP_MODEL_B)
			}
		}
		
		CheckDelay2[id] = get_gametime()
	}
}

public Activate_Zoom(id, Level)
{
	switch(Level)
	{
		case ZOOM_NONE:
		{
			g_Zoom[id] = Level
			set_pev(id, pev_viewmodel2, V_MODEL)
		}
		case ZOOM_ACT:
		{
			g_Zoom[id] = Level
			
			set_pev(id, pev_viewmodel2, SNIP_MODEL_B)
			emit_sound(id, CHAN_WEAPON, WeaponSounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
		default:
		{
			g_Zoom[id] = ZOOM_NONE
			Set_UserFov(id, 90)
			
			set_pev(id, pev_viewmodel2, V_MODEL)
		}
	}
}

public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_TempAttack, id))
		return FMRES_IGNORED
		
	if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i')
	{
		if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')
			return FMRES_SUPERCEDE
		if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't')
		{
			if (sample[17] == 'w')  return FMRES_SUPERCEDE
			else  return FMRES_SUPERCEDE
		}
		if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')
			return FMRES_SUPERCEDE;
	}
	
	return FMRES_IGNORED
}

public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_TempAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)

	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
{
	if(!Get_BitVar(g_IsAlive, id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_TempAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)
	
	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_PlayerSpawn_Post(id) Set_BitVar(g_IsAlive, id)
public fw_AddToPlayer_Post(ent, id)
{
	if(pev(ent, pev_impulse) == WEAPON_SECRETCODE)
	{
		Set_BitVar(g_Had_Thunderbolt, id)
		cs_set_user_bpammo(id, CSW_THUNDERBOLT, pev(ent, pev_iuser4))
		
		set_pev(ent, pev_impulse, 0)
	}			
	
	message_begin(MSG_ONE_UNRELIABLE, g_Msg_WeaponList, _, id)
	write_string((Get_BitVar(g_Had_Thunderbolt, id) ? "weapon_sfsniperF" : "weapon_awp"))
	write_byte(1)
	write_byte(30)
	write_byte(-1)
	write_byte(-1)
	write_byte(0)
	write_byte(2)
	write_byte(CSW_THUNDERBOLT)
	write_byte(0)
	message_end()
}

public fw_Item_Deploy_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return
	if(!Get_BitVar(g_Had_Thunderbolt, Id))
		return
	
	set_pev(Id, pev_viewmodel2, V_MODEL)
	set_pev(Id, pev_weaponmodel2, P_MODEL)
	
	Set_WeaponAnim(Id, TB_ANIM_DRAW)
	remove_task(Id+111)
}

public fw_Weapon_WeaponIdle_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return HAM_IGNORED	
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return HAM_IGNORED	
	if(!Get_BitVar(g_Had_Thunderbolt, Id))
		return HAM_IGNORED	

	if(get_pdata_float(Ent, 48, 4) <= 0.1) 
	{
		Set_WeaponAnim(Id, TB_ANIM_IDLE)
		set_pdata_float(Ent, 48, 20.0, 4)
	}
	
	return HAM_IGNORED	
}

public fw_Weapon_SecondaryAttack(Ent)
{
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	//if(get_pdata_cbase(Id, 373) != Ent)
		//return HAM_IGNORED	
	if(!Get_BitVar(g_Had_Thunderbolt, Id))
		return HAM_IGNORED	
		
	return HAM_SUPERCEDE
}

public Thunderbolt_Shooting(id)
{
	if(cs_get_user_bpammo(id, CSW_THUNDERBOLT) <= 0)
		return
		
	Set_BitVar(g_TempAttack, id)
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
	if(pev_valid(Ent)) ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
	UnSet_BitVar(g_TempAttack, id)
	
	cs_set_user_bpammo(id, CSW_THUNDERBOLT, cs_get_user_bpammo(id, CSW_THUNDERBOLT) - 1)
	set_pev(id, pev_viewmodel2, V_MODEL)
	
	set_task(RELOAD_TIME - 0.15, "Set_SniperModel", id+111)
	
	Set_WeaponAnim(id, TB_ANIM_SHOOT)
	emit_sound(id, CHAN_WEAPON, WeaponSounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)	
	
	Make_FakePunch(id)
	
	// Set Idle
	Ent = fm_get_user_weapon_entity(id, CSW_THUNDERBOLT)
	if(pev_valid(Ent)) 
	{
		set_pdata_float(id, 83, RELOAD_TIME, 5)
		
		set_pdata_float(Ent, 46, RELOAD_TIME, 4)
		set_pdata_float(Ent, 47, RELOAD_TIME, 4)
		set_pdata_float(Ent, 48, RELOAD_TIME + 0.25, 4)
	}
		
	Check_Damage(id)
		
	// Set Bullet reject
	set_pdata_float(id, 111, 0.0)
}

public Set_SniperModel(id)
{
	id -= 111
	if(!is_user_alive(id))
		return
	if(!Get_BitVar(g_Had_Thunderbolt, id))
		return
	if(g_Zoom[id] != ZOOM_ACT)
		return
		
	g_Zoom[id] = ZOOM_ACT
	set_pev(id, pev_viewmodel2, SNIP_MODEL_B)
}

public Make_FakePunch(id)
{
	static Float:PunchAngles[3]
	PunchAngles[0] = random_float(-3.5, -7.0)
	
	set_pev(id, pev_punchangle, PunchAngles)
}

public Check_Damage(id)
{
	static Float:StartOrigin[3], Float:EndOrigin[3], Float:EndOrigin2[3]
	
	Stock_Get_Postion(id, 40.0, 7.5, -5.0, StartOrigin)
	Stock_Get_Postion(id, 4096.0, 0.0, 0.0, EndOrigin)
	
	static TrResult; TrResult = create_tr2()
	engfunc(EngFunc_TraceLine, StartOrigin, EndOrigin, IGNORE_MONSTERS, id, TrResult) 
	get_tr2(TrResult, TR_vecEndPos, EndOrigin2)
	free_tr2(TrResult)
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMPOINTS)
	engfunc(EngFunc_WriteCoord, StartOrigin[0])
	engfunc(EngFunc_WriteCoord, StartOrigin[1])
	engfunc(EngFunc_WriteCoord, StartOrigin[2])
	engfunc(EngFunc_WriteCoord, EndOrigin2[0])
	engfunc(EngFunc_WriteCoord, EndOrigin2[1])
	engfunc(EngFunc_WriteCoord, EndOrigin2[2])
	write_short(g_Beam_SprId)
	write_byte(0)
	write_byte(0)
	write_byte(10)
	write_byte(25)
	write_byte(0)
	write_byte(0)
	write_byte(0)
	write_byte(200)
	write_byte(200)
	write_byte(0)
	message_end()	

	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_SPARKS) //TE_SPARKS
	engfunc(EngFunc_WriteCoord, EndOrigin2[0])
	engfunc(EngFunc_WriteCoord, EndOrigin2[1])
	engfunc(EngFunc_WriteCoord, EndOrigin2[2])
	message_end()	
	
	DealDamage(id, StartOrigin, EndOrigin2)	
}

public DealDamage(id, Float:Start[3], Float:End[3])
{
	static TrResult; TrResult = create_tr2()
	
	// Trace First Time
	engfunc(EngFunc_TraceLine, Start, End, DONT_IGNORE_MONSTERS, id, TrResult) 
	new pHit1; pHit1 = get_tr2(TrResult, TR_pHit)
	static Float:End1[3]; get_tr2(TrResult, TR_vecEndPos, End1)
	
	if(is_user_alive(pHit1)) 
	{
		do_attack(id, pHit1, 0, float(DAMAGE) * 1.5)
		engfunc(EngFunc_TraceLine, End1, End, DONT_IGNORE_MONSTERS, pHit1, TrResult) 
	} else engfunc(EngFunc_TraceLine, End1, End, DONT_IGNORE_MONSTERS, -1, TrResult) 
	
	// Trace Second Time
	new pHit2; pHit2 = get_tr2(TrResult, TR_pHit)
	static Float:End2[3]; get_tr2(TrResult, TR_vecEndPos, End2)
	
	if(is_user_alive(pHit2)) 
	{
		do_attack(id, pHit2, 0, float(DAMAGE) * 1.5)
		engfunc(EngFunc_TraceLine, End2, End, DONT_IGNORE_MONSTERS, pHit2, TrResult) 
	} else engfunc(EngFunc_TraceLine, End2, End, DONT_IGNORE_MONSTERS, -1, TrResult) 
	
	// Trace Third Time
	new pHit3; pHit3 = get_tr2(TrResult, TR_pHit)
	static Float:End3[3]; get_tr2(TrResult, TR_vecEndPos, End3)
	
	if(is_user_alive(pHit3)) 
	{
		do_attack(id, pHit3, 0, float(DAMAGE) * 1.5)
		engfunc(EngFunc_TraceLine, End3, End, DONT_IGNORE_MONSTERS, pHit3, TrResult) 
	} else engfunc(EngFunc_TraceLine, End3, End, DONT_IGNORE_MONSTERS, -1, TrResult) 
	
	// Trace Fourth Time
	new pHit4; pHit4 = get_tr2(TrResult, TR_pHit)
	if(is_user_alive(pHit4)) do_attack(id, pHit4, 0, float(DAMAGE) * 1.5)

	free_tr2(TrResult)
}

public UpdateAmmo(Id, Ammo, BpAmmo)
{
	static weapon_ent; weapon_ent = fm_get_user_weapon_entity(Id, CSW_THUNDERBOLT)
	if(pev_valid(weapon_ent))
	{
		if(BpAmmo > 0) cs_set_weapon_ammo(weapon_ent, 1)
		else cs_set_weapon_ammo(weapon_ent, 0)
	}
	
	engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, g_Msg_CurWeapon, {0, 0, 0}, Id)
	write_byte(1)
	write_byte(CSW_THUNDERBOLT)
	write_byte(-1)
	message_end()
	
	message_begin(MSG_ONE_UNRELIABLE, g_Msg_AmmoX, _, Id)
	write_byte(1)
	write_byte(BpAmmo)
	message_end()
	
	cs_set_user_bpammo(Id, CSW_THUNDERBOLT, BpAmmo)
}

stock Set_WeaponAnim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock Stock_Get_Postion(id,Float:forw,Float:right, Float:up,Float:vStart[])
{
	static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
} 


do_attack(Attacker, Victim, Inflictor, Float:fDamage)
{
	fake_player_trace_attack(Attacker, Victim, fDamage)
	fake_take_damage(Attacker, Victim, fDamage, Inflictor)
}

fake_player_trace_attack(iAttacker, iVictim, &Float:fDamage)
{
	// get fDirection
	new Float:fAngles[3], Float:fDirection[3]
	pev(iAttacker, pev_angles, fAngles)
	angle_vector(fAngles, ANGLEVECTOR_FORWARD, fDirection)
	
	// get fStart
	new Float:fStart[3], Float:fViewOfs[3]
	pev(iAttacker, pev_origin, fStart)
	pev(iAttacker, pev_view_ofs, fViewOfs)
	xs_vec_add(fViewOfs, fStart, fStart)
	
	// get aimOrigin
	new iAimOrigin[3], Float:fAimOrigin[3]
	get_user_origin(iAttacker, iAimOrigin, 3)
	IVecFVec(iAimOrigin, fAimOrigin)
	
	// TraceLine from fStart to AimOrigin
	new pentru; pentru = create_tr2() 
	engfunc(EngFunc_TraceLine, fStart, fAimOrigin, DONT_IGNORE_MONSTERS, iAttacker, pentru)
	new pHit; pHit = get_tr2(pentru, TR_pHit)
	new iHitgroup; iHitgroup = get_tr2(pentru, TR_iHitgroup)
	new Float:fEndPos[3]
	get_tr2(pentru, TR_vecEndPos, fEndPos)

	// get target & body at aiming
	new iTarget, iBody
	get_user_aiming(iAttacker, iTarget, iBody)
	
	// if aiming find target is iVictim then update iHitgroup
	if (iTarget == iVictim)
	{
		iHitgroup = iBody
	}
	
	// if pentru find target not is iVictim
	else if (pHit != iVictim)
	{
		// get AimOrigin in iVictim
		new Float:fVicOrigin[3], Float:fVicViewOfs[3], Float:fAimInVictim[3]
		pev(iVictim, pev_origin, fVicOrigin)
		pev(iVictim, pev_view_ofs, fVicViewOfs) 
		xs_vec_add(fVicViewOfs, fVicOrigin, fAimInVictim)
		fAimInVictim[2] = fStart[2]
		fAimInVictim[2] += get_distance_f(fStart, fAimInVictim) * floattan( fAngles[0] * 2.0, degrees )
		
		// check aim in size of iVictim
		new iAngleToVictim; iAngleToVictim = get_angle_to_target(iAttacker, fVicOrigin)
		iAngleToVictim = abs(iAngleToVictim)
		new Float:fDis; fDis = 2.0 * get_distance_f(fStart, fAimInVictim) * floatsin( float(iAngleToVictim) * 0.5, degrees )
		new Float:fVicSize[3]
		pev(iVictim, pev_size , fVicSize)
		if ( fDis <= fVicSize[0] * 0.5 )
		{
			// TraceLine from fStart to aimOrigin in iVictim
			new ptr2; ptr2 = create_tr2() 
			engfunc(EngFunc_TraceLine, fStart, fAimInVictim, DONT_IGNORE_MONSTERS, iAttacker, ptr2)
			new pHit2; pHit2 = get_tr2(ptr2, TR_pHit)
			new iHitgroup2; iHitgroup2 = get_tr2(ptr2, TR_iHitgroup)
			
			// if ptr2 find target is iVictim
			if ( pHit2 == iVictim && (iHitgroup2 != HIT_HEAD || fDis <= fVicSize[0] * 0.25) )
			{
				pHit = iVictim
				iHitgroup = iHitgroup2
				get_tr2(ptr2, TR_vecEndPos, fEndPos)
			}
			
			free_tr2(ptr2)
		}
		
		// if pHit still not is iVictim then set default HitGroup
		if (pHit != iVictim)
		{
			// set default iHitgroup
			iHitgroup = HIT_GENERIC
			
			new ptr3; ptr3 = create_tr2() 
			engfunc(EngFunc_TraceLine, fStart, fVicOrigin, DONT_IGNORE_MONSTERS, iAttacker, ptr3)
			get_tr2(ptr3, TR_vecEndPos, fEndPos)
			
			// free ptr3
			free_tr2(ptr3)
		}
	}
	
	// set new Hit & Hitgroup & EndPos
	set_tr2(pentru, TR_pHit, iVictim)
	set_tr2(pentru, TR_iHitgroup, iHitgroup)
	set_tr2(pentru, TR_vecEndPos, fEndPos)

	// ExecuteHam
	fake_trake_attack(iAttacker, iVictim, fDamage, fDirection, pentru)
	
	// free pentru
	free_tr2(pentru)
}

stock fake_trake_attack(iAttacker, iVictim, Float:fDamage, Float:fDirection[3], iTraceHandle, iDamageBit = (DMG_NEVERGIB | DMG_BULLET))
{
	ExecuteHamB(Ham_TraceAttack, iVictim, iAttacker, fDamage, fDirection, iTraceHandle, iDamageBit)
}

stock fake_take_damage(iAttacker, iVictim, Float:fDamage, iInflictor, iDamageBit = (DMG_NEVERGIB | DMG_BULLET))
{
	ExecuteHamB(Ham_TakeDamage, iVictim, iInflictor, iAttacker, fDamage, iDamageBit)
}

stock get_angle_to_target(id, const Float:fTarget[3], Float:TargetSize = 0.0)
{
	new Float:fOrigin[3], iAimOrigin[3], Float:fAimOrigin[3], Float:fV1[3]
	pev(id, pev_origin, fOrigin)
	get_user_origin(id, iAimOrigin, 3) // end position from eyes
	IVecFVec(iAimOrigin, fAimOrigin)
	xs_vec_sub(fAimOrigin, fOrigin, fV1)
	
	new Float:fV2[3]
	xs_vec_sub(fTarget, fOrigin, fV2)
	
	new iResult; iResult = get_angle_between_vectors(fV1, fV2)
	
	if (TargetSize > 0.0)
	{
		new Float:fTan; fTan = TargetSize / get_distance_f(fOrigin, fTarget)
		new fAngleToTargetSize; fAngleToTargetSize = floatround( floatatan(fTan, degrees) )
		iResult -= (iResult > 0) ? fAngleToTargetSize : -fAngleToTargetSize
	}
	
	return iResult
}

stock get_angle_between_vectors(const Float:fV1[3], const Float:fV2[3])
{
	new Float:fA1[3], Float:fA2[3]
	engfunc(EngFunc_VecToAngles, fV1, fA1)
	engfunc(EngFunc_VecToAngles, fV2, fA2)
	
	new iResult; iResult = floatround(fA1[1] - fA2[1])
	iResult = iResult % 360
	iResult = (iResult > 180) ? (iResult - 360) : iResult
	
	return iResult
}

stock Set_UserFov(id, FOV)
{
	if(!is_user_connected(id))
		return
		
	set_pdata_int(id, 363, FOV, 5)
	set_pev(id, pev_fov, FOV)
}


Nume: CSO Shop
Versiune: 0.1
Link oficial: https://www.extreamcs.com/forum

Instalare:
1. Fisierul csx_shopcso.sma il puneti in addons/amxmodx/scripting
2. Fisierul csx_shopcso.amxx il puneti in addons/amxmodx/plugins
3. Intrati in fisierul addons/amxmodx/configs/plugins.ini si adaugati la urma:

Code: Select all

csx_shopcso.amxx
4. In folderul shopcso , luati toate armele la rand aveti foldere "models" "sound" etc , doar le bagati in cstrike si apoi bagati pluginul si il conectati simplu.

Cvar-uri (se adauga in fisierul amxmodx\configs\amxx.cfg):
Nu exista nici cvar-uri !

Comenzi administrative (se tasteaza in consola si trebuie sa fiti administrator):
Nu exista nici comenzi administrative !

Comenzi publice (se tasteaza in joc prin apasarea tastei Y):
  • /csoshop - deschide shopul
Module necesare (se sterge ; din fata modulului de mai jos; acestea le gasiti in fisierul amxmodx\configs\modules.ini):
- CStrike
- Fun
- alte module necesare..

Imagini: Poza 1 - Click!
Poza 2 - Click!

Ofer support pentru acest plugin , orice eroare poate fi lasata aici in topic cu doar un singur reply.
Pluginul va fi actualizat saptamanal si voi pune si VIP CSO Weapons si Extra Items pentru servere classice tin sa mentionez ca in extra items va aparea (jetpack , grenazi din cso adica grenada aia pumpkin , aceea in forma de inimioara si multe altele !)

Credite: iNdio / Dias !
Multumiri: London (Versiune optimizata) !

Nu doresc hate sau altele.
Btw spor la joc !
Last edited by dragonCSX on 29 Jan 2019, 18:33, edited 18 times in total.
User avatar
LondoN eXtream
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 2889
Joined: 10 Oct 2014, 05:21
Detinator Steam: Da
SteamID: /id/london_extreamcs
Reputatie: Scripter eXtreamCS
Moderator ajutator
Membru Club eXtreamCS (6 luni)
Fond eXtream: 0
Location: Roman, Neamț
Has thanked: 2 times
Been thanked: 2 times

06 Jan 2019, 23:22

Code: Select all

client_cmd(id, "say /buyethereal") 
Native..
User avatar
dragonCSX
Membru, skill +1
Membru, skill +1
Posts: 189
Joined: 04 Feb 2017, 17:36
Detinator Steam: Da
CS Status: Web Developer / Scripting AMXX.
Detinator server CS: da
SteamID: weedakadulceata
Fond eXtream: 0
Location: Ploiesti
Contact:

06 Jan 2019, 23:32

LondoN eXtream wrote:

Code: Select all

client_cmd(id, "say /buyethereal") 
Native..
In urmatorul update probabil de dimineata o sa il fac prin native :*

Putea si lumea sa faca manual facand in sursele "extraitem_thanatos11" sau celelalte

adaugand

Code: Select all

public plugin_natives()
{
	register_native("get_user_thanatos","buy_thanatos",1)
}
public buy_thanatos(id)
{
	get_thanatos(id)
}
Apoi se punea in case-ul meniului.

Code: Select all

cs_set_user_money(id, cs_get_user_money(id) - 800);
get_user_thanatos(id)
Dar il actualizez maine la 0.2 setat pe native
Lux0R^
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 1225
Joined: 13 Jul 2013, 15:31
Detinator Steam: Da
Reputatie: Scripter eXtreamCS
Moderator ajutator
Has thanked: 15 times
Been thanked: 8 times

07 Jan 2019, 03:15

Pune sursa direct in topic sau pe pastebin
Pauza pana in iulie... licenta ^^

Fara pm-uri pentru pluginuri de zm/furien + tot ce tine de vip.

Codul Scripterului: scripting/codul-scripterului-t362300.html#p2754224
User avatar
dragonCSX
Membru, skill +1
Membru, skill +1
Posts: 189
Joined: 04 Feb 2017, 17:36
Detinator Steam: Da
CS Status: Web Developer / Scripting AMXX.
Detinator server CS: da
SteamID: weedakadulceata
Fond eXtream: 0
Location: Ploiesti
Contact:

07 Jan 2019, 11:35

Lux0R^ wrote:Pune sursa direct in topic sau pe pastebin
Sursa e conectata la mai multe pluginuri .
o sa reactualizez linkul de download dupa ce il mut le native
si las si poze.


UPDATE-ul intarzie.
Pozele au fost puse !
User avatar
Rainq
Manager ZM
Manager ZM
Posts: 2585
Joined: 21 Jul 2015, 18:50
Detinator Steam: Da
CS Status: Busy
Detinator server CS: ---
Reputatie: Fost moderator
Manager ZM.eXtreamCS.COM
Fost Membru Club eXtreamCS (trei luni)
Fond eXtream: 0
Location: Bucuresti
Been thanked: 10 times
Contact:

07 Jan 2019, 15:27

zic sa pui si sursa aici in caz expira link-ul sa fie aici , foarte reusit pluginul din poze
RETRAS
Image
Leul si tigru sunt mai puternici ca lupul,dar lupul la circ nu participa.
User avatar
dragonCSX
Membru, skill +1
Membru, skill +1
Posts: 189
Joined: 04 Feb 2017, 17:36
Detinator Steam: Da
CS Status: Web Developer / Scripting AMXX.
Detinator server CS: da
SteamID: weedakadulceata
Fond eXtream: 0
Location: Ploiesti
Contact:

07 Jan 2019, 15:45

Rainq wrote:zic sa pui si sursa aici in caz expira link-ul sa fie aici , foarte reusit pluginul din poze
Multumesc , revin cu edit .
Deoarece acum lucrez la update , si o sa las in topic toate sursele !

UPDATE PE V0.2 !
Adaugare: NATIVE LA ARME !


In 0.3 o sa adaug ca shopul sa fie pe un fel de sistem de ammo packs
Si va veni la pachet cu suport VIP.
User avatar
kmking
Membru, skill 0
Membru, skill 0
Posts: 30
Joined: 31 Oct 2018, 22:47
Detinator Steam: Nu
Detinator server CS: CS.PLAY4CS.RO
Fond eXtream: 0
Contact:

28 Jan 2019, 01:57

Salut !

Am adaugat pluginul tau , imi deschide meniul se descarca armele totul ok , dar :

Cand deschid meniul /csoshop apas pe o arma oricare dintre ele , imi apare mesajul ,
dar nu imi da arma , de la ce poate fi ?
Image
CONNECT CS.PLAY4CS.RO
User avatar
Diversity
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 501
Joined: 02 Nov 2014, 18:21
Detinator Steam: Nu
CS Status: Citesc forumul eXtreamCS.com...!
Reputatie: Scripter eXtreamCS
Fost Membru Club eXtreamCS (doua luni)
Nume anterior: IIiFF
Fond eXtream: 0
Location: Constanta
Has thanked: 17 times
Been thanked: 3 times

28 Jan 2019, 17:55

case 0: { .. }
===>

Code: Select all

case 0: 
		{ 
			if(cs_get_user_money(id) < 800) return chat_color( id, "!g[!y%s!g] !yBai zoofiule , nu ai bani sa o cumperi !", prefixCSO );
		
			cs_set_user_money(id, cs_get_user_money(id) - 800);
            give_lightsaber( id );
			chat_color( id, "!g[!y%s!g] !yAi cumparat !g(!yLightsaber!g) !", prefixCSO );
			chat_color( id, "!g[!y%s!g] !yEu sunt !gTATAL TAU !", prefixCSO ); 
		}

Code: Select all

menu_additem( menu, "\wLightsaber \y[ \r800$ \y]", "0", 0); 
	menu_additem( menu, "\wDart Pistol \y[ \r1500$ \y]", "1", 0); 
    menu_additem( menu, "\wThanatos-11 \y[ \r4500 \y]", "2", 0);
    menu_additem( menu, "\wEthereal Gun \y[ \r6500$ \y]", "3", 0);
    menu_additem( menu, "\wDual Uzi \y[ \r8500$ \y]", "4", 0);
    menu_additem( menu, "\wSpear Gun \y[ \r12500$ \y]", "5", 0);
    menu_additem( menu, "\wThunderbolt \y[ \r16000$ \y]^n", "6", 0);
	
	menu_setprop( menu, MPROP_EXITNAME, "\wIesire"); 
	
	menu_display( id, menu, 0 ); 
====>

Code: Select all

menu_additem( menu, "\wLightsaber \y[ \r800$ \y]"); 
	menu_additem( menu, "\wDart Pistol \y[ \r1500$ \y]"); 
    menu_additem( menu, "\wThanatos-11 \y[ \r4500 \y]");
    menu_additem( menu, "\wEthereal Gun \y[ \r6500$ \y]");
    menu_additem( menu, "\wDual Uzi \y[ \r8500$ \y]");
    menu_additem( menu, "\wSpear Gun \y[ \r12500$ \y]");
    menu_additem( menu, "\wThunderbolt \y[ \r16000$ \y]^n");
	
	menu_setprop( menu, MPROP_EXITNAME, "\wIesire"); 
	
	menu_display( id, menu ); 
publicul handlel la ce il folosesti? ca vad ca apelezi directi player()
User avatar
dragonCSX
Membru, skill +1
Membru, skill +1
Posts: 189
Joined: 04 Feb 2017, 17:36
Detinator Steam: Da
CS Status: Web Developer / Scripting AMXX.
Detinator server CS: da
SteamID: weedakadulceata
Fond eXtream: 0
Location: Ploiesti
Contact:

29 Jan 2019, 01:18

@Diversity
Multumesc de raspuns.
O sa scot ce este inutil in 0.3

@kmking
Ti-am lasat in PM.


ATENTIE.
Nu compilati sursele din arhiva de resurse , sunt neactualizate.
Luati sursele din topic !!

In 10/02/2019 , adaug suport pentru cei cu urmatorul FLAG: ADMIN_LEVEL_H si ADMIN_RCON + points.
O sa vedeti de ce am inclus si persoanele cu imunitate.
Stay tunned.
User avatar
LondoN eXtream
Scripter eXtreamCS
Scripter eXtreamCS
Posts: 2889
Joined: 10 Oct 2014, 05:21
Detinator Steam: Da
SteamID: /id/london_extreamcs
Reputatie: Scripter eXtreamCS
Moderator ajutator
Membru Club eXtreamCS (6 luni)
Fond eXtream: 0
Location: Roman, Neamț
Has thanked: 2 times
Been thanked: 2 times

29 Jan 2019, 14:20

cso_Shop.sma | Afiseaza codul
#include < amxmodx >
#include < amxmisc >
#include < cstrike >

// Declarand o constanta cu tag-ul e doar o pierdere de memorie
#define CHAT_TAG	"^x04[CSDM NEW]^x01"

// Declaram nativele
native give_dualuzi ( Player );
native give_dartpistol ( Player );
native give_ethereal ( Player );
native give_thanatos ( Player );
native give_spear ( Player );
native give_lightsaber ( Player );
native give_thunderbolt ( Player );

public plugin_init ( )
{
	register_plugin ( "CSO Shop", "0.2", "dragonCSX" );
	register_clcmd ( "say", "PlayerMenu" );
	register_clcmd ( "say_team", "PlayerMenu" );
}

public PlayerMenu ( Player )
{
	new szArg [ 32 ];
	read_args ( szArg, charsmax ( szArg ) );
	remove_quotes ( szArg );

	if ( containi ( szArg, "/shop" ) != -1 || equal ( szArg, "/shop" ) && is_user_alive ( Player ) )
		ShowPlayerWeapons ( Player );

	return szArg [ 0 ] == '/' ? PLUGIN_HANDLED : PLUGIN_CONTINUE;
}

public ShowPlayerWeapons ( Player )
{
	new szName [ 32 ], szTitle [ 128 ];
	get_user_name ( Player, szName, charsmax ( szName ) );
	formatex ( szTitle, charsmax ( szTitle ), "\w[\rCSO NST\w] Magazin Arme \rCSO^n\wBun venit [\r%s\w]", szName );

	new MenuID = menu_create ( szTitle, "MenuHandler" );

	menu_additem ( MenuID, "\wLightsaber \r[800$]" );
	menu_additem ( MenuID, "\wDart Pistol \r[1500$]" );
	menu_additem ( MenuID, "\wThanatos-11 \r[4500$]" );
	menu_additem ( MenuID, "\wEhereal Gun \r[6500$]" );
	menu_additem ( MenuID, "\wDual Uzi \r[8500$]" );
	menu_additem ( MenuID, "\wSpear Gun \r[12500$]" );
	menu_additem ( MenuID, "\wThunderbolt \r[16000$]" );

	menu_setprop ( MenuID, MPROP_EXITNAME, "\wIesire" );
	menu_setprop ( MenuID, MPROP_EXIT, MEXIT_ALL );
	menu_display ( Player, MenuID, 0 );
}

public MenuHandler ( Player, MenuID, ITEM )
{
	if ( !( ITEM == MENU_EXIT ) )
	{
		static Money;	Money = cs_get_user_money ( Player );

		switch ( ITEM )
		{
			case 0:		
			{
				if ( Money < 800 )
					ErrorShow ( Player, 800 );

				cs_set_user_money ( Player, Money - 800 );
				give_lightsaber ( Player );
				chat_color ( Player, "Ai cumparat^x04 Light Saber" );
			}

			case 1:
			{
				if ( Money < 2500 )
					ErrorShow ( Player, 2500 );

				cs_set_user_money ( Player, Money - 2500 );
				give_dartpistol ( Player );
				chat_color ( Player, "Ai cumparat^x04 Dart Pistol" );
			}

			case 2:
			{
				if ( Money < 4500 )
					ErrorShow ( Player, 4500 );
			
				cs_set_user_money ( Player, Money - 4500 );
				give_thanatos ( Player );
				chat_color ( Player, "Ai cumparat^x04 Thanatos-11" );
			}

			case 3:
			{
				if ( Money < 6500 )
					ErrorShow ( Player, 6500 );	
				
				cs_set_user_money ( Player, Money - 6500 );
				give_ethereal ( Player );
				chat_color ( Player, "Ai cumparat^x04 Ethereal" );
			}

			case 4:
			{
				if ( Money < 8500 )
					ErrorShow ( Player, 8500 );

				cs_set_user_money ( Player, Money - 8500 );
				give_dualuzi ( Player );
				chat_color ( Player, "Ai cumparat^x04 Dual U.Z.I" );
			}

			case 5:
			{
				if ( Money < 12500 )
					ErrorShow ( Player, 12500 );

				cs_set_user_money ( Player, Money - 12500 );
				give_spear ( Player );
				chat_color ( Player, "Ai cumparat^x04 Spear Gun" );
			}

			case 6:
			{
				if ( Money < 16000 )
					ErrorShow ( Player, 16000 );

				cs_set_user_money ( Player, Money - 16000 );
				give_thunderbolt ( Player );
				chat_color ( Player, "Ai cumparat^x04 Thunder Bolt" );
			}
		}
	}

	menu_destroy ( MenuID );
	return PLUGIN_HANDLED;
}

public ErrorShow ( Player, Money )
{
	chat_color ( Player, "Ai nevoie de^x04 %d $^x01 pentru a cumpara acest item", Money );
	return PLUGIN_HANDLED;
}

stock chat_color ( const Player, const Text [ ], any:... )
{
	static Message [ 191 ];
	new Players [ 32 ], Count = 1;
	vformat ( Message, charsmax ( Message ), Text, 3 );

	formatex ( Message, charsmax ( Message ), "%s %s", CHAT_TAG, Message );

	static SayText;

	if ( !SayText )
		SayText = get_user_msgid ( "SayText" );

	if ( Player )	Players [ 0 ] = Player; else get_players ( Players, Count, "ch" )
	{
		for ( new i = 0; i < Count; i++ )
		{
			if ( !is_user_connected ( Players [ i ] ) )
				continue;
			
			message_begin ( MSG_ONE_UNRELIABLE, SayText, _, Players [ i ] );
			write_byte ( Players [ i ] );
			write_string ( Message );
			message_end ( );
		}
	}
}
Optimizat. Cu placere
User avatar
dragonCSX
Membru, skill +1
Membru, skill +1
Posts: 189
Joined: 04 Feb 2017, 17:36
Detinator Steam: Da
CS Status: Web Developer / Scripting AMXX.
Detinator server CS: da
SteamID: weedakadulceata
Fond eXtream: 0
Location: Ploiesti
Contact:

29 Jan 2019, 18:31

LondoN eXtream wrote:
cso_Shop.sma | Afiseaza codul
#include < amxmodx >
#include < amxmisc >
#include < cstrike >

// Declarand o constanta cu tag-ul e doar o pierdere de memorie
#define CHAT_TAG	"^x04[CSDM NEW]^x01"

// Declaram nativele
native give_dualuzi ( Player );
native give_dartpistol ( Player );
native give_ethereal ( Player );
native give_thanatos ( Player );
native give_spear ( Player );
native give_lightsaber ( Player );
native give_thunderbolt ( Player );

public plugin_init ( )
{
	register_plugin ( "CSO Shop", "0.2", "dragonCSX" );
	register_clcmd ( "say", "PlayerMenu" );
	register_clcmd ( "say_team", "PlayerMenu" );
}

public PlayerMenu ( Player )
{
	new szArg [ 32 ];
	read_args ( szArg, charsmax ( szArg ) );
	remove_quotes ( szArg );

	if ( containi ( szArg, "/shop" ) != -1 || equal ( szArg, "/shop" ) && is_user_alive ( Player ) )
		ShowPlayerWeapons ( Player );

	return szArg [ 0 ] == '/' ? PLUGIN_HANDLED : PLUGIN_CONTINUE;
}

public ShowPlayerWeapons ( Player )
{
	new szName [ 32 ], szTitle [ 128 ];
	get_user_name ( Player, szName, charsmax ( szName ) );
	formatex ( szTitle, charsmax ( szTitle ), "\w[\rCSO NST\w] Magazin Arme \rCSO^n\wBun venit [\r%s\w]", szName );

	new MenuID = menu_create ( szTitle, "MenuHandler" );

	menu_additem ( MenuID, "\wLightsaber \r[800$]" );
	menu_additem ( MenuID, "\wDart Pistol \r[1500$]" );
	menu_additem ( MenuID, "\wThanatos-11 \r[4500$]" );
	menu_additem ( MenuID, "\wEhereal Gun \r[6500$]" );
	menu_additem ( MenuID, "\wDual Uzi \r[8500$]" );
	menu_additem ( MenuID, "\wSpear Gun \r[12500$]" );
	menu_additem ( MenuID, "\wThunderbolt \r[16000$]" );

	menu_setprop ( MenuID, MPROP_EXITNAME, "\wIesire" );
	menu_setprop ( MenuID, MPROP_EXIT, MEXIT_ALL );
	menu_display ( Player, MenuID, 0 );
}

public MenuHandler ( Player, MenuID, ITEM )
{
	if ( !( ITEM == MENU_EXIT ) )
	{
		static Money;	Money = cs_get_user_money ( Player );

		switch ( ITEM )
		{
			case 0:		
			{
				if ( Money < 800 )
					ErrorShow ( Player, 800 );

				cs_set_user_money ( Player, Money - 800 );
				give_lightsaber ( Player );
				chat_color ( Player, "Ai cumparat^x04 Light Saber" );
			}

			case 1:
			{
				if ( Money < 2500 )
					ErrorShow ( Player, 2500 );

				cs_set_user_money ( Player, Money - 2500 );
				give_dartpistol ( Player );
				chat_color ( Player, "Ai cumparat^x04 Dart Pistol" );
			}

			case 2:
			{
				if ( Money < 4500 )
					ErrorShow ( Player, 4500 );
			
				cs_set_user_money ( Player, Money - 4500 );
				give_thanatos ( Player );
				chat_color ( Player, "Ai cumparat^x04 Thanatos-11" );
			}

			case 3:
			{
				if ( Money < 6500 )
					ErrorShow ( Player, 6500 );	
				
				cs_set_user_money ( Player, Money - 6500 );
				give_ethereal ( Player );
				chat_color ( Player, "Ai cumparat^x04 Ethereal" );
			}

			case 4:
			{
				if ( Money < 8500 )
					ErrorShow ( Player, 8500 );

				cs_set_user_money ( Player, Money - 8500 );
				give_dualuzi ( Player );
				chat_color ( Player, "Ai cumparat^x04 Dual U.Z.I" );
			}

			case 5:
			{
				if ( Money < 12500 )
					ErrorShow ( Player, 12500 );

				cs_set_user_money ( Player, Money - 12500 );
				give_spear ( Player );
				chat_color ( Player, "Ai cumparat^x04 Spear Gun" );
			}

			case 6:
			{
				if ( Money < 16000 )
					ErrorShow ( Player, 16000 );

				cs_set_user_money ( Player, Money - 16000 );
				give_thunderbolt ( Player );
				chat_color ( Player, "Ai cumparat^x04 Thunder Bolt" );
			}
		}
	}

	menu_destroy ( MenuID );
	return PLUGIN_HANDLED;
}

public ErrorShow ( Player, Money )
{
	chat_color ( Player, "Ai nevoie de^x04 %d $^x01 pentru a cumpara acest item", Money );
	return PLUGIN_HANDLED;
}

stock chat_color ( const Player, const Text [ ], any:... )
{
	static Message [ 191 ];
	new Players [ 32 ], Count = 1;
	vformat ( Message, charsmax ( Message ), Text, 3 );

	formatex ( Message, charsmax ( Message ), "%s %s", CHAT_TAG, Message );

	static SayText;

	if ( !SayText )
		SayText = get_user_msgid ( "SayText" );

	if ( Player )	Players [ 0 ] = Player; else get_players ( Players, Count, "ch" )
	{
		for ( new i = 0; i < Count; i++ )
		{
			if ( !is_user_connected ( Players [ i ] ) )
				continue;
			
			message_begin ( MSG_ONE_UNRELIABLE, SayText, _, Players [ i ] );
			write_byte ( Players [ i ] );
			write_string ( Message );
			message_end ( );
		}
	}
}
Optimizat. Cu placere
Multumesc London <3
Sunt cu munca si de aia am pus un termen prestabilit , tot apare 0.3 <3
Sursa actualizata in topic , cea de baza !
Post Reply

Return to “AmxModX”

  • Information