Plugin Available magnum

Unpaid Requests, Public Plugins
Post Reply
czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 477
Joined: 2 Years Ago
Has thanked: 18 times
Been thanked: 1 time
Contact:

magnum

#1

Post by czirimbolo » 10 Months Ago

I am testing new guns in our mod, please can someone help to convert this gun?

Code: Select all

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <engine>
#include <hamsandwich>
#include <xs>

#define PLUGIN "Magnum Lancer"
#define VERSION "2.0"
#define AUTHOR "Bim Bim Cay"

// Models
#define v_model "models/v_sgmissile.mdl"
#define w_model "models/w_sgmissile.mdl"
#define p_modela "models/p_sgmissile_a.mdl"
#define p_modelb "models/p_sgmissile_b.mdl"

// Sounds
#define attack1_sound "weapons/sgmissile-1.wav"
#define attack2_sound "weapons/sgmissile-2.wav"
#define reload_sound "weapons/sgmissile_reload.wav"	
#define explode_sound "weapons/sgmissile_exp.wav"

// Sprites
#define ef_ball "sprites/ef_sgmissile_line.spr"
#define ef_explode "sprites/ef_sgmissile.spr"
#define muzzle_flash1 "sprites/muzzleflash64.spr"
#define muzzle_flash2 "sprites/muzzleflash75.spr" 

// Anims
#define ANIM_IDLE		0
#define ANIM_RELOAD		1
#define ANIM_DRAW		2
#define ANIM_SHOOT		3
#define ANIM_IDLEB		4
#define ANIM_RELOADB		5
#define ANIM_DRAWB		6
#define ANIM_SHOOTB1		7
#define ANIM_SHOOTB2		8
#define ANIM_SHOOTMISSLE	9
#define ANIM_SHOOTMISSLELAST	10
#define ANIM_MISSLEON		11

#define ANIM_EXTENSION 		"m249"

// Entity Classname
#define BALL_CLASSNAME "Magnum_EfBall"
#define LINE_CLASSNAME "Magnum_EfLine"
#define MUZZLEFLASH1_CLASSNAME "Muzzle_MagnumLancer1"
#define MUZZLEFLASH2_CLASSNAME "Muzzle_MagnumLancer2"

// Configs
#define WEAPON_NAME 		"weapon_sgmissile"
#define WEAPON_BASE		"weapon_m3"

#define WEAPON_MAX_CLIP		30
#define WEAPON_DEFAULT_AMMO	90
#define WEAPON_MAX_BATTERY	10

#define WEAPON_SHOOT_DAMAGE	100.0
#define WEAPON_EXPLODE_DAMAGE	2000.0
#define WEAPON_EXPLODE_RADIUS	75.0

#define WEAPON_TIME_NEXT_IDLE 	10.0
#define WEAPON_TIME_NEXT_ATTACK 0.25
#define WEAPON_TIME_NEXT_ATTACK2 0.4
#define WEAPON_TIME_DELAY_DEPLOY 1.0
#define WEAPON_TIME_DELAY_RELOAD 2.0
#define WEAPON_TIME_DELAY_CHARGE 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))

#define INSTANCE(%0) ((%0 == -1) ? 0 : %0)
#define IsValidPev(%0) (pev_valid(%0) == 2)
#define IsObserver(%0) pev(%0,pev_iuser1)
#define OBS_IN_EYE 4
#define MSGID_WEAPONLIST 78

new g_iszWeaponKey
new g_iForwardDecalIndex
new g_Fire_SprId

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

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Safety
	Register_SafetyFunc()
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_TraceLine, "fw_TraceLine_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	register_forward(FM_SetModel, "fw_SetModel")
	
	unregister_forward(FM_DecalIndex, g_iForwardDecalIndex, 1)
	
	// Think
	register_think(MUZZLEFLASH1_CLASSNAME, "fw_MuzzleFlash1_Think") 
	register_think(MUZZLEFLASH2_CLASSNAME, "fw_MuzzleFlash2_Think") 
	register_think(BALL_CLASSNAME, "fw_Ball_Think")
	register_think(LINE_CLASSNAME, "fw_Line_Think")
	
	register_touch(BALL_CLASSNAME, "*", "fw_Ball_Touch")
	
	// Ham
	RegisterHam(Ham_Spawn, "weaponbox", "fw_Weaponbox_Spawn_Post", 1)
	
	RegisterHam(Ham_Item_Deploy, WEAPON_BASE, "fw_Item_Deploy_Post", 1)
	RegisterHam(Ham_Item_AddToPlayer, WEAPON_BASE, "fw_Item_AddToPlayer")
	RegisterHam(Ham_Item_PostFrame, WEAPON_BASE, "fw_Item_PostFrame")
	RegisterHam(Ham_Weapon_Reload, WEAPON_BASE, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_BASE, "fw_Weapon_WeaponIdle")
	RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_BASE, "fw_Weapon_PrimaryAttack")
	
	RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack_Entity")
	RegisterHam(Ham_TraceAttack, "info_target", "fw_TraceAttack_Entity")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Entity")
	
	register_clcmd("say /get", "Get_MyWeapon")
}

public plugin_precache()
{
	precache_model(v_model)
	precache_model(w_model)
	precache_model(p_modela)
	precache_model(p_modelb)
	
	precache_model(ef_ball)
	precache_model(muzzle_flash1)
	precache_model(muzzle_flash2)
	
	g_Fire_SprId = precache_model(ef_explode)
	
	precache_sound(attack1_sound)
	precache_sound(attack2_sound)
	precache_sound(reload_sound)
	precache_sound(explode_sound)
	
	new TextFile[32]
	formatex(TextFile, charsmax(TextFile), "sprites/%s.txt", WEAPON_NAME)
	
	precache_generic(TextFile)
	
	g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
	g_iForwardDecalIndex = register_forward(FM_DecalIndex, "fw_DecalIndex_Post", 1)
	
	register_message(MSGID_WEAPONLIST, "MsgHook_WeaponList")
}

public client_putinserver(iPlayer)
{
	Safety_Connected(iPlayer)
	
	if(!g_HamBot && is_user_bot(iPlayer))
	{
		g_HamBot = 1
		set_task(0.1, "Register_HamBot", iPlayer)
	}
}
 
public Register_HamBot(iPlayer)
{
	Register_SafetyFuncBot(iPlayer)
	RegisterHamFromEntity(Ham_TraceAttack, iPlayer, "fw_TraceAttack_Entity")	
}
 
public client_disconnect(iPlayer)
{
	Safety_Disconnected(iPlayer)
}

public Get_MyWeapon(iPlayer)
{
	Weapon_Give(iPlayer)
}

public fw_UpdateClientData_Post(iPlayer, sendweapons, CD_Handle)
{
	enum
	{
		SPEC_MODE,
		SPEC_TARGET,
		SPEC_END
	}
	 
	static aSpecInfo[33][SPEC_END]
	
	static iTarget
	static iSpecMode 
	static iActiveItem
	
	iTarget = (iSpecMode = IsObserver(iPlayer)) ? pev(iPlayer, pev_iuser2) : iPlayer
	
	if(!is_alive(iTarget))
		return FMRES_IGNORED
	
	iActiveItem = get_pdata_cbase(iTarget, 373, 5)
	
	if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
		return FMRES_IGNORED
	
	if(iSpecMode)
	{
		if(aSpecInfo[iPlayer][SPEC_MODE] != iSpecMode)
		{
			aSpecInfo[iPlayer][SPEC_MODE] = iSpecMode
			aSpecInfo[iPlayer][SPEC_TARGET] = 0
		}
		
		if(iSpecMode == OBS_IN_EYE && aSpecInfo[iPlayer][SPEC_TARGET] != iTarget)
		{
			aSpecInfo[iPlayer][SPEC_TARGET] = iTarget
			
			if(get_pdata_int(iActiveItem, 30, 4))
			{
				Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLEB)
			}
			else
			{
				Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLE)
			}
		}
	}
	
	set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
	
	return FMRES_HANDLED
}

public fw_TraceLine_Post(Float:TraceStart[3], Float:TraceEnd[3], fNoMonsters, iEntToSkip, iTrace) <FireBullets: Enabled>
{
	static Float:vecEndPos[3]
	
	get_tr2(iTrace, TR_vecEndPos, vecEndPos)
	engfunc(EngFunc_TraceLine, vecEndPos, TraceStart, fNoMonsters, iEntToSkip, 0)
	
	UTIL_GunshotDecalTrace(0)
	UTIL_GunshotDecalTrace(iTrace, true)
}

public fw_TraceLine_Post() </* Empty statement */>
{
	/* Fallback */
}

public fw_TraceLine_Post() <FireBullets: Disabled>	
{
	/* Do notning */
}

public fw_PlaybackEvent() <FireBullets: Enabled>
{
	return FMRES_SUPERCEDE
}

public fw_PlaybackEvent() </* Empty statement */>		
{ 
	return FMRES_IGNORED 
}

public fw_PlaybackEvent() <FireBullets: Disabled>		
{ 
	return FMRES_IGNORED 
}

//**********************************************
//* Weaponbox world model.                     *
//**********************************************
public fw_SetModel(iEntity) <WeaponBox: Enabled>
{
	state WeaponBox: Disabled
	
	if(!IsValidPev(iEntity))
		return FMRES_IGNORED
	
	#define MAX_ITEM_TYPES	6
	for(new i, iItem; i < MAX_ITEM_TYPES; i++)
	{
		iItem = get_pdata_cbase(iEntity, 34 + i, 4)
		
		if(IsValidPev(iItem) && IsCustomItem(iItem))
		{
			engfunc(EngFunc_SetModel, iEntity, w_model)
			return FMRES_SUPERCEDE
		}
	}
	
	return FMRES_IGNORED
}

public fw_SetModel() </* Empty statement */>	
{ 
	/*  Fallback  */ 
	return FMRES_IGNORED 
}
public fw_SetModel() <WeaponBox: Disabled>	
{ 
	/* Do nothing */ 
	return FMRES_IGNORED 
}

public fw_Weaponbox_Spawn_Post(iWeaponBox)
{
	if(IsValidPev(iWeaponBox))
	{
		state (IsValidPev(pev(iWeaponBox, pev_owner))) WeaponBox: Enabled
	}
	
	return HAM_IGNORED
}

//**********************************************
//* Weapon's codes.                     *
//**********************************************
public fw_Item_Deploy_Post(iItem)
{
	if(!IsCustomItem(iItem))
		return
		
	static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)	
	static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)

	//I need to disable because there is no dummy anim
	//static Sex; Sex = 0 //Get your sex: 0 - Male; 1 - Female
	//set_pev(iItem, pev_body, Sex)
	
	set_pev(iPlayer, pev_viewmodel2, v_model)
	
	if(SecondaryAmmo)
	{
		set_pev(iPlayer, pev_weaponmodel2, p_modelb)
		Weapon_SendAnim(iPlayer, iItem, ANIM_DRAWB)
	}
	else
	{
		set_pev(iPlayer, pev_weaponmodel2, p_modela)
		Weapon_SendAnim(iPlayer, iItem, ANIM_DRAW)
	}

	Notice(iPlayer, SecondaryAmmo)
	
	set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_DEPLOY, 4)
	set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE + WEAPON_TIME_DELAY_DEPLOY, 4)
	
	set_pdata_string(iPlayer, (492) * 4, ANIM_EXTENSION, -1 , 20)
}

public fw_Item_PostFrame(iItem)
{
	if(!IsCustomItem(iItem))
		return HAM_IGNORED
	
	static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
	
	if(get_pdata_int(iItem, 54, 4))
	{
		static iClip; iClip = get_pdata_int(iItem, 51, 4)
		static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
		static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
		static iAmount; iAmount = min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary)
		
		set_pdata_int(iItem, 51, iClip + iAmount, 4)
		SetAmmoInventory(iPlayer, iPrimaryAmmoIndex, iAmmoPrimary - iAmount)
		
		set_pdata_int(iItem, 54, 0, 4)
		set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)
		
		return HAM_IGNORED
	}	
	
	static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
	static Float:flLastEventCheck; flLastEventCheck = get_pdata_float(iItem, 38, 4)
	
	if(flLastEventCheck < get_gametime())
	{
		flLastEventCheck = get_gametime() + WEAPON_TIME_DELAY_CHARGE
		set_pdata_float(iItem, 38, flLastEventCheck, 4)
		
		if(SecondaryAmmo < WEAPON_MAX_BATTERY)
		{
			if(!SecondaryAmmo)
			{
				set_pdata_float(iItem, 48, 1.0, 4)
				Weapon_SendAnim(iPlayer, iItem, ANIM_MISSLEON)

				set_pev(iPlayer, pev_weaponmodel2, p_modelb)
			}
			
			SecondaryAmmo++
			set_pdata_int(iItem, 30, SecondaryAmmo, 4)
			
			Notice(iPlayer, SecondaryAmmo)
			emit_sound(iPlayer, CHAN_ITEM, reload_sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
		}
	}
	
	static iButton; iButton = pev(iPlayer, pev_button)
	
	if(iButton & IN_ATTACK2)
	{
		iButton &= ~IN_ATTACK2
		iButton &= ~IN_ATTACK
		set_pev(iPlayer, pev_button, iButton)
		
		if(!SecondaryAmmo)
			return HAM_IGNORED
			
		if(get_pdata_float(iItem, 47, 4) > 0.0)
			return HAM_IGNORED
			
		set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)	
		
		set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK2, 4)
		set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK2, 4)	
		
		emit_sound(iPlayer, CHAN_WEAPON, attack2_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
		
		if(SecondaryAmmo > 1)
		{
			Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLE)
			set_pdata_float(iItem, 48, 0.87, 4)
		}
		else
		{
			Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLELAST)
			set_pdata_float(iItem, 48, 1.2, 4)
			
			set_pev(iPlayer, pev_weaponmodel2, p_modela)
		}
		
		static szAnimation[64]
		
		if(pev(iPlayer, pev_flags) & FL_DUCKING)
		{
			formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
		}
		else
		{
			formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
		}
		
		Player_SetAnimation(iPlayer, szAnimation)
		
		SecondaryAmmo--
		set_pdata_int(iItem, 30, SecondaryAmmo, 4)
			
		Notice(iPlayer, SecondaryAmmo)
		
		Attack2(iPlayer)
		MakeMuzzleFlash2(iPlayer)
	} 
	
	return HAM_IGNORED
}

public fw_Weapon_Reload(iItem)
{
	if(!IsCustomItem(iItem))
		return HAM_IGNORED
		
	static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)	
	
	static iClip; iClip = get_pdata_int(iItem, 51, 4)
	static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
	static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
	
	if(min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary) <= 0)
		return HAM_SUPERCEDE
	
	set_pdata_int(iItem, 51, 0, 4)
	
	ExecuteHam(Ham_Weapon_Reload, iItem)
	
	//Remove shotgun reload
	set_pdata_int(iItem, 55, 0, 4)
	set_pdata_int(iItem, 54, 1, 4)
	
	set_pdata_int(iItem, 51, iClip, 4)
	
	set_pdata_float(iPlayer, 83, WEAPON_TIME_DELAY_RELOAD, 5)
	set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_RELOAD, 4)
	
	static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
	
	if(SecondaryAmmo)
	{
		Weapon_SendAnim(iPlayer, iItem, ANIM_RELOADB)
	}
	else
	{
		Weapon_SendAnim(iPlayer, iItem, ANIM_RELOAD)
	}
	
	return HAM_SUPERCEDE	
}

public fw_Weapon_WeaponIdle(iItem)
{
	if(!IsCustomItem(iItem))
		return HAM_IGNORED
		
	static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)	
	
	ExecuteHamB(Ham_Weapon_ResetEmptySound, iItem)

	if(get_pdata_float(iItem, 48, 4) > 0.0)
		return HAM_SUPERCEDE
	
	set_pdata_float(iItem, 48, WEAPON_TIME_NEXT_IDLE, 4)
	
	static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
	
	if(SecondaryAmmo)
	{
		Weapon_SendAnim(iPlayer, iItem, ANIM_IDLEB)
	}
	else
	{
		Weapon_SendAnim(iPlayer, iItem, ANIM_IDLE)
	}
	
	return HAM_SUPERCEDE
}

public fw_Weapon_PrimaryAttack(iItem)
{
	if(!IsCustomItem(iItem))
		return HAM_IGNORED
		
	static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)	
	static iClip; iClip = get_pdata_int(iItem, 51, 4)
	
	if(iClip <= 0)
	{
		// No ammo, play empty sound and cancel
		if(get_pdata_int(iItem, 45, 4))
		{
			ExecuteHamB(Ham_Weapon_PlayEmptySound, iItem)
			set_pdata_float(iItem, 46, 0.2, 4)
		}
	
		return HAM_SUPERCEDE
	}
	
	CallOriginalFireBullets(iItem, iPlayer)
	
	static iFlags
	static szAnimation[64], Float:Velocity[3]

	iFlags = pev(iPlayer, pev_flags)
	
	if(iFlags & FL_DUCKING)
	{
		formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
	}
	else
	{
		formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
	}
	
	Player_SetAnimation(iPlayer, szAnimation)
	
	static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
	
	if(SecondaryAmmo)
	{
		Weapon_SendAnim(iPlayer, iItem, random_num(ANIM_SHOOTB1, ANIM_SHOOTB2))
	}
	else
	{
		Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
	}
	
	set_pdata_float(iItem, 48, 0.7, 4)
	set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK, 4)
	set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK, 4)
	
	pev(iPlayer, pev_velocity, Velocity)
	
	if(xs_vec_len(Velocity) > 0)
	{
		Weapon_KickBack(iItem, iPlayer, 1.5, 0.45, 0.225, 0.05, 6.5, 2.5, 7)
	}
	else if(!(iFlags & FL_ONGROUND))
	{
		Weapon_KickBack(iItem, iPlayer, 2.0, 1.0, 0.5, 0.35, 9.0, 6.0, 5)
	}
	else if(iFlags & FL_DUCKING)
	{
		Weapon_KickBack(iItem, iPlayer, 0.9, 0.35, 0.15, 0.025, 5.5, 1.5, 9)
	}
	else
	{
		Weapon_KickBack(iItem, iPlayer, 1.0, 0.375, 0.175, 0.0375, 5.75, 1.75, 8)
	}

	emit_sound(iPlayer, CHAN_WEAPON, attack1_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
	
	MakeMuzzleFlash1(iPlayer)
	
	return HAM_SUPERCEDE
}

public fw_TraceAttack_Entity(iEntity, iAttacker, Float: flDamage) <FireBullets: Enabled>
{
	SetHamParamFloat(3, WEAPON_SHOOT_DAMAGE)
}

public fw_TraceAttack_Entity() </* Empty statement */>		
{ 
	/* Fallback */ 
}

public fw_TraceAttack_Entity() <FireBullets: Disabled>		
{ 
	/* Do notning */ 
}

//**********************************************
//* Weapon list update.                        *
//**********************************************
public fw_Item_AddToPlayer(iItem, iPlayer)
{
	if(!IsValidPev(iItem) || !IsValidPev(iPlayer))
		return HAM_IGNORED
	
	MsgHook_WeaponList(MSGID_WEAPONLIST, iItem, iPlayer)
	
	return HAM_IGNORED
}

public MsgHook_WeaponList(iMsgID, iMsgDest, iMsgEntity)
{
	static arrWeaponListData[8]
	
	if(!iMsgEntity)
	{
		new szWeaponName[32]
		get_msg_arg_string(1, szWeaponName, charsmax(szWeaponName))
		
		if(!strcmp(szWeaponName, WEAPON_BASE))
		{
			for(new i, a = sizeof arrWeaponListData; i < a; i++)
			{
				arrWeaponListData[i] = get_msg_arg_int(i + 2)
			}
		}
	}
	else
	{
		if(!IsCustomItem(iMsgDest) && pev(iMsgDest, pev_impulse))
			return
		
		engfunc(EngFunc_MessageBegin, MSG_ONE, iMsgID, {0.0, 0.0, 0.0}, iMsgEntity)
		write_string(IsCustomItem(iMsgDest) ? WEAPON_NAME : WEAPON_BASE)
		
		for(new i, a = sizeof arrWeaponListData; i < a; i++)
		{
			write_byte(arrWeaponListData[i])
		}
		
		message_end()
	}
}

//**********************************************
//* Effects                                    *
//**********************************************
Notice(iPlayer, SecondaryAmmo)
{
	client_print(iPlayer, print_center, "Fire Ammo: %d", SecondaryAmmo)
}

public MakeMuzzleFlash1(iPlayer)
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	if(!pev_valid(Ent)) return
	
	set_pev(Ent, pev_classname, MUZZLEFLASH1_CLASSNAME)
	
	set_pev(Ent, pev_owner, iPlayer)
	set_pev(Ent, pev_body, 1)
	set_pev(Ent, pev_skin, iPlayer)
	set_pev(Ent, pev_aiment, iPlayer)
	set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
	
	set_pev(Ent, pev_scale, 0.085)
	set_pev(Ent, pev_frame, 0.0)
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 255.0)
	
	engfunc(EngFunc_SetModel, Ent,  muzzle_flash1)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
}

public fw_MuzzleFlash1_Think(Ent)
{
	if(!pev_valid(Ent))
		return
	
	static Owner; Owner = pev(Ent, pev_owner)
	
	if(!is_alive(Owner))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
	
	if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}

	static Float:Frame; pev(Ent, pev_frame, Frame)
	if(Frame > 8.0) 
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	else
	{
		Frame += 1.0
		set_pev(Ent, pev_frame, Frame)
	}
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
}

public MakeMuzzleFlash2(iPlayer)
{
	static Ent
	
	for(new i = 2; i < 5; i++)
	{
		Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
		if(!pev_valid(Ent)) continue
	
		set_pev(Ent, pev_classname, MUZZLEFLASH2_CLASSNAME)
	
		set_pev(Ent, pev_owner, iPlayer)
		set_pev(Ent, pev_body, i)
		set_pev(Ent, pev_skin, iPlayer)
		set_pev(Ent, pev_aiment, iPlayer)
		set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
	
		set_pev(Ent, pev_scale, 0.02)
		set_pev(Ent, pev_frame, 0.0)
		set_pev(Ent, pev_rendermode, kRenderTransAdd)
		set_pev(Ent, pev_renderamt, 255.0)
	
		engfunc(EngFunc_SetModel, Ent,  muzzle_flash2)
	
		set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
	}
}

public fw_MuzzleFlash2_Think(Ent)
{
	if(!pev_valid(Ent))
		return
	
	static Owner; Owner = pev(Ent, pev_owner)
	
	if(!is_alive(Owner))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
	
	if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	static Float:Frame; pev(Ent, pev_frame, Frame)
	if(Frame > 9.0) 
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	else
	{
		Frame += 1.0
		set_pev(Ent, pev_frame, Frame)
	}
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
}

public Attack2(iPlayer)
{
	static Float:StartOrigin[3], Float:EndOrigin[9][3]
	Get_WeaponAttachment(iPlayer, StartOrigin, 40.0)
	
	// Left
	Get_Position(iPlayer, 512.0, 50.0, 0.0, EndOrigin[0])
	Get_Position(iPlayer, 512.0, 100.0, 0.0, EndOrigin[1])
	Get_Position(iPlayer, 512.0, 150.0, 0.0, EndOrigin[2])
	Get_Position(iPlayer, 512.0, 200.0, 0.0, EndOrigin[3])
	
	// Center
	Get_Position(iPlayer, 512.0, 0.0, 0.0, EndOrigin[4])
	
	// Right
	Get_Position(iPlayer, 512.0, -50.0, 0.0, EndOrigin[5])
	Get_Position(iPlayer, 512.0, -100.0, 0.0, EndOrigin[6])
	Get_Position(iPlayer, 512.0, -150.0, 0.0, EndOrigin[7])
	Get_Position(iPlayer, 512.0, -200.0, 0.0, EndOrigin[8])
	
	// Create Fire
	for(new i = 0; i < 9; i++) Create_System(iPlayer, StartOrigin, EndOrigin[i])
}

public Create_System(iPlayer, Float:StartOrigin[3], Float:EndOrigin[3])
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	if(!pev_valid(Ent))
		return
		
	set_pev(Ent, pev_classname, BALL_CLASSNAME)	
	set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	
	engfunc(EngFunc_SetModel, Ent, ef_ball)
	
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 150.0)
	set_pev(Ent, pev_scale, 0.3)
	set_pev(Ent, pev_frame, 0.0)
	
	set_pev(Ent, pev_mins, Float:{-5.0, -5.0, -5.0})
	set_pev(Ent, pev_maxs, Float:{5.0, 5.0, 5.0})
	
	set_pev(Ent, pev_origin, StartOrigin)
	
	set_pev(Ent, pev_owner, iPlayer)	
	set_pev(Ent, pev_iuser3, get_user_team(iPlayer))
	set_pev(Ent, pev_fuser4, get_gametime())
	
	// Create Velocity
	static Float:Velocity[3]
	get_speed_vector(StartOrigin, EndOrigin, 1000.0, Velocity)//Or 750, 1500, 2000, 2500 
	set_pev(Ent, pev_velocity, Velocity)	
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}

public fw_Ball_Think(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Float:Frame
	pev(Ent, pev_frame, Frame)
	
	if(Frame > 14.0)
	{
		static Float:Amount
		pev(Ent, pev_renderamt, Amount)
		
		if(Amount <= 15.0)
		{
			set_pev(Ent, pev_flags, FL_KILLME)
			return
		}
		
		Amount -= 15.0
		set_pev(Ent, pev_renderamt, Amount)
		
		set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
	}
	else
	{
		Frame += 1.0
		set_pev(Ent, pev_frame, Frame)
		
		static Float:Origin[3]
		pev(Ent, pev_origin, Origin)
		
		static Float:Scale
		pev(Ent, pev_scale, Scale)
		
		Scale += 0.02
		set_pev(Ent, pev_scale, Scale)
		
		static Float:Time
		pev(Ent, pev_fuser4, Time)
		
		Create_Line(Origin)
		set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
	}
}

public fw_Ball_Touch(Ent, Touch)
{
	if(!pev_valid(Ent))
		return
	
	static Classname[36]; pev(Touch, pev_classname, Classname, sizeof(Classname))
	
	if(equali(Classname, BALL_CLASSNAME))
		return
	
	static Float:Origin[3]
	pev(Ent, pev_origin, Origin)
	
	static TE_FLAG
	
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	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_Fire_SprId)	// sprite index
	write_byte(15)	// scale in 3.4's
	write_byte(15)	// framerate
	write_byte(TE_FLAG)	// flags
	message_end()
	
	emit_sound(Ent, CHAN_BODY, explode_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	static Team; Team = pev(Ent, pev_iuser3)
	static Owner; Owner = pev(Ent, pev_owner)
	
	static Victim; Victim = -1
	while((Victim = find_ent_in_sphere(Victim, Origin, WEAPON_EXPLODE_RADIUS)) != 0)
	{
		if(is_alive(Victim))
		{
			if(get_user_team(Victim) == Team)
				continue
		}
		else
		{
			if(pev(Victim, pev_takedamage) == DAMAGE_NO)
				continue
		}
		
		ExecuteHamB(Ham_TakeDamage, Victim, Owner, Owner, WEAPON_EXPLODE_DAMAGE, DMG_BULLET)
	}
	
	set_pev(Ent, pev_flags, FL_KILLME)	
}

public Create_Line(Float:Origin[3])
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	if(!pev_valid(Ent))
		return
	
	set_pev(Ent, pev_classname, LINE_CLASSNAME)	
	set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
	set_pev(Ent, pev_solid, SOLID_NOT)
	
	engfunc(EngFunc_SetModel, Ent, ef_ball)
	
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 120.0)
	set_pev(Ent, pev_scale, 0.3)
	set_pev(Ent, pev_frame, 0.0)
	
	set_pev(Ent, pev_origin, Origin)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}

public fw_Line_Think(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Float:Amount
	pev(Ent, pev_renderamt, Amount)	
	
	if(Amount <= 15.0)
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		return
	}
	
	Amount -= 15.0
	set_pev(Ent, pev_renderamt, Amount)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}
/* ===============================
------------- 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(iPlayer)
{
	RegisterHamFromEntity(Ham_Spawn, iPlayer, "fw_Safety_Spawn_Post", 1)
	RegisterHamFromEntity(Ham_Killed, iPlayer, "fw_Safety_Killed_Post", 1)
}

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

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

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

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

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

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

	return 1
}

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

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

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

//**********************************************
//* Create and check our custom weapon.        *
//**********************************************
IsCustomItem(iItem)
{
	return (pev(iItem, pev_impulse) == g_iszWeaponKey)
}

Weapon_Create(Float: Origin[3] = {0.0, 0.0, 0.0}, Float: Angles[3] = {0.0, 0.0, 0.0})
{
	new iWeapon

	static iszAllocStringCached
	if (iszAllocStringCached || (iszAllocStringCached = engfunc(EngFunc_AllocString, WEAPON_BASE)))
	{
		iWeapon = engfunc(EngFunc_CreateNamedEntity, iszAllocStringCached)
	}
	
	if(!IsValidPev(iWeapon))
		return FM_NULLENT
	
	dllfunc(DLLFunc_Spawn, iWeapon)
	set_pev(iWeapon, pev_origin, Origin)

	set_pdata_int(iWeapon, 51, WEAPON_MAX_CLIP, 4)
	set_pdata_int(iWeapon, 30, 0, 4)

	set_pev_string(iWeapon, pev_classname, g_iszWeaponKey)
	set_pev(iWeapon, pev_impulse, g_iszWeaponKey)
	set_pev(iWeapon, pev_angles, Angles)
	
	engfunc(EngFunc_SetModel, iWeapon, w_model)

	return iWeapon
}

Weapon_Give(iPlayer)
{
	if(!IsValidPev(iPlayer))
	{
		return FM_NULLENT
	}
	
	new iWeapon, Float: vecOrigin[3]
	pev(iPlayer, pev_origin, vecOrigin)
	
	if((iWeapon = Weapon_Create(vecOrigin)) != FM_NULLENT)
	{
		Player_DropWeapons(iPlayer, ExecuteHamB(Ham_Item_ItemSlot, iWeapon))
		
		set_pev(iWeapon, pev_spawnflags, pev(iWeapon, pev_spawnflags) | SF_NORESPAWN)
		dllfunc(DLLFunc_Touch, iWeapon, iPlayer)
		
		SetAmmoInventory(iPlayer, PrimaryAmmoIndex(iWeapon), WEAPON_DEFAULT_AMMO)
		
		return iWeapon
	}
	
	return FM_NULLENT
}

Player_DropWeapons(iPlayer, iSlot)
{
	new szWeaponName[32], iItem = get_pdata_cbase(iPlayer, 367 + iSlot, 5)

	while(IsValidPev(iItem))
	{
		pev(iItem, pev_classname, szWeaponName, charsmax(szWeaponName))
		engclient_cmd(iPlayer, "drop", szWeaponName)

		iItem = get_pdata_cbase(iItem, 42, 4)
	}
}

//**********************************************
//* Ammo Inventory.                            *
//**********************************************
PrimaryAmmoIndex(iItem)
{
	return get_pdata_int(iItem, 49, 4)
}

GetAmmoInventory(iPlayer, iAmmoIndex)
{
	if(iAmmoIndex == -1)
		return -1
	
	return get_pdata_int(iPlayer, 376 + iAmmoIndex, 5)
}

SetAmmoInventory(iPlayer, iAmmoIndex, iAmount)
{
	if(iAmmoIndex == -1)
		return 0
	
	set_pdata_int(iPlayer, 376 + iAmmoIndex, iAmount, 5)
	
	return 1
}

//**********************************************
//* Fire Bullets.                              *
//**********************************************
CallOriginalFireBullets(iItem, iPlayer)
{
	state FireBullets: Enabled
	static Float:g_Recoil[3]

	pev(iPlayer, pev_punchangle, g_Recoil)
	ExecuteHam(Ham_Weapon_PrimaryAttack, iItem)
	set_pev(iPlayer, pev_punchangle, g_Recoil)
	
	state FireBullets: Disabled
}

//**********************************************
//* Decals.                                    *
//**********************************************
new Array: g_hDecals

public fw_DecalIndex_Post()
{
	if(!g_hDecals)
	{
		g_hDecals = ArrayCreate(1, 1)
	}
	
	ArrayPushCell(g_hDecals, get_orig_retval())
}

UTIL_GunshotDecalTrace(iTrace, bool: bIsGunshot = false)
{
	static iHit
	static iMessage
	static iDecalIndex
	
	static Float:flFraction 
	static Float:vecEndPos[3]
	
	iHit = INSTANCE(get_tr2(iTrace, TR_pHit))
	
	if(iHit && !IsValidPev(iHit) || (pev(iHit, pev_flags) & FL_KILLME))
		return
	
	if(pev(iHit, pev_solid) != SOLID_BSP && pev(iHit, pev_movetype) != MOVETYPE_PUSHSTEP)
		return
	
	iDecalIndex = ExecuteHamB(Ham_DamageDecal, iHit, 0)
	
	if(iDecalIndex < 0 || iDecalIndex >=  ArraySize(g_hDecals))
		return
	
	iDecalIndex = ArrayGetCell(g_hDecals, iDecalIndex)
	
	get_tr2(iTrace, TR_flFraction, flFraction)
	get_tr2(iTrace, TR_vecEndPos, vecEndPos)
	
	if(iDecalIndex < 0 || flFraction >= 1.0)
		return
	
	if(bIsGunshot)
	{
		iMessage = TE_GUNSHOTDECAL
	}
	else
	{
		iMessage = TE_DECAL
		
		if(iHit != 0)
		{
			if(iDecalIndex > 255)
			{
				iMessage = TE_DECALHIGH
				iDecalIndex -= 256
			}
		}
		else
		{
			iMessage = TE_WORLDDECAL
			
			if(iDecalIndex > 255)
			{
				iMessage = TE_WORLDDECALHIGH
				iDecalIndex -= 256
			}
		}
	}
	
	engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEndPos, 0)
	write_byte(iMessage)
	engfunc(EngFunc_WriteCoord, vecEndPos[0])
	engfunc(EngFunc_WriteCoord, vecEndPos[1])
	engfunc(EngFunc_WriteCoord, vecEndPos[2])

	if(bIsGunshot)
	{
		write_short(iHit)
		write_byte(iDecalIndex)
	}
	else 
	{
		write_byte(iDecalIndex)
		
		if(iHit)
		{
			write_short(iHit)
		}
	}
    
	message_end()
}

//**********************************************
//* Set Animations.                            *
//**********************************************
stock Weapon_SendAnim(iPlayer, iItem, iAnim)
{
	static i, iCount, iSpectator, aSpectators[32]
	
	set_pev(iPlayer, pev_weaponanim, iAnim)

	message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iPlayer)
	write_byte(iAnim)
	write_byte(pev(iItem, pev_body))
	message_end()
	
	if(IsObserver(iPlayer))
		return
	
	get_players(aSpectators, iCount, "bch")

	for(i = 0; i < iCount; i++)
	{
		iSpectator = aSpectators[i]
		
		if(IsObserver(iSpectator) != OBS_IN_EYE || pev(iSpectator, pev_iuser2) != iPlayer)
			continue
		
		set_pev(iSpectator, pev_weaponanim, iAnim)

		message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iSpectator)
		write_byte(iAnim)
		write_byte(pev(iItem, pev_body))
		message_end()
	}
}

stock Player_SetAnimation(iPlayer, szAnim[])
{
	#define ACT_RANGE_ATTACK1   28
   
	// Linux extra offsets
	#define extra_offset_animating   4
	#define extra_offset_player 5
   
	// CBaseAnimating
	#define m_flFrameRate      36
	#define m_flGroundSpeed      37
	#define m_flLastEventCheck   38
	#define m_fSequenceFinished   39
	#define m_fSequenceLoops   40
   
	// CBaseMonster
	#define m_Activity      73
	#define m_IdealActivity      74
   
	// CBasePlayer
	#define m_flLastAttackTime   220
   
	new iAnimDesired, Float:flFrameRate, Float:flGroundSpeed, bool:bLoops
      
	if((iAnimDesired = lookup_sequence(iPlayer, szAnim, flFrameRate, bLoops, flGroundSpeed)) == -1)
	{
		iAnimDesired = 0
	}
   
	static Float:flGametime; flGametime = get_gametime()

	set_pev(iPlayer, pev_frame, 0.0)
	set_pev(iPlayer, pev_framerate, 1.0)
	set_pev(iPlayer, pev_animtime, flGametime)
	set_pev(iPlayer, pev_sequence, iAnimDesired)
   
	set_pdata_int(iPlayer, m_fSequenceLoops, bLoops, extra_offset_animating)
	set_pdata_int(iPlayer, m_fSequenceFinished, 0, extra_offset_animating)
   
	set_pdata_float(iPlayer, m_flFrameRate, flFrameRate, extra_offset_animating)
	set_pdata_float(iPlayer, m_flGroundSpeed, flGroundSpeed, extra_offset_animating)
	set_pdata_float(iPlayer, m_flLastEventCheck, flGametime , extra_offset_animating)
   
	set_pdata_int(iPlayer, m_Activity, ACT_RANGE_ATTACK1, extra_offset_player)
	set_pdata_int(iPlayer, m_IdealActivity, ACT_RANGE_ATTACK1, extra_offset_player)  
	set_pdata_float(iPlayer, m_flLastAttackTime, flGametime , extra_offset_player)
}

//**********************************************
//* Kick back.                                 *
//**********************************************
Weapon_KickBack(iItem, iPlayer, Float:upBase, Float:lateralBase, Float:upMod, Float:lateralMod, Float:upMax, Float:lateralMax, directionChange)
{
	static iDirection
	static iShotsFired 
	
	static Float: Punchangle[3]
	pev(iPlayer, pev_punchangle, Punchangle)
	
	if((iShotsFired = get_pdata_int(iItem, 64, 4)) != 1)
	{
		upBase += iShotsFired * upMod
		lateralBase += iShotsFired * lateralMod
	}
	
	upMax *= -1.0
	Punchangle[0] -= upBase
 
	if(upMax >= Punchangle[0])
	{
		Punchangle[0] = upMax
	}
	
	if((iDirection = get_pdata_int(iItem, 60, 4)))
	{
		Punchangle[1] += lateralBase
		
		if(lateralMax < Punchangle[1])
		{
			Punchangle[1] = lateralMax
		}
	}
	else
	{
		lateralMax *= -1.0;
		Punchangle[1] -= lateralBase
		
		if(lateralMax > Punchangle[1])
		{
			Punchangle[1] = lateralMax
		}
	}
	
	if(!random_num(0, directionChange))
	{
		set_pdata_int(iItem, 60, !iDirection, 4)
	}
	
	set_pev(iPlayer, pev_punchangle, Punchangle)
}

//**********************************************
//* Some useful stocks.                        *
//**********************************************
stock get_speed_vector(Float:Origin1[3], Float:Origin2[3], Float:Speed, Float:NewVelocity[3])
{
	NewVelocity[0] = Origin2[0] - Origin1[0]
	NewVelocity[1] = Origin2[1] - Origin1[1]
	NewVelocity[2] = Origin2[2] - Origin1[2]
	new Float:num = floatsqroot(Speed*Speed / (NewVelocity[0]*NewVelocity[0] + NewVelocity[1]*NewVelocity[1] + NewVelocity[2]*NewVelocity[2]))
	NewVelocity[0] *= num
	NewVelocity[1] *= num
	NewVelocity[2] *= num
	
	return 1
}

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

stock Get_WeaponAttachment(iPlayer, Float:Output[3], Float:fDis = 40.0)
{ 
	static Float:vfEnd[3], viEnd[3] 
	get_user_origin(iPlayer, viEnd, 3)  
	IVecFVec(viEnd, vfEnd) 
	
	static Float:fOrigin[3], Float:fAngle[3]
	
	pev(iPlayer, pev_origin, fOrigin) 
	pev(iPlayer, 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)
}

This gun have /get command. Please can you remove it and make it showing in item menu. Many thanks
Image

User avatar
SexY DeviL CJ
Mod Tester
Mod Tester
Posts: 73
Joined: 1 Year Ago
Has thanked: 1 time
Been thanked: 10 times
Contact:

#2

Post by SexY DeviL CJ » 10 Months Ago

try:
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <zombie_escape>
  4. #include <fakemeta_util>
  5. #include <engine>
  6. #include <xs>
  7.  
  8. #define PLUGIN "Magnum Lancer"
  9. #define VERSION "2.0"
  10. #define AUTHOR "Bim Bim Cay"
  11.  
  12. // Models
  13. #define v_model "models/v_sgmissile.mdl"
  14. #define w_model "models/w_sgmissile.mdl"
  15. #define p_modela "models/p_sgmissile_a.mdl"
  16. #define p_modelb "models/p_sgmissile_b.mdl"
  17.  
  18. // Sounds
  19. #define attack1_sound "weapons/sgmissile-1.wav"
  20. #define attack2_sound "weapons/sgmissile-2.wav"
  21. #define reload_sound "weapons/sgmissile_reload.wav"
  22. #define explode_sound "weapons/sgmissile_exp.wav"
  23.  
  24. // Sprites
  25. #define ef_ball "sprites/ef_sgmissile_line.spr"
  26. #define ef_explode "sprites/ef_sgmissile.spr"
  27. #define muzzle_flash1 "sprites/muzzleflash64.spr"
  28. #define muzzle_flash2 "sprites/muzzleflash75.spr"
  29.  
  30. // Anims
  31. #define ANIM_IDLE       0
  32. #define ANIM_RELOAD     1
  33. #define ANIM_DRAW       2
  34. #define ANIM_SHOOT      3
  35. #define ANIM_IDLEB      4
  36. #define ANIM_RELOADB        5
  37. #define ANIM_DRAWB      6
  38. #define ANIM_SHOOTB1        7
  39. #define ANIM_SHOOTB2        8
  40. #define ANIM_SHOOTMISSLE    9
  41. #define ANIM_SHOOTMISSLELAST    10
  42. #define ANIM_MISSLEON       11
  43.  
  44. #define ANIM_EXTENSION      "m249"
  45.  
  46. // Entity Classname
  47. #define BALL_CLASSNAME "Magnum_EfBall"
  48. #define LINE_CLASSNAME "Magnum_EfLine"
  49. #define MUZZLEFLASH1_CLASSNAME "Muzzle_MagnumLancer1"
  50. #define MUZZLEFLASH2_CLASSNAME "Muzzle_MagnumLancer2"
  51.  
  52. // Configs
  53. #define WEAPON_NAME         "weapon_sgmissile"
  54. #define WEAPON_BASE     "weapon_m3"
  55.  
  56. #define WEAPON_MAX_CLIP     30
  57. #define WEAPON_DEFAULT_AMMO 90
  58. #define WEAPON_MAX_BATTERY  10
  59.  
  60. #define WEAPON_SHOOT_DAMAGE 100.0
  61. #define WEAPON_EXPLODE_DAMAGE   2000.0
  62. #define WEAPON_EXPLODE_RADIUS   75.0
  63.  
  64. #define WEAPON_TIME_NEXT_IDLE   10.0
  65. #define WEAPON_TIME_NEXT_ATTACK 0.25
  66. #define WEAPON_TIME_NEXT_ATTACK2 0.4
  67. #define WEAPON_TIME_DELAY_DEPLOY 1.0
  68. #define WEAPON_TIME_DELAY_RELOAD 2.0
  69. #define WEAPON_TIME_DELAY_CHARGE 3.0
  70.  
  71. // MACROS
  72. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  73. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  74. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  75.  
  76. #define INSTANCE(%0) ((%0 == -1) ? 0 : %0)
  77. #define IsValidPev(%0) (pev_valid(%0) == 2)
  78. #define IsObserver(%0) pev(%0,pev_iuser1)
  79. #define OBS_IN_EYE 4
  80. #define MSGID_WEAPONLIST 78
  81.  
  82. new g_iszWeaponKey
  83. new g_iForwardDecalIndex
  84. new g_Fire_SprId
  85. new g_itemid
  86.  
  87. // Safety
  88. new g_HamBot
  89. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
  90.  
  91. public plugin_init()
  92. {
  93.     register_plugin(PLUGIN, VERSION, AUTHOR)
  94.    
  95.     // Safety
  96.     Register_SafetyFunc()
  97.    
  98.     // Forward
  99.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  100.     register_forward(FM_TraceLine, "fw_TraceLine_Post", 1)
  101.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
  102.     register_forward(FM_SetModel, "fw_SetModel")
  103.    
  104.     unregister_forward(FM_DecalIndex, g_iForwardDecalIndex, 1)
  105.    
  106.     // Think
  107.     register_think(MUZZLEFLASH1_CLASSNAME, "fw_MuzzleFlash1_Think")
  108.     register_think(MUZZLEFLASH2_CLASSNAME, "fw_MuzzleFlash2_Think")
  109.     register_think(BALL_CLASSNAME, "fw_Ball_Think")
  110.     register_think(LINE_CLASSNAME, "fw_Line_Think")
  111.    
  112.     register_touch(BALL_CLASSNAME, "*", "fw_Ball_Touch")
  113.    
  114.     // Ham
  115.     RegisterHam(Ham_Spawn, "weaponbox", "fw_Weaponbox_Spawn_Post", 1)
  116.    
  117.     RegisterHam(Ham_Item_Deploy, WEAPON_BASE, "fw_Item_Deploy_Post", 1)
  118.     RegisterHam(Ham_Item_AddToPlayer, WEAPON_BASE, "fw_Item_AddToPlayer")
  119.     RegisterHam(Ham_Item_PostFrame, WEAPON_BASE, "fw_Item_PostFrame")
  120.     RegisterHam(Ham_Weapon_Reload, WEAPON_BASE, "fw_Weapon_Reload")
  121.     RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_BASE, "fw_Weapon_WeaponIdle")
  122.     RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_BASE, "fw_Weapon_PrimaryAttack")
  123.    
  124.     RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack_Entity")
  125.     RegisterHam(Ham_TraceAttack, "info_target", "fw_TraceAttack_Entity")
  126.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Entity")
  127.    
  128.     g_itemid = ze_register_item("Magnum lancer", 20, 0)
  129. }
  130.  
  131. public plugin_precache()
  132. {
  133.     precache_model(v_model)
  134.     precache_model(w_model)
  135.     precache_model(p_modela)
  136.     precache_model(p_modelb)
  137.    
  138.     precache_model(ef_ball)
  139.     precache_model(muzzle_flash1)
  140.     precache_model(muzzle_flash2)
  141.    
  142.     g_Fire_SprId = precache_model(ef_explode)
  143.    
  144.     precache_sound(attack1_sound)
  145.     precache_sound(attack2_sound)
  146.     precache_sound(reload_sound)
  147.     precache_sound(explode_sound)
  148.    
  149.     new TextFile[32]
  150.     formatex(TextFile, charsmax(TextFile), "sprites/%s.txt", WEAPON_NAME)
  151.    
  152.     precache_generic(TextFile)
  153.    
  154.     g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
  155.     g_iForwardDecalIndex = register_forward(FM_DecalIndex, "fw_DecalIndex_Post", 1)
  156.    
  157.     register_message(MSGID_WEAPONLIST, "MsgHook_WeaponList")
  158. }
  159.  
  160. public client_putinserver(iPlayer)
  161. {
  162.     Safety_Connected(iPlayer)
  163.    
  164.     if(!g_HamBot && is_user_bot(iPlayer))
  165.     {
  166.         g_HamBot = 1
  167.         set_task(0.1, "Register_HamBot", iPlayer)
  168.     }
  169. }
  170.  
  171. public Register_HamBot(iPlayer)
  172. {
  173.     Register_SafetyFuncBot(iPlayer)
  174.     RegisterHamFromEntity(Ham_TraceAttack, iPlayer, "fw_TraceAttack_Entity")   
  175. }
  176.  
  177. public client_disconnected(iPlayer)
  178. {
  179.     Safety_Disconnected(iPlayer)
  180. }
  181.  
  182. public Get_MyWeapon(iPlayer)
  183. {
  184.     Weapon_Give(iPlayer)
  185. }
  186.  
  187. public fw_UpdateClientData_Post(iPlayer, sendweapons, CD_Handle)
  188. {
  189.     enum
  190.     {
  191.         SPEC_MODE,
  192.         SPEC_TARGET,
  193.         SPEC_END
  194.     }
  195.      
  196.     static aSpecInfo[33][SPEC_END]
  197.    
  198.     static iTarget
  199.     static iSpecMode
  200.     static iActiveItem
  201.    
  202.     iTarget = (iSpecMode = IsObserver(iPlayer)) ? pev(iPlayer, pev_iuser2) : iPlayer
  203.    
  204.     if(!is_alive(iTarget))
  205.         return FMRES_IGNORED
  206.    
  207.     iActiveItem = get_pdata_cbase(iTarget, 373, 5)
  208.    
  209.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  210.         return FMRES_IGNORED
  211.    
  212.     if(iSpecMode)
  213.     {
  214.         if(aSpecInfo[iPlayer][SPEC_MODE] != iSpecMode)
  215.         {
  216.             aSpecInfo[iPlayer][SPEC_MODE] = iSpecMode
  217.             aSpecInfo[iPlayer][SPEC_TARGET] = 0
  218.         }
  219.        
  220.         if(iSpecMode == OBS_IN_EYE && aSpecInfo[iPlayer][SPEC_TARGET] != iTarget)
  221.         {
  222.             aSpecInfo[iPlayer][SPEC_TARGET] = iTarget
  223.            
  224.             if(get_pdata_int(iActiveItem, 30, 4))
  225.             {
  226.                 Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLEB)
  227.             }
  228.             else
  229.             {
  230.                 Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLE)
  231.             }
  232.         }
  233.     }
  234.    
  235.     set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
  236.    
  237.     return FMRES_HANDLED
  238. }
  239.  
  240. public fw_TraceLine_Post(Float:TraceStart[3], Float:TraceEnd[3], fNoMonsters, iEntToSkip, iTrace) <FireBullets: Enabled>
  241. {
  242.     static Float:vecEndPos[3]
  243.    
  244.     get_tr2(iTrace, TR_vecEndPos, vecEndPos)
  245.     engfunc(EngFunc_TraceLine, vecEndPos, TraceStart, fNoMonsters, iEntToSkip, 0)
  246.    
  247.     UTIL_GunshotDecalTrace(0)
  248.     UTIL_GunshotDecalTrace(iTrace, true)
  249. }
  250.  
  251. public fw_TraceLine_Post() </* Empty statement */>
  252. {
  253.     /* Fallback */
  254. }
  255.  
  256. public fw_TraceLine_Post() <FireBullets: Disabled> 
  257. {
  258.     /* Do notning */
  259. }
  260.  
  261. public fw_PlaybackEvent() <FireBullets: Enabled>
  262. {
  263.     return FMRES_SUPERCEDE
  264. }
  265.  
  266. public fw_PlaybackEvent() </* Empty statement */>      
  267. {
  268.     return FMRES_IGNORED
  269. }
  270.  
  271. public fw_PlaybackEvent() <FireBullets: Disabled>      
  272. {
  273.     return FMRES_IGNORED
  274. }
  275.  
  276. //**********************************************
  277. //* Weaponbox world model.                     *
  278. //**********************************************
  279. public fw_SetModel(iEntity) <WeaponBox: Enabled>
  280. {
  281.     state WeaponBox: Disabled
  282.    
  283.     if(!IsValidPev(iEntity))
  284.         return FMRES_IGNORED
  285.    
  286.     #define MAX_ITEM_TYPES  6
  287.     for(new i, iItem; i < MAX_ITEM_TYPES; i++)
  288.     {
  289.         iItem = get_pdata_cbase(iEntity, 34 + i, 4)
  290.        
  291.         if(IsValidPev(iItem) && IsCustomItem(iItem))
  292.         {
  293.             engfunc(EngFunc_SetModel, iEntity, w_model)
  294.             return FMRES_SUPERCEDE
  295.         }
  296.     }
  297.    
  298.     return FMRES_IGNORED
  299. }
  300.  
  301. public ze_select_item_pre(id, itemid)
  302. {
  303.     // Return Available and we will block it in Post, So it dosen't affect other plugins
  304.     if (itemid != g_itemid)
  305.         return ZE_ITEM_AVAILABLE
  306.    
  307.     // Available for Humans only, So don't show it for zombies
  308.     if (ze_is_user_zombie(id))
  309.         return ZE_ITEM_DONT_SHOW
  310.    
  311.     return ZE_ITEM_AVAILABLE
  312. }
  313.  
  314. public fw_SetModel() </* Empty statement */>   
  315. {
  316.     /*  Fallback  */
  317.     return FMRES_IGNORED
  318. }
  319. public fw_SetModel() <WeaponBox: Disabled> 
  320. {
  321.     /* Do nothing */
  322.     return FMRES_IGNORED
  323. }
  324.  
  325. public fw_Weaponbox_Spawn_Post(iWeaponBox)
  326. {
  327.     if(IsValidPev(iWeaponBox))
  328.     {
  329.         state (IsValidPev(pev(iWeaponBox, pev_owner))) WeaponBox: Enabled
  330.     }
  331.    
  332.     return HAM_IGNORED
  333. }
  334.  
  335. //**********************************************
  336. //* Weapon's codes.                     *
  337. //**********************************************
  338. public fw_Item_Deploy_Post(iItem)
  339. {
  340.     if(!IsCustomItem(iItem))
  341.         return
  342.        
  343.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  344.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  345.  
  346.     //I need to disable because there is no dummy anim
  347.     //static Sex; Sex = 0 //Get your sex: 0 - Male; 1 - Female
  348.     //set_pev(iItem, pev_body, Sex)
  349.    
  350.     set_pev(iPlayer, pev_viewmodel2, v_model)
  351.    
  352.     if(SecondaryAmmo)
  353.     {
  354.         set_pev(iPlayer, pev_weaponmodel2, p_modelb)
  355.         Weapon_SendAnim(iPlayer, iItem, ANIM_DRAWB)
  356.     }
  357.     else
  358.     {
  359.         set_pev(iPlayer, pev_weaponmodel2, p_modela)
  360.         Weapon_SendAnim(iPlayer, iItem, ANIM_DRAW)
  361.     }
  362.  
  363.     Notice(iPlayer, SecondaryAmmo)
  364.    
  365.     set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_DEPLOY, 4)
  366.     set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE + WEAPON_TIME_DELAY_DEPLOY, 4)
  367.    
  368.     set_pdata_string(iPlayer, (492) * 4, ANIM_EXTENSION, -1 , 20)
  369. }
  370.  
  371. public fw_Item_PostFrame(iItem)
  372. {
  373.     if(!IsCustomItem(iItem))
  374.         return HAM_IGNORED
  375.    
  376.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  377.    
  378.     if(get_pdata_int(iItem, 54, 4))
  379.     {
  380.         static iClip; iClip = get_pdata_int(iItem, 51, 4)
  381.         static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
  382.         static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
  383.         static iAmount; iAmount = min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary)
  384.        
  385.         set_pdata_int(iItem, 51, iClip + iAmount, 4)
  386.         SetAmmoInventory(iPlayer, iPrimaryAmmoIndex, iAmmoPrimary - iAmount)
  387.        
  388.         set_pdata_int(iItem, 54, 0, 4)
  389.         set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)
  390.        
  391.         return HAM_IGNORED
  392.     }  
  393.    
  394.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  395.     static Float:flLastEventCheck; flLastEventCheck = get_pdata_float(iItem, 38, 4)
  396.    
  397.     if(flLastEventCheck < get_gametime())
  398.     {
  399.         flLastEventCheck = get_gametime() + WEAPON_TIME_DELAY_CHARGE
  400.         set_pdata_float(iItem, 38, flLastEventCheck, 4)
  401.        
  402.         if(SecondaryAmmo < WEAPON_MAX_BATTERY)
  403.         {
  404.             if(!SecondaryAmmo)
  405.             {
  406.                 set_pdata_float(iItem, 48, 1.0, 4)
  407.                 Weapon_SendAnim(iPlayer, iItem, ANIM_MISSLEON)
  408.  
  409.                 set_pev(iPlayer, pev_weaponmodel2, p_modelb)
  410.             }
  411.            
  412.             SecondaryAmmo++
  413.             set_pdata_int(iItem, 30, SecondaryAmmo, 4)
  414.            
  415.             Notice(iPlayer, SecondaryAmmo)
  416.             emit_sound(iPlayer, CHAN_ITEM, reload_sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
  417.         }
  418.     }
  419.    
  420.     static iButton; iButton = pev(iPlayer, pev_button)
  421.    
  422.     if(iButton & IN_ATTACK2)
  423.     {
  424.         iButton &= ~IN_ATTACK2
  425.         iButton &= ~IN_ATTACK
  426.         set_pev(iPlayer, pev_button, iButton)
  427.        
  428.         if(!SecondaryAmmo)
  429.             return HAM_IGNORED
  430.            
  431.         if(get_pdata_float(iItem, 47, 4) > 0.0)
  432.             return HAM_IGNORED
  433.            
  434.         set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)   
  435.        
  436.         set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK2, 4)
  437.         set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK2, 4)
  438.        
  439.         emit_sound(iPlayer, CHAN_WEAPON, attack2_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
  440.        
  441.         if(SecondaryAmmo > 1)
  442.         {
  443.             Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLE)
  444.             set_pdata_float(iItem, 48, 0.87, 4)
  445.         }
  446.         else
  447.         {
  448.             Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLELAST)
  449.             set_pdata_float(iItem, 48, 1.2, 4)
  450.            
  451.             set_pev(iPlayer, pev_weaponmodel2, p_modela)
  452.         }
  453.        
  454.         static szAnimation[64]
  455.        
  456.         if(pev(iPlayer, pev_flags) & FL_DUCKING)
  457.         {
  458.             formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
  459.         }
  460.         else
  461.         {
  462.             formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
  463.         }
  464.        
  465.         Player_SetAnimation(iPlayer, szAnimation)
  466.        
  467.         SecondaryAmmo--
  468.         set_pdata_int(iItem, 30, SecondaryAmmo, 4)
  469.            
  470.         Notice(iPlayer, SecondaryAmmo)
  471.        
  472.         Attack2(iPlayer)
  473.         MakeMuzzleFlash2(iPlayer)
  474.     }
  475.    
  476.     return HAM_IGNORED
  477. }
  478.  
  479. public fw_Weapon_Reload(iItem)
  480. {
  481.     if(!IsCustomItem(iItem))
  482.         return HAM_IGNORED
  483.        
  484.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  485.    
  486.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
  487.     static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
  488.     static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
  489.    
  490.     if(min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary) <= 0)
  491.         return HAM_SUPERCEDE
  492.    
  493.     set_pdata_int(iItem, 51, 0, 4)
  494.    
  495.     ExecuteHam(Ham_Weapon_Reload, iItem)
  496.    
  497.     //Remove shotgun reload
  498.     set_pdata_int(iItem, 55, 0, 4)
  499.     set_pdata_int(iItem, 54, 1, 4)
  500.    
  501.     set_pdata_int(iItem, 51, iClip, 4)
  502.    
  503.     set_pdata_float(iPlayer, 83, WEAPON_TIME_DELAY_RELOAD, 5)
  504.     set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_RELOAD, 4)
  505.    
  506.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  507.    
  508.     if(SecondaryAmmo)
  509.     {
  510.         Weapon_SendAnim(iPlayer, iItem, ANIM_RELOADB)
  511.     }
  512.     else
  513.     {
  514.         Weapon_SendAnim(iPlayer, iItem, ANIM_RELOAD)
  515.     }
  516.    
  517.     return HAM_SUPERCEDE   
  518. }
  519.  
  520. public fw_Weapon_WeaponIdle(iItem)
  521. {
  522.     if(!IsCustomItem(iItem))
  523.         return HAM_IGNORED
  524.        
  525.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  526.    
  527.     ExecuteHamB(Ham_Weapon_ResetEmptySound, iItem)
  528.  
  529.     if(get_pdata_float(iItem, 48, 4) > 0.0)
  530.         return HAM_SUPERCEDE
  531.    
  532.     set_pdata_float(iItem, 48, WEAPON_TIME_NEXT_IDLE, 4)
  533.    
  534.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  535.    
  536.     if(SecondaryAmmo)
  537.     {
  538.         Weapon_SendAnim(iPlayer, iItem, ANIM_IDLEB)
  539.     }
  540.     else
  541.     {
  542.         Weapon_SendAnim(iPlayer, iItem, ANIM_IDLE)
  543.     }
  544.    
  545.     return HAM_SUPERCEDE
  546. }
  547.  
  548. public fw_Weapon_PrimaryAttack(iItem)
  549. {
  550.     if(!IsCustomItem(iItem))
  551.         return HAM_IGNORED
  552.        
  553.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  554.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
  555.    
  556.     if(iClip <= 0)
  557.     {
  558.         // No ammo, play empty sound and cancel
  559.         if(get_pdata_int(iItem, 45, 4))
  560.         {
  561.             ExecuteHamB(Ham_Weapon_PlayEmptySound, iItem)
  562.             set_pdata_float(iItem, 46, 0.2, 4)
  563.         }
  564.    
  565.         return HAM_SUPERCEDE
  566.     }
  567.    
  568.     CallOriginalFireBullets(iItem, iPlayer)
  569.    
  570.     static iFlags
  571.     static szAnimation[64], Float:Velocity[3]
  572.  
  573.     iFlags = pev(iPlayer, pev_flags)
  574.    
  575.     if(iFlags & FL_DUCKING)
  576.     {
  577.         formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
  578.     }
  579.     else
  580.     {
  581.         formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
  582.     }
  583.    
  584.     Player_SetAnimation(iPlayer, szAnimation)
  585.    
  586.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  587.    
  588.     if(SecondaryAmmo)
  589.     {
  590.         Weapon_SendAnim(iPlayer, iItem, random_num(ANIM_SHOOTB1, ANIM_SHOOTB2))
  591.     }
  592.     else
  593.     {
  594.         Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
  595.     }
  596.    
  597.     set_pdata_float(iItem, 48, 0.7, 4)
  598.     set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK, 4)
  599.     set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK, 4)
  600.    
  601.     pev(iPlayer, pev_velocity, Velocity)
  602.    
  603.     if(xs_vec_len(Velocity) > 0)
  604.     {
  605.         Weapon_KickBack(iItem, iPlayer, 1.5, 0.45, 0.225, 0.05, 6.5, 2.5, 7)
  606.     }
  607.     else if(!(iFlags & FL_ONGROUND))
  608.     {
  609.         Weapon_KickBack(iItem, iPlayer, 2.0, 1.0, 0.5, 0.35, 9.0, 6.0, 5)
  610.     }
  611.     else if(iFlags & FL_DUCKING)
  612.     {
  613.         Weapon_KickBack(iItem, iPlayer, 0.9, 0.35, 0.15, 0.025, 5.5, 1.5, 9)
  614.     }
  615.     else
  616.     {
  617.         Weapon_KickBack(iItem, iPlayer, 1.0, 0.375, 0.175, 0.0375, 5.75, 1.75, 8)
  618.     }
  619.  
  620.     emit_sound(iPlayer, CHAN_WEAPON, attack1_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
  621.    
  622.     MakeMuzzleFlash1(iPlayer)
  623.    
  624.     return HAM_SUPERCEDE
  625. }
  626.  
  627. public fw_TraceAttack_Entity(iEntity, iAttacker, Float: flDamage) <FireBullets: Enabled>
  628. {
  629.     SetHamParamFloat(3, WEAPON_SHOOT_DAMAGE)
  630. }
  631.  
  632. public fw_TraceAttack_Entity() </* Empty statement */>     
  633. {
  634.     /* Fallback */
  635. }
  636.  
  637. public fw_TraceAttack_Entity() <FireBullets: Disabled>     
  638. {
  639.     /* Do notning */
  640. }
  641.  
  642. //**********************************************
  643. //* Weapon list update.                        *
  644. //**********************************************
  645. public fw_Item_AddToPlayer(iItem, iPlayer)
  646. {
  647.     if(!IsValidPev(iItem) || !IsValidPev(iPlayer))
  648.         return HAM_IGNORED
  649.    
  650.     MsgHook_WeaponList(MSGID_WEAPONLIST, iItem, iPlayer)
  651.    
  652.     return HAM_IGNORED
  653. }
  654.  
  655. public MsgHook_WeaponList(iMsgID, iMsgDest, iMsgEntity)
  656. {
  657.     static arrWeaponListData[8]
  658.    
  659.     if(!iMsgEntity)
  660.     {
  661.         new szWeaponName[32]
  662.         get_msg_arg_string(1, szWeaponName, charsmax(szWeaponName))
  663.        
  664.         if(!strcmp(szWeaponName, WEAPON_BASE))
  665.         {
  666.             for(new i, a = sizeof arrWeaponListData; i < a; i++)
  667.             {
  668.                 arrWeaponListData[i] = get_msg_arg_int(i + 2)
  669.             }
  670.         }
  671.     }
  672.     else
  673.     {
  674.         if(!IsCustomItem(iMsgDest) && pev(iMsgDest, pev_impulse))
  675.             return
  676.        
  677.         engfunc(EngFunc_MessageBegin, MSG_ONE, iMsgID, {0.0, 0.0, 0.0}, iMsgEntity)
  678.         write_string(IsCustomItem(iMsgDest) ? WEAPON_NAME : WEAPON_BASE)
  679.        
  680.         for(new i, a = sizeof arrWeaponListData; i < a; i++)
  681.         {
  682.             write_byte(arrWeaponListData[i])
  683.         }
  684.        
  685.         message_end()
  686.     }
  687. }
  688.  
  689. //**********************************************
  690. //* Effects                                    *
  691. //**********************************************
  692. Notice(iPlayer, SecondaryAmmo)
  693. {
  694.     client_print(iPlayer, print_center, "Fire Ammo: %d", SecondaryAmmo)
  695. }
  696.  
  697. public MakeMuzzleFlash1(iPlayer)
  698. {
  699.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  700.     if(!pev_valid(Ent)) return
  701.    
  702.     set_pev(Ent, pev_classname, MUZZLEFLASH1_CLASSNAME)
  703.    
  704.     set_pev(Ent, pev_owner, iPlayer)
  705.     set_pev(Ent, pev_body, 1)
  706.     set_pev(Ent, pev_skin, iPlayer)
  707.     set_pev(Ent, pev_aiment, iPlayer)
  708.     set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
  709.    
  710.     set_pev(Ent, pev_scale, 0.085)
  711.     set_pev(Ent, pev_frame, 0.0)
  712.     set_pev(Ent, pev_rendermode, kRenderTransAdd)
  713.     set_pev(Ent, pev_renderamt, 255.0)
  714.    
  715.     engfunc(EngFunc_SetModel, Ent,  muzzle_flash1)
  716.    
  717.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  718. }
  719.  
  720. public fw_MuzzleFlash1_Think(Ent)
  721. {
  722.     if(!pev_valid(Ent))
  723.         return
  724.    
  725.     static Owner; Owner = pev(Ent, pev_owner)
  726.    
  727.     if(!is_alive(Owner))
  728.     {
  729.         set_pev(Ent, pev_flags, FL_KILLME)
  730.         return
  731.     }
  732.    
  733.     static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
  734.    
  735.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  736.     {
  737.         set_pev(Ent, pev_flags, FL_KILLME)
  738.         return
  739.     }
  740.  
  741.     static Float:Frame; pev(Ent, pev_frame, Frame)
  742.     if(Frame > 8.0)
  743.     {
  744.         set_pev(Ent, pev_flags, FL_KILLME)
  745.         return
  746.     }
  747.     else
  748.     {
  749.         Frame += 1.0
  750.         set_pev(Ent, pev_frame, Frame)
  751.     }
  752.    
  753.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  754. }
  755.  
  756. public MakeMuzzleFlash2(iPlayer)
  757. {
  758.     static Ent
  759.    
  760.     for(new i = 2; i < 5; i++)
  761.     {
  762.         Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  763.         if(!pev_valid(Ent)) continue
  764.    
  765.         set_pev(Ent, pev_classname, MUZZLEFLASH2_CLASSNAME)
  766.    
  767.         set_pev(Ent, pev_owner, iPlayer)
  768.         set_pev(Ent, pev_body, i)
  769.         set_pev(Ent, pev_skin, iPlayer)
  770.         set_pev(Ent, pev_aiment, iPlayer)
  771.         set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
  772.    
  773.         set_pev(Ent, pev_scale, 0.02)
  774.         set_pev(Ent, pev_frame, 0.0)
  775.         set_pev(Ent, pev_rendermode, kRenderTransAdd)
  776.         set_pev(Ent, pev_renderamt, 255.0)
  777.    
  778.         engfunc(EngFunc_SetModel, Ent,  muzzle_flash2)
  779.    
  780.         set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  781.     }
  782. }
  783.  
  784. public fw_MuzzleFlash2_Think(Ent)
  785. {
  786.     if(!pev_valid(Ent))
  787.         return
  788.    
  789.     static Owner; Owner = pev(Ent, pev_owner)
  790.    
  791.     if(!is_alive(Owner))
  792.     {
  793.         set_pev(Ent, pev_flags, FL_KILLME)
  794.         return
  795.     }
  796.    
  797.     static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
  798.    
  799.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  800.     {
  801.         set_pev(Ent, pev_flags, FL_KILLME)
  802.         return
  803.     }
  804.    
  805.     static Float:Frame; pev(Ent, pev_frame, Frame)
  806.     if(Frame > 9.0)
  807.     {
  808.         set_pev(Ent, pev_flags, FL_KILLME)
  809.         return
  810.     }
  811.     else
  812.     {
  813.         Frame += 1.0
  814.         set_pev(Ent, pev_frame, Frame)
  815.     }
  816.    
  817.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  818. }
  819.  
  820. public Attack2(iPlayer)
  821. {
  822.     static Float:StartOrigin[3], Float:EndOrigin[9][3]
  823.     Get_WeaponAttachment(iPlayer, StartOrigin, 40.0)
  824.    
  825.     // Left
  826.     Get_Position(iPlayer, 512.0, 50.0, 0.0, EndOrigin[0])
  827.     Get_Position(iPlayer, 512.0, 100.0, 0.0, EndOrigin[1])
  828.     Get_Position(iPlayer, 512.0, 150.0, 0.0, EndOrigin[2])
  829.     Get_Position(iPlayer, 512.0, 200.0, 0.0, EndOrigin[3])
  830.    
  831.     // Center
  832.     Get_Position(iPlayer, 512.0, 0.0, 0.0, EndOrigin[4])
  833.    
  834.     // Right
  835.     Get_Position(iPlayer, 512.0, -50.0, 0.0, EndOrigin[5])
  836.     Get_Position(iPlayer, 512.0, -100.0, 0.0, EndOrigin[6])
  837.     Get_Position(iPlayer, 512.0, -150.0, 0.0, EndOrigin[7])
  838.     Get_Position(iPlayer, 512.0, -200.0, 0.0, EndOrigin[8])
  839.    
  840.     // Create Fire
  841.     for(new i = 0; i < 9; i++) Create_System(iPlayer, StartOrigin, EndOrigin[i])
  842. }
  843.  
  844. public Create_System(iPlayer, Float:StartOrigin[3], Float:EndOrigin[3])
  845. {
  846.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  847.    
  848.     if(!pev_valid(Ent))
  849.         return
  850.        
  851.     set_pev(Ent, pev_classname, BALL_CLASSNAME)
  852.     set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
  853.     set_pev(Ent, pev_solid, SOLID_TRIGGER)
  854.    
  855.     engfunc(EngFunc_SetModel, Ent, ef_ball)
  856.    
  857.     set_pev(Ent, pev_rendermode, kRenderTransAdd)
  858.     set_pev(Ent, pev_renderamt, 150.0)
  859.     set_pev(Ent, pev_scale, 0.3)
  860.     set_pev(Ent, pev_frame, 0.0)
  861.    
  862.     set_pev(Ent, pev_mins, Float:{-5.0, -5.0, -5.0})
  863.     set_pev(Ent, pev_maxs, Float:{5.0, 5.0, 5.0})
  864.    
  865.     set_pev(Ent, pev_origin, StartOrigin)
  866.    
  867.     set_pev(Ent, pev_owner, iPlayer)   
  868.     set_pev(Ent, pev_iuser3, get_user_team(iPlayer))
  869.     set_pev(Ent, pev_fuser4, get_gametime())
  870.    
  871.     // Create Velocity
  872.     static Float:Velocity[3]
  873.     get_speed_vector(StartOrigin, EndOrigin, 1000.0, Velocity)//Or 750, 1500, 2000, 2500
  874.     set_pev(Ent, pev_velocity, Velocity)   
  875.    
  876.     set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  877. }
  878.  
  879. public fw_Ball_Think(Ent)
  880. {
  881.     if(!pev_valid(Ent))
  882.         return
  883.        
  884.     static Float:Frame
  885.     pev(Ent, pev_frame, Frame)
  886.    
  887.     if(Frame > 14.0)
  888.     {
  889.         static Float:Amount
  890.         pev(Ent, pev_renderamt, Amount)
  891.        
  892.         if(Amount <= 15.0)
  893.         {
  894.             set_pev(Ent, pev_flags, FL_KILLME)
  895.             return
  896.         }
  897.        
  898.         Amount -= 15.0
  899.         set_pev(Ent, pev_renderamt, Amount)
  900.        
  901.         set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
  902.     }
  903.     else
  904.     {
  905.         Frame += 1.0
  906.         set_pev(Ent, pev_frame, Frame)
  907.        
  908.         static Float:Origin[3]
  909.         pev(Ent, pev_origin, Origin)
  910.        
  911.         static Float:Scale
  912.         pev(Ent, pev_scale, Scale)
  913.        
  914.         Scale += 0.02
  915.         set_pev(Ent, pev_scale, Scale)
  916.        
  917.         static Float:Time
  918.         pev(Ent, pev_fuser4, Time)
  919.        
  920.         Create_Line(Origin)
  921.         set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  922.     }
  923. }
  924.  
  925. public fw_Ball_Touch(Ent, Touch)
  926. {
  927.     if(!pev_valid(Ent))
  928.         return
  929.    
  930.     static Classname[36]; pev(Touch, pev_classname, Classname, sizeof(Classname))
  931.    
  932.     if(equali(Classname, BALL_CLASSNAME))
  933.         return
  934.    
  935.     static Float:Origin[3]
  936.     pev(Ent, pev_origin, Origin)
  937.    
  938.     static TE_FLAG
  939.    
  940.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  941.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
  942.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  943.    
  944.     message_begin(MSG_BROADCAST ,SVC_TEMPENTITY)
  945.     write_byte(TE_EXPLOSION)
  946.     engfunc(EngFunc_WriteCoord, Origin[0])
  947.     engfunc(EngFunc_WriteCoord, Origin[1])
  948.     engfunc(EngFunc_WriteCoord, Origin[2])
  949.     write_short(g_Fire_SprId)   // sprite index
  950.     write_byte(15)  // scale in 3.4's
  951.     write_byte(15)  // framerate
  952.     write_byte(TE_FLAG) // flags
  953.     message_end()
  954.    
  955.     emit_sound(Ent, CHAN_BODY, explode_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  956.    
  957.     static Team; Team = pev(Ent, pev_iuser3)
  958.     static Owner; Owner = pev(Ent, pev_owner)
  959.    
  960.     static Victim; Victim = -1
  961.     while((Victim = find_ent_in_sphere(Victim, Origin, WEAPON_EXPLODE_RADIUS)) != 0)
  962.     {
  963.         if(is_alive(Victim))
  964.         {
  965.             if(get_user_team(Victim) == Team)
  966.                 continue
  967.         }
  968.         else
  969.         {
  970.             if(pev(Victim, pev_takedamage) == DAMAGE_NO)
  971.                 continue
  972.         }
  973.        
  974.         ExecuteHamB(Ham_TakeDamage, Victim, Owner, Owner, WEAPON_EXPLODE_DAMAGE, DMG_BULLET)
  975.     }
  976.    
  977.     set_pev(Ent, pev_flags, FL_KILLME) 
  978. }
  979.  
  980. public Create_Line(Float:Origin[3])
  981. {
  982.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  983.    
  984.     if(!pev_valid(Ent))
  985.         return
  986.    
  987.     set_pev(Ent, pev_classname, LINE_CLASSNAME)
  988.     set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
  989.     set_pev(Ent, pev_solid, SOLID_NOT)
  990.    
  991.     engfunc(EngFunc_SetModel, Ent, ef_ball)
  992.    
  993.     set_pev(Ent, pev_rendermode, kRenderTransAdd)
  994.     set_pev(Ent, pev_renderamt, 120.0)
  995.     set_pev(Ent, pev_scale, 0.3)
  996.     set_pev(Ent, pev_frame, 0.0)
  997.    
  998.     set_pev(Ent, pev_origin, Origin)
  999.    
  1000.     set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  1001. }
  1002.  
  1003. public fw_Line_Think(Ent)
  1004. {
  1005.     if(!pev_valid(Ent))
  1006.         return
  1007.        
  1008.     static Float:Amount
  1009.     pev(Ent, pev_renderamt, Amount)
  1010.    
  1011.     if(Amount <= 15.0)
  1012.     {
  1013.         set_pev(Ent, pev_flags, FL_KILLME)
  1014.         return
  1015.     }
  1016.    
  1017.     Amount -= 15.0
  1018.     set_pev(Ent, pev_renderamt, Amount)
  1019.    
  1020.     set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  1021. }
  1022. /* ===============================
  1023. ------------- SAFETY -------------
  1024. =================================*/
  1025. public Register_SafetyFunc()
  1026. {
  1027.     register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
  1028.    
  1029.     RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
  1030.     RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
  1031. }
  1032.  
  1033. public Register_SafetyFuncBot(iPlayer)
  1034. {
  1035.     RegisterHamFromEntity(Ham_Spawn, iPlayer, "fw_Safety_Spawn_Post", 1)
  1036.     RegisterHamFromEntity(Ham_Killed, iPlayer, "fw_Safety_Killed_Post", 1)
  1037. }
  1038.  
  1039. public Safety_Connected(iPlayer)
  1040. {
  1041.     Set_BitVar(g_IsConnected, iPlayer)
  1042.     UnSet_BitVar(g_IsAlive, iPlayer)
  1043.    
  1044.     g_PlayerWeapon[iPlayer] = 0
  1045. }
  1046.  
  1047. public Safety_Disconnected(iPlayer)
  1048. {
  1049.     UnSet_BitVar(g_IsConnected, iPlayer)
  1050.     UnSet_BitVar(g_IsAlive, iPlayer)
  1051.    
  1052.     g_PlayerWeapon[iPlayer] = 0
  1053. }
  1054.  
  1055. public Safety_CurWeapon(iPlayer)
  1056. {
  1057.     if(!is_alive(iPlayer))
  1058.         return
  1059.        
  1060.     static CSW; CSW = read_data(2)
  1061.     if(g_PlayerWeapon[iPlayer] != CSW) g_PlayerWeapon[iPlayer] = CSW
  1062. }
  1063.  
  1064. public fw_Safety_Spawn_Post(iPlayer)
  1065. {
  1066.     if(!is_user_alive(iPlayer))
  1067.         return
  1068.        
  1069.     Set_BitVar(g_IsAlive, iPlayer)
  1070. }
  1071.  
  1072. public fw_Safety_Killed_Post(iPlayer)
  1073. {
  1074.     UnSet_BitVar(g_IsAlive, iPlayer)
  1075. }
  1076.  
  1077. public is_connected(iPlayer)
  1078. {
  1079.     if(!(1 <= iPlayer <= 32))
  1080.         return 0
  1081.     if(!Get_BitVar(g_IsConnected, iPlayer))
  1082.         return 0
  1083.  
  1084.     return 1
  1085. }
  1086.  
  1087. public is_alive(iPlayer)
  1088. {
  1089.     if(!is_connected(iPlayer))
  1090.         return 0
  1091.     if(!Get_BitVar(g_IsAlive, iPlayer))
  1092.         return 0
  1093.        
  1094.     return 1
  1095. }
  1096.  
  1097. public get_player_weapon(iPlayer)
  1098. {
  1099.     if(!is_alive(iPlayer))
  1100.         return 0
  1101.    
  1102.     return g_PlayerWeapon[iPlayer]
  1103. }
  1104.  
  1105. /* ===============================
  1106. --------- END OF SAFETY  ---------
  1107. =================================*/
  1108.  
  1109. //**********************************************
  1110. //* Create and check our custom weapon.        *
  1111. //**********************************************
  1112. IsCustomItem(iItem)
  1113. {
  1114.     return (pev(iItem, pev_impulse) == g_iszWeaponKey)
  1115. }
  1116.  
  1117. Weapon_Create(Float: Origin[3] = {0.0, 0.0, 0.0}, Float: Angles[3] = {0.0, 0.0, 0.0})
  1118. {
  1119.     new iWeapon
  1120.  
  1121.     static iszAllocStringCached
  1122.     if (iszAllocStringCached || (iszAllocStringCached = engfunc(EngFunc_AllocString, WEAPON_BASE)))
  1123.     {
  1124.         iWeapon = engfunc(EngFunc_CreateNamedEntity, iszAllocStringCached)
  1125.     }
  1126.    
  1127.     if(!IsValidPev(iWeapon))
  1128.         return FM_NULLENT
  1129.    
  1130.     dllfunc(DLLFunc_Spawn, iWeapon)
  1131.     set_pev(iWeapon, pev_origin, Origin)
  1132.  
  1133.     set_pdata_int(iWeapon, 51, WEAPON_MAX_CLIP, 4)
  1134.     set_pdata_int(iWeapon, 30, 0, 4)
  1135.  
  1136.     set_pev_string(iWeapon, pev_classname, g_iszWeaponKey)
  1137.     set_pev(iWeapon, pev_impulse, g_iszWeaponKey)
  1138.     set_pev(iWeapon, pev_angles, Angles)
  1139.    
  1140.     engfunc(EngFunc_SetModel, iWeapon, w_model)
  1141.  
  1142.     return iWeapon
  1143. }
  1144.  
  1145. Weapon_Give(iPlayer)
  1146. {
  1147.     if(!IsValidPev(iPlayer))
  1148.     {
  1149.         return FM_NULLENT
  1150.     }
  1151.    
  1152.     new iWeapon, Float: vecOrigin[3]
  1153.     pev(iPlayer, pev_origin, vecOrigin)
  1154.    
  1155.     if((iWeapon = Weapon_Create(vecOrigin)) != FM_NULLENT)
  1156.     {
  1157.         Player_DropWeapons(iPlayer, ExecuteHamB(Ham_Item_ItemSlot, iWeapon))
  1158.        
  1159.         set_pev(iWeapon, pev_spawnflags, pev(iWeapon, pev_spawnflags) | SF_NORESPAWN)
  1160.         dllfunc(DLLFunc_Touch, iWeapon, iPlayer)
  1161.        
  1162.         SetAmmoInventory(iPlayer, PrimaryAmmoIndex(iWeapon), WEAPON_DEFAULT_AMMO)
  1163.        
  1164.         return iWeapon
  1165.     }
  1166.    
  1167.     return FM_NULLENT
  1168. }
  1169.  
  1170. Player_DropWeapons(iPlayer, iSlot)
  1171. {
  1172.     new szWeaponName[32], iItem = get_pdata_cbase(iPlayer, 367 + iSlot, 5)
  1173.  
  1174.     while(IsValidPev(iItem))
  1175.     {
  1176.         pev(iItem, pev_classname, szWeaponName, charsmax(szWeaponName))
  1177.         engclient_cmd(iPlayer, "drop", szWeaponName)
  1178.  
  1179.         iItem = get_pdata_cbase(iItem, 42, 4)
  1180.     }
  1181. }
  1182.  
  1183. //**********************************************
  1184. //* Ammo Inventory.                            *
  1185. //**********************************************
  1186. PrimaryAmmoIndex(iItem)
  1187. {
  1188.     return get_pdata_int(iItem, 49, 4)
  1189. }
  1190.  
  1191. GetAmmoInventory(iPlayer, iAmmoIndex)
  1192. {
  1193.     if(iAmmoIndex == -1)
  1194.         return -1
  1195.    
  1196.     return get_pdata_int(iPlayer, 376 + iAmmoIndex, 5)
  1197. }
  1198.  
  1199. SetAmmoInventory(iPlayer, iAmmoIndex, iAmount)
  1200. {
  1201.     if(iAmmoIndex == -1)
  1202.         return 0
  1203.    
  1204.     set_pdata_int(iPlayer, 376 + iAmmoIndex, iAmount, 5)
  1205.    
  1206.     return 1
  1207. }
  1208.  
  1209. //**********************************************
  1210. //* Fire Bullets.                              *
  1211. //**********************************************
  1212. CallOriginalFireBullets(iItem, iPlayer)
  1213. {
  1214.     state FireBullets: Enabled
  1215.     static Float:g_Recoil[3]
  1216.  
  1217.     pev(iPlayer, pev_punchangle, g_Recoil)
  1218.     ExecuteHam(Ham_Weapon_PrimaryAttack, iItem)
  1219.     set_pev(iPlayer, pev_punchangle, g_Recoil)
  1220.    
  1221.     state FireBullets: Disabled
  1222. }
  1223.  
  1224. //**********************************************
  1225. //* Decals.                                    *
  1226. //**********************************************
  1227. new Array: g_hDecals
  1228.  
  1229. public fw_DecalIndex_Post()
  1230. {
  1231.     if(!g_hDecals)
  1232.     {
  1233.         g_hDecals = ArrayCreate(1, 1)
  1234.     }
  1235.    
  1236.     ArrayPushCell(g_hDecals, get_orig_retval())
  1237. }
  1238.  
  1239. UTIL_GunshotDecalTrace(iTrace, bool: bIsGunshot = false)
  1240. {
  1241.     static iHit
  1242.     static iMessage
  1243.     static iDecalIndex
  1244.    
  1245.     static Float:flFraction
  1246.     static Float:vecEndPos[3]
  1247.    
  1248.     iHit = INSTANCE(get_tr2(iTrace, TR_pHit))
  1249.    
  1250.     if(iHit && !IsValidPev(iHit) || (pev(iHit, pev_flags) & FL_KILLME))
  1251.         return
  1252.    
  1253.     if(pev(iHit, pev_solid) != SOLID_BSP && pev(iHit, pev_movetype) != MOVETYPE_PUSHSTEP)
  1254.         return
  1255.    
  1256.     iDecalIndex = ExecuteHamB(Ham_DamageDecal, iHit, 0)
  1257.    
  1258.     if(iDecalIndex < 0 || iDecalIndex >=  ArraySize(g_hDecals))
  1259.         return
  1260.    
  1261.     iDecalIndex = ArrayGetCell(g_hDecals, iDecalIndex)
  1262.    
  1263.     get_tr2(iTrace, TR_flFraction, flFraction)
  1264.     get_tr2(iTrace, TR_vecEndPos, vecEndPos)
  1265.    
  1266.     if(iDecalIndex < 0 || flFraction >= 1.0)
  1267.         return
  1268.    
  1269.     if(bIsGunshot)
  1270.     {
  1271.         iMessage = TE_GUNSHOTDECAL
  1272.     }
  1273.     else
  1274.     {
  1275.         iMessage = TE_DECAL
  1276.        
  1277.         if(iHit != 0)
  1278.         {
  1279.             if(iDecalIndex > 255)
  1280.             {
  1281.                 iMessage = TE_DECALHIGH
  1282.                 iDecalIndex -= 256
  1283.             }
  1284.         }
  1285.         else
  1286.         {
  1287.             iMessage = TE_WORLDDECAL
  1288.            
  1289.             if(iDecalIndex > 255)
  1290.             {
  1291.                 iMessage = TE_WORLDDECALHIGH
  1292.                 iDecalIndex -= 256
  1293.             }
  1294.         }
  1295.     }
  1296.    
  1297.     engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEndPos, 0)
  1298.     write_byte(iMessage)
  1299.     engfunc(EngFunc_WriteCoord, vecEndPos[0])
  1300.     engfunc(EngFunc_WriteCoord, vecEndPos[1])
  1301.     engfunc(EngFunc_WriteCoord, vecEndPos[2])
  1302.  
  1303.     if(bIsGunshot)
  1304.     {
  1305.         write_short(iHit)
  1306.         write_byte(iDecalIndex)
  1307.     }
  1308.     else
  1309.     {
  1310.         write_byte(iDecalIndex)
  1311.        
  1312.         if(iHit)
  1313.         {
  1314.             write_short(iHit)
  1315.         }
  1316.     }
  1317.    
  1318.     message_end()
  1319. }
  1320.  
  1321. //**********************************************
  1322. //* Set Animations.                            *
  1323. //**********************************************
  1324. stock Weapon_SendAnim(iPlayer, iItem, iAnim)
  1325. {
  1326.     static i, iCount, iSpectator, aSpectators[32]
  1327.    
  1328.     set_pev(iPlayer, pev_weaponanim, iAnim)
  1329.  
  1330.     message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iPlayer)
  1331.     write_byte(iAnim)
  1332.     write_byte(pev(iItem, pev_body))
  1333.     message_end()
  1334.    
  1335.     if(IsObserver(iPlayer))
  1336.         return
  1337.    
  1338.     get_players(aSpectators, iCount, "bch")
  1339.  
  1340.     for(i = 0; i < iCount; i++)
  1341.     {
  1342.         iSpectator = aSpectators[i]
  1343.        
  1344.         if(IsObserver(iSpectator) != OBS_IN_EYE || pev(iSpectator, pev_iuser2) != iPlayer)
  1345.             continue
  1346.        
  1347.         set_pev(iSpectator, pev_weaponanim, iAnim)
  1348.  
  1349.         message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iSpectator)
  1350.         write_byte(iAnim)
  1351.         write_byte(pev(iItem, pev_body))
  1352.         message_end()
  1353.     }
  1354. }
  1355.  
  1356. stock Player_SetAnimation(iPlayer, szAnim[])
  1357. {
  1358.     #define ACT_RANGE_ATTACK1   28
  1359.    
  1360.     // Linux extra offsets
  1361.     #define extra_offset_animating   4
  1362.     #define extra_offset_player 5
  1363.    
  1364.     // CBaseAnimating
  1365.     #define m_flFrameRate      36
  1366.     #define m_flGroundSpeed      37
  1367.     #define m_flLastEventCheck   38
  1368.     #define m_fSequenceFinished   39
  1369.     #define m_fSequenceLoops   40
  1370.    
  1371.     // CBaseMonster
  1372.     #define m_Activity      73
  1373.     #define m_IdealActivity      74
  1374.    
  1375.     // CBasePlayer
  1376.     #define m_flLastAttackTime   220
  1377.    
  1378.     new iAnimDesired, Float:flFrameRate, Float:flGroundSpeed, bool:bLoops
  1379.      
  1380.     if((iAnimDesired = lookup_sequence(iPlayer, szAnim, flFrameRate, bLoops, flGroundSpeed)) == -1)
  1381.     {
  1382.         iAnimDesired = 0
  1383.     }
  1384.    
  1385.     static Float:flGametime; flGametime = get_gametime()
  1386.  
  1387.     set_pev(iPlayer, pev_frame, 0.0)
  1388.     set_pev(iPlayer, pev_framerate, 1.0)
  1389.     set_pev(iPlayer, pev_animtime, flGametime)
  1390.     set_pev(iPlayer, pev_sequence, iAnimDesired)
  1391.    
  1392.     set_pdata_int(iPlayer, m_fSequenceLoops, bLoops, extra_offset_animating)
  1393.     set_pdata_int(iPlayer, m_fSequenceFinished, 0, extra_offset_animating)
  1394.    
  1395.     set_pdata_float(iPlayer, m_flFrameRate, flFrameRate, extra_offset_animating)
  1396.     set_pdata_float(iPlayer, m_flGroundSpeed, flGroundSpeed, extra_offset_animating)
  1397.     set_pdata_float(iPlayer, m_flLastEventCheck, flGametime , extra_offset_animating)
  1398.    
  1399.     set_pdata_int(iPlayer, m_Activity, ACT_RANGE_ATTACK1, extra_offset_player)
  1400.     set_pdata_int(iPlayer, m_IdealActivity, ACT_RANGE_ATTACK1, extra_offset_player)  
  1401.     set_pdata_float(iPlayer, m_flLastAttackTime, flGametime , extra_offset_player)
  1402. }
  1403.  
  1404. //**********************************************
  1405. //* Kick back.                                 *
  1406. //**********************************************
  1407. Weapon_KickBack(iItem, iPlayer, Float:upBase, Float:lateralBase, Float:upMod, Float:lateralMod, Float:upMax, Float:lateralMax, directionChange)
  1408. {
  1409.     static iDirection
  1410.     static iShotsFired
  1411.    
  1412.     static Float: Punchangle[3]
  1413.     pev(iPlayer, pev_punchangle, Punchangle)
  1414.    
  1415.     if((iShotsFired = get_pdata_int(iItem, 64, 4)) != 1)
  1416.     {
  1417.         upBase += iShotsFired * upMod
  1418.         lateralBase += iShotsFired * lateralMod
  1419.     }
  1420.    
  1421.     upMax *= -1.0
  1422.     Punchangle[0] -= upBase
  1423.  
  1424.     if(upMax >= Punchangle[0])
  1425.     {
  1426.         Punchangle[0] = upMax
  1427.     }
  1428.    
  1429.     if((iDirection = get_pdata_int(iItem, 60, 4)))
  1430.     {
  1431.         Punchangle[1] += lateralBase
  1432.        
  1433.         if(lateralMax < Punchangle[1])
  1434.         {
  1435.             Punchangle[1] = lateralMax
  1436.         }
  1437.     }
  1438.     else
  1439.     {
  1440.         lateralMax *= -1.0;
  1441.         Punchangle[1] -= lateralBase
  1442.        
  1443.         if(lateralMax > Punchangle[1])
  1444.         {
  1445.             Punchangle[1] = lateralMax
  1446.         }
  1447.     }
  1448.    
  1449.     if(!random_num(0, directionChange))
  1450.     {
  1451.         set_pdata_int(iItem, 60, !iDirection, 4)
  1452.     }
  1453.    
  1454.     set_pev(iPlayer, pev_punchangle, Punchangle)
  1455. }
  1456.  
  1457. //**********************************************
  1458. //* Some useful stocks.                        *
  1459. //**********************************************
  1460. stock get_speed_vector(Float:Origin1[3], Float:Origin2[3], Float:Speed, Float:NewVelocity[3])
  1461. {
  1462.     NewVelocity[0] = Origin2[0] - Origin1[0]
  1463.     NewVelocity[1] = Origin2[1] - Origin1[1]
  1464.     NewVelocity[2] = Origin2[2] - Origin1[2]
  1465.     new Float:num = floatsqroot(Speed*Speed / (NewVelocity[0]*NewVelocity[0] + NewVelocity[1]*NewVelocity[1] + NewVelocity[2]*NewVelocity[2]))
  1466.     NewVelocity[0] *= num
  1467.     NewVelocity[1] *= num
  1468.     NewVelocity[2] *= num
  1469.    
  1470.     return 1
  1471. }
  1472.  
  1473. stock Get_Position(iPlayer, Float:forw, Float:right, Float:up, Float:vStart[])
  1474. {
  1475.     new Float:Origin[3], Float:Angles[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  1476.    
  1477.     pev(iPlayer, pev_origin, Origin)
  1478.     pev(iPlayer, pev_view_ofs,vUp) //for player
  1479.     xs_vec_add(Origin, vUp, Origin)
  1480.     pev(iPlayer, pev_v_angle, Angles) // if normal entity ,use pev_angles
  1481.    
  1482.     angle_vector(Angles, ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
  1483.     angle_vector(Angles, ANGLEVECTOR_RIGHT, vRight)
  1484.     angle_vector(Angles, ANGLEVECTOR_UP, vUp)
  1485.    
  1486.     vStart[0] = Origin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  1487.     vStart[1] = Origin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  1488.     vStart[2] = Origin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  1489. }
  1490.  
  1491. stock Get_WeaponAttachment(iPlayer, Float:Output[3], Float:fDis = 40.0)
  1492. {
  1493.     static Float:vfEnd[3], viEnd[3]
  1494.     get_user_origin(iPlayer, viEnd, 3)  
  1495.     IVecFVec(viEnd, vfEnd)
  1496.    
  1497.     static Float:fOrigin[3], Float:fAngle[3]
  1498.    
  1499.     pev(iPlayer, pev_origin, fOrigin)
  1500.     pev(iPlayer, pev_view_ofs, fAngle)
  1501.    
  1502.     xs_vec_add(fOrigin, fAngle, fOrigin)
  1503.    
  1504.     static Float:fAttack[3]
  1505.    
  1506.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1507.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1508.    
  1509.     static Float:fRate
  1510.    
  1511.     fRate = fDis / vector_length(fAttack)
  1512.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
  1513.    
  1514.     xs_vec_add(fOrigin, fAttack, Output)
  1515. }
These users thanked the author SexY DeviL CJ for the post:
czirimbolo (10 Months Ago)
......Devil Was Here......

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 477
Joined: 2 Years Ago
Has thanked: 18 times
Been thanked: 1 time
Contact:

#3

Post by czirimbolo » 10 Months Ago

I see this weapon in menu, I can buy it but it does nothing. It takes only my coins, can you fix it?
Image

User avatar
Jack GamePlay
Mod Developer
Mod Developer
Egypt
Posts: 576
Joined: 2 Years Ago
Location: Egypt
Has thanked: 34 times
Been thanked: 47 times
Age: 19
Contact:

#4

Post by Jack GamePlay » 10 Months Ago

  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <zombie_escape>
  4. #include <fakemeta_util>
  5. #include <engine>
  6. #include <xs>
  7.  
  8. #define PLUGIN "Magnum Lancer"
  9. #define VERSION "2.0"
  10. #define AUTHOR "Bim Bim Cay"
  11.  
  12. // Models
  13. #define v_model "models/v_sgmissile.mdl"
  14. #define w_model "models/w_sgmissile.mdl"
  15. #define p_modela "models/p_sgmissile_a.mdl"
  16. #define p_modelb "models/p_sgmissile_b.mdl"
  17.  
  18. // Sounds
  19. #define attack1_sound "weapons/sgmissile-1.wav"
  20. #define attack2_sound "weapons/sgmissile-2.wav"
  21. #define reload_sound "weapons/sgmissile_reload.wav"
  22. #define explode_sound "weapons/sgmissile_exp.wav"
  23.  
  24. // Sprites
  25. #define ef_ball "sprites/ef_sgmissile_line.spr"
  26. #define ef_explode "sprites/ef_sgmissile.spr"
  27. #define muzzle_flash1 "sprites/muzzleflash64.spr"
  28. #define muzzle_flash2 "sprites/muzzleflash75.spr"
  29.  
  30. // Anims
  31. #define ANIM_IDLE       0
  32. #define ANIM_RELOAD     1
  33. #define ANIM_DRAW       2
  34. #define ANIM_SHOOT      3
  35. #define ANIM_IDLEB      4
  36. #define ANIM_RELOADB        5
  37. #define ANIM_DRAWB      6
  38. #define ANIM_SHOOTB1        7
  39. #define ANIM_SHOOTB2        8
  40. #define ANIM_SHOOTMISSLE    9
  41. #define ANIM_SHOOTMISSLELAST    10
  42. #define ANIM_MISSLEON       11
  43.  
  44. #define ANIM_EXTENSION      "m249"
  45.  
  46. // Entity Classname
  47. #define BALL_CLASSNAME "Magnum_EfBall"
  48. #define LINE_CLASSNAME "Magnum_EfLine"
  49. #define MUZZLEFLASH1_CLASSNAME "Muzzle_MagnumLancer1"
  50. #define MUZZLEFLASH2_CLASSNAME "Muzzle_MagnumLancer2"
  51.  
  52. // Configs
  53. #define WEAPON_NAME         "weapon_sgmissile"
  54. #define WEAPON_BASE     "weapon_m3"
  55.  
  56. #define WEAPON_MAX_CLIP     30
  57. #define WEAPON_DEFAULT_AMMO 90
  58. #define WEAPON_MAX_BATTERY  10
  59.  
  60. #define WEAPON_SHOOT_DAMAGE 100.0
  61. #define WEAPON_EXPLODE_DAMAGE   2000.0
  62. #define WEAPON_EXPLODE_RADIUS   75.0
  63.  
  64. #define WEAPON_TIME_NEXT_IDLE   10.0
  65. #define WEAPON_TIME_NEXT_ATTACK 0.25
  66. #define WEAPON_TIME_NEXT_ATTACK2 0.4
  67. #define WEAPON_TIME_DELAY_DEPLOY 1.0
  68. #define WEAPON_TIME_DELAY_RELOAD 2.0
  69. #define WEAPON_TIME_DELAY_CHARGE 3.0
  70.  
  71. // MACROS
  72. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  73. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  74. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  75.  
  76. #define INSTANCE(%0) ((%0 == -1) ? 0 : %0)
  77. #define IsValidPev(%0) (pev_valid(%0) == 2)
  78. #define IsObserver(%0) pev(%0,pev_iuser1)
  79. #define OBS_IN_EYE 4
  80. #define MSGID_WEAPONLIST 78
  81.  
  82. new g_iszWeaponKey
  83. new g_iForwardDecalIndex
  84. new g_Fire_SprId
  85.  
  86. // Safety
  87. new g_HamBot
  88. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
  89. new g_iItemID
  90.  
  91. public plugin_init()
  92. {
  93.     register_plugin(PLUGIN, VERSION, AUTHOR)
  94.    
  95.     // Safety
  96.     Register_SafetyFunc()
  97.    
  98.     // Forward
  99.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  100.     register_forward(FM_TraceLine, "fw_TraceLine_Post", 1)
  101.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
  102.     register_forward(FM_SetModel, "fw_SetModel")
  103.    
  104.     unregister_forward(FM_DecalIndex, g_iForwardDecalIndex, 1)
  105.    
  106.     // Think
  107.     register_think(MUZZLEFLASH1_CLASSNAME, "fw_MuzzleFlash1_Think")
  108.     register_think(MUZZLEFLASH2_CLASSNAME, "fw_MuzzleFlash2_Think")
  109.     register_think(BALL_CLASSNAME, "fw_Ball_Think")
  110.     register_think(LINE_CLASSNAME, "fw_Line_Think")
  111.    
  112.     register_touch(BALL_CLASSNAME, "*", "fw_Ball_Touch")
  113.    
  114.     // Ham
  115.     RegisterHam(Ham_Spawn, "weaponbox", "fw_Weaponbox_Spawn_Post", 1)
  116.    
  117.     RegisterHam(Ham_Item_Deploy, WEAPON_BASE, "fw_Item_Deploy_Post", 1)
  118.     RegisterHam(Ham_Item_AddToPlayer, WEAPON_BASE, "fw_Item_AddToPlayer")
  119.     RegisterHam(Ham_Item_PostFrame, WEAPON_BASE, "fw_Item_PostFrame")
  120.     RegisterHam(Ham_Weapon_Reload, WEAPON_BASE, "fw_Weapon_Reload")
  121.     RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_BASE, "fw_Weapon_WeaponIdle")
  122.     RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_BASE, "fw_Weapon_PrimaryAttack")
  123.    
  124.     RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack_Entity")
  125.     RegisterHam(Ham_TraceAttack, "info_target", "fw_TraceAttack_Entity")
  126.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Entity")
  127.    
  128.     g_iItemID = ze_register_item("Magnum", 0, 0)
  129. }
  130.  
  131. public ze_select_item_pre(id, itemid)
  132. {
  133.     if (itemid != g_iItemID)
  134.         return ZE_ITEM_AVAILABLE
  135.  
  136.     if (ze_is_user_zombie(id))
  137.         return ZE_ITEM_DONT_SHOW
  138.  
  139.     return ZE_ITEM_AVAILABLE
  140. }
  141.  
  142. public ze_select_item_post(id, itemid)
  143. {
  144.     if (itemid != g_iItemID)
  145.         return
  146.  
  147.     Get_MyWeapon(id)
  148. }
  149.  
  150. public plugin_precache()
  151. {
  152.     precache_model(v_model)
  153.     precache_model(w_model)
  154.     precache_model(p_modela)
  155.     precache_model(p_modelb)
  156.    
  157.     precache_model(ef_ball)
  158.     precache_model(muzzle_flash1)
  159.     precache_model(muzzle_flash2)
  160.    
  161.     g_Fire_SprId = precache_model(ef_explode)
  162.    
  163.     precache_sound(attack1_sound)
  164.     precache_sound(attack2_sound)
  165.     precache_sound(reload_sound)
  166.     precache_sound(explode_sound)
  167.    
  168.     new TextFile[32]
  169.     formatex(TextFile, charsmax(TextFile), "sprites/%s.txt", WEAPON_NAME)
  170.    
  171.     precache_generic(TextFile)
  172.    
  173.     g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
  174.     g_iForwardDecalIndex = register_forward(FM_DecalIndex, "fw_DecalIndex_Post", 1)
  175.    
  176.     register_message(MSGID_WEAPONLIST, "MsgHook_WeaponList")
  177. }
  178.  
  179. public client_putinserver(iPlayer)
  180. {
  181.     Safety_Connected(iPlayer)
  182.    
  183.     if(!g_HamBot && is_user_bot(iPlayer))
  184.     {
  185.         g_HamBot = 1
  186.         set_task(0.1, "Register_HamBot", iPlayer)
  187.     }
  188. }
  189.  
  190. public Register_HamBot(iPlayer)
  191. {
  192.     Register_SafetyFuncBot(iPlayer)
  193.     RegisterHamFromEntity(Ham_TraceAttack, iPlayer, "fw_TraceAttack_Entity")   
  194. }
  195.  
  196. public client_disconnected(iPlayer)
  197. {
  198.     Safety_Disconnected(iPlayer)
  199. }
  200.  
  201. public Get_MyWeapon(iPlayer)
  202. {
  203.     Weapon_Give(iPlayer)
  204. }
  205.  
  206. public fw_UpdateClientData_Post(iPlayer, sendweapons, CD_Handle)
  207. {
  208.     enum
  209.     {
  210.         SPEC_MODE,
  211.         SPEC_TARGET,
  212.         SPEC_END
  213.     }
  214.      
  215.     static aSpecInfo[33][SPEC_END]
  216.    
  217.     static iTarget
  218.     static iSpecMode
  219.     static iActiveItem
  220.    
  221.     iTarget = (iSpecMode = IsObserver(iPlayer)) ? pev(iPlayer, pev_iuser2) : iPlayer
  222.    
  223.     if(!is_alive(iTarget))
  224.         return FMRES_IGNORED
  225.    
  226.     iActiveItem = get_pdata_cbase(iTarget, 373, 5)
  227.    
  228.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  229.         return FMRES_IGNORED
  230.    
  231.     if(iSpecMode)
  232.     {
  233.         if(aSpecInfo[iPlayer][SPEC_MODE] != iSpecMode)
  234.         {
  235.             aSpecInfo[iPlayer][SPEC_MODE] = iSpecMode
  236.             aSpecInfo[iPlayer][SPEC_TARGET] = 0
  237.         }
  238.        
  239.         if(iSpecMode == OBS_IN_EYE && aSpecInfo[iPlayer][SPEC_TARGET] != iTarget)
  240.         {
  241.             aSpecInfo[iPlayer][SPEC_TARGET] = iTarget
  242.            
  243.             if(get_pdata_int(iActiveItem, 30, 4))
  244.             {
  245.                 Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLEB)
  246.             }
  247.             else
  248.             {
  249.                 Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLE)
  250.             }
  251.         }
  252.     }
  253.    
  254.     set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
  255.    
  256.     return FMRES_HANDLED
  257. }
  258.  
  259. public fw_TraceLine_Post(Float:TraceStart[3], Float:TraceEnd[3], fNoMonsters, iEntToSkip, iTrace) <FireBullets: Enabled>
  260. {
  261.     static Float:vecEndPos[3]
  262.    
  263.     get_tr2(iTrace, TR_vecEndPos, vecEndPos)
  264.     engfunc(EngFunc_TraceLine, vecEndPos, TraceStart, fNoMonsters, iEntToSkip, 0)
  265.    
  266.     UTIL_GunshotDecalTrace(0)
  267.     UTIL_GunshotDecalTrace(iTrace, true)
  268. }
  269.  
  270. public fw_TraceLine_Post() </* Empty statement */>
  271. {
  272.     /* Fallback */
  273. }
  274.  
  275. public fw_TraceLine_Post() <FireBullets: Disabled> 
  276. {
  277.     /* Do notning */
  278. }
  279.  
  280. public fw_PlaybackEvent() <FireBullets: Enabled>
  281. {
  282.     return FMRES_SUPERCEDE
  283. }
  284.  
  285. public fw_PlaybackEvent() </* Empty statement */>      
  286. {
  287.     return FMRES_IGNORED
  288. }
  289.  
  290. public fw_PlaybackEvent() <FireBullets: Disabled>      
  291. {
  292.     return FMRES_IGNORED
  293. }
  294.  
  295. //**********************************************
  296. //* Weaponbox world model.                     *
  297. //**********************************************
  298. public fw_SetModel(iEntity) <WeaponBox: Enabled>
  299. {
  300.     state WeaponBox: Disabled
  301.    
  302.     if(!IsValidPev(iEntity))
  303.         return FMRES_IGNORED
  304.    
  305.     #define MAX_ITEM_TYPES  6
  306.     for(new i, iItem; i < MAX_ITEM_TYPES; i++)
  307.     {
  308.         iItem = get_pdata_cbase(iEntity, 34 + i, 4)
  309.        
  310.         if(IsValidPev(iItem) && IsCustomItem(iItem))
  311.         {
  312.             engfunc(EngFunc_SetModel, iEntity, w_model)
  313.             return FMRES_SUPERCEDE
  314.         }
  315.     }
  316.    
  317.     return FMRES_IGNORED
  318. }
  319.  
  320. public fw_SetModel() </* Empty statement */>   
  321. {
  322.     /*  Fallback  */
  323.     return FMRES_IGNORED
  324. }
  325. public fw_SetModel() <WeaponBox: Disabled> 
  326. {
  327.     /* Do nothing */
  328.     return FMRES_IGNORED
  329. }
  330.  
  331. public fw_Weaponbox_Spawn_Post(iWeaponBox)
  332. {
  333.     if(IsValidPev(iWeaponBox))
  334.     {
  335.         state (IsValidPev(pev(iWeaponBox, pev_owner))) WeaponBox: Enabled
  336.     }
  337.    
  338.     return HAM_IGNORED
  339. }
  340.  
  341. //**********************************************
  342. //* Weapon's codes.                     *
  343. //**********************************************
  344. public fw_Item_Deploy_Post(iItem)
  345. {
  346.     if(!IsCustomItem(iItem))
  347.         return
  348.        
  349.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  350.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  351.  
  352.     //I need to disable because there is no dummy anim
  353.     //static Sex; Sex = 0 //Get your sex: 0 - Male; 1 - Female
  354.     //set_pev(iItem, pev_body, Sex)
  355.    
  356.     set_pev(iPlayer, pev_viewmodel2, v_model)
  357.    
  358.     if(SecondaryAmmo)
  359.     {
  360.         set_pev(iPlayer, pev_weaponmodel2, p_modelb)
  361.         Weapon_SendAnim(iPlayer, iItem, ANIM_DRAWB)
  362.     }
  363.     else
  364.     {
  365.         set_pev(iPlayer, pev_weaponmodel2, p_modela)
  366.         Weapon_SendAnim(iPlayer, iItem, ANIM_DRAW)
  367.     }
  368.  
  369.     Notice(iPlayer, SecondaryAmmo)
  370.    
  371.     set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_DEPLOY, 4)
  372.     set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE + WEAPON_TIME_DELAY_DEPLOY, 4)
  373.    
  374.     set_pdata_string(iPlayer, (492) * 4, ANIM_EXTENSION, -1 , 20)
  375. }
  376.  
  377. public fw_Item_PostFrame(iItem)
  378. {
  379.     if(!IsCustomItem(iItem))
  380.         return HAM_IGNORED
  381.    
  382.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  383.    
  384.     if(get_pdata_int(iItem, 54, 4))
  385.     {
  386.         static iClip; iClip = get_pdata_int(iItem, 51, 4)
  387.         static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
  388.         static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
  389.         static iAmount; iAmount = min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary)
  390.        
  391.         set_pdata_int(iItem, 51, iClip + iAmount, 4)
  392.         SetAmmoInventory(iPlayer, iPrimaryAmmoIndex, iAmmoPrimary - iAmount)
  393.        
  394.         set_pdata_int(iItem, 54, 0, 4)
  395.         set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)
  396.        
  397.         return HAM_IGNORED
  398.     }  
  399.    
  400.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  401.     static Float:flLastEventCheck; flLastEventCheck = get_pdata_float(iItem, 38, 4)
  402.    
  403.     if(flLastEventCheck < get_gametime())
  404.     {
  405.         flLastEventCheck = get_gametime() + WEAPON_TIME_DELAY_CHARGE
  406.         set_pdata_float(iItem, 38, flLastEventCheck, 4)
  407.        
  408.         if(SecondaryAmmo < WEAPON_MAX_BATTERY)
  409.         {
  410.             if(!SecondaryAmmo)
  411.             {
  412.                 set_pdata_float(iItem, 48, 1.0, 4)
  413.                 Weapon_SendAnim(iPlayer, iItem, ANIM_MISSLEON)
  414.  
  415.                 set_pev(iPlayer, pev_weaponmodel2, p_modelb)
  416.             }
  417.            
  418.             SecondaryAmmo++
  419.             set_pdata_int(iItem, 30, SecondaryAmmo, 4)
  420.            
  421.             Notice(iPlayer, SecondaryAmmo)
  422.             emit_sound(iPlayer, CHAN_ITEM, reload_sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
  423.         }
  424.     }
  425.    
  426.     static iButton; iButton = pev(iPlayer, pev_button)
  427.    
  428.     if(iButton & IN_ATTACK2)
  429.     {
  430.         iButton &= ~IN_ATTACK2
  431.         iButton &= ~IN_ATTACK
  432.         set_pev(iPlayer, pev_button, iButton)
  433.        
  434.         if(!SecondaryAmmo)
  435.             return HAM_IGNORED
  436.            
  437.         if(get_pdata_float(iItem, 47, 4) > 0.0)
  438.             return HAM_IGNORED
  439.            
  440.         set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)   
  441.        
  442.         set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK2, 4)
  443.         set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK2, 4)
  444.        
  445.         emit_sound(iPlayer, CHAN_WEAPON, attack2_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
  446.        
  447.         if(SecondaryAmmo > 1)
  448.         {
  449.             Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLE)
  450.             set_pdata_float(iItem, 48, 0.87, 4)
  451.         }
  452.         else
  453.         {
  454.             Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLELAST)
  455.             set_pdata_float(iItem, 48, 1.2, 4)
  456.            
  457.             set_pev(iPlayer, pev_weaponmodel2, p_modela)
  458.         }
  459.        
  460.         static szAnimation[64]
  461.        
  462.         if(pev(iPlayer, pev_flags) & FL_DUCKING)
  463.         {
  464.             formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
  465.         }
  466.         else
  467.         {
  468.             formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
  469.         }
  470.        
  471.         Player_SetAnimation(iPlayer, szAnimation)
  472.        
  473.         SecondaryAmmo--
  474.         set_pdata_int(iItem, 30, SecondaryAmmo, 4)
  475.            
  476.         Notice(iPlayer, SecondaryAmmo)
  477.        
  478.         Attack2(iPlayer)
  479.         MakeMuzzleFlash2(iPlayer)
  480.     }
  481.    
  482.     return HAM_IGNORED
  483. }
  484.  
  485. public fw_Weapon_Reload(iItem)
  486. {
  487.     if(!IsCustomItem(iItem))
  488.         return HAM_IGNORED
  489.        
  490.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  491.    
  492.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
  493.     static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
  494.     static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
  495.    
  496.     if(min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary) <= 0)
  497.         return HAM_SUPERCEDE
  498.    
  499.     set_pdata_int(iItem, 51, 0, 4)
  500.    
  501.     ExecuteHam(Ham_Weapon_Reload, iItem)
  502.    
  503.     //Remove shotgun reload
  504.     set_pdata_int(iItem, 55, 0, 4)
  505.     set_pdata_int(iItem, 54, 1, 4)
  506.    
  507.     set_pdata_int(iItem, 51, iClip, 4)
  508.    
  509.     set_pdata_float(iPlayer, 83, WEAPON_TIME_DELAY_RELOAD, 5)
  510.     set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_RELOAD, 4)
  511.    
  512.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  513.    
  514.     if(SecondaryAmmo)
  515.     {
  516.         Weapon_SendAnim(iPlayer, iItem, ANIM_RELOADB)
  517.     }
  518.     else
  519.     {
  520.         Weapon_SendAnim(iPlayer, iItem, ANIM_RELOAD)
  521.     }
  522.    
  523.     return HAM_SUPERCEDE   
  524. }
  525.  
  526. public fw_Weapon_WeaponIdle(iItem)
  527. {
  528.     if(!IsCustomItem(iItem))
  529.         return HAM_IGNORED
  530.        
  531.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  532.    
  533.     ExecuteHamB(Ham_Weapon_ResetEmptySound, iItem)
  534.  
  535.     if(get_pdata_float(iItem, 48, 4) > 0.0)
  536.         return HAM_SUPERCEDE
  537.    
  538.     set_pdata_float(iItem, 48, WEAPON_TIME_NEXT_IDLE, 4)
  539.    
  540.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  541.    
  542.     if(SecondaryAmmo)
  543.     {
  544.         Weapon_SendAnim(iPlayer, iItem, ANIM_IDLEB)
  545.     }
  546.     else
  547.     {
  548.         Weapon_SendAnim(iPlayer, iItem, ANIM_IDLE)
  549.     }
  550.    
  551.     return HAM_SUPERCEDE
  552. }
  553.  
  554. public fw_Weapon_PrimaryAttack(iItem)
  555. {
  556.     if(!IsCustomItem(iItem))
  557.         return HAM_IGNORED
  558.        
  559.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  560.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
  561.    
  562.     if(iClip <= 0)
  563.     {
  564.         // No ammo, play empty sound and cancel
  565.         if(get_pdata_int(iItem, 45, 4))
  566.         {
  567.             ExecuteHamB(Ham_Weapon_PlayEmptySound, iItem)
  568.             set_pdata_float(iItem, 46, 0.2, 4)
  569.         }
  570.    
  571.         return HAM_SUPERCEDE
  572.     }
  573.    
  574.     CallOriginalFireBullets(iItem, iPlayer)
  575.    
  576.     static iFlags
  577.     static szAnimation[64], Float:Velocity[3]
  578.  
  579.     iFlags = pev(iPlayer, pev_flags)
  580.    
  581.     if(iFlags & FL_DUCKING)
  582.     {
  583.         formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
  584.     }
  585.     else
  586.     {
  587.         formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
  588.     }
  589.    
  590.     Player_SetAnimation(iPlayer, szAnimation)
  591.    
  592.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  593.    
  594.     if(SecondaryAmmo)
  595.     {
  596.         Weapon_SendAnim(iPlayer, iItem, random_num(ANIM_SHOOTB1, ANIM_SHOOTB2))
  597.     }
  598.     else
  599.     {
  600.         Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
  601.     }
  602.    
  603.     set_pdata_float(iItem, 48, 0.7, 4)
  604.     set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK, 4)
  605.     set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK, 4)
  606.    
  607.     pev(iPlayer, pev_velocity, Velocity)
  608.    
  609.     if(xs_vec_len(Velocity) > 0)
  610.     {
  611.         Weapon_KickBack(iItem, iPlayer, 1.5, 0.45, 0.225, 0.05, 6.5, 2.5, 7)
  612.     }
  613.     else if(!(iFlags & FL_ONGROUND))
  614.     {
  615.         Weapon_KickBack(iItem, iPlayer, 2.0, 1.0, 0.5, 0.35, 9.0, 6.0, 5)
  616.     }
  617.     else if(iFlags & FL_DUCKING)
  618.     {
  619.         Weapon_KickBack(iItem, iPlayer, 0.9, 0.35, 0.15, 0.025, 5.5, 1.5, 9)
  620.     }
  621.     else
  622.     {
  623.         Weapon_KickBack(iItem, iPlayer, 1.0, 0.375, 0.175, 0.0375, 5.75, 1.75, 8)
  624.     }
  625.  
  626.     emit_sound(iPlayer, CHAN_WEAPON, attack1_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
  627.    
  628.     MakeMuzzleFlash1(iPlayer)
  629.    
  630.     return HAM_SUPERCEDE
  631. }
  632.  
  633. public fw_TraceAttack_Entity(iEntity, iAttacker, Float: flDamage) <FireBullets: Enabled>
  634. {
  635.     SetHamParamFloat(3, WEAPON_SHOOT_DAMAGE)
  636. }
  637.  
  638. public fw_TraceAttack_Entity() </* Empty statement */>     
  639. {
  640.     /* Fallback */
  641. }
  642.  
  643. public fw_TraceAttack_Entity() <FireBullets: Disabled>     
  644. {
  645.     /* Do notning */
  646. }
  647.  
  648. //**********************************************
  649. //* Weapon list update.                        *
  650. //**********************************************
  651. public fw_Item_AddToPlayer(iItem, iPlayer)
  652. {
  653.     if(!IsValidPev(iItem) || !IsValidPev(iPlayer))
  654.         return HAM_IGNORED
  655.    
  656.     MsgHook_WeaponList(MSGID_WEAPONLIST, iItem, iPlayer)
  657.    
  658.     return HAM_IGNORED
  659. }
  660.  
  661. public MsgHook_WeaponList(iMsgID, iMsgDest, iMsgEntity)
  662. {
  663.     static arrWeaponListData[8]
  664.    
  665.     if(!iMsgEntity)
  666.     {
  667.         new szWeaponName[32]
  668.         get_msg_arg_string(1, szWeaponName, charsmax(szWeaponName))
  669.        
  670.         if(!strcmp(szWeaponName, WEAPON_BASE))
  671.         {
  672.             for(new i, a = sizeof arrWeaponListData; i < a; i++)
  673.             {
  674.                 arrWeaponListData[i] = get_msg_arg_int(i + 2)
  675.             }
  676.         }
  677.     }
  678.     else
  679.     {
  680.         if(!IsCustomItem(iMsgDest) && pev(iMsgDest, pev_impulse))
  681.             return
  682.        
  683.         engfunc(EngFunc_MessageBegin, MSG_ONE, iMsgID, {0.0, 0.0, 0.0}, iMsgEntity)
  684.         write_string(IsCustomItem(iMsgDest) ? WEAPON_NAME : WEAPON_BASE)
  685.        
  686.         for(new i, a = sizeof arrWeaponListData; i < a; i++)
  687.         {
  688.             write_byte(arrWeaponListData[i])
  689.         }
  690.        
  691.         message_end()
  692.     }
  693. }
  694.  
  695. //**********************************************
  696. //* Effects                                    *
  697. //**********************************************
  698. Notice(iPlayer, SecondaryAmmo)
  699. {
  700.     client_print(iPlayer, print_center, "Fire Ammo: %d", SecondaryAmmo)
  701. }
  702.  
  703. public MakeMuzzleFlash1(iPlayer)
  704. {
  705.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  706.     if(!pev_valid(Ent)) return
  707.    
  708.     set_pev(Ent, pev_classname, MUZZLEFLASH1_CLASSNAME)
  709.    
  710.     set_pev(Ent, pev_owner, iPlayer)
  711.     set_pev(Ent, pev_body, 1)
  712.     set_pev(Ent, pev_skin, iPlayer)
  713.     set_pev(Ent, pev_aiment, iPlayer)
  714.     set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
  715.    
  716.     set_pev(Ent, pev_scale, 0.085)
  717.     set_pev(Ent, pev_frame, 0.0)
  718.     set_pev(Ent, pev_rendermode, kRenderTransAdd)
  719.     set_pev(Ent, pev_renderamt, 255.0)
  720.    
  721.     engfunc(EngFunc_SetModel, Ent,  muzzle_flash1)
  722.    
  723.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  724. }
  725.  
  726. public fw_MuzzleFlash1_Think(Ent)
  727. {
  728.     if(!pev_valid(Ent))
  729.         return
  730.    
  731.     static Owner; Owner = pev(Ent, pev_owner)
  732.    
  733.     if(!is_alive(Owner))
  734.     {
  735.         set_pev(Ent, pev_flags, FL_KILLME)
  736.         return
  737.     }
  738.    
  739.     static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
  740.    
  741.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  742.     {
  743.         set_pev(Ent, pev_flags, FL_KILLME)
  744.         return
  745.     }
  746.  
  747.     static Float:Frame; pev(Ent, pev_frame, Frame)
  748.     if(Frame > 8.0)
  749.     {
  750.         set_pev(Ent, pev_flags, FL_KILLME)
  751.         return
  752.     }
  753.     else
  754.     {
  755.         Frame += 1.0
  756.         set_pev(Ent, pev_frame, Frame)
  757.     }
  758.    
  759.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  760. }
  761.  
  762. public MakeMuzzleFlash2(iPlayer)
  763. {
  764.     static Ent
  765.    
  766.     for(new i = 2; i < 5; i++)
  767.     {
  768.         Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  769.         if(!pev_valid(Ent)) continue
  770.    
  771.         set_pev(Ent, pev_classname, MUZZLEFLASH2_CLASSNAME)
  772.    
  773.         set_pev(Ent, pev_owner, iPlayer)
  774.         set_pev(Ent, pev_body, i)
  775.         set_pev(Ent, pev_skin, iPlayer)
  776.         set_pev(Ent, pev_aiment, iPlayer)
  777.         set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
  778.    
  779.         set_pev(Ent, pev_scale, 0.02)
  780.         set_pev(Ent, pev_frame, 0.0)
  781.         set_pev(Ent, pev_rendermode, kRenderTransAdd)
  782.         set_pev(Ent, pev_renderamt, 255.0)
  783.    
  784.         engfunc(EngFunc_SetModel, Ent,  muzzle_flash2)
  785.    
  786.         set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  787.     }
  788. }
  789.  
  790. public fw_MuzzleFlash2_Think(Ent)
  791. {
  792.     if(!pev_valid(Ent))
  793.         return
  794.    
  795.     static Owner; Owner = pev(Ent, pev_owner)
  796.    
  797.     if(!is_alive(Owner))
  798.     {
  799.         set_pev(Ent, pev_flags, FL_KILLME)
  800.         return
  801.     }
  802.    
  803.     static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
  804.    
  805.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  806.     {
  807.         set_pev(Ent, pev_flags, FL_KILLME)
  808.         return
  809.     }
  810.    
  811.     static Float:Frame; pev(Ent, pev_frame, Frame)
  812.     if(Frame > 9.0)
  813.     {
  814.         set_pev(Ent, pev_flags, FL_KILLME)
  815.         return
  816.     }
  817.     else
  818.     {
  819.         Frame += 1.0
  820.         set_pev(Ent, pev_frame, Frame)
  821.     }
  822.    
  823.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  824. }
  825.  
  826. public Attack2(iPlayer)
  827. {
  828.     static Float:StartOrigin[3], Float:EndOrigin[9][3]
  829.     Get_WeaponAttachment(iPlayer, StartOrigin, 40.0)
  830.    
  831.     // Left
  832.     Get_Position(iPlayer, 512.0, 50.0, 0.0, EndOrigin[0])
  833.     Get_Position(iPlayer, 512.0, 100.0, 0.0, EndOrigin[1])
  834.     Get_Position(iPlayer, 512.0, 150.0, 0.0, EndOrigin[2])
  835.     Get_Position(iPlayer, 512.0, 200.0, 0.0, EndOrigin[3])
  836.    
  837.     // Center
  838.     Get_Position(iPlayer, 512.0, 0.0, 0.0, EndOrigin[4])
  839.    
  840.     // Right
  841.     Get_Position(iPlayer, 512.0, -50.0, 0.0, EndOrigin[5])
  842.     Get_Position(iPlayer, 512.0, -100.0, 0.0, EndOrigin[6])
  843.     Get_Position(iPlayer, 512.0, -150.0, 0.0, EndOrigin[7])
  844.     Get_Position(iPlayer, 512.0, -200.0, 0.0, EndOrigin[8])
  845.    
  846.     // Create Fire
  847.     for(new i = 0; i < 9; i++) Create_System(iPlayer, StartOrigin, EndOrigin[i])
  848. }
  849.  
  850. public Create_System(iPlayer, Float:StartOrigin[3], Float:EndOrigin[3])
  851. {
  852.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  853.    
  854.     if(!pev_valid(Ent))
  855.         return
  856.        
  857.     set_pev(Ent, pev_classname, BALL_CLASSNAME)
  858.     set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
  859.     set_pev(Ent, pev_solid, SOLID_TRIGGER)
  860.    
  861.     engfunc(EngFunc_SetModel, Ent, ef_ball)
  862.    
  863.     set_pev(Ent, pev_rendermode, kRenderTransAdd)
  864.     set_pev(Ent, pev_renderamt, 150.0)
  865.     set_pev(Ent, pev_scale, 0.3)
  866.     set_pev(Ent, pev_frame, 0.0)
  867.    
  868.     set_pev(Ent, pev_mins, Float:{-5.0, -5.0, -5.0})
  869.     set_pev(Ent, pev_maxs, Float:{5.0, 5.0, 5.0})
  870.    
  871.     set_pev(Ent, pev_origin, StartOrigin)
  872.    
  873.     set_pev(Ent, pev_owner, iPlayer)   
  874.     set_pev(Ent, pev_iuser3, get_user_team(iPlayer))
  875.     set_pev(Ent, pev_fuser4, get_gametime())
  876.    
  877.     // Create Velocity
  878.     static Float:Velocity[3]
  879.     get_speed_vector(StartOrigin, EndOrigin, 1000.0, Velocity)//Or 750, 1500, 2000, 2500
  880.     set_pev(Ent, pev_velocity, Velocity)   
  881.    
  882.     set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  883. }
  884.  
  885. public fw_Ball_Think(Ent)
  886. {
  887.     if(!pev_valid(Ent))
  888.         return
  889.        
  890.     static Float:Frame
  891.     pev(Ent, pev_frame, Frame)
  892.    
  893.     if(Frame > 14.0)
  894.     {
  895.         static Float:Amount
  896.         pev(Ent, pev_renderamt, Amount)
  897.        
  898.         if(Amount <= 15.0)
  899.         {
  900.             set_pev(Ent, pev_flags, FL_KILLME)
  901.             return
  902.         }
  903.        
  904.         Amount -= 15.0
  905.         set_pev(Ent, pev_renderamt, Amount)
  906.        
  907.         set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
  908.     }
  909.     else
  910.     {
  911.         Frame += 1.0
  912.         set_pev(Ent, pev_frame, Frame)
  913.        
  914.         static Float:Origin[3]
  915.         pev(Ent, pev_origin, Origin)
  916.        
  917.         static Float:Scale
  918.         pev(Ent, pev_scale, Scale)
  919.        
  920.         Scale += 0.02
  921.         set_pev(Ent, pev_scale, Scale)
  922.        
  923.         static Float:Time
  924.         pev(Ent, pev_fuser4, Time)
  925.        
  926.         Create_Line(Origin)
  927.         set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  928.     }
  929. }
  930.  
  931. public fw_Ball_Touch(Ent, Touch)
  932. {
  933.     if(!pev_valid(Ent))
  934.         return
  935.    
  936.     static Classname[36]; pev(Touch, pev_classname, Classname, sizeof(Classname))
  937.    
  938.     if(equali(Classname, BALL_CLASSNAME))
  939.         return
  940.    
  941.     static Float:Origin[3]
  942.     pev(Ent, pev_origin, Origin)
  943.    
  944.     static TE_FLAG
  945.    
  946.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  947.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
  948.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  949.    
  950.     message_begin(MSG_BROADCAST ,SVC_TEMPENTITY)
  951.     write_byte(TE_EXPLOSION)
  952.     engfunc(EngFunc_WriteCoord, Origin[0])
  953.     engfunc(EngFunc_WriteCoord, Origin[1])
  954.     engfunc(EngFunc_WriteCoord, Origin[2])
  955.     write_short(g_Fire_SprId)   // sprite index
  956.     write_byte(15)  // scale in 3.4's
  957.     write_byte(15)  // framerate
  958.     write_byte(TE_FLAG) // flags
  959.     message_end()
  960.    
  961.     emit_sound(Ent, CHAN_BODY, explode_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  962.    
  963.     static Team; Team = pev(Ent, pev_iuser3)
  964.     static Owner; Owner = pev(Ent, pev_owner)
  965.    
  966.     static Victim; Victim = -1
  967.     while((Victim = find_ent_in_sphere(Victim, Origin, WEAPON_EXPLODE_RADIUS)) != 0)
  968.     {
  969.         if(is_alive(Victim))
  970.         {
  971.             if(get_user_team(Victim) == Team)
  972.                 continue
  973.         }
  974.         else
  975.         {
  976.             if(pev(Victim, pev_takedamage) == DAMAGE_NO)
  977.                 continue
  978.         }
  979.        
  980.         ExecuteHamB(Ham_TakeDamage, Victim, Owner, Owner, WEAPON_EXPLODE_DAMAGE, DMG_BULLET)
  981.     }
  982.    
  983.     set_pev(Ent, pev_flags, FL_KILLME) 
  984. }
  985.  
  986. public Create_Line(Float:Origin[3])
  987. {
  988.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  989.    
  990.     if(!pev_valid(Ent))
  991.         return
  992.    
  993.     set_pev(Ent, pev_classname, LINE_CLASSNAME)
  994.     set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
  995.     set_pev(Ent, pev_solid, SOLID_NOT)
  996.    
  997.     engfunc(EngFunc_SetModel, Ent, ef_ball)
  998.    
  999.     set_pev(Ent, pev_rendermode, kRenderTransAdd)
  1000.     set_pev(Ent, pev_renderamt, 120.0)
  1001.     set_pev(Ent, pev_scale, 0.3)
  1002.     set_pev(Ent, pev_frame, 0.0)
  1003.    
  1004.     set_pev(Ent, pev_origin, Origin)
  1005.    
  1006.     set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  1007. }
  1008.  
  1009. public fw_Line_Think(Ent)
  1010. {
  1011.     if(!pev_valid(Ent))
  1012.         return
  1013.        
  1014.     static Float:Amount
  1015.     pev(Ent, pev_renderamt, Amount)
  1016.    
  1017.     if(Amount <= 15.0)
  1018.     {
  1019.         set_pev(Ent, pev_flags, FL_KILLME)
  1020.         return
  1021.     }
  1022.    
  1023.     Amount -= 15.0
  1024.     set_pev(Ent, pev_renderamt, Amount)
  1025.    
  1026.     set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
  1027. }
  1028. /* ===============================
  1029. ------------- SAFETY -------------
  1030. =================================*/
  1031. public Register_SafetyFunc()
  1032. {
  1033.     register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
  1034.    
  1035.     RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
  1036.     RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
  1037. }
  1038.  
  1039. public Register_SafetyFuncBot(iPlayer)
  1040. {
  1041.     RegisterHamFromEntity(Ham_Spawn, iPlayer, "fw_Safety_Spawn_Post", 1)
  1042.     RegisterHamFromEntity(Ham_Killed, iPlayer, "fw_Safety_Killed_Post", 1)
  1043. }
  1044.  
  1045. public Safety_Connected(iPlayer)
  1046. {
  1047.     Set_BitVar(g_IsConnected, iPlayer)
  1048.     UnSet_BitVar(g_IsAlive, iPlayer)
  1049.    
  1050.     g_PlayerWeapon[iPlayer] = 0
  1051. }
  1052.  
  1053. public Safety_Disconnected(iPlayer)
  1054. {
  1055.     UnSet_BitVar(g_IsConnected, iPlayer)
  1056.     UnSet_BitVar(g_IsAlive, iPlayer)
  1057.    
  1058.     g_PlayerWeapon[iPlayer] = 0
  1059. }
  1060.  
  1061. public Safety_CurWeapon(iPlayer)
  1062. {
  1063.     if(!is_alive(iPlayer))
  1064.         return
  1065.        
  1066.     static CSW; CSW = read_data(2)
  1067.     if(g_PlayerWeapon[iPlayer] != CSW) g_PlayerWeapon[iPlayer] = CSW
  1068. }
  1069.  
  1070. public fw_Safety_Spawn_Post(iPlayer)
  1071. {
  1072.     if(!is_user_alive(iPlayer))
  1073.         return
  1074.        
  1075.     Set_BitVar(g_IsAlive, iPlayer)
  1076. }
  1077.  
  1078. public fw_Safety_Killed_Post(iPlayer)
  1079. {
  1080.     UnSet_BitVar(g_IsAlive, iPlayer)
  1081. }
  1082.  
  1083. public is_connected(iPlayer)
  1084. {
  1085.     if(!(1 <= iPlayer <= 32))
  1086.         return 0
  1087.     if(!Get_BitVar(g_IsConnected, iPlayer))
  1088.         return 0
  1089.  
  1090.     return 1
  1091. }
  1092.  
  1093. public is_alive(iPlayer)
  1094. {
  1095.     if(!is_connected(iPlayer))
  1096.         return 0
  1097.     if(!Get_BitVar(g_IsAlive, iPlayer))
  1098.         return 0
  1099.        
  1100.     return 1
  1101. }
  1102.  
  1103. public get_player_weapon(iPlayer)
  1104. {
  1105.     if(!is_alive(iPlayer))
  1106.         return 0
  1107.    
  1108.     return g_PlayerWeapon[iPlayer]
  1109. }
  1110.  
  1111. /* ===============================
  1112. --------- END OF SAFETY  ---------
  1113. =================================*/
  1114.  
  1115. //**********************************************
  1116. //* Create and check our custom weapon.        *
  1117. //**********************************************
  1118. IsCustomItem(iItem)
  1119. {
  1120.     return (pev(iItem, pev_impulse) == g_iszWeaponKey)
  1121. }
  1122.  
  1123. Weapon_Create(Float: Origin[3] = {0.0, 0.0, 0.0}, Float: Angles[3] = {0.0, 0.0, 0.0})
  1124. {
  1125.     new iWeapon
  1126.  
  1127.     static iszAllocStringCached
  1128.     if (iszAllocStringCached || (iszAllocStringCached = engfunc(EngFunc_AllocString, WEAPON_BASE)))
  1129.     {
  1130.         iWeapon = engfunc(EngFunc_CreateNamedEntity, iszAllocStringCached)
  1131.     }
  1132.    
  1133.     if(!IsValidPev(iWeapon))
  1134.         return FM_NULLENT
  1135.    
  1136.     dllfunc(DLLFunc_Spawn, iWeapon)
  1137.     set_pev(iWeapon, pev_origin, Origin)
  1138.  
  1139.     set_pdata_int(iWeapon, 51, WEAPON_MAX_CLIP, 4)
  1140.     set_pdata_int(iWeapon, 30, 0, 4)
  1141.  
  1142.     set_pev_string(iWeapon, pev_classname, g_iszWeaponKey)
  1143.     set_pev(iWeapon, pev_impulse, g_iszWeaponKey)
  1144.     set_pev(iWeapon, pev_angles, Angles)
  1145.    
  1146.     engfunc(EngFunc_SetModel, iWeapon, w_model)
  1147.  
  1148.     return iWeapon
  1149. }
  1150.  
  1151. Weapon_Give(iPlayer)
  1152. {
  1153.     if(!IsValidPev(iPlayer))
  1154.     {
  1155.         return FM_NULLENT
  1156.     }
  1157.    
  1158.     new iWeapon, Float: vecOrigin[3]
  1159.     pev(iPlayer, pev_origin, vecOrigin)
  1160.    
  1161.     if((iWeapon = Weapon_Create(vecOrigin)) != FM_NULLENT)
  1162.     {
  1163.         Player_DropWeapons(iPlayer, ExecuteHamB(Ham_Item_ItemSlot, iWeapon))
  1164.        
  1165.         set_pev(iWeapon, pev_spawnflags, pev(iWeapon, pev_spawnflags) | SF_NORESPAWN)
  1166.         dllfunc(DLLFunc_Touch, iWeapon, iPlayer)
  1167.        
  1168.         SetAmmoInventory(iPlayer, PrimaryAmmoIndex(iWeapon), WEAPON_DEFAULT_AMMO)
  1169.        
  1170.         return iWeapon
  1171.     }
  1172.    
  1173.     return FM_NULLENT
  1174. }
  1175.  
  1176. Player_DropWeapons(iPlayer, iSlot)
  1177. {
  1178.     new szWeaponName[32], iItem = get_pdata_cbase(iPlayer, 367 + iSlot, 5)
  1179.  
  1180.     while(IsValidPev(iItem))
  1181.     {
  1182.         pev(iItem, pev_classname, szWeaponName, charsmax(szWeaponName))
  1183.         engclient_cmd(iPlayer, "drop", szWeaponName)
  1184.  
  1185.         iItem = get_pdata_cbase(iItem, 42, 4)
  1186.     }
  1187. }
  1188.  
  1189. //**********************************************
  1190. //* Ammo Inventory.                            *
  1191. //**********************************************
  1192. PrimaryAmmoIndex(iItem)
  1193. {
  1194.     return get_pdata_int(iItem, 49, 4)
  1195. }
  1196.  
  1197. GetAmmoInventory(iPlayer, iAmmoIndex)
  1198. {
  1199.     if(iAmmoIndex == -1)
  1200.         return -1
  1201.    
  1202.     return get_pdata_int(iPlayer, 376 + iAmmoIndex, 5)
  1203. }
  1204.  
  1205. SetAmmoInventory(iPlayer, iAmmoIndex, iAmount)
  1206. {
  1207.     if(iAmmoIndex == -1)
  1208.         return 0
  1209.    
  1210.     set_pdata_int(iPlayer, 376 + iAmmoIndex, iAmount, 5)
  1211.    
  1212.     return 1
  1213. }
  1214.  
  1215. //**********************************************
  1216. //* Fire Bullets.                              *
  1217. //**********************************************
  1218. CallOriginalFireBullets(iItem, iPlayer)
  1219. {
  1220.     state FireBullets: Enabled
  1221.     static Float:g_Recoil[3]
  1222.  
  1223.     pev(iPlayer, pev_punchangle, g_Recoil)
  1224.     ExecuteHam(Ham_Weapon_PrimaryAttack, iItem)
  1225.     set_pev(iPlayer, pev_punchangle, g_Recoil)
  1226.    
  1227.     state FireBullets: Disabled
  1228. }
  1229.  
  1230. //**********************************************
  1231. //* Decals.                                    *
  1232. //**********************************************
  1233. new Array: g_hDecals
  1234.  
  1235. public fw_DecalIndex_Post()
  1236. {
  1237.     if(!g_hDecals)
  1238.     {
  1239.         g_hDecals = ArrayCreate(1, 1)
  1240.     }
  1241.    
  1242.     ArrayPushCell(g_hDecals, get_orig_retval())
  1243. }
  1244.  
  1245. UTIL_GunshotDecalTrace(iTrace, bool: bIsGunshot = false)
  1246. {
  1247.     static iHit
  1248.     static iMessage
  1249.     static iDecalIndex
  1250.    
  1251.     static Float:flFraction
  1252.     static Float:vecEndPos[3]
  1253.    
  1254.     iHit = INSTANCE(get_tr2(iTrace, TR_pHit))
  1255.    
  1256.     if(iHit && !IsValidPev(iHit) || (pev(iHit, pev_flags) & FL_KILLME))
  1257.         return
  1258.    
  1259.     if(pev(iHit, pev_solid) != SOLID_BSP && pev(iHit, pev_movetype) != MOVETYPE_PUSHSTEP)
  1260.         return
  1261.    
  1262.     iDecalIndex = ExecuteHamB(Ham_DamageDecal, iHit, 0)
  1263.    
  1264.     if(iDecalIndex < 0 || iDecalIndex >=  ArraySize(g_hDecals))
  1265.         return
  1266.    
  1267.     iDecalIndex = ArrayGetCell(g_hDecals, iDecalIndex)
  1268.    
  1269.     get_tr2(iTrace, TR_flFraction, flFraction)
  1270.     get_tr2(iTrace, TR_vecEndPos, vecEndPos)
  1271.    
  1272.     if(iDecalIndex < 0 || flFraction >= 1.0)
  1273.         return
  1274.    
  1275.     if(bIsGunshot)
  1276.     {
  1277.         iMessage = TE_GUNSHOTDECAL
  1278.     }
  1279.     else
  1280.     {
  1281.         iMessage = TE_DECAL
  1282.        
  1283.         if(iHit != 0)
  1284.         {
  1285.             if(iDecalIndex > 255)
  1286.             {
  1287.                 iMessage = TE_DECALHIGH
  1288.                 iDecalIndex -= 256
  1289.             }
  1290.         }
  1291.         else
  1292.         {
  1293.             iMessage = TE_WORLDDECAL
  1294.            
  1295.             if(iDecalIndex > 255)
  1296.             {
  1297.                 iMessage = TE_WORLDDECALHIGH
  1298.                 iDecalIndex -= 256
  1299.             }
  1300.         }
  1301.     }
  1302.    
  1303.     engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEndPos, 0)
  1304.     write_byte(iMessage)
  1305.     engfunc(EngFunc_WriteCoord, vecEndPos[0])
  1306.     engfunc(EngFunc_WriteCoord, vecEndPos[1])
  1307.     engfunc(EngFunc_WriteCoord, vecEndPos[2])
  1308.  
  1309.     if(bIsGunshot)
  1310.     {
  1311.         write_short(iHit)
  1312.         write_byte(iDecalIndex)
  1313.     }
  1314.     else
  1315.     {
  1316.         write_byte(iDecalIndex)
  1317.        
  1318.         if(iHit)
  1319.         {
  1320.             write_short(iHit)
  1321.         }
  1322.     }
  1323.    
  1324.     message_end()
  1325. }
  1326.  
  1327. //**********************************************
  1328. //* Set Animations.                            *
  1329. //**********************************************
  1330. stock Weapon_SendAnim(iPlayer, iItem, iAnim)
  1331. {
  1332.     static i, iCount, iSpectator, aSpectators[32]
  1333.    
  1334.     set_pev(iPlayer, pev_weaponanim, iAnim)
  1335.  
  1336.     message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iPlayer)
  1337.     write_byte(iAnim)
  1338.     write_byte(pev(iItem, pev_body))
  1339.     message_end()
  1340.    
  1341.     if(IsObserver(iPlayer))
  1342.         return
  1343.    
  1344.     get_players(aSpectators, iCount, "bch")
  1345.  
  1346.     for(i = 0; i < iCount; i++)
  1347.     {
  1348.         iSpectator = aSpectators[i]
  1349.        
  1350.         if(IsObserver(iSpectator) != OBS_IN_EYE || pev(iSpectator, pev_iuser2) != iPlayer)
  1351.             continue
  1352.        
  1353.         set_pev(iSpectator, pev_weaponanim, iAnim)
  1354.  
  1355.         message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iSpectator)
  1356.         write_byte(iAnim)
  1357.         write_byte(pev(iItem, pev_body))
  1358.         message_end()
  1359.     }
  1360. }
  1361.  
  1362. stock Player_SetAnimation(iPlayer, szAnim[])
  1363. {
  1364.     #define ACT_RANGE_ATTACK1   28
  1365.    
  1366.     // Linux extra offsets
  1367.     #define extra_offset_animating   4
  1368.     #define extra_offset_player 5
  1369.    
  1370.     // CBaseAnimating
  1371.     #define m_flFrameRate      36
  1372.     #define m_flGroundSpeed      37
  1373.     #define m_flLastEventCheck   38
  1374.     #define m_fSequenceFinished   39
  1375.     #define m_fSequenceLoops   40
  1376.    
  1377.     // CBaseMonster
  1378.     #define m_Activity      73
  1379.     #define m_IdealActivity      74
  1380.    
  1381.     // CBasePlayer
  1382.     #define m_flLastAttackTime   220
  1383.    
  1384.     new iAnimDesired, Float:flFrameRate, Float:flGroundSpeed, bool:bLoops
  1385.      
  1386.     if((iAnimDesired = lookup_sequence(iPlayer, szAnim, flFrameRate, bLoops, flGroundSpeed)) == -1)
  1387.     {
  1388.         iAnimDesired = 0
  1389.     }
  1390.    
  1391.     static Float:flGametime; flGametime = get_gametime()
  1392.  
  1393.     set_pev(iPlayer, pev_frame, 0.0)
  1394.     set_pev(iPlayer, pev_framerate, 1.0)
  1395.     set_pev(iPlayer, pev_animtime, flGametime)
  1396.     set_pev(iPlayer, pev_sequence, iAnimDesired)
  1397.    
  1398.     set_pdata_int(iPlayer, m_fSequenceLoops, bLoops, extra_offset_animating)
  1399.     set_pdata_int(iPlayer, m_fSequenceFinished, 0, extra_offset_animating)
  1400.    
  1401.     set_pdata_float(iPlayer, m_flFrameRate, flFrameRate, extra_offset_animating)
  1402.     set_pdata_float(iPlayer, m_flGroundSpeed, flGroundSpeed, extra_offset_animating)
  1403.     set_pdata_float(iPlayer, m_flLastEventCheck, flGametime , extra_offset_animating)
  1404.    
  1405.     set_pdata_int(iPlayer, m_Activity, ACT_RANGE_ATTACK1, extra_offset_player)
  1406.     set_pdata_int(iPlayer, m_IdealActivity, ACT_RANGE_ATTACK1, extra_offset_player)  
  1407.     set_pdata_float(iPlayer, m_flLastAttackTime, flGametime , extra_offset_player)
  1408. }
  1409.  
  1410. //**********************************************
  1411. //* Kick back.                                 *
  1412. //**********************************************
  1413. Weapon_KickBack(iItem, iPlayer, Float:upBase, Float:lateralBase, Float:upMod, Float:lateralMod, Float:upMax, Float:lateralMax, directionChange)
  1414. {
  1415.     static iDirection
  1416.     static iShotsFired
  1417.    
  1418.     static Float: Punchangle[3]
  1419.     pev(iPlayer, pev_punchangle, Punchangle)
  1420.    
  1421.     if((iShotsFired = get_pdata_int(iItem, 64, 4)) != 1)
  1422.     {
  1423.         upBase += iShotsFired * upMod
  1424.         lateralBase += iShotsFired * lateralMod
  1425.     }
  1426.    
  1427.     upMax *= -1.0
  1428.     Punchangle[0] -= upBase
  1429.  
  1430.     if(upMax >= Punchangle[0])
  1431.     {
  1432.         Punchangle[0] = upMax
  1433.     }
  1434.    
  1435.     if((iDirection = get_pdata_int(iItem, 60, 4)))
  1436.     {
  1437.         Punchangle[1] += lateralBase
  1438.        
  1439.         if(lateralMax < Punchangle[1])
  1440.         {
  1441.             Punchangle[1] = lateralMax
  1442.         }
  1443.     }
  1444.     else
  1445.     {
  1446.         lateralMax *= -1.0;
  1447.         Punchangle[1] -= lateralBase
  1448.        
  1449.         if(lateralMax > Punchangle[1])
  1450.         {
  1451.             Punchangle[1] = lateralMax
  1452.         }
  1453.     }
  1454.    
  1455.     if(!random_num(0, directionChange))
  1456.     {
  1457.         set_pdata_int(iItem, 60, !iDirection, 4)
  1458.     }
  1459.    
  1460.     set_pev(iPlayer, pev_punchangle, Punchangle)
  1461. }
  1462.  
  1463. //**********************************************
  1464. //* Some useful stocks.                        *
  1465. //**********************************************
  1466. stock get_speed_vector(Float:Origin1[3], Float:Origin2[3], Float:Speed, Float:NewVelocity[3])
  1467. {
  1468.     NewVelocity[0] = Origin2[0] - Origin1[0]
  1469.     NewVelocity[1] = Origin2[1] - Origin1[1]
  1470.     NewVelocity[2] = Origin2[2] - Origin1[2]
  1471.     new Float:num = floatsqroot(Speed*Speed / (NewVelocity[0]*NewVelocity[0] + NewVelocity[1]*NewVelocity[1] + NewVelocity[2]*NewVelocity[2]))
  1472.     NewVelocity[0] *= num
  1473.     NewVelocity[1] *= num
  1474.     NewVelocity[2] *= num
  1475.    
  1476.     return 1
  1477. }
  1478.  
  1479. stock Get_Position(iPlayer, Float:forw, Float:right, Float:up, Float:vStart[])
  1480. {
  1481.     new Float:Origin[3], Float:Angles[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  1482.    
  1483.     pev(iPlayer, pev_origin, Origin)
  1484.     pev(iPlayer, pev_view_ofs,vUp) //for player
  1485.     xs_vec_add(Origin, vUp, Origin)
  1486.     pev(iPlayer, pev_v_angle, Angles) // if normal entity ,use pev_angles
  1487.    
  1488.     angle_vector(Angles, ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
  1489.     angle_vector(Angles, ANGLEVECTOR_RIGHT, vRight)
  1490.     angle_vector(Angles, ANGLEVECTOR_UP, vUp)
  1491.    
  1492.     vStart[0] = Origin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  1493.     vStart[1] = Origin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  1494.     vStart[2] = Origin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  1495. }
  1496.  
  1497. stock Get_WeaponAttachment(iPlayer, Float:Output[3], Float:fDis = 40.0)
  1498. {
  1499.     static Float:vfEnd[3], viEnd[3]
  1500.     get_user_origin(iPlayer, viEnd, 3)  
  1501.     IVecFVec(viEnd, vfEnd)
  1502.    
  1503.     static Float:fOrigin[3], Float:fAngle[3]
  1504.    
  1505.     pev(iPlayer, pev_origin, fOrigin)
  1506.     pev(iPlayer, pev_view_ofs, fAngle)
  1507.    
  1508.     xs_vec_add(fOrigin, fAngle, fOrigin)
  1509.    
  1510.     static Float:fAttack[3]
  1511.    
  1512.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1513.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1514.    
  1515.     static Float:fRate
  1516.    
  1517.     fRate = fDis / vector_length(fAttack)
  1518.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
  1519.    
  1520.     xs_vec_add(fOrigin, fAttack, Output)
  1521. }


@SexY DeviL CJ
You forgot to add ze_select_item_post forward
These users thanked the author Jack GamePlay for the post:
czirimbolo (10 Months Ago)
Not interested in CS/Pawn anymore.
Accepting web projects.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 477
Joined: 2 Years Ago
Has thanked: 18 times
Been thanked: 1 time
Contact:

#5

Post by czirimbolo » 10 Months Ago

Thanks, works fine! Solved
Image

User avatar
SexY DeviL CJ
Mod Tester
Mod Tester
Posts: 73
Joined: 1 Year Ago
Has thanked: 1 time
Been thanked: 10 times
Contact:

#6

Post by SexY DeviL CJ » 10 Months Ago

Jack GamePlay wrote:
10 Months Ago
  1. /* Plugin generated by AMXX-Studio */
  2.  
  3. #include <zombie_escape>
  4. #include <fakemeta_util>
  5. #include <engine>
  6. #include <xs>
  7.  
  8. #define PLUGIN "Magnum Lancer"
  9. #define VERSION "2.0"
  10. #define AUTHOR "Bim Bim Cay"
  11.  
  12. // Models
  13. #define v_model "models/v_sgmissile.mdl"
  14. #define w_model "models/w_sgmissile.mdl"
  15. #define p_modela "models/p_sgmissile_a.mdl"
  16. #define p_modelb "models/p_sgmissile_b.mdl"
  17.  
  18. // Sounds
  19. #define attack1_sound "weapons/sgmissile-1.wav"
  20. #define attack2_sound "weapons/sgmissile-2.wav"
  21. #define reload_sound "weapons/sgmissile_reload.wav"
  22. #define explode_sound "weapons/sgmissile_exp.wav"
  23.  
  24. // Sprites
  25. #define ef_ball "sprites/ef_sgmissile_line.spr"
  26. #define ef_explode "sprites/ef_sgmissile.spr"
  27. #define muzzle_flash1 "sprites/muzzleflash64.spr"
  28. #define muzzle_flash2 "sprites/muzzleflash75.spr"
  29.  
  30. // Anims
  31. #define ANIM_IDLE       0
  32. #define ANIM_RELOAD     1
  33. #define ANIM_DRAW       2
  34. #define ANIM_SHOOT      3
  35. #define ANIM_IDLEB      4
  36. #define ANIM_RELOADB        5
  37. #define ANIM_DRAWB      6
  38. #define ANIM_SHOOTB1        7
  39. #define ANIM_SHOOTB2        8
  40. #define ANIM_SHOOTMISSLE    9
  41. #define ANIM_SHOOTMISSLELAST    10
  42. #define ANIM_MISSLEON       11
  43.  
  44. #define ANIM_EXTENSION      "m249"
  45.  
  46. // Entity Classname
  47. #define BALL_CLASSNAME "Magnum_EfBall"
  48. #define LINE_CLASSNAME "Magnum_EfLine"
  49. #define MUZZLEFLASH1_CLASSNAME "Muzzle_MagnumLancer1"
  50. #define MUZZLEFLASH2_CLASSNAME "Muzzle_MagnumLancer2"
  51.  
  52. // Configs
  53. #define WEAPON_NAME         "weapon_sgmissile"
  54. #define WEAPON_BASE     "weapon_m3"
  55.  
  56. #define WEAPON_MAX_CLIP     30
  57. #define WEAPON_DEFAULT_AMMO 90
  58. #define WEAPON_MAX_BATTERY  10
  59.  
  60. #define WEAPON_SHOOT_DAMAGE 100.0
  61. #define WEAPON_EXPLODE_DAMAGE   2000.0
  62. #define WEAPON_EXPLODE_RADIUS   75.0
  63.  
  64. #define WEAPON_TIME_NEXT_IDLE   10.0
  65. #define WEAPON_TIME_NEXT_ATTACK 0.25
  66. #define WEAPON_TIME_NEXT_ATTACK2 0.4
  67. #define WEAPON_TIME_DELAY_DEPLOY 1.0
  68. #define WEAPON_TIME_DELAY_RELOAD 2.0
  69. #define WEAPON_TIME_DELAY_CHARGE 3.0
  70.  
  71. // MACROS
  72. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
  73. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
  74. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
  75.  
  76. #define INSTANCE(%0) ((%0 == -1) ? 0 : %0)
  77. #define IsValidPev(%0) (pev_valid(%0) == 2)
  78. #define IsObserver(%0) pev(%0,pev_iuser1)
  79. #define OBS_IN_EYE 4
  80. #define MSGID_WEAPONLIST 78
  81.  
  82. new g_iszWeaponKey
  83. new g_iForwardDecalIndex
  84. new g_Fire_SprId
  85.  
  86. // Safety
  87. new g_HamBot
  88. new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
  89. new g_iItemID
  90.  
  91. public plugin_init()
  92. {
  93.     register_plugin(PLUGIN, VERSION, AUTHOR)
  94.    
  95.     // Safety
  96.     Register_SafetyFunc()
  97.    
  98.     // Forward
  99.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  100.     register_forward(FM_TraceLine, "fw_TraceLine_Post", 1)
  101.     register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
  102.     register_forward(FM_SetModel, "fw_SetModel")
  103.    
  104.     unregister_forward(FM_DecalIndex, g_iForwardDecalIndex, 1)
  105.    
  106.     // Think
  107.     register_think(MUZZLEFLASH1_CLASSNAME, "fw_MuzzleFlash1_Think")
  108.     register_think(MUZZLEFLASH2_CLASSNAME, "fw_MuzzleFlash2_Think")
  109.     register_think(BALL_CLASSNAME, "fw_Ball_Think")
  110.     register_think(LINE_CLASSNAME, "fw_Line_Think")
  111.    
  112.     register_touch(BALL_CLASSNAME, "*", "fw_Ball_Touch")
  113.    
  114.     // Ham
  115.     RegisterHam(Ham_Spawn, "weaponbox", "fw_Weaponbox_Spawn_Post", 1)
  116.    
  117.     RegisterHam(Ham_Item_Deploy, WEAPON_BASE, "fw_Item_Deploy_Post", 1)
  118.     RegisterHam(Ham_Item_AddToPlayer, WEAPON_BASE, "fw_Item_AddToPlayer")
  119.     RegisterHam(Ham_Item_PostFrame, WEAPON_BASE, "fw_Item_PostFrame")
  120.     RegisterHam(Ham_Weapon_Reload, WEAPON_BASE, "fw_Weapon_Reload")
  121.     RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_BASE, "fw_Weapon_WeaponIdle")
  122.     RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_BASE, "fw_Weapon_PrimaryAttack")
  123.    
  124.     RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack_Entity")
  125.     RegisterHam(Ham_TraceAttack, "info_target", "fw_TraceAttack_Entity")
  126.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Entity")
  127.    
  128.     g_iItemID = ze_register_item("Magnum", 0, 0)
  129. }
  130.  
  131. public ze_select_item_pre(id, itemid)
  132. {
  133.     if (itemid != g_iItemID)
  134.         return ZE_ITEM_AVAILABLE
  135.  
  136.     if (ze_is_user_zombie(id))
  137.         return ZE_ITEM_DONT_SHOW
  138.  
  139.     return ZE_ITEM_AVAILABLE
  140. }
  141.  
  142. public ze_select_item_post(id, itemid)
  143. {
  144.     if (itemid != g_iItemID)
  145.         return
  146.  
  147.     Get_MyWeapon(id)
  148. }
  149.  
  150. public plugin_precache()
  151. {
  152.     precache_model(v_model)
  153.     precache_model(w_model)
  154.     precache_model(p_modela)
  155.     precache_model(p_modelb)
  156.    
  157.     precache_model(ef_ball)
  158.     precache_model(muzzle_flash1)
  159.     precache_model(muzzle_flash2)
  160.    
  161.     g_Fire_SprId = precache_model(ef_explode)
  162.    
  163.     precache_sound(attack1_sound)
  164.     precache_sound(attack2_sound)
  165.     precache_sound(reload_sound)
  166.     precache_sound(explode_sound)
  167.    
  168.     new TextFile[32]
  169.     formatex(TextFile, charsmax(TextFile), "sprites/%s.txt", WEAPON_NAME)
  170.    
  171.     precache_generic(TextFile)
  172.    
  173.     g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
  174.     g_iForwardDecalIndex = register_forward(FM_DecalIndex, "fw_DecalIndex_Post", 1)
  175.    
  176.     register_message(MSGID_WEAPONLIST, "MsgHook_WeaponList")
  177. }
  178.  
  179. public client_putinserver(iPlayer)
  180. {
  181.     Safety_Connected(iPlayer)
  182.    
  183.     if(!g_HamBot && is_user_bot(iPlayer))
  184.     {
  185.         g_HamBot = 1
  186.         set_task(0.1, "Register_HamBot", iPlayer)
  187.     }
  188. }
  189.  
  190. public Register_HamBot(iPlayer)
  191. {
  192.     Register_SafetyFuncBot(iPlayer)
  193.     RegisterHamFromEntity(Ham_TraceAttack, iPlayer, "fw_TraceAttack_Entity")   
  194. }
  195.  
  196. public client_disconnected(iPlayer)
  197. {
  198.     Safety_Disconnected(iPlayer)
  199. }
  200.  
  201. public Get_MyWeapon(iPlayer)
  202. {
  203.     Weapon_Give(iPlayer)
  204. }
  205.  
  206. public fw_UpdateClientData_Post(iPlayer, sendweapons, CD_Handle)
  207. {
  208.     enum
  209.     {
  210.         SPEC_MODE,
  211.         SPEC_TARGET,
  212.         SPEC_END
  213.     }
  214.      
  215.     static aSpecInfo[33][SPEC_END]
  216.    
  217.     static iTarget
  218.     static iSpecMode
  219.     static iActiveItem
  220.    
  221.     iTarget = (iSpecMode = IsObserver(iPlayer)) ? pev(iPlayer, pev_iuser2) : iPlayer
  222.    
  223.     if(!is_alive(iTarget))
  224.         return FMRES_IGNORED
  225.    
  226.     iActiveItem = get_pdata_cbase(iTarget, 373, 5)
  227.    
  228.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  229.         return FMRES_IGNORED
  230.    
  231.     if(iSpecMode)
  232.     {
  233.         if(aSpecInfo[iPlayer][SPEC_MODE] != iSpecMode)
  234.         {
  235.             aSpecInfo[iPlayer][SPEC_MODE] = iSpecMode
  236.             aSpecInfo[iPlayer][SPEC_TARGET] = 0
  237.         }
  238.        
  239.         if(iSpecMode == OBS_IN_EYE && aSpecInfo[iPlayer][SPEC_TARGET] != iTarget)
  240.         {
  241.             aSpecInfo[iPlayer][SPEC_TARGET] = iTarget
  242.            
  243.             if(get_pdata_int(iActiveItem, 30, 4))
  244.             {
  245.                 Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLEB)
  246.             }
  247.             else
  248.             {
  249.                 Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLE)
  250.             }
  251.         }
  252.     }
  253.    
  254.     set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
  255.    
  256.     return FMRES_HANDLED
  257. }
  258.  
  259. public fw_TraceLine_Post(Float:TraceStart[3], Float:TraceEnd[3], fNoMonsters, iEntToSkip, iTrace) <FireBullets: Enabled>
  260. {
  261.     static Float:vecEndPos[3]
  262.    
  263.     get_tr2(iTrace, TR_vecEndPos, vecEndPos)
  264.     engfunc(EngFunc_TraceLine, vecEndPos, TraceStart, fNoMonsters, iEntToSkip, 0)
  265.    
  266.     UTIL_GunshotDecalTrace(0)
  267.     UTIL_GunshotDecalTrace(iTrace, true)
  268. }
  269.  
  270. public fw_TraceLine_Post() </* Empty statement */>
  271. {
  272.     /* Fallback */
  273. }
  274.  
  275. public fw_TraceLine_Post() <FireBullets: Disabled> 
  276. {
  277.     /* Do notning */
  278. }
  279.  
  280. public fw_PlaybackEvent() <FireBullets: Enabled>
  281. {
  282.     return FMRES_SUPERCEDE
  283. }
  284.  
  285. public fw_PlaybackEvent() </* Empty statement */>      
  286. {
  287.     return FMRES_IGNORED
  288. }
  289.  
  290. public fw_PlaybackEvent() <FireBullets: Disabled>      
  291. {
  292.     return FMRES_IGNORED
  293. }
  294.  
  295. //**********************************************
  296. //* Weaponbox world model.                     *
  297. //**********************************************
  298. public fw_SetModel(iEntity) <WeaponBox: Enabled>
  299. {
  300.     state WeaponBox: Disabled
  301.    
  302.     if(!IsValidPev(iEntity))
  303.         return FMRES_IGNORED
  304.    
  305.     #define MAX_ITEM_TYPES  6
  306.     for(new i, iItem; i < MAX_ITEM_TYPES; i++)
  307.     {
  308.         iItem = get_pdata_cbase(iEntity, 34 + i, 4)
  309.        
  310.         if(IsValidPev(iItem) && IsCustomItem(iItem))
  311.         {
  312.             engfunc(EngFunc_SetModel, iEntity, w_model)
  313.             return FMRES_SUPERCEDE
  314.         }
  315.     }
  316.    
  317.     return FMRES_IGNORED
  318. }
  319.  
  320. public fw_SetModel() </* Empty statement */>   
  321. {
  322.     /*  Fallback  */
  323.     return FMRES_IGNORED
  324. }
  325. public fw_SetModel() <WeaponBox: Disabled> 
  326. {
  327.     /* Do nothing */
  328.     return FMRES_IGNORED
  329. }
  330.  
  331. public fw_Weaponbox_Spawn_Post(iWeaponBox)
  332. {
  333.     if(IsValidPev(iWeaponBox))
  334.     {
  335.         state (IsValidPev(pev(iWeaponBox, pev_owner))) WeaponBox: Enabled
  336.     }
  337.    
  338.     return HAM_IGNORED
  339. }
  340.  
  341. //**********************************************
  342. //* Weapon's codes.                     *
  343. //**********************************************
  344. public fw_Item_Deploy_Post(iItem)
  345. {
  346.     if(!IsCustomItem(iItem))
  347.         return
  348.        
  349.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  350.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  351.  
  352.     //I need to disable because there is no dummy anim
  353.     //static Sex; Sex = 0 //Get your sex: 0 - Male; 1 - Female
  354.     //set_pev(iItem, pev_body, Sex)
  355.    
  356.     set_pev(iPlayer, pev_viewmodel2, v_model)
  357.    
  358.     if(SecondaryAmmo)
  359.     {
  360.         set_pev(iPlayer, pev_weaponmodel2, p_modelb)
  361.         Weapon_SendAnim(iPlayer, iItem, ANIM_DRAWB)
  362.     }
  363.     else
  364.     {
  365.         set_pev(iPlayer, pev_weaponmodel2, p_modela)
  366.         Weapon_SendAnim(iPlayer, iItem, ANIM_DRAW)
  367.     }
  368.  
  369.     Notice(iPlayer, SecondaryAmmo)
  370.    
  371.     set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_DEPLOY, 4)
  372.     set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE + WEAPON_TIME_DELAY_DEPLOY, 4)
  373.    
  374.     set_pdata_string(iPlayer, (492) * 4, ANIM_EXTENSION, -1 , 20)
  375. }
  376.  
  377. public fw_Item_PostFrame(iItem)
  378. {
  379.     if(!IsCustomItem(iItem))
  380.         return HAM_IGNORED
  381.    
  382.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  383.    
  384.     if(get_pdata_int(iItem, 54, 4))
  385.     {
  386.         static iClip; iClip = get_pdata_int(iItem, 51, 4)
  387.         static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
  388.         static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
  389.         static iAmount; iAmount = min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary)
  390.        
  391.         set_pdata_int(iItem, 51, iClip + iAmount, 4)
  392.         SetAmmoInventory(iPlayer, iPrimaryAmmoIndex, iAmmoPrimary - iAmount)
  393.        
  394.         set_pdata_int(iItem, 54, 0, 4)
  395.         set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)
  396.        
  397.         return HAM_IGNORED
  398.     }  
  399.    
  400.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  401.     static Float:flLastEventCheck; flLastEventCheck = get_pdata_float(iItem, 38, 4)
  402.    
  403.     if(flLastEventCheck < get_gametime())
  404.     {
  405.         flLastEventCheck = get_gametime() + WEAPON_TIME_DELAY_CHARGE
  406.         set_pdata_float(iItem, 38, flLastEventCheck, 4)
  407.        
  408.         if(SecondaryAmmo < WEAPON_MAX_BATTERY)
  409.         {
  410.             if(!SecondaryAmmo)
  411.             {
  412.                 set_pdata_float(iItem, 48, 1.0, 4)
  413.                 Weapon_SendAnim(iPlayer, iItem, ANIM_MISSLEON)
  414.  
  415.                 set_pev(iPlayer, pev_weaponmodel2, p_modelb)
  416.             }
  417.            
  418.             SecondaryAmmo++
  419.             set_pdata_int(iItem, 30, SecondaryAmmo, 4)
  420.            
  421.             Notice(iPlayer, SecondaryAmmo)
  422.             emit_sound(iPlayer, CHAN_ITEM, reload_sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
  423.         }
  424.     }
  425.    
  426.     static iButton; iButton = pev(iPlayer, pev_button)
  427.    
  428.     if(iButton & IN_ATTACK2)
  429.     {
  430.         iButton &= ~IN_ATTACK2
  431.         iButton &= ~IN_ATTACK
  432.         set_pev(iPlayer, pev_button, iButton)
  433.        
  434.         if(!SecondaryAmmo)
  435.             return HAM_IGNORED
  436.            
  437.         if(get_pdata_float(iItem, 47, 4) > 0.0)
  438.             return HAM_IGNORED
  439.            
  440.         set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)   
  441.        
  442.         set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK2, 4)
  443.         set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK2, 4)
  444.        
  445.         emit_sound(iPlayer, CHAN_WEAPON, attack2_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
  446.        
  447.         if(SecondaryAmmo > 1)
  448.         {
  449.             Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLE)
  450.             set_pdata_float(iItem, 48, 0.87, 4)
  451.         }
  452.         else
  453.         {
  454.             Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLELAST)
  455.             set_pdata_float(iItem, 48, 1.2, 4)
  456.            
  457.             set_pev(iPlayer, pev_weaponmodel2, p_modela)
  458.         }
  459.        
  460.         static szAnimation[64]
  461.        
  462.         if(pev(iPlayer, pev_flags) & FL_DUCKING)
  463.         {
  464.             formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
  465.         }
  466.         else
  467.         {
  468.             formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
  469.         }
  470.        
  471.         Player_SetAnimation(iPlayer, szAnimation)
  472.        
  473.         SecondaryAmmo--
  474.         set_pdata_int(iItem, 30, SecondaryAmmo, 4)
  475.            
  476.         Notice(iPlayer, SecondaryAmmo)
  477.        
  478.         Attack2(iPlayer)
  479.         MakeMuzzleFlash2(iPlayer)
  480.     }
  481.    
  482.     return HAM_IGNORED
  483. }
  484.  
  485. public fw_Weapon_Reload(iItem)
  486. {
  487.     if(!IsCustomItem(iItem))
  488.         return HAM_IGNORED
  489.        
  490.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  491.    
  492.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
  493.     static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
  494.     static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
  495.    
  496.     if(min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary) <= 0)
  497.         return HAM_SUPERCEDE
  498.    
  499.     set_pdata_int(iItem, 51, 0, 4)
  500.    
  501.     ExecuteHam(Ham_Weapon_Reload, iItem)
  502.    
  503.     //Remove shotgun reload
  504.     set_pdata_int(iItem, 55, 0, 4)
  505.     set_pdata_int(iItem, 54, 1, 4)
  506.    
  507.     set_pdata_int(iItem, 51, iClip, 4)
  508.    
  509.     set_pdata_float(iPlayer, 83, WEAPON_TIME_DELAY_RELOAD, 5)
  510.     set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_RELOAD, 4)
  511.    
  512.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  513.    
  514.     if(SecondaryAmmo)
  515.     {
  516.         Weapon_SendAnim(iPlayer, iItem, ANIM_RELOADB)
  517.     }
  518.     else
  519.     {
  520.         Weapon_SendAnim(iPlayer, iItem, ANIM_RELOAD)
  521.     }
  522.    
  523.     return HAM_SUPERCEDE   
  524. }
  525.  
  526. public fw_Weapon_WeaponIdle(iItem)
  527. {
  528.     if(!IsCustomItem(iItem))
  529.         return HAM_IGNORED
  530.        
  531.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  532.    
  533.     ExecuteHamB(Ham_Weapon_ResetEmptySound, iItem)
  534.  
  535.     if(get_pdata_float(iItem, 48, 4) > 0.0)
  536.         return HAM_SUPERCEDE
  537.    
  538.     set_pdata_float(iItem, 48, WEAPON_TIME_NEXT_IDLE, 4)
  539.    
  540.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  541.    
  542.     if(SecondaryAmmo)
  543.     {
  544.         Weapon_SendAnim(iPlayer, iItem, ANIM_IDLEB)
  545.     }
  546.     else
  547.     {
  548.         Weapon_SendAnim(iPlayer, iItem, ANIM_IDLE)
  549.     }
  550.    
  551.     return HAM_SUPERCEDE
  552. }
  553.  
  554. public fw_Weapon_PrimaryAttack(iItem)
  555. {
  556.     if(!IsCustomItem(iItem))
  557.         return HAM_IGNORED
  558.        
  559.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
  560.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
  561.    
  562.     if(iClip <= 0)
  563.     {
  564.         // No ammo, play empty sound and cancel
  565.         if(get_pdata_int(iItem, 45, 4))
  566.         {
  567.             ExecuteHamB(Ham_Weapon_PlayEmptySound, iItem)
  568.             set_pdata_float(iItem, 46, 0.2, 4)
  569.         }
  570.    
  571.         return HAM_SUPERCEDE
  572.     }
  573.    
  574.     CallOriginalFireBullets(iItem, iPlayer)
  575.    
  576.     static iFlags
  577.     static szAnimation[64], Float:Velocity[3]
  578.  
  579.     iFlags = pev(iPlayer, pev_flags)
  580.    
  581.     if(iFlags & FL_DUCKING)
  582.     {
  583.         formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
  584.     }
  585.     else
  586.     {
  587.         formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
  588.     }
  589.    
  590.     Player_SetAnimation(iPlayer, szAnimation)
  591.    
  592.     static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
  593.    
  594.     if(SecondaryAmmo)
  595.     {
  596.         Weapon_SendAnim(iPlayer, iItem, random_num(ANIM_SHOOTB1, ANIM_SHOOTB2))
  597.     }
  598.     else
  599.     {
  600.         Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
  601.     }
  602.    
  603.     set_pdata_float(iItem, 48, 0.7, 4)
  604.     set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK, 4)
  605.     set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK, 4)
  606.    
  607.     pev(iPlayer, pev_velocity, Velocity)
  608.    
  609.     if(xs_vec_len(Velocity) > 0)
  610.     {
  611.         Weapon_KickBack(iItem, iPlayer, 1.5, 0.45, 0.225, 0.05, 6.5, 2.5, 7)
  612.     }
  613.     else if(!(iFlags & FL_ONGROUND))
  614.     {
  615.         Weapon_KickBack(iItem, iPlayer, 2.0, 1.0, 0.5, 0.35, 9.0, 6.0, 5)
  616.     }
  617.     else if(iFlags & FL_DUCKING)
  618.     {
  619.         Weapon_KickBack(iItem, iPlayer, 0.9, 0.35, 0.15, 0.025, 5.5, 1.5, 9)
  620.     }
  621.     else
  622.     {
  623.         Weapon_KickBack(iItem, iPlayer, 1.0, 0.375, 0.175, 0.0375, 5.75, 1.75, 8)
  624.     }
  625.  
  626.     emit_sound(iPlayer, CHAN_WEAPON, attack1_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
  627.    
  628.     MakeMuzzleFlash1(iPlayer)
  629.    
  630.     return HAM_SUPERCEDE
  631. }
  632.  
  633. public fw_TraceAttack_Entity(iEntity, iAttacker, Float: flDamage) <FireBullets: Enabled>
  634. {
  635.     SetHamParamFloat(3, WEAPON_SHOOT_DAMAGE)
  636. }
  637.  
  638. public fw_TraceAttack_Entity() </* Empty statement */>     
  639. {
  640.     /* Fallback */
  641. }
  642.  
  643. public fw_TraceAttack_Entity() <FireBullets: Disabled>     
  644. {
  645.     /* Do notning */
  646. }
  647.  
  648. //**********************************************
  649. //* Weapon list update.                        *
  650. //**********************************************
  651. public fw_Item_AddToPlayer(iItem, iPlayer)
  652. {
  653.     if(!IsValidPev(iItem) || !IsValidPev(iPlayer))
  654.         return HAM_IGNORED
  655.    
  656.     MsgHook_WeaponList(MSGID_WEAPONLIST, iItem, iPlayer)
  657.    
  658.     return HAM_IGNORED
  659. }
  660.  
  661. public MsgHook_WeaponList(iMsgID, iMsgDest, iMsgEntity)
  662. {
  663.     static arrWeaponListData[8]
  664.    
  665.     if(!iMsgEntity)
  666.     {
  667.         new szWeaponName[32]
  668.         get_msg_arg_string(1, szWeaponName, charsmax(szWeaponName))
  669.        
  670.         if(!strcmp(szWeaponName, WEAPON_BASE))
  671.         {
  672.             for(new i, a = sizeof arrWeaponListData; i < a; i++)
  673.             {
  674.                 arrWeaponListData[i] = get_msg_arg_int(i + 2)
  675.             }
  676.         }
  677.     }
  678.     else
  679.     {
  680.         if(!IsCustomItem(iMsgDest) && pev(iMsgDest, pev_impulse))
  681.             return
  682.        
  683.         engfunc(EngFunc_MessageBegin, MSG_ONE, iMsgID, {0.0, 0.0, 0.0}, iMsgEntity)
  684.         write_string(IsCustomItem(iMsgDest) ? WEAPON_NAME : WEAPON_BASE)
  685.        
  686.         for(new i, a = sizeof arrWeaponListData; i < a; i++)
  687.         {
  688.             write_byte(arrWeaponListData[i])
  689.         }
  690.        
  691.         message_end()
  692.     }
  693. }
  694.  
  695. //**********************************************
  696. //* Effects                                    *
  697. //**********************************************
  698. Notice(iPlayer, SecondaryAmmo)
  699. {
  700.     client_print(iPlayer, print_center, "Fire Ammo: %d", SecondaryAmmo)
  701. }
  702.  
  703. public MakeMuzzleFlash1(iPlayer)
  704. {
  705.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  706.     if(!pev_valid(Ent)) return
  707.    
  708.     set_pev(Ent, pev_classname, MUZZLEFLASH1_CLASSNAME)
  709.    
  710.     set_pev(Ent, pev_owner, iPlayer)
  711.     set_pev(Ent, pev_body, 1)
  712.     set_pev(Ent, pev_skin, iPlayer)
  713.     set_pev(Ent, pev_aiment, iPlayer)
  714.     set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
  715.    
  716.     set_pev(Ent, pev_scale, 0.085)
  717.     set_pev(Ent, pev_frame, 0.0)
  718.     set_pev(Ent, pev_rendermode, kRenderTransAdd)
  719.     set_pev(Ent, pev_renderamt, 255.0)
  720.    
  721.     engfunc(EngFunc_SetModel, Ent,  muzzle_flash1)
  722.    
  723.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  724. }
  725.  
  726. public fw_MuzzleFlash1_Think(Ent)
  727. {
  728.     if(!pev_valid(Ent))
  729.         return
  730.    
  731.     static Owner; Owner = pev(Ent, pev_owner)
  732.    
  733.     if(!is_alive(Owner))
  734.     {
  735.         set_pev(Ent, pev_flags, FL_KILLME)
  736.         return
  737.     }
  738.    
  739.     static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
  740.    
  741.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
  742.     {
  743.         set_pev(Ent, pev_flags, FL_KILLME)
  744.         return
  745.     }
  746.  
  747.     static Float:Frame; pev(Ent, pev_frame, Frame)
  748.     if(Frame > 8.0)
  749.     {
  750.         set_pev(Ent, pev_flags, FL_KILLME)
  751.         return
  752.     }
  753.     else
  754.     {
  755.         Frame += 1.0
  756.         set_pev(Ent, pev_frame, Frame)
  757.     }
  758.    
  759.     set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  760. }
  761.  
  762. public MakeMuzzleFlash2(iPlayer)
  763. {
  764.     static Ent
  765.    
  766.     for(new i = 2; i < 5; i++)
  767.     {
  768.         Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  769.         if(!pev_valid(Ent)) continue
  770.    
  771.         set_pev(Ent, pev_classname, MUZZLEFLASH2_CLASSNAME)
  772.    
  773.         set_pev(Ent, pev_owner, iPlayer)
  774.         set_pev(Ent, pev_body, i)
  775.         set_pev(Ent, pev_skin, iPlayer)
  776.         set_pev(Ent, pev_aiment, iPlayer)
  777.         set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
  778.    
  779.         set_pev(Ent, pev_scale, 0.02)
  780.         set_pev(Ent, pev_frame, 0.0)
  781.         set_pev(Ent, pev_rendermode, kRenderTransAdd)
  782.         set_pev(Ent, pev_renderamt, 255.0)
  783.    
  784.         engfunc(EngFunc_SetModel, Ent,  muzzle_flash2)
  785.    
  786.         set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
  787.     }
  788. }
  789.  
  790. public fw_MuzzleFlash2_Think(Ent)
  791. {
  792.     if(!pev_valid(Ent))
  793.         return
  794.    
  795.     static Owner; Owner = pev(Ent, pev_owner)
  796.    
  797.     if(!is_alive(Owner))
  798.     {
  799.         set_pev(Ent, pev_flags, FL_KILLME)
  800.         return
  801.     }
  802.    
  803.     static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
  804.    
  805.     if(