limit weapons

Unpaid Requests, Public Plugins
Post Reply
czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 439
Joined: 1 Year Ago
Has thanked: 17 times
Been thanked: 1 time
Contact:

limit weapons

#1

Post by czirimbolo » 3 Weeks Ago

Hello,

I want a plugin with limiting weapon. For example, I have a powerful gun on the server and its too strong for zombies when every human can have it at the same time. So I want to make for example this gun for max. 4 players per round.

To sum up:
Four players bought powerful gun and after that gun is blocked in extra item menu and nobody can buy it
Image

Rain1153
Senior Member
Senior Member
India
Posts: 270
Joined: 11 Months Ago
Has thanked: 2 times
Been thanked: 1 time
Age: 18
Contact:

#2

Post by Rain1153 » 3 Weeks Ago

  1. new  bool:g_bCanUse
  2.  
  3.  
  4. if (!g_bCanUse || ze_get_humans_number() <= x)  // where  x is the number of humans that are need to be there so that the gun is auto limited!
  5.         return ZE_ITEM_UNAVAILABLE
use this code in your ze_select_item_pre() of the gun u wanna limit
LOL

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1717
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#3

Post by Raheem » 3 Weeks Ago

Need to check number of players have this item, and if they more than 4 alive then block buy in select item pre as rain said.

Rain, ze_get_humans_number() will return alive players number, you need to count how many players have the item by make new boolean array (For every player variable) like g_bHasItem[33] and then check if there is more than 4 is true in this array if yes then block buy.

  1. stock getTrueNumber(bool:g_bArray[])
  2. {
  3.     new iTrueCount
  4.    
  5.     for(new i = 0; i <= charsmax(g_bArray[]); i++)
  6.     {
  7.         if (g_bArray[i])
  8.             iTrueCount++
  9.     }
  10.    
  11.     return iTrueCount
  12. }
You don't know? Learn and you will know.

Rain1153
Senior Member
Senior Member
India
Posts: 270
Joined: 11 Months Ago
Has thanked: 2 times
Been thanked: 1 time
Age: 18
Contact:

#4

Post by Rain1153 » 3 Weeks Ago

Raheem wrote:
3 Weeks Ago
Need to check number of players have this item, and if they more than 4 alive then block buy in select item pre as rain said.

Rain, ze_get_humans_number() will return alive players number, you need to count how many players have the item by make new boolean array (For every player variable) like g_bHasItem[33] and then check if there is more than 4 is true in this array if yes then block buy.

  1. stock getTrueNumber(bool:g_bArray[])
  2. {
  3.     new iTrueCount
  4.    
  5.     for(new i = 0; i <= charsmax(g_bArray); i++)
  6.     {
  7.         if (g_bArray[i])
  8.             iTrueCount++
  9.     }
  10.    
  11.     return iTrueCount
  12. }
oh thanks raheem
LOL

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1717
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#5

Post by Raheem » 3 Weeks Ago

Forget to say, you need to set for every player have the item g_bHaveItem[id] to ture. You may make task and check every x second if this player have this item or not.
You don't know? Learn and you will know.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 439
Joined: 1 Year Ago
Has thanked: 17 times
Been thanked: 1 time
Contact:

#6

Post by czirimbolo » 3 Weeks Ago

Ok so what I should add to every gun?
Image

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1717
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#7

Post by Raheem » 3 Weeks Ago

Maybe you post an item and i'll show you example.
You don't know? Learn and you will know.

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 439
Joined: 1 Year Ago
Has thanked: 17 times
Been thanked: 1 time
Contact:

#8

Post by czirimbolo » 3 Weeks Ago

Raheem wrote:
3 Weeks Ago
Maybe you post an item and i'll show you example.

Code: Select all

/* Made with the information from HLSDK*/

#include <zombie_escape>
#include <fakemeta_util>
#include <engine>
#include <xs> 

#define PLUGIN "Hornet Gun"
#define VERSION "1.0"
#define AUTHOR "Bim Bim Cay"

// Models
#define v_model "models/v_hgun.mdl"
#define p_model "models/p_hgun.mdl"
#define w_model "models/w_hgun.mdl"
#define hornet_model "models/hornet.mdl"

// Sounds
new const HornetGuns_Sounds[9][] =
{
	"agrunt/ag_fire1.wav",
	"agrunt/ag_fire2.wav",
	"agrunt/ag_fire3.wav",
	"hornet/ag_hornethit1.wav",
	"hornet/ag_hornethit2.wav",
	"hornet/ag_hornethit3.wav",
	"hornet/ag_buzz1.wav",
	"hornet/ag_buzz2.wav",
	"hornet/ag_buzz3.wav"
}

// Sprites
#define spr_trail "sprites/laserbeam.spr"

// Animations 
#define ANIM_IDLE1		0
#define ANIM_FIDGETSWAY		1
#define ANIM_FIDGETSHAKE	2
#define ANIM_DOWN		3
#define ANIM_UP			4
#define ANIM_SHOOT		5

#define ANIM_EXTENSION 		"m249"

// Entity Classname
#define HORNET_CLASSNAME 	"CSHivehand_Hornet"

// FireMode
#define FIREMODE_TRACK		1
#define FIREMODE_FAST		2
#define FIREMODE_DIE		3

// State
#define STATE_STARTTRACK	1
#define STATE_STARTDART		2
#define STATE_TRACKTARGET	3
#define STATE_REMOVEHORNET	4

// Configs
#define WEAPON_NAME 		"weapon_hgun"
#define WEAPON_BASE		"weapon_famas"

#define HORNET_TYPE_RED      	0
#define HORNET_TYPE_ORANGE	1

#define NOT_IN_WATER  		0
#define HEAD_IN_WATER 		3

#define HG_FLY_SPEED   		pev_fuser4
#define HG_FIRE_MODE   		pev_iuser2
#define HG_TYPE_COLOR  		pev_iuser3
#define HG_THINK_STEP  		pev_iuser4
#define HG_ENEMY_LKP   		pev_vuser4
#define HG_STOP_ATTACK 		pev_ltime

#define HIVEHAND_REFIRE_PRI  	0.25   // Refire rate for primary attack
#define HIVEHAND_REFIRE_SEC  	0.1    // Refire rate for secondary attack
#define HIVEHAND_AMMO        	20      // Max hornets
#define HIVEGUN_REGEN_TIME  	0.3    // Regenerate time 
#define HORNET_RED_SPEED     	600.0  // Red hornet speed 
#define HORNET_ORANGE_SPEED 	800.0  // Orage hornet speed 
#define HORNET_BUZZ_VOLUME   	0.8    // Buzz volume
#define HORNET_FOV           	0.1    // hornet's field of vision | 0.9 = +- 25 degrees ( float ).
#define HORNET_SEARCH_RADIUS 	1024.0  // How far should the hornets searh enemy? ( float ).
#define HORNET_DAMAGE        	200.0    // Damage by hornet.

// 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 MUZZLE_INTOLERANCE 100
#define OBS_IN_EYE 4

#define VIP_FLAG "VIP_A"
     
new g_iszWeaponKey
new g_SprTrail

new g_MaxEntities
new g_FriendlyFire

// Safety
new g_HamBot
new g_IsConnected, g_IsAlive
new g_item

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Safety
	Register_SafetyFunc()
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_SetModel, "fw_SetModel")
	
	// Think
	register_think(HORNET_CLASSNAME, "fw_Hornet_Think") 
	
	// Touch
	register_touch(HORNET_CLASSNAME, "*", "fw_Hornet_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_Holster, WEAPON_BASE, "fw_Item_Holster_Post", 1)
	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_Weapon_SecondaryAttack, WEAPON_BASE, "fw_Weapon_SecondaryAttack")
	
	g_item = ze_register_item("Hornet Gun", 300, 0)
	ze_set_item_vip(g_item, VIP_FLAG)
}

public plugin_precache()
{
	precache_model(v_model)
	precache_model(p_model)
	precache_model(w_model)
	precache_model(hornet_model)
	
	g_SprTrail = precache_model(spr_trail)
	
	for(new i = 0; i < sizeof(HornetGuns_Sounds); i++)
		precache_sound(HornetGuns_Sounds[i])
	
	g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
}

public plugin_cfg()
{
	g_MaxEntities = global_get(glb_maxEntities)
	g_FriendlyFire = get_pcvar_num(get_cvar_pointer("mp_friendlyfire")) 
}

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)
}

public client_disconnected(iPlayer)
{
	Safety_Disconnected(iPlayer)
}

public Get_MyWeapon(iPlayer)
{
	Weapon_Give(iPlayer)
}

public ze_select_item_pre(id, itemid)
{
    // Return Available and we will block it in Post, So it dosen't affect other plugins
    if (itemid != g_item)
        return ZE_ITEM_AVAILABLE
   
    // Available for Humans only, So don't show it for zombies
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
   
    return ZE_ITEM_AVAILABLE
}

public ze_select_item_post(id, itemid)
{
	// Here we just block buying the gun if it is not the gun the player is willing to buy so we just add return without values.
	if (itemid != g_item)
		return

	Get_MyWeapon(id)
}
 

//**********************************************
//* Forward Hooking                            *
//********************************************** 
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
			
			Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLE1)
		}
	}
	
	set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
	
	return FMRES_HANDLED
}

//**********************************************
//* 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)
	
	set_pev(iPlayer, pev_viewmodel2, v_model)
	set_pev(iPlayer, pev_weaponmodel2, p_model)
	
	Weapon_SendAnim(iPlayer, iItem, ANIM_UP)
	
	set_pdata_string(iPlayer, (492) * 4, ANIM_EXTENSION, -1 , 20)
}

public fw_Item_Holster_Post(iItem)
{
	if(!IsCustomItem(iItem))
		return
	
	//!!!HACKHACK - can't select hornetgun if it's empty! no way to get ammo for it, either.
	if(get_pdata_int(iItem, 51, 4) <= 0)
	{
		set_pdata_int(iItem, 51, 1, 4)
	}
}

public fw_Item_PostFrame(iItem)
{
	if(!IsCustomItem(iItem))
		return HAM_IGNORED
	
	static Float:flLastEventCheck; flLastEventCheck = get_pdata_float(iItem, 38, 4)
	
	if(flLastEventCheck < get_gametime())
	{
		flLastEventCheck = get_gametime() + HIVEGUN_REGEN_TIME 
		set_pdata_float(iItem, 38, flLastEventCheck, 4)
		
		static iClip; iClip = get_pdata_int(iItem, 51, 4)
		
		if(iClip < HIVEHAND_AMMO)
		{
			iClip++
			set_pdata_int(iItem, 51, iClip, 4)
		}
	}
	
	return HAM_IGNORED
}

public fw_Weapon_Reload(iItem)
{
	if(!IsCustomItem(iItem))
		return HAM_IGNORED
		
	return HAM_SUPERCEDE	
}

public fw_Weapon_WeaponIdle(iItem)
{
	if(!IsCustomItem(iItem))
		return HAM_IGNORED
		
	static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)	
	
	if(get_pdata_float(iItem, 48, 4) > 0.0)
		return HAM_SUPERCEDE
	
	static Float:f_Rand; f_Rand = random_float(0.0, 1.0)
        
	if(f_Rand <= 0.75)
	{
		set_pdata_float(iItem, 48, 30.0 / 16.0 * 2.0, 4)
		
		Weapon_SendAnim(iPlayer, iItem, ANIM_IDLE1)
	}
	else if (f_Rand <= 0.875)
	{
		set_pdata_float(iItem, 48, 40.0 / 16.0, 4)
		
		Weapon_SendAnim(iPlayer, iItem, ANIM_FIDGETSWAY)
	}
	else
	{   
		set_pdata_float(iItem, 48, 35.0 / 16.0, 4)
		
		Weapon_SendAnim(iPlayer, iItem, ANIM_FIDGETSHAKE)
	}
	
	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)
		return HAM_SUPERCEDE
	
	set_pdata_float(iItem, 38, get_gametime() + HIVEGUN_REGEN_TIME, 4)
	
	iClip--
	set_pdata_int(iItem, 51, iClip, 4)
	
	static Float:Punchangle[3]
	Punchangle[0] = float(random_num(0, 2))
	
	set_pev(iPlayer, pev_punchangle, Punchangle)
	
	set_pdata_float(iItem, 46, HIVEHAND_REFIRE_PRI, 4)
	set_pdata_float(iItem, 47, HIVEHAND_REFIRE_PRI, 4)
	set_pdata_float(iItem, 48, random_float(10.0, 15.0), 4)
	
	static iFlags, szAnimation[64]
	
	if(iFlags & FL_DUCKING)
	{
		formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
	}
	else
	{
		formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
	}
	
	Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
	
	switch(random_num(0, 2))
	{	
		case 0: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		case 1: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		case 2: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	}
	
	static Float:Origin[3]
	Get_Position(iPlayer, 16.0, !get_cvar_num("cl_righthand") ? -8.0 : 8.0, -12.0, Origin)
	
	static HornetEnt; HornetEnt = Hornet_Create(iPlayer, Origin) 
	
	if(HornetEnt > 0)
	{
		static Float:vAngle[3], Float:vForward[3], Float:Velocity[3]
		
		pev(iPlayer, pev_v_angle, vAngle)
		angle_vector(vAngle, ANGLEVECTOR_FORWARD, vForward)
		
		xs_vec_mul_scalar(vForward, 300.0, Velocity)
		set_pev(HornetEnt, pev_velocity, Velocity)
		
		Hornet_Spawn(HornetEnt, FIREMODE_TRACK)
	}
	
	return HAM_SUPERCEDE
}

public fw_Weapon_SecondaryAttack(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)
		return HAM_SUPERCEDE
		
	set_pdata_float(iItem, 38, get_gametime() + HIVEGUN_REGEN_TIME, 4)	
		
	iClip--
	set_pdata_int(iItem, 51, iClip, 4)
	
	static Float:Punchangle[3]
	Punchangle[0] = float(random_num(0, 2))
	
	set_pev(iPlayer, pev_punchangle, Punchangle)
	
	set_pdata_float(iItem, 46, HIVEHAND_REFIRE_SEC, 4)
	set_pdata_float(iItem, 47, HIVEHAND_REFIRE_SEC, 4)
	set_pdata_float(iItem, 48, random_float(10.0, 15.0), 4)
	
	static iFlags, szAnimation[64]
	
	if(iFlags & FL_DUCKING)
	{
		formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
	}
	else
	{
		formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
	}
	
	Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
	
	switch(random_num(0, 2))
	{	
		case 0: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		case 1: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		case 2: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	}
	
	static Float:Right, Float:Up
	static FirePhase; FirePhase = get_pdata_int(iItem, 30, 4)
	
	FirePhase++
	set_pdata_int(iItem, 30, FirePhase, 4)
	
	switch(FirePhase)
	{
		case 1:
		{
			Up = 8.0
			Right = 0.0
		}
		case 2:
		{
			Up = 8.0
			Right = 8.0
		}
		case 3:
		{
			Up = 0.0
			Right = 8.0
		}
		case 4:
		{
			Up = -8.0
			Right = 8.0
		}
		case 5:
		{
			Up = -8.0
			Right = 0.0
		}
		case 6:
		{
			Up = -8.0
			Right = -8.0	
		}
		case 7:
		{
			Up = 0.0
			Right = -8.0	
		}
		case 8:
		{
			Up = 8.0
			Right = -8.0
			
			set_pdata_int(iItem, 30, FirePhase, 4)
		}
	}
	
	static Float:Origin[3]
	Get_Position(iPlayer, 16.0, (!get_cvar_num("cl_righthand") ? -8.0 : 8.0) + Right, -12.0 + Up, Origin)
	
	static HornetEnt; HornetEnt = Hornet_Create(iPlayer, Origin) 
	
	if(HornetEnt > 0)
	{
		static Float:vAngle[3], Float:vForward[3], Float:Velocity[3]
		
		pev(iPlayer, pev_v_angle, vAngle)
		angle_vector(vAngle, ANGLEVECTOR_FORWARD, vForward)
		
		xs_vec_mul_scalar(vForward, 1200.0, Velocity)
		set_pev(HornetEnt, pev_velocity, Velocity)
		
		Hornet_Spawn(HornetEnt, FIREMODE_FAST)
	}
	
	return HAM_SUPERCEDE
}

Hornet_Create(iPlayer, Float:Origin[3])
{
	static Float:Angles[3]
	pev(iPlayer, pev_v_angle, Angles)
	
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	if(!pev_valid(Ent))
		return FM_NULLENT
		
	set_pev(Ent, pev_classname, HORNET_CLASSNAME)
	set_pev(Ent, pev_owner, iPlayer)
	
	set_pev(Ent, pev_origin, Origin)
	set_pev(Ent, pev_angles, Angles)
	
	return Ent
}

Hornet_Spawn(HornetEnt, FireMode)
{
	set_pev(HornetEnt, pev_movetype, MOVETYPE_FLY)
	set_pev(HornetEnt, pev_solid, SOLID_BBOX)
	set_pev(HornetEnt, pev_flags, pev(HornetEnt, pev_flags ) | FL_MONSTER)
	set_pev(HornetEnt, pev_health, 1.0)

	if(random_num (1, 5) <= 2)
	{
		set_pev(HornetEnt, HG_TYPE_COLOR, HORNET_TYPE_RED)
		set_pev(HornetEnt, HG_FLY_SPEED, HORNET_RED_SPEED)
	}
	else
	{
		set_pev(HornetEnt, HG_TYPE_COLOR, HORNET_TYPE_ORANGE)
		set_pev(HornetEnt, HG_FLY_SPEED, HORNET_ORANGE_SPEED)
	}

	if(FireMode == FIREMODE_TRACK)
	{
		set_pev(HornetEnt, HG_STOP_ATTACK, get_gametime() + 3.5)
	}

	engfunc(EngFunc_SetModel, HornetEnt, hornet_model)
	engfunc(EngFunc_SetSize, HornetEnt, Float:{-4.0, -4.0, -4.0}, Float:{4.0, 4.0, 4.0})

	set_pev(HornetEnt, HG_FIRE_MODE, FIREMODE_DIE)
	set_pev(HornetEnt, HG_THINK_STEP, FireMode == FIREMODE_TRACK ? STATE_STARTTRACK : STATE_STARTDART)
	set_pev(HornetEnt, pev_nextthink, get_gametime() + 0.1)
}

public fw_Hornet_Think(Ent)
{
	if(!pev_valid(Ent))
		return

	switch(pev(Ent, HG_THINK_STEP))
	{
		case STATE_STARTTRACK:
		{
			IgniteTrail(Ent)

			set_pev(Ent, HG_FIRE_MODE, FIREMODE_TRACK)
			set_pev(Ent, HG_THINK_STEP, STATE_TRACKTARGET)
		}
		case STATE_STARTDART:
		{
			IgniteTrail(Ent)

			set_pev(Ent, HG_FIRE_MODE, FIREMODE_FAST)
			set_pev(Ent, HG_THINK_STEP, STATE_REMOVEHORNET)

			set_pev(Ent, pev_nextthink, get_gametime() + 4.0)
			
			return
		}
		case STATE_TRACKTARGET:
		{
			TrackingTarget(Ent)
		}
		case STATE_REMOVEHORNET:
		{
			RemovingHornet(Ent)
		}
        }

        set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
}


public fw_Hornet_Touch(Ent, Touch)
{
	if(!pev_valid(Ent))
		return

	switch(pev(Ent, HG_FIRE_MODE))
	{
		case FIREMODE_TRACK: TrackTouch(Ent, Touch)
		case FIREMODE_FAST: DartTouch(Ent, Touch)
		case FIREMODE_DIE: DieTouch(Ent, Touch)
	}
}

RemovingHornet(Ent)
{
	set_pev(Ent, pev_flags, FL_KILLME)
}

IgniteTrail(Ent)
{
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMFOLLOW)
	write_short(Ent)       
	write_short(g_SprTrail )
	write_byte(10)
	write_byte(2)

	switch(pev(Ent, HG_TYPE_COLOR))
	{
		case HORNET_TYPE_RED:
		{
			write_byte(179)
			write_byte(39)
			write_byte(14)
		}
		case HORNET_TYPE_ORANGE:
		{
			write_byte(255)
			write_byte(128)
			write_byte(0)
		}
        }

        write_byte(128)
        message_end()
}

TrackingTarget(Ent)
{
	if(IsHornetShouldDie(Ent))
	{
		set_pev(Ent, HG_FIRE_MODE, 0)
		set_pev(Ent, HG_THINK_STEP, STATE_REMOVEHORNET)

		set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
	}

	static Float:FlightDir[3], Float:DirToEnnemy[3]
	static Float:EnemyLKP[3], Float:Velocity[3]
	static Float:Origin[3], Float:Angles[3]
	static Float:Delta, Float:FlySpeed, Enemy

	pev(Ent, pev_velocity, Velocity)
	pev(Ent, pev_origin, Origin)

	Enemy = pev(Ent, pev_enemy)

	if(!IsEnemyValid(Ent, Enemy))
	{
		set_pev(Ent, pev_enemy, 0)
		Enemy = 0
	}

	if(!Enemy)
	{
		Enemy = BestVisibleEnemy(Ent, Origin)
	}

	if(Enemy != 0 && FVisible(Ent,Enemy))
	{
		pev(Enemy, pev_origin, EnemyLKP)
		set_pev(Ent, HG_ENEMY_LKP, EnemyLKP)
	}
	else
	{
		pev(Ent, HG_FLY_SPEED, FlySpeed)
		pev(Ent, HG_ENEMY_LKP, EnemyLKP)

		VectorMA(EnemyLKP, FlySpeed * 0.1, Velocity)
		set_pev(Ent, HG_ENEMY_LKP, EnemyLKP)
	}

	pev(Ent, pev_origin, Origin)

	xs_vec_sub(EnemyLKP, Origin, Origin)
	xs_vec_normalize(Origin, DirToEnnemy)

	xs_vec_len(Velocity) < 0.1 ? xs_vec_copy(DirToEnnemy, FlightDir) : xs_vec_normalize(Velocity, FlightDir)
	Delta = xs_vec_dot(FlightDir, DirToEnnemy)

	if(Delta < 0.5)
	{
		switch(random_num(0, 2))
		{
			case 0: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[6], HORNET_BUZZ_VOLUME, ATTN_NORM, 0, PITCH_NORM)
			case 1: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[7], HORNET_BUZZ_VOLUME, ATTN_NORM, 0, PITCH_NORM)
			case 2: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[8], HORNET_BUZZ_VOLUME, ATTN_NORM, 0, PITCH_NORM)
		}
	}

	if(Delta <= 0 && pev(Ent, HG_TYPE_COLOR) == HORNET_TYPE_RED)
	{
		Delta = 0.25
	}

	xs_vec_add(FlightDir, DirToEnnemy, DirToEnnemy)
	xs_vec_normalize(DirToEnnemy, Velocity)

	switch(pev(Ent, HG_TYPE_COLOR))
	{
		case HORNET_TYPE_RED:
		{
			pev(Ent, HG_FLY_SPEED, FlySpeed)
			xs_vec_mul_scalar(Velocity, FlySpeed * Delta, Velocity)

			set_pev(Ent, pev_velocity, Velocity)
			set_pev(Ent, pev_nextthink, get_gametime() + random_float(0.1, 0.3))
		}
		case HORNET_TYPE_ORANGE:
		{
			pev(Ent, HG_FLY_SPEED, FlySpeed)
			xs_vec_mul_scalar(Velocity, FlySpeed, Velocity)

			set_pev(Ent, pev_velocity, Velocity)
			set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
		}
	}

	engfunc(EngFunc_VecToAngles, Velocity, Angles)

	set_pev(Ent, pev_angles, Angles)
	set_pev(Ent, pev_solid, SOLID_BBOX)
}

IsHornetShouldDie(Ent)
{
	static Float:LifeTime; pev(Ent, HG_STOP_ATTACK, LifeTime)

	if(get_gametime() > LifeTime)
		return 1
        
	return 0
}
    
IsEnemyValid(Ent, Enemy)
{
	if(!pev_valid(Enemy))
                return 0
        
	static Flags; Flags = pev(Enemy, pev_flags)
        
	if(Flags & (FL_CLIENT | FL_FAKECLIENT))
	{
		if(!is_alive(Enemy) || pev(Enemy, pev_deadflag) > DEAD_NO)
		{
			return 0
		}
		else if(!g_FriendlyFire && IsSameTeam(Enemy, pev(Ent, pev_owner)))
		{
			return 0
		}
	}
	else if(Flags & FL_MONSTER)
	{
		static Float:Health; pev(Enemy, pev_health, Health)
            
		if(Health <= 0)
			return 0
	}
        
	return 1
}

BestVisibleEnemy(Ent, Float:Origin[3])
{
	static Target, Flags
        
	static Float:Mins[3], Float:Maxs[3]
	static Float:Absmins[3], Float:Absmaxs[3]
        
	xs_vec_sub(Origin, Float:{HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS}, Mins)
	xs_vec_add(Origin, Float:{HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS}, Maxs)

	for(Target = 1; Target < g_MaxEntities; Target++)
	{
		if(!pev_valid(Target))
			continue
            
		Flags = pev(Target, pev_flags)

		if(!(Flags & (FL_CLIENT | FL_FAKECLIENT | FL_MONSTER)))
			continue
            
		if(Flags & FL_MONSTER)
		{
			if(IsHornet(Target))
				continue
		}
            
		if(Target == Ent)
			continue
            
		pev(Target, pev_absmin, Absmins)
		pev(Target, pev_absmax, Absmaxs)
            
		if(Mins[0] > Absmaxs[0] || Mins[1] > Absmaxs[1] || Mins[2] > Absmaxs[2] || Maxs[0] < Absmins[0] || Maxs[1] < Absmins[1] || Maxs[2] < Absmins[2])
			continue
            
		if(IsEnemyValid(Ent, Target))
		{
			if(FInViewCone(Ent, Target) && !(Flags & FL_NOTARGET) && FVisible(Ent, Target))
			{
				set_pev(Ent, pev_enemy, Target)
				return Target
			}
		}
        }

        return 0
}

FVisible(Hornet, Other)
{
	if(!pev_valid(Hornet) || pev(Other, pev_flags) & FL_NOTARGET)
		return 0
        
	static LookerWLevel, TargetWLevel

	LookerWLevel = pev(Hornet, pev_waterlevel)
	TargetWLevel = pev(Other , pev_waterlevel)

	if((LookerWLevel != HEAD_IN_WATER && TargetWLevel == HEAD_IN_WATER ) || (LookerWLevel == HEAD_IN_WATER && TargetWLevel == NOT_IN_WATER))
		return 0
        
	static Float:LookerOrigin[3], Float:TargetOrigin[3]

	EyePosition(Hornet, LookerOrigin)
	EyePosition(Other, TargetOrigin)

	engfunc(EngFunc_TraceLine, LookerOrigin, TargetOrigin, IGNORE_MONSTERS, Hornet, 0)

	static Float:Fraction
	get_tr2(0, TR_flFraction, Fraction)

	if(Fraction == 1.0)
		return 1
        
	return 0
}


EyePosition(Ent, Float:Origin[3])
{
	static Float:ViewOfs[3];

	pev(Ent, pev_origin, Origin)
	pev(Ent, pev_view_ofs, ViewOfs)

	xs_vec_add(Origin, ViewOfs, Origin)
}

VectorMA(Float:vOutput[], Float:Scale, Float:vMult[])
{
	vOutput[0] = vOutput[0] + vMult[0] * Scale
	vOutput[1] = vOutput[1] + vMult[1] * Scale
	vOutput[2] = vOutput[2] + vMult[2] * Scale
}    

IsSameTeam(FirstId, SecondId)
{
	return (get_pdata_int(FirstId, 114, 5) == get_pdata_int(SecondId, 114, 5))
}

IsHornet(Ent)
{
	if(!pev_valid(Ent))
		return 0
        
	static Classname[32]; pev(Ent, pev_classname, Classname, charsmax(Classname))

	if(!equali(Classname, HORNET_CLASSNAME))
		return 0
		
	return 1
}

FInViewCone(Hornet, Other)
{
	static Float:Angles[3], Float:Dot
	static Float:HOrigin[3], Float:Origin[3]
        
	pev(Hornet, pev_angles, Angles)

	engfunc(EngFunc_MakeVectors, Angles)
	global_get(glb_v_forward, Angles)

	Angles[2] = 0.0

	pev(Hornet, pev_origin, HOrigin)
	pev(Other, pev_origin, Origin)

	xs_vec_sub(Origin, HOrigin, Origin)
	Origin[2] = 0.0

	xs_vec_normalize(Origin, Origin)
	Dot = xs_vec_dot(Origin, Angles)

	if(Dot > HORNET_FOV)
		return 1
	
	return 0
}

DartTouch(Ent, Other)
{
	DieTouch(Ent, Other)
}

TrackTouch(Ent, Other)
{
	if(Other == pev(Ent, pev_owner))
	{
		set_pev(Ent, HG_FIRE_MODE, 0)
		set_pev(Ent, pev_solid, SOLID_NOT)

		return 
	} 

	if(!Other || IsHornet(Other))
	{
		static Float:Velocity[3]
		static Float:Origin[3]
		static Float:FlySpeed

		pev(Ent, pev_velocity, Velocity)
		xs_vec_normalize(Velocity, Velocity)

		Velocity[0] *= -1.0
		Velocity[1] *= -1.0

		pev(Ent, pev_origin, Origin)
		VectorMA(Origin, 4.0, Velocity)

		if(xs_vec_len(Origin) > 0)
		{
			set_pev(Ent, pev_origin, Origin)
		}

		pev(Ent, HG_FLY_SPEED, FlySpeed)
		xs_vec_mul_scalar(Velocity, FlySpeed, Velocity)

		if(xs_vec_len(Velocity) > 0)
		{
			set_pev(Ent, pev_velocity, Velocity)
		}

		return 
        } 
        
        DieTouch(Ent, Other)
}

DieTouch(Ent, Other)
{
	static FireMode; FireMode = pev(Ent, HG_FIRE_MODE)
	
	if(FireMode == FIREMODE_TRACK)
	{
		if(CanTakeDamage(Other, FireMode))
		{
			switch(random_num(0, 2))
			{
				case 0: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[3], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
				case 1: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[4], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
				case 2: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[5], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
			}

			ExecuteHamB(Ham_TakeDamage, Other, Ent, pev(Ent, pev_owner), HORNET_DAMAGE, DMG_BULLET | DMG_NEVERGIB)
		}
	}
	else
	{
		if(CanTakeDamage(Other, FireMode))
		{
			if(pev(Other, pev_flags) & (FL_CLIENT | FL_FAKECLIENT | FL_MONSTER))
			{
				switch(random_num(0, 2))
				{
					case 0: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[3], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
					case 1: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[4], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
					case 2: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[5], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
				}
			}

			ExecuteHamB(Ham_TakeDamage, Other, Ent, pev(Ent, pev_owner), HORNET_DAMAGE, DMG_BULLET | DMG_NEVERGIB)
		}
	}
	
	set_pev(Ent, pev_modelindex, 0)
	set_pev(Ent, pev_solid, SOLID_NOT)

	set_pev(Ent, HG_THINK_STEP, STATE_REMOVEHORNET)
	set_pev(Ent, pev_nextthink, get_gametime() + 1.0)
}

CanTakeDamage(Other, FireMode)
{
	static Float:TakeDamage
	pev(Other, pev_takedamage, TakeDamage)

	if(FireMode == FIREMODE_TRACK)
	{
		if(pev(Other, pev_flags) & (FL_CLIENT | FL_FAKECLIENT | FL_MONSTER) && TakeDamage != DAMAGE_NO)
			return 1
	}
	else
	{
		if(TakeDamage != DAMAGE_NO)
			return 1
	}
	
	return 0
}
    
//**********************************************
//* Safety Functions        		       *
//**********************************************
public Register_SafetyFunc()
{
	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)
}

public Safety_Disconnected(iPlayer)
{
	UnSet_BitVar(g_IsConnected, iPlayer)
	UnSet_BitVar(g_IsAlive, iPlayer)
}

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
}

//**********************************************
//* 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, HIVEHAND_AMMO, 4)
	set_pdata_int(iWeapon, 30, 0, 4)
	
	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)
		
		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)
	}
}

//**********************************************
//* 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)
}

//**********************************************
//* Some useful stocks.                        *
//**********************************************
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_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
}
Image

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1717
Joined: 1 Year Ago
Location: Egypt
Has thanked: 28 times
Been thanked: 78 times
Age: 21
Contact:

#9

Post by Raheem » 3 Weeks Ago

Try:
    1. /* Made with the information from HLSDK*/
    2.  
    3. #include <zombie_escape>
    4. #include <fakemeta_util>
    5. #include <engine>
    6. #include <xs>
    7.  
    8. #define PLUGIN "Hornet Gun"
    9. #define VERSION "1.0"
    10. #define AUTHOR "Bim Bim Cay"
    11.  
    12. // Models
    13. #define v_model "models/v_hgun.mdl"
    14. #define p_model "models/p_hgun.mdl"
    15. #define w_model "models/w_hgun.mdl"
    16. #define hornet_model "models/hornet.mdl"
    17.  
    18. // Sounds
    19. new const HornetGuns_Sounds[9][] =
    20. {
    21.     "agrunt/ag_fire1.wav",
    22.     "agrunt/ag_fire2.wav",
    23.     "agrunt/ag_fire3.wav",
    24.     "hornet/ag_hornethit1.wav",
    25.     "hornet/ag_hornethit2.wav",
    26.     "hornet/ag_hornethit3.wav",
    27.     "hornet/ag_buzz1.wav",
    28.     "hornet/ag_buzz2.wav",
    29.     "hornet/ag_buzz3.wav"
    30. }
    31.  
    32. // Sprites
    33. #define spr_trail "sprites/laserbeam.spr"
    34.  
    35. // Animations
    36. #define ANIM_IDLE1      0
    37. #define ANIM_FIDGETSWAY     1
    38. #define ANIM_FIDGETSHAKE    2
    39. #define ANIM_DOWN       3
    40. #define ANIM_UP         4
    41. #define ANIM_SHOOT      5
    42.  
    43. #define ANIM_EXTENSION      "m249"
    44.  
    45. // Entity Classname
    46. #define HORNET_CLASSNAME    "CSHivehand_Hornet"
    47.  
    48. // FireMode
    49. #define FIREMODE_TRACK      1
    50. #define FIREMODE_FAST       2
    51. #define FIREMODE_DIE        3
    52.  
    53. // State
    54. #define STATE_STARTTRACK    1
    55. #define STATE_STARTDART     2
    56. #define STATE_TRACKTARGET   3
    57. #define STATE_REMOVEHORNET  4
    58.  
    59. // Configs
    60. #define WEAPON_NAME         "weapon_hgun"
    61. #define WEAPON_BASE     "weapon_famas"
    62.  
    63. #define HORNET_TYPE_RED         0
    64. #define HORNET_TYPE_ORANGE  1
    65.  
    66. #define NOT_IN_WATER        0
    67. #define HEAD_IN_WATER       3
    68.  
    69. #define HG_FLY_SPEED        pev_fuser4
    70. #define HG_FIRE_MODE        pev_iuser2
    71. #define HG_TYPE_COLOR       pev_iuser3
    72. #define HG_THINK_STEP       pev_iuser4
    73. #define HG_ENEMY_LKP        pev_vuser4
    74. #define HG_STOP_ATTACK      pev_ltime
    75.  
    76. #define HIVEHAND_REFIRE_PRI     0.25   // Refire rate for primary attack
    77. #define HIVEHAND_REFIRE_SEC     0.1    // Refire rate for secondary attack
    78. #define HIVEHAND_AMMO           20      // Max hornets
    79. #define HIVEGUN_REGEN_TIME      0.3    // Regenerate time
    80. #define HORNET_RED_SPEED        600.0  // Red hornet speed
    81. #define HORNET_ORANGE_SPEED     800.0  // Orage hornet speed
    82. #define HORNET_BUZZ_VOLUME      0.8    // Buzz volume
    83. #define HORNET_FOV              0.1    // hornet's field of vision | 0.9 = +- 25 degrees ( float ).
    84. #define HORNET_SEARCH_RADIUS    1024.0  // How far should the hornets searh enemy? ( float ).
    85. #define HORNET_DAMAGE           200.0    // Damage by hornet.
    86.  
    87. // MACROS
    88. #define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
    89. #define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
    90. #define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
    91.  
    92. #define INSTANCE(%0) ((%0 == -1) ? 0 : %0)
    93. #define IsValidPev(%0) (pev_valid(%0) == 2)
    94. #define IsObserver(%0) pev(%0,pev_iuser1)
    95. #define MUZZLE_INTOLERANCE 100
    96. #define OBS_IN_EYE 4
    97.  
    98. #define VIP_FLAG "VIP_A"
    99.      
    100. new g_iszWeaponKey
    101. new g_SprTrail
    102.  
    103. new g_MaxEntities
    104. new g_FriendlyFire
    105.  
    106. // Safety
    107. new g_HamBot
    108. new g_IsConnected, g_IsAlive
    109. new g_item
    110.  
    111. new bool:g_bHaveItem[33]
    112.  
    113. public plugin_init()
    114. {
    115.     register_plugin(PLUGIN, VERSION, AUTHOR)
    116.    
    117.     // Safety
    118.     Register_SafetyFunc()
    119.    
    120.     // Forward
    121.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
    122.     register_forward(FM_SetModel, "fw_SetModel")
    123.    
    124.     // Think
    125.     register_think(HORNET_CLASSNAME, "fw_Hornet_Think")
    126.    
    127.     // Touch
    128.     register_touch(HORNET_CLASSNAME, "*", "fw_Hornet_Touch")
    129.    
    130.     // Ham
    131.     RegisterHam(Ham_Spawn, "weaponbox", "fw_Weaponbox_Spawn_Post", 1)
    132.    
    133.     RegisterHam(Ham_Item_Deploy, WEAPON_BASE, "fw_Item_Deploy_Post", 1)
    134.     RegisterHam(Ham_Item_Holster, WEAPON_BASE, "fw_Item_Holster_Post", 1)
    135.     RegisterHam(Ham_Item_PostFrame, WEAPON_BASE, "fw_Item_PostFrame")
    136.     RegisterHam(Ham_Weapon_Reload, WEAPON_BASE, "fw_Weapon_Reload")
    137.     RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_BASE, "fw_Weapon_WeaponIdle")
    138.     RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_BASE, "fw_Weapon_PrimaryAttack")
    139.     RegisterHam(Ham_Weapon_SecondaryAttack, WEAPON_BASE, "fw_Weapon_SecondaryAttack")
    140.    
    141.     g_item = ze_register_item("Hornet Gun", 300, 0)
    142.     ze_set_item_vip(g_item, VIP_FLAG)
    143. }
    144.  
    145. public plugin_precache()
    146. {
    147.     precache_model(v_model)
    148.     precache_model(p_model)
    149.     precache_model(w_model)
    150.     precache_model(hornet_model)
    151.    
    152.     g_SprTrail = precache_model(spr_trail)
    153.    
    154.     for(new i = 0; i < sizeof(HornetGuns_Sounds); i++)
    155.         precache_sound(HornetGuns_Sounds[i])
    156.    
    157.     g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
    158. }
    159.  
    160. public plugin_cfg()
    161. {
    162.     g_MaxEntities = global_get(glb_maxEntities)
    163.     g_FriendlyFire = get_pcvar_num(get_cvar_pointer("mp_friendlyfire"))
    164. }
    165.  
    166. public client_putinserver(iPlayer)
    167. {
    168.     Safety_Connected(iPlayer)
    169.    
    170.     if(!g_HamBot && is_user_bot(iPlayer))
    171.     {
    172.         g_HamBot = 1
    173.         set_task(0.1, "Register_HamBot", iPlayer)
    174.     }
    175. }
    176.  
    177. public Register_HamBot(iPlayer)
    178. {
    179.     Register_SafetyFuncBot(iPlayer)
    180. }
    181.  
    182. public client_disconnected(iPlayer)
    183. {
    184.     Safety_Disconnected(iPlayer)
    185. }
    186.  
    187. public Get_MyWeapon(iPlayer)
    188. {
    189.     Weapon_Give(iPlayer)
    190. }
    191.  
    192. public ze_select_item_pre(id, itemid)
    193. {
    194.     // Return Available and we will block it in Post, So it dosen't affect other plugins
    195.     if (itemid != g_item)
    196.         return ZE_ITEM_AVAILABLE
    197.    
    198.     // Available for Humans only, So don't show it for zombies
    199.     if (ze_is_user_zombie(id))
    200.         return ZE_ITEM_DONT_SHOW
    201.    
    202.     if (get_true_number(g_bHaveItem) >= 4)
    203.         return ZE_ITEM_UNAVAILABLE
    204.    
    205.     return ZE_ITEM_AVAILABLE
    206. }
    207.  
    208. public ze_select_item_post(id, itemid)
    209. {
    210.     // Here we just block buying the gun if it is not the gun the player is willing to buy so we just add return without values.
    211.     if (itemid != g_item)
    212.         return
    213.  
    214.     Get_MyWeapon(id)
    215. }
    216.  
    217.  
    218. //**********************************************
    219. //* Forward Hooking                            *
    220. //**********************************************
    221. public fw_UpdateClientData_Post(iPlayer, sendweapons, CD_Handle)
    222. {
    223.     enum
    224.     {
    225.         SPEC_MODE,
    226.         SPEC_TARGET,
    227.         SPEC_END
    228.     }
    229.      
    230.     static aSpecInfo[33][SPEC_END]
    231.    
    232.     static iTarget
    233.     static iSpecMode
    234.     static iActiveItem
    235.    
    236.     iTarget = (iSpecMode = IsObserver(iPlayer)) ? pev(iPlayer, pev_iuser2) : iPlayer
    237.    
    238.     if(!is_alive(iTarget))
    239.         return FMRES_IGNORED
    240.    
    241.     iActiveItem = get_pdata_cbase(iTarget, 373, 5)
    242.    
    243.     if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
    244.         return FMRES_IGNORED
    245.    
    246.     if(iSpecMode)
    247.     {
    248.         if(aSpecInfo[iPlayer][SPEC_MODE] != iSpecMode)
    249.         {
    250.             aSpecInfo[iPlayer][SPEC_MODE] = iSpecMode
    251.             aSpecInfo[iPlayer][SPEC_TARGET] = 0
    252.         }
    253.        
    254.         if(iSpecMode == OBS_IN_EYE && aSpecInfo[iPlayer][SPEC_TARGET] != iTarget)
    255.         {
    256.             aSpecInfo[iPlayer][SPEC_TARGET] = iTarget
    257.            
    258.             Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLE1)
    259.         }
    260.     }
    261.    
    262.     set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
    263.    
    264.     return FMRES_HANDLED
    265. }
    266.  
    267. //**********************************************
    268. //* Weaponbox world model.                     *
    269. //**********************************************
    270. public fw_SetModel(iEntity) <WeaponBox: Enabled>
    271. {
    272.     state WeaponBox: Disabled
    273.    
    274.     if(!IsValidPev(iEntity))
    275.         return FMRES_IGNORED
    276.    
    277.     #define MAX_ITEM_TYPES  6
    278.     for(new i, iItem; i < MAX_ITEM_TYPES; i++)
    279.     {
    280.         iItem = get_pdata_cbase(iEntity, 34 + i, 4)
    281.        
    282.         if(IsValidPev(iItem) && IsCustomItem(iItem))
    283.         {
    284.             engfunc(EngFunc_SetModel, iEntity, w_model)
    285.             return FMRES_SUPERCEDE
    286.         }
    287.     }
    288.    
    289.     return FMRES_IGNORED
    290. }
    291.  
    292. public fw_SetModel() </* Empty statement */>   
    293. {
    294.     /*  Fallback  */
    295.     return FMRES_IGNORED
    296. }
    297. public fw_SetModel() <WeaponBox: Disabled> 
    298. {
    299.     /* Do nothing */
    300.     return FMRES_IGNORED
    301. }
    302.  
    303. public fw_Weaponbox_Spawn_Post(iWeaponBox)
    304. {
    305.     if(IsValidPev(iWeaponBox))
    306.     {
    307.         state (IsValidPev(pev(iWeaponBox, pev_owner))) WeaponBox: Enabled
    308.     }
    309.    
    310.     return HAM_IGNORED
    311. }
    312.  
    313. //**********************************************
    314. //* Weapon's codes.                            *
    315. //**********************************************
    316. public fw_Item_Deploy_Post(iItem)
    317. {
    318.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
    319.    
    320.     if(!IsCustomItem(iItem))
    321.     {
    322.         g_bHaveItem[iPlayer] = false
    323.         return
    324.     }
    325.    
    326.     g_bHaveItem[iPlayer] = true
    327.    
    328.     set_pev(iPlayer, pev_viewmodel2, v_model)
    329.     set_pev(iPlayer, pev_weaponmodel2, p_model)
    330.    
    331.     Weapon_SendAnim(iPlayer, iItem, ANIM_UP)
    332.    
    333.     set_pdata_string(iPlayer, (492) * 4, ANIM_EXTENSION, -1 , 20)
    334. }
    335.  
    336. public fw_Item_Holster_Post(iItem)
    337. {
    338.     if(!IsCustomItem(iItem))
    339.         return
    340.    
    341.     //!!!HACKHACK - can't select hornetgun if it's empty! no way to get ammo for it, either.
    342.     if(get_pdata_int(iItem, 51, 4) <= 0)
    343.     {
    344.         set_pdata_int(iItem, 51, 1, 4)
    345.     }
    346. }
    347.  
    348. public fw_Item_PostFrame(iItem)
    349. {
    350.     if(!IsCustomItem(iItem))
    351.         return HAM_IGNORED
    352.    
    353.     static Float:flLastEventCheck; flLastEventCheck = get_pdata_float(iItem, 38, 4)
    354.    
    355.     if(flLastEventCheck < get_gametime())
    356.     {
    357.         flLastEventCheck = get_gametime() + HIVEGUN_REGEN_TIME
    358.         set_pdata_float(iItem, 38, flLastEventCheck, 4)
    359.        
    360.         static iClip; iClip = get_pdata_int(iItem, 51, 4)
    361.        
    362.         if(iClip < HIVEHAND_AMMO)
    363.         {
    364.             iClip++
    365.             set_pdata_int(iItem, 51, iClip, 4)
    366.         }
    367.     }
    368.    
    369.     return HAM_IGNORED
    370. }
    371.  
    372. public fw_Weapon_Reload(iItem)
    373. {
    374.     if(!IsCustomItem(iItem))
    375.         return HAM_IGNORED
    376.        
    377.     return HAM_SUPERCEDE   
    378. }
    379.  
    380. public fw_Weapon_WeaponIdle(iItem)
    381. {
    382.     if(!IsCustomItem(iItem))
    383.         return HAM_IGNORED
    384.        
    385.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
    386.    
    387.     if(get_pdata_float(iItem, 48, 4) > 0.0)
    388.         return HAM_SUPERCEDE
    389.    
    390.     static Float:f_Rand; f_Rand = random_float(0.0, 1.0)
    391.        
    392.     if(f_Rand <= 0.75)
    393.     {
    394.         set_pdata_float(iItem, 48, 30.0 / 16.0 * 2.0, 4)
    395.        
    396.         Weapon_SendAnim(iPlayer, iItem, ANIM_IDLE1)
    397.     }
    398.     else if (f_Rand <= 0.875)
    399.     {
    400.         set_pdata_float(iItem, 48, 40.0 / 16.0, 4)
    401.        
    402.         Weapon_SendAnim(iPlayer, iItem, ANIM_FIDGETSWAY)
    403.     }
    404.     else
    405.     {  
    406.         set_pdata_float(iItem, 48, 35.0 / 16.0, 4)
    407.        
    408.         Weapon_SendAnim(iPlayer, iItem, ANIM_FIDGETSHAKE)
    409.     }
    410.    
    411.     return HAM_SUPERCEDE
    412. }
    413.  
    414. public fw_Weapon_PrimaryAttack(iItem)
    415. {
    416.     if(!IsCustomItem(iItem))
    417.         return HAM_IGNORED
    418.        
    419.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
    420.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
    421.        
    422.     if(iClip <= 0)
    423.         return HAM_SUPERCEDE
    424.    
    425.     set_pdata_float(iItem, 38, get_gametime() + HIVEGUN_REGEN_TIME, 4)
    426.    
    427.     iClip--
    428.     set_pdata_int(iItem, 51, iClip, 4)
    429.    
    430.     static Float:Punchangle[3]
    431.     Punchangle[0] = float(random_num(0, 2))
    432.    
    433.     set_pev(iPlayer, pev_punchangle, Punchangle)
    434.    
    435.     set_pdata_float(iItem, 46, HIVEHAND_REFIRE_PRI, 4)
    436.     set_pdata_float(iItem, 47, HIVEHAND_REFIRE_PRI, 4)
    437.     set_pdata_float(iItem, 48, random_float(10.0, 15.0), 4)
    438.    
    439.     static iFlags, szAnimation[64]
    440.    
    441.     if(iFlags & FL_DUCKING)
    442.     {
    443.         formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
    444.     }
    445.     else
    446.     {
    447.         formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
    448.     }
    449.    
    450.     Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
    451.    
    452.     switch(random_num(0, 2))
    453.     {  
    454.         case 0: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    455.         case 1: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    456.         case 2: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    457.     }
    458.    
    459.     static Float:Origin[3]
    460.     Get_Position(iPlayer, 16.0, !get_cvar_num("cl_righthand") ? -8.0 : 8.0, -12.0, Origin)
    461.    
    462.     static HornetEnt; HornetEnt = Hornet_Create(iPlayer, Origin)
    463.    
    464.     if(HornetEnt > 0)
    465.     {
    466.         static Float:vAngle[3], Float:vForward[3], Float:Velocity[3]
    467.        
    468.         pev(iPlayer, pev_v_angle, vAngle)
    469.         angle_vector(vAngle, ANGLEVECTOR_FORWARD, vForward)
    470.        
    471.         xs_vec_mul_scalar(vForward, 300.0, Velocity)
    472.         set_pev(HornetEnt, pev_velocity, Velocity)
    473.        
    474.         Hornet_Spawn(HornetEnt, FIREMODE_TRACK)
    475.     }
    476.    
    477.     return HAM_SUPERCEDE
    478. }
    479.  
    480. public fw_Weapon_SecondaryAttack(iItem)
    481. {
    482.     if(!IsCustomItem(iItem))
    483.         return HAM_IGNORED
    484.        
    485.     static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
    486.     static iClip; iClip = get_pdata_int(iItem, 51, 4)
    487.        
    488.     if(iClip <= 0)
    489.         return HAM_SUPERCEDE
    490.        
    491.     set_pdata_float(iItem, 38, get_gametime() + HIVEGUN_REGEN_TIME, 4) 
    492.        
    493.     iClip--
    494.     set_pdata_int(iItem, 51, iClip, 4)
    495.    
    496.     static Float:Punchangle[3]
    497.     Punchangle[0] = float(random_num(0, 2))
    498.    
    499.     set_pev(iPlayer, pev_punchangle, Punchangle)
    500.    
    501.     set_pdata_float(iItem, 46, HIVEHAND_REFIRE_SEC, 4)
    502.     set_pdata_float(iItem, 47, HIVEHAND_REFIRE_SEC, 4)
    503.     set_pdata_float(iItem, 48, random_float(10.0, 15.0), 4)
    504.    
    505.     static iFlags, szAnimation[64]
    506.    
    507.     if(iFlags & FL_DUCKING)
    508.     {
    509.         formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
    510.     }
    511.     else
    512.     {
    513.         formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
    514.     }
    515.    
    516.     Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
    517.    
    518.     switch(random_num(0, 2))
    519.     {  
    520.         case 0: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    521.         case 1: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    522.         case 2: emit_sound(iPlayer, CHAN_WEAPON, HornetGuns_Sounds[2], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    523.     }
    524.    
    525.     static Float:Right, Float:Up
    526.     static FirePhase; FirePhase = get_pdata_int(iItem, 30, 4)
    527.    
    528.     FirePhase++
    529.     set_pdata_int(iItem, 30, FirePhase, 4)
    530.    
    531.     switch(FirePhase)
    532.     {
    533.         case 1:
    534.         {
    535.             Up = 8.0
    536.             Right = 0.0
    537.         }
    538.         case 2:
    539.         {
    540.             Up = 8.0
    541.             Right = 8.0
    542.         }
    543.         case 3:
    544.         {
    545.             Up = 0.0
    546.             Right = 8.0
    547.         }
    548.         case 4:
    549.         {
    550.             Up = -8.0
    551.             Right = 8.0
    552.         }
    553.         case 5:
    554.         {
    555.             Up = -8.0
    556.             Right = 0.0
    557.         }
    558.         case 6:
    559.         {
    560.             Up = -8.0
    561.             Right = -8.0   
    562.         }
    563.         case 7:
    564.         {
    565.             Up = 0.0
    566.             Right = -8.0   
    567.         }
    568.         case 8:
    569.         {
    570.             Up = 8.0
    571.             Right = -8.0
    572.            
    573.             set_pdata_int(iItem, 30, FirePhase, 4)
    574.         }
    575.     }
    576.    
    577.     static Float:Origin[3]
    578.     Get_Position(iPlayer, 16.0, (!get_cvar_num("cl_righthand") ? -8.0 : 8.0) + Right, -12.0 + Up, Origin)
    579.    
    580.     static HornetEnt; HornetEnt = Hornet_Create(iPlayer, Origin)
    581.    
    582.     if(HornetEnt > 0)
    583.     {
    584.         static Float:vAngle[3], Float:vForward[3], Float:Velocity[3]
    585.        
    586.         pev(iPlayer, pev_v_angle, vAngle)
    587.         angle_vector(vAngle, ANGLEVECTOR_FORWARD, vForward)
    588.        
    589.         xs_vec_mul_scalar(vForward, 1200.0, Velocity)
    590.         set_pev(HornetEnt, pev_velocity, Velocity)
    591.        
    592.         Hornet_Spawn(HornetEnt, FIREMODE_FAST)
    593.     }
    594.    
    595.     return HAM_SUPERCEDE
    596. }
    597.  
    598. Hornet_Create(iPlayer, Float:Origin[3])
    599. {
    600.     static Float:Angles[3]
    601.     pev(iPlayer, pev_v_angle, Angles)
    602.    
    603.     static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
    604.    
    605.     if(!pev_valid(Ent))
    606.         return FM_NULLENT
    607.        
    608.     set_pev(Ent, pev_classname, HORNET_CLASSNAME)
    609.     set_pev(Ent, pev_owner, iPlayer)
    610.    
    611.     set_pev(Ent, pev_origin, Origin)
    612.     set_pev(Ent, pev_angles, Angles)
    613.    
    614.     return Ent
    615. }
    616.  
    617. Hornet_Spawn(HornetEnt, FireMode)
    618. {
    619.     set_pev(HornetEnt, pev_movetype, MOVETYPE_FLY)
    620.     set_pev(HornetEnt, pev_solid, SOLID_BBOX)
    621.     set_pev(HornetEnt, pev_flags, pev(HornetEnt, pev_flags ) | FL_MONSTER)
    622.     set_pev(HornetEnt, pev_health, 1.0)
    623.  
    624.     if(random_num (1, 5) <= 2)
    625.     {
    626.         set_pev(HornetEnt, HG_TYPE_COLOR, HORNET_TYPE_RED)
    627.         set_pev(HornetEnt, HG_FLY_SPEED, HORNET_RED_SPEED)
    628.     }
    629.     else
    630.     {
    631.         set_pev(HornetEnt, HG_TYPE_COLOR, HORNET_TYPE_ORANGE)
    632.         set_pev(HornetEnt, HG_FLY_SPEED, HORNET_ORANGE_SPEED)
    633.     }
    634.  
    635.     if(FireMode == FIREMODE_TRACK)
    636.     {
    637.         set_pev(HornetEnt, HG_STOP_ATTACK, get_gametime() + 3.5)
    638.     }
    639.  
    640.     engfunc(EngFunc_SetModel, HornetEnt, hornet_model)
    641.     engfunc(EngFunc_SetSize, HornetEnt, Float:{-4.0, -4.0, -4.0}, Float:{4.0, 4.0, 4.0})
    642.  
    643.     set_pev(HornetEnt, HG_FIRE_MODE, FIREMODE_DIE)
    644.     set_pev(HornetEnt, HG_THINK_STEP, FireMode == FIREMODE_TRACK ? STATE_STARTTRACK : STATE_STARTDART)
    645.     set_pev(HornetEnt, pev_nextthink, get_gametime() + 0.1)
    646. }
    647.  
    648. public fw_Hornet_Think(Ent)
    649. {
    650.     if(!pev_valid(Ent))
    651.         return
    652.  
    653.     switch(pev(Ent, HG_THINK_STEP))
    654.     {
    655.         case STATE_STARTTRACK:
    656.         {
    657.             IgniteTrail(Ent)
    658.  
    659.             set_pev(Ent, HG_FIRE_MODE, FIREMODE_TRACK)
    660.             set_pev(Ent, HG_THINK_STEP, STATE_TRACKTARGET)
    661.         }
    662.         case STATE_STARTDART:
    663.         {
    664.             IgniteTrail(Ent)
    665.  
    666.             set_pev(Ent, HG_FIRE_MODE, FIREMODE_FAST)
    667.             set_pev(Ent, HG_THINK_STEP, STATE_REMOVEHORNET)
    668.  
    669.             set_pev(Ent, pev_nextthink, get_gametime() + 4.0)
    670.            
    671.             return
    672.         }
    673.         case STATE_TRACKTARGET:
    674.         {
    675.             TrackingTarget(Ent)
    676.         }
    677.         case STATE_REMOVEHORNET:
    678.         {
    679.             RemovingHornet(Ent)
    680.         }
    681.         }
    682.  
    683.         set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
    684. }
    685.  
    686.  
    687. public fw_Hornet_Touch(Ent, Touch)
    688. {
    689.     if(!pev_valid(Ent))
    690.         return
    691.  
    692.     switch(pev(Ent, HG_FIRE_MODE))
    693.     {
    694.         case FIREMODE_TRACK: TrackTouch(Ent, Touch)
    695.         case FIREMODE_FAST: DartTouch(Ent, Touch)
    696.         case FIREMODE_DIE: DieTouch(Ent, Touch)
    697.     }
    698. }
    699.  
    700. RemovingHornet(Ent)
    701. {
    702.     set_pev(Ent, pev_flags, FL_KILLME)
    703. }
    704.  
    705. IgniteTrail(Ent)
    706. {
    707.     message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
    708.     write_byte(TE_BEAMFOLLOW)
    709.     write_short(Ent)      
    710.     write_short(g_SprTrail )
    711.     write_byte(10)
    712.     write_byte(2)
    713.  
    714.     switch(pev(Ent, HG_TYPE_COLOR))
    715.     {
    716.         case HORNET_TYPE_RED:
    717.         {
    718.             write_byte(179)
    719.             write_byte(39)
    720.             write_byte(14)
    721.         }
    722.         case HORNET_TYPE_ORANGE:
    723.         {
    724.             write_byte(255)
    725.             write_byte(128)
    726.             write_byte(0)
    727.         }
    728.         }
    729.  
    730.         write_byte(128)
    731.         message_end()
    732. }
    733.  
    734. TrackingTarget(Ent)
    735. {
    736.     if(IsHornetShouldDie(Ent))
    737.     {
    738.         set_pev(Ent, HG_FIRE_MODE, 0)
    739.         set_pev(Ent, HG_THINK_STEP, STATE_REMOVEHORNET)
    740.  
    741.         set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
    742.     }
    743.  
    744.     static Float:FlightDir[3], Float:DirToEnnemy[3]
    745.     static Float:EnemyLKP[3], Float:Velocity[3]
    746.     static Float:Origin[3], Float:Angles[3]
    747.     static Float:Delta, Float:FlySpeed, Enemy
    748.  
    749.     pev(Ent, pev_velocity, Velocity)
    750.     pev(Ent, pev_origin, Origin)
    751.  
    752.     Enemy = pev(Ent, pev_enemy)
    753.  
    754.     if(!IsEnemyValid(Ent, Enemy))
    755.     {
    756.         set_pev(Ent, pev_enemy, 0)
    757.         Enemy = 0
    758.     }
    759.  
    760.     if(!Enemy)
    761.     {
    762.         Enemy = BestVisibleEnemy(Ent, Origin)
    763.     }
    764.  
    765.     if(Enemy != 0 && FVisible(Ent,Enemy))
    766.     {
    767.         pev(Enemy, pev_origin, EnemyLKP)
    768.         set_pev(Ent, HG_ENEMY_LKP, EnemyLKP)
    769.     }
    770.     else
    771.     {
    772.         pev(Ent, HG_FLY_SPEED, FlySpeed)
    773.         pev(Ent, HG_ENEMY_LKP, EnemyLKP)
    774.  
    775.         VectorMA(EnemyLKP, FlySpeed * 0.1, Velocity)
    776.         set_pev(Ent, HG_ENEMY_LKP, EnemyLKP)
    777.     }
    778.  
    779.     pev(Ent, pev_origin, Origin)
    780.  
    781.     xs_vec_sub(EnemyLKP, Origin, Origin)
    782.     xs_vec_normalize(Origin, DirToEnnemy)
    783.  
    784.     xs_vec_len(Velocity) < 0.1 ? xs_vec_copy(DirToEnnemy, FlightDir) : xs_vec_normalize(Velocity, FlightDir)
    785.     Delta = xs_vec_dot(FlightDir, DirToEnnemy)
    786.  
    787.     if(Delta < 0.5)
    788.     {
    789.         switch(random_num(0, 2))
    790.         {
    791.             case 0: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[6], HORNET_BUZZ_VOLUME, ATTN_NORM, 0, PITCH_NORM)
    792.             case 1: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[7], HORNET_BUZZ_VOLUME, ATTN_NORM, 0, PITCH_NORM)
    793.             case 2: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[8], HORNET_BUZZ_VOLUME, ATTN_NORM, 0, PITCH_NORM)
    794.         }
    795.     }
    796.  
    797.     if(Delta <= 0 && pev(Ent, HG_TYPE_COLOR) == HORNET_TYPE_RED)
    798.     {
    799.         Delta = 0.25
    800.     }
    801.  
    802.     xs_vec_add(FlightDir, DirToEnnemy, DirToEnnemy)
    803.     xs_vec_normalize(DirToEnnemy, Velocity)
    804.  
    805.     switch(pev(Ent, HG_TYPE_COLOR))
    806.     {
    807.         case HORNET_TYPE_RED:
    808.         {
    809.             pev(Ent, HG_FLY_SPEED, FlySpeed)
    810.             xs_vec_mul_scalar(Velocity, FlySpeed * Delta, Velocity)
    811.  
    812.             set_pev(Ent, pev_velocity, Velocity)
    813.             set_pev(Ent, pev_nextthink, get_gametime() + random_float(0.1, 0.3))
    814.         }
    815.         case HORNET_TYPE_ORANGE:
    816.         {
    817.             pev(Ent, HG_FLY_SPEED, FlySpeed)
    818.             xs_vec_mul_scalar(Velocity, FlySpeed, Velocity)
    819.  
    820.             set_pev(Ent, pev_velocity, Velocity)
    821.             set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
    822.         }
    823.     }
    824.  
    825.     engfunc(EngFunc_VecToAngles, Velocity, Angles)
    826.  
    827.     set_pev(Ent, pev_angles, Angles)
    828.     set_pev(Ent, pev_solid, SOLID_BBOX)
    829. }
    830.  
    831. IsHornetShouldDie(Ent)
    832. {
    833.     static Float:LifeTime; pev(Ent, HG_STOP_ATTACK, LifeTime)
    834.  
    835.     if(get_gametime() > LifeTime)
    836.         return 1
    837.        
    838.     return 0
    839. }
    840.    
    841. IsEnemyValid(Ent, Enemy)
    842. {
    843.     if(!pev_valid(Enemy))
    844.                 return 0
    845.        
    846.     static Flags; Flags = pev(Enemy, pev_flags)
    847.        
    848.     if(Flags & (FL_CLIENT | FL_FAKECLIENT))
    849.     {
    850.         if(!is_alive(Enemy) || pev(Enemy, pev_deadflag) > DEAD_NO)
    851.         {
    852.             return 0
    853.         }
    854.         else if(!g_FriendlyFire && IsSameTeam(Enemy, pev(Ent, pev_owner)))
    855.         {
    856.             return 0
    857.         }
    858.     }
    859.     else if(Flags & FL_MONSTER)
    860.     {
    861.         static Float:Health; pev(Enemy, pev_health, Health)
    862.            
    863.         if(Health <= 0)
    864.             return 0
    865.     }
    866.        
    867.     return 1
    868. }
    869.  
    870. BestVisibleEnemy(Ent, Float:Origin[3])
    871. {
    872.     static Target, Flags
    873.        
    874.     static Float:Mins[3], Float:Maxs[3]
    875.     static Float:Absmins[3], Float:Absmaxs[3]
    876.        
    877.     xs_vec_sub(Origin, Float:{HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS}, Mins)
    878.     xs_vec_add(Origin, Float:{HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS, HORNET_SEARCH_RADIUS}, Maxs)
    879.  
    880.     for(Target = 1; Target < g_MaxEntities; Target++)
    881.     {
    882.         if(!pev_valid(Target))
    883.             continue
    884.            
    885.         Flags = pev(Target, pev_flags)
    886.  
    887.         if(!(Flags & (FL_CLIENT | FL_FAKECLIENT | FL_MONSTER)))
    888.             continue
    889.            
    890.         if(Flags & FL_MONSTER)
    891.         {
    892.             if(IsHornet(Target))
    893.                 continue
    894.         }
    895.            
    896.         if(Target == Ent)
    897.             continue
    898.            
    899.         pev(Target, pev_absmin, Absmins)
    900.         pev(Target, pev_absmax, Absmaxs)
    901.            
    902.         if(Mins[0] > Absmaxs[0] || Mins[1] > Absmaxs[1] || Mins[2] > Absmaxs[2] || Maxs[0] < Absmins[0] || Maxs[1] < Absmins[1] || Maxs[2] < Absmins[2])
    903.             continue
    904.            
    905.         if(IsEnemyValid(Ent, Target))
    906.         {
    907.             if(FInViewCone(Ent, Target) && !(Flags & FL_NOTARGET) && FVisible(Ent, Target))
    908.             {
    909.                 set_pev(Ent, pev_enemy, Target)
    910.                 return Target
    911.             }
    912.         }
    913.         }
    914.  
    915.         return 0
    916. }
    917.  
    918. FVisible(Hornet, Other)
    919. {
    920.     if(!pev_valid(Hornet) || pev(Other, pev_flags) & FL_NOTARGET)
    921.         return 0
    922.        
    923.     static LookerWLevel, TargetWLevel
    924.  
    925.     LookerWLevel = pev(Hornet, pev_waterlevel)
    926.     TargetWLevel = pev(Other , pev_waterlevel)
    927.  
    928.     if((LookerWLevel != HEAD_IN_WATER && TargetWLevel == HEAD_IN_WATER ) || (LookerWLevel == HEAD_IN_WATER && TargetWLevel == NOT_IN_WATER))
    929.         return 0
    930.        
    931.     static Float:LookerOrigin[3], Float:TargetOrigin[3]
    932.  
    933.     EyePosition(Hornet, LookerOrigin)
    934.     EyePosition(Other, TargetOrigin)
    935.  
    936.     engfunc(EngFunc_TraceLine, LookerOrigin, TargetOrigin, IGNORE_MONSTERS, Hornet, 0)
    937.  
    938.     static Float:Fraction
    939.     get_tr2(0, TR_flFraction, Fraction)
    940.  
    941.     if(Fraction == 1.0)
    942.         return 1
    943.        
    944.     return 0
    945. }
    946.  
    947.  
    948. EyePosition(Ent, Float:Origin[3])
    949. {
    950.     static Float:ViewOfs[3];
    951.  
    952.     pev(Ent, pev_origin, Origin)
    953.     pev(Ent, pev_view_ofs, ViewOfs)
    954.  
    955.     xs_vec_add(Origin, ViewOfs, Origin)
    956. }
    957.  
    958. VectorMA(Float:vOutput[], Float:Scale, Float:vMult[])
    959. {
    960.     vOutput[0] = vOutput[0] + vMult[0] * Scale
    961.     vOutput[1] = vOutput[1] + vMult[1] * Scale
    962.     vOutput[2] = vOutput[2] + vMult[2] * Scale
    963. }    
    964.  
    965. IsSameTeam(FirstId, SecondId)
    966. {
    967.     return (get_pdata_int(FirstId, 114, 5) == get_pdata_int(SecondId, 114, 5))
    968. }
    969.  
    970. IsHornet(Ent)
    971. {
    972.     if(!pev_valid(Ent))
    973.         return 0
    974.        
    975.     static Classname[32]; pev(Ent, pev_classname, Classname, charsmax(Classname))
    976.  
    977.     if(!equali(Classname, HORNET_CLASSNAME))
    978.         return 0
    979.        
    980.     return 1
    981. }
    982.  
    983. FInViewCone(Hornet, Other)
    984. {
    985.     static Float:Angles[3], Float:Dot
    986.     static Float:HOrigin[3], Float:Origin[3]
    987.        
    988.     pev(Hornet, pev_angles, Angles)
    989.  
    990.     engfunc(EngFunc_MakeVectors, Angles)
    991.     global_get(glb_v_forward, Angles)
    992.  
    993.     Angles[2] = 0.0
    994.  
    995.     pev(Hornet, pev_origin, HOrigin)
    996.     pev(Other, pev_origin, Origin)
    997.  
    998.     xs_vec_sub(Origin, HOrigin, Origin)
    999.     Origin[2] = 0.0
    1000.  
    1001.     xs_vec_normalize(Origin, Origin)
    1002.     Dot = xs_vec_dot(Origin, Angles)
    1003.  
    1004.     if(Dot > HORNET_FOV)
    1005.         return 1
    1006.    
    1007.     return 0
    1008. }
    1009.  
    1010. DartTouch(Ent, Other)
    1011. {
    1012.     DieTouch(Ent, Other)
    1013. }
    1014.  
    1015. TrackTouch(Ent, Other)
    1016. {
    1017.     if(Other == pev(Ent, pev_owner))
    1018.     {
    1019.         set_pev(Ent, HG_FIRE_MODE, 0)
    1020.         set_pev(Ent, pev_solid, SOLID_NOT)
    1021.  
    1022.         return
    1023.     }
    1024.  
    1025.     if(!Other || IsHornet(Other))
    1026.     {
    1027.         static Float:Velocity[3]
    1028.         static Float:Origin[3]
    1029.         static Float:FlySpeed
    1030.  
    1031.         pev(Ent, pev_velocity, Velocity)
    1032.         xs_vec_normalize(Velocity, Velocity)
    1033.  
    1034.         Velocity[0] *= -1.0
    1035.         Velocity[1] *= -1.0
    1036.  
    1037.         pev(Ent, pev_origin, Origin)
    1038.         VectorMA(Origin, 4.0, Velocity)
    1039.  
    1040.         if(xs_vec_len(Origin) > 0)
    1041.         {
    1042.             set_pev(Ent, pev_origin, Origin)
    1043.         }
    1044.  
    1045.         pev(Ent, HG_FLY_SPEED, FlySpeed)
    1046.         xs_vec_mul_scalar(Velocity, FlySpeed, Velocity)
    1047.  
    1048.         if(xs_vec_len(Velocity) > 0)
    1049.         {
    1050.             set_pev(Ent, pev_velocity, Velocity)
    1051.         }
    1052.  
    1053.         return
    1054.         }
    1055.        
    1056.         DieTouch(Ent, Other)
    1057. }
    1058.  
    1059. DieTouch(Ent, Other)
    1060. {
    1061.     static FireMode; FireMode = pev(Ent, HG_FIRE_MODE)
    1062.    
    1063.     if(FireMode == FIREMODE_TRACK)
    1064.     {
    1065.         if(CanTakeDamage(Other, FireMode))
    1066.         {
    1067.             switch(random_num(0, 2))
    1068.             {
    1069.                 case 0: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[3], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    1070.                 case 1: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[4], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    1071.                 case 2: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[5], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    1072.             }
    1073.  
    1074.             ExecuteHamB(Ham_TakeDamage, Other, Ent, pev(Ent, pev_owner), HORNET_DAMAGE, DMG_BULLET | DMG_NEVERGIB)
    1075.         }
    1076.     }
    1077.     else
    1078.     {
    1079.         if(CanTakeDamage(Other, FireMode))
    1080.         {
    1081.             if(pev(Other, pev_flags) & (FL_CLIENT | FL_FAKECLIENT | FL_MONSTER))
    1082.             {
    1083.                 switch(random_num(0, 2))
    1084.                 {
    1085.                     case 0: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[3], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    1086.                     case 1: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[4], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    1087.                     case 2: emit_sound(Ent, CHAN_VOICE, HornetGuns_Sounds[5], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
    1088.                 }
    1089.             }
    1090.  
    1091.             ExecuteHamB(Ham_TakeDamage, Other, Ent, pev(Ent, pev_owner), HORNET_DAMAGE, DMG_BULLET | DMG_NEVERGIB)
    1092.         }
    1093.     }
    1094.    
    1095.     set_pev(Ent, pev_modelindex, 0)
    1096.     set_pev(Ent, pev_solid, SOLID_NOT)
    1097.  
    1098.     set_pev(Ent, HG_THINK_STEP, STATE_REMOVEHORNET)
    1099.     set_pev(Ent, pev_nextthink, get_gametime() + 1.0)
    1100. }
    1101.  
    1102. CanTakeDamage(Other, FireMode)
    1103. {
    1104.     static Float:TakeDamage
    1105.     pev(Other, pev_takedamage, TakeDamage)
    1106.  
    1107.     if(FireMode == FIREMODE_TRACK)
    1108.     {
    1109.         if(pev(Other, pev_flags) & (FL_CLIENT | FL_FAKECLIENT | FL_MONSTER) && TakeDamage != DAMAGE_NO)
    1110.             return 1
    1111.     }
    1112.     else
    1113.     {
    1114.         if(TakeDamage != DAMAGE_NO)
    1115.             return 1
    1116.     }
    1117.    
    1118.     return 0
    1119. }
    1120.    
    1121. //**********************************************
    1122. //* Safety Functions                       *
    1123. //**********************************************
    1124. public Register_SafetyFunc()
    1125. {
    1126.     RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
    1127.     RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
    1128. }
    1129.  
    1130. public Register_SafetyFuncBot(iPlayer)
    1131. {
    1132.     RegisterHamFromEntity(Ham_Spawn, iPlayer, "fw_Safety_Spawn_Post", 1)
    1133.     RegisterHamFromEntity(Ham_Killed, iPlayer, "fw_Safety_Killed_Post", 1)
    1134. }
    1135.  
    1136. public Safety_Connected(iPlayer)
    1137. {
    1138.     Set_BitVar(g_IsConnected, iPlayer)
    1139.     UnSet_BitVar(g_IsAlive, iPlayer)
    1140. }
    1141.  
    1142. public Safety_Disconnected(iPlayer)
    1143. {
    1144.     UnSet_BitVar(g_IsConnected, iPlayer)
    1145.     UnSet_BitVar(g_IsAlive, iPlayer)
    1146. }
    1147.  
    1148. public fw_Safety_Spawn_Post(iPlayer)
    1149. {
    1150.     if(!is_user_alive(iPlayer))
    1151.         return
    1152.        
    1153.     Set_BitVar(g_IsAlive, iPlayer)
    1154. }
    1155.  
    1156. public fw_Safety_Killed_Post(iPlayer)
    1157. {
    1158.     UnSet_BitVar(g_IsAlive, iPlayer)
    1159. }
    1160.  
    1161. public is_connected(iPlayer)
    1162. {
    1163.     if(!(1 <= iPlayer <= 32))
    1164.         return 0
    1165.     if(!Get_BitVar(g_IsConnected, iPlayer))
    1166.         return 0
    1167.  
    1168.     return 1
    1169. }
    1170.  
    1171. public is_alive(iPlayer)
    1172. {
    1173.     if(!is_connected(iPlayer))
    1174.         return 0
    1175.     if(!Get_BitVar(g_IsAlive, iPlayer))
    1176.         return 0
    1177.        
    1178.     return 1
    1179. }
    1180.  
    1181. //**********************************************
    1182. //* Create and check our custom weapon.        *
    1183. //**********************************************
    1184. IsCustomItem(iItem)
    1185. {
    1186.     return (pev(iItem, pev_impulse) == g_iszWeaponKey)
    1187. }
    1188.  
    1189. Weapon_Create(Float: Origin[3] = {0.0, 0.0, 0.0}, Float: Angles[3] = {0.0, 0.0, 0.0})
    1190. {
    1191.     new iWeapon
    1192.  
    1193.     static iszAllocStringCached
    1194.     if (iszAllocStringCached || (iszAllocStringCached = engfunc(EngFunc_AllocString, WEAPON_BASE)))
    1195.     {
    1196.         iWeapon = engfunc(EngFunc_CreateNamedEntity, iszAllocStringCached)
    1197.     }
    1198.    
    1199.     if(!IsValidPev(iWeapon))
    1200.         return FM_NULLENT
    1201.    
    1202.     dllfunc(DLLFunc_Spawn, iWeapon)
    1203.     set_pev(iWeapon, pev_origin, Origin)
    1204.  
    1205.     set_pdata_int(iWeapon, 51, HIVEHAND_AMMO, 4)
    1206.     set_pdata_int(iWeapon, 30, 0, 4)
    1207.    
    1208.     set_pev(iWeapon, pev_impulse, g_iszWeaponKey)
    1209.     set_pev(iWeapon, pev_angles, Angles)
    1210.    
    1211.     engfunc(EngFunc_SetModel, iWeapon, w_model)
    1212.  
    1213.     return iWeapon
    1214. }
    1215.  
    1216. Weapon_Give(iPlayer)
    1217. {
    1218.     if(!IsValidPev(iPlayer))
    1219.     {
    1220.         return FM_NULLENT
    1221.     }
    1222.    
    1223.     new iWeapon, Float: vecOrigin[3]
    1224.     pev(iPlayer, pev_origin, vecOrigin)
    1225.    
    1226.     if((iWeapon = Weapon_Create(vecOrigin)) != FM_NULLENT)
    1227.     {
    1228.         Player_DropWeapons(iPlayer, ExecuteHamB(Ham_Item_ItemSlot, iWeapon))
    1229.        
    1230.         g_bHaveItem[iPlayer] = true
    1231.        
    1232.         set_pev(iWeapon, pev_spawnflags, pev(iWeapon, pev_spawnflags) | SF_NORESPAWN)
    1233.         dllfunc(DLLFunc_Touch, iWeapon, iPlayer)
    1234.        
    1235.         return iWeapon
    1236.     }
    1237.    
    1238.     return FM_NULLENT
    1239. }
    1240.  
    1241. Player_DropWeapons(iPlayer, iSlot)
    1242. {
    1243.     new szWeaponName[32], iItem = get_pdata_cbase(iPlayer, 367 + iSlot, 5)
    1244.  
    1245.     while(IsValidPev(iItem))
    1246.     {
    1247.         pev(iItem, pev_classname, szWeaponName, charsmax(szWeaponName))
    1248.         engclient_cmd(iPlayer, "drop", szWeaponName)
    1249.  
    1250.         iItem = get_pdata_cbase(iItem, 42, 4)
    1251.     }
    1252. }
    1253.  
    1254. //**********************************************
    1255. //* Set Animations.                            *
    1256. //**********************************************
    1257. stock Weapon_SendAnim(iPlayer, iItem, iAnim)
    1258. {
    1259.     static i, iCount, iSpectator, aSpectators[32]
    1260.    
    1261.     set_pev(iPlayer, pev_weaponanim, iAnim)
    1262.  
    1263.     message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iPlayer)
    1264.     write_byte(iAnim)
    1265.     write_byte(pev(iItem, pev_body))
    1266.     message_end()
    1267.    
    1268.     if(IsObserver(iPlayer))
    1269.         return
    1270.    
    1271.     get_players(aSpectators, iCount, "bch")
    1272.  
    1273.     for(i = 0; i < iCount; i++)
    1274.     {
    1275.         iSpectator = aSpectators[i]
    1276.        
    1277.         if(IsObserver(iSpectator) != OBS_IN_EYE || pev(iSpectator, pev_iuser2) != iPlayer)
    1278.             continue
    1279.        
    1280.         set_pev(iSpectator, pev_weaponanim, iAnim)
    1281.  
    1282.         message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iSpectator)
    1283.         write_byte(iAnim)
    1284.         write_byte(pev(iItem, pev_body))
    1285.         message_end()
    1286.     }
    1287. }
    1288.  
    1289. stock Player_SetAnimation(iPlayer, szAnim[])
    1290. {
    1291.     #define ACT_RANGE_ATTACK1   28
    1292.    
    1293.     // Linux extra offsets
    1294.     #define extra_offset_animating   4
    1295.     #define extra_offset_player 5
    1296.    
    1297.     // CBaseAnimating
    1298.     #define m_flFrameRate      36
    1299.     #define m_flGroundSpeed      37
    1300.     #define m_flLastEventCheck   38
    1301.     #define m_fSequenceFinished   39
    1302.     #define m_fSequenceLoops   40
    1303.    
    1304.     // CBaseMonster
    1305.     #define m_Activity      73
    1306.     #define m_IdealActivity      74
    1307.    
    1308.     // CBasePlayer
    1309.     #define m_flLastAttackTime   220
    1310.    
    1311.     new iAnimDesired, Float:flFrameRate, Float:flGroundSpeed, bool:bLoops
    1312.      
    1313.     if((iAnimDesired = lookup_sequence(iPlayer, szAnim, flFrameRate, bLoops, flGroundSpeed)) == -1)
    1314.     {
    1315.         iAnimDesired = 0
    1316.     }
    1317.    
    1318.     static Float:flGametime; flGametime = get_gametime()
    1319.  
    1320.     set_pev(iPlayer, pev_frame, 0.0)
    1321.     set_pev(iPlayer, pev_framerate, 1.0)
    1322.     set_pev(iPlayer, pev_animtime, flGametime)
    1323.     set_pev(iPlayer, pev_sequence, iAnimDesired)
    1324.    
    1325.     set_pdata_int(iPlayer, m_fSequenceLoops, bLoops, extra_offset_animating)
    1326.     set_pdata_int(iPlayer, m_fSequenceFinished, 0, extra_offset_animating)
    1327.    
    1328.     set_pdata_float(iPlayer, m_flFrameRate, flFrameRate, extra_offset_animating)
    1329.     set_pdata_float(iPlayer, m_flGroundSpeed, flGroundSpeed, extra_offset_animating)
    1330.     set_pdata_float(iPlayer, m_flLastEventCheck, flGametime , extra_offset_animating)
    1331.    
    1332.     set_pdata_int(iPlayer, m_Activity, ACT_RANGE_ATTACK1, extra_offset_player)
    1333.     set_pdata_int(iPlayer, m_IdealActivity, ACT_RANGE_ATTACK1, extra_offset_player)  
    1334.     set_pdata_float(iPlayer, m_flLastAttackTime, flGametime , extra_offset_player)
    1335. }
    1336.  
    1337. //**********************************************
    1338. //* Some useful stocks.                        *
    1339. //**********************************************
    1340. stock Get_Position(iPlayer, Float:forw, Float:right, Float:up, Float:vStart[])
    1341. {
    1342.     new Float:Origin[3], Float:Angles[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
    1343.    
    1344.     pev(iPlayer, pev_origin, Origin)
    1345.     pev(iPlayer, pev_view_ofs,vUp) //for player
    1346.     xs_vec_add(Origin, vUp, Origin)
    1347.     pev(iPlayer, pev_v_angle, Angles) // if normal entity ,use pev_angles
    1348.    
    1349.     angle_vector(Angles, ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
    1350.     angle_vector(Angles, ANGLEVECTOR_RIGHT, vRight)
    1351.     angle_vector(Angles, ANGLEVECTOR_UP, vUp)
    1352.    
    1353.     vStart[0] = Origin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    1354.     vStart[1] = Origin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    1355.     vStart[2] = Origin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
    1356. }
    1357.  
    1358. stock get_speed_vector(Float:Origin1[3], Float:Origin2[3], Float:Speed, Float:NewVelocity[3])
    1359. {
    1360.     NewVelocity[0] = Origin2[0] - Origin1[0]
    1361.     NewVelocity[1] = Origin2[1] - Origin1[1]
    1362.     NewVelocity[2] = Origin2[2] - Origin1[2]
    1363.     new Float:num = floatsqroot(Speed*Speed / (NewVelocity[0]*NewVelocity[0] + NewVelocity[1]*NewVelocity[1] + NewVelocity[2]*NewVelocity[2]))
    1364.     NewVelocity[0] *= num
    1365.     NewVelocity[1] *= num
    1366.     NewVelocity[2] *= num
    1367.    
    1368.     return 1
    1369. }
    1370.  
    1371. stock get_true_number(bool:g_bArray[])
    1372. {
    1373.     new iTrueCount
    1374.    
    1375.     for(new i = 0; i <= charsmax(g_bArray[]); i++)
    1376.     {
    1377.         if (g_bArray[i])
    1378.             iTrueCount++
    1379.     }
    1380.    
    1381.     return iTrueCount
    1382. }
You don't know? Learn and you will know.

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests