New Extra Items

Unpaid Requests, Public Plugins
Post Reply
Mystic Viper
Member
Member
Romania
Posts: 27
Joined: 6 Months Ago
Has thanked: 0
Been thanked: 0
Contact:

New Extra Items

#1

Post by Mystic Viper » 2 Months Ago

I want to compile this extra items with mode and make just for vips in shop
Attachments
Advanced_Crossbow.sma
(18.63 KiB) Downloaded 8 times
Advanced_Crossbow.sma
(18.63 KiB) Downloaded 8 times
m32_venom.sma
(20.75 KiB) Downloaded 8 times
m32_venom.sma
(20.75 KiB) Downloaded 8 times
starchaserar.sma
(26.89 KiB) Downloaded 8 times
starchaserar.sma
(26.89 KiB) Downloaded 8 times
DualChinese_Handgun.sma
(18.44 KiB) Downloaded 8 times
DualChinese_Handgun.sma
(18.44 KiB) Downloaded 8 times
CSO_PoisonGun.sma
(18.18 KiB) Downloaded 9 times
CSO_PoisonGun.sma
(18.18 KiB) Downloaded 9 times

User avatar
Muhammet20
Senior Member
Senior Member
Turkey
Posts: 101
Joined: 7 Months Ago
Has thanked: 10 times
Been thanked: 1 time
Contact:

#2

Post by Muhammet20 » 2 Months Ago

Advanced Crossbow :
_______________________

Code: Select all

#include <engine>
#include <fakemeta_util>
#include <cstrike>
#include <xs>
#include <fun>
#include <zombie_escape>
#include <ze_vip>

#define PLUGIN "[CSO] Advanced Crossbow"
#define VERSION "1.0"
#define AUTHOR "Dias"

#define DAMAGE 45
#define CLIP 50
#define BPAMMO 200
#define TIME_RELOAD 3.5
#define TIME_SHOOT 0.125

#define CSW_CRBOW CSW_M4A1
#define weapon_crbow "weapon_m4a1"

#define BOLT_SPEED 2000
#define BOLT_LIVETIME 10.0

#define MODEL_V "models/v_crossbowex.mdl"
#define MODEL_P "models/p_crossbowex.mdl"
#define MODEL_W "models/w_crossbowex.mdl"
#define MODEL_S "models/s_crossbowex.mdl"

#define MODEL_W_OLD "models/w_m4a1.mdl"
#define BOLT_CLASSNAME "dias_der_gott"

new const WeaponSounds[6][] =
{
	"weapons/crossbow-1.wav",
	"weapons/crossbowex_draw.wav",
	"weapons/crossbow_foley1.wav",
	"weapons/crossbow_foley2.wav",
	"weapons/crossbow_foley3.wav",
	"weapons/crossbow_foley4.wav"
}

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

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

const pev_user = pev_iuser1
const pev_time = pev_fuser1
const m_iLastHitGroup = 75

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

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

new name = "Advanced Crossbow"
new cost = 7
new teams = 0
new item

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Safety
	Register_SafetyFunc()
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_SetModel, "fw_SetModel")	
	
	register_think(BOLT_CLASSNAME, "fw_SpearThink")
	register_touch(BOLT_CLASSNAME, "*", "fw_SpearTouch")
	
	// Ham
	RegisterHam(Ham_Item_Deploy, weapon_crbow, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_crbow, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_crbow, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_crbow, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_crbow, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_crbow, "fw_Weapon_Reload_Post", 1)	
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	g_CvarFriendlyFire = get_cvar_pointer("mp_friendlyfire")
	
	item = ze_register_item(name,cost,teams)
}
public ze_select_item_pre(id,itemid)
{
	// This not our item?
    if (itemid != item)
        return ZE_ITEM_AVAILABLE
   
	// Available for V.I.P only, So don't show it for others
   if (!(ze_get_vip_flags(id) & VIP_A))
        return ZE_ITEM_DONT_SHOW
	
	// Available for Humans only, So don't show it for zombies
   if (ze_is_user_zombie(id)
        return ZE_ITEM_DONT_SHOW
   
	// Finally return that it's available
    return ZE_ITEM_AVAILABLE
}
public ze_select_item_post(id,itemid)
{
	if(itemid != item)
		return
		
	Get_DartPistol(id)
}
public plugin_precache()
{
	precache_model(MODEL_V)
	precache_model(MODEL_P)
	precache_model(MODEL_W)
	precache_model(MODEL_S)

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

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

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

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

public client_disconnect(id)
{
	Safety_Disconnected(id)
}

public Get_DartPistol(id)
{
	Set_BitVar(g_Had_DartPistol, id)
	give_item(id, weapon_crbow)
	
	// Clip & Ammo
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_CRBOW)
	if(!pev_valid(Ent)) return
	
	cs_set_weapon_ammo(Ent, CLIP)
	cs_set_user_bpammo(id, CSW_CRBOW, BPAMMO)
	
	cs_set_weapon_silen(Ent, 0, 0)
}

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

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

	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_CRBOW)
	if(!pev_valid(Ent)) return
	
	set_pdata_float(Ent, 46, TIME_SHOOT, 4)
	set_pdata_float(Ent, 47, TIME_SHOOT, 4)
}

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

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

	Set_WeaponAnim(invoker, ANIME_SHOOT)
	emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
	
	Create_Dart(invoker)
	
	return FMRES_IGNORED
}

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

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_alive(id))
		return FMRES_IGNORED
	if(get_user_weapon(id) != CSW_CRBOW || !Get_BitVar(g_Had_DartPistol, id))
		return FMRES_IGNORED
		
	static Button; Button = get_uc(uc_handle, UC_Buttons)	
	
	if(Button & IN_ATTACK2)
	{
		static Float:Time; Time = get_pdata_float(id, 83, 5)
		if(Time > 0.0) return FMRES_IGNORED
		
		if(cs_get_user_zoom(id) != CS_SET_FIRST_ZOOM) 
		{
			cs_set_user_zoom(id, CS_SET_FIRST_ZOOM, 1)
			set_pev(id, pev_viewmodel2, "")
		} else {
			cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
			set_pev(id, pev_viewmodel2, MODEL_V)
		}
		
		Time = 0.25
		set_pdata_float(id, 83, Time, 5)
	}
	
	return FMRES_HANDLED
}


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

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

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

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

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

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

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

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


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

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

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

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

public fw_SpearThink(Ent)
{
	if(!pev_valid(Ent))
		return
	if(pev(Ent, pev_flags) == FL_KILLME)
		return

	if(pev(Ent, pev_time) <= get_gametime())
		set_pev(Ent, pev_flags, FL_KILLME)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}

public fw_SpearTouch(Ent, Touched)
{
	if(!pev_valid(Ent))
		return
	
	static id; id = pev(Ent, pev_user)
	if(!is_connected(id))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
		
		return
	}
	if(pev(Ent, pev_movetype) == MOVETYPE_NONE)
		return
	
	if(is_alive(Touched))
	{
		if(id == Touched)
			return
		if(!get_pcvar_num(g_CvarFriendlyFire))
		{
			if(cs_get_user_team(id) == cs_get_user_team(Touched))
				return
		}
		
		ExecuteHamB(Ham_TakeDamage, Touched, 0, id, float(DAMAGE), DMG_BULLET)
		
		set_pev(Ent, pev_movetype, MOVETYPE_NONE)
		set_pev(Ent, pev_time, get_gametime())
		set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
	} else {
		set_pev(Ent, pev_movetype, MOVETYPE_NONE)
		set_pev(Ent, pev_time, get_gametime() + 1.5)
	}
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

wait i will convert others
Don't Say This Is Impossible , Because Nothing Impossible.

User avatar
Muhammet20
Senior Member
Senior Member
Turkey
Posts: 101
Joined: 7 Months Ago
Has thanked: 10 times
Been thanked: 1 time
Contact:

#3

Post by Muhammet20 » 2 Months Ago

m32 venom :
___________________

Code: Select all

#include <engine>
#include <fakemeta_util>
#include <fun>
#include <xs>
#include <cstrike>
#include <zombie_escape>
#include <ze_vip>

#define M32_CLIP 6
#define M32_BPAMMO 54
#define M32_DAMAGE_EXPLOSION 1.0
#define M32_DAMAGE_POISON 5.0
#define M32_RANGE 120.0

#define MODEL_V "models/v_m32venom.mdl"
#define MODEL_P "models/p_m32venom.mdl"
#define MODEL_W "models/w_m32venom.mdl"
 
#define GRENADE_MODEL "models/grenade.mdl"
 
#define ENG_NULLENT -1
#define EV_INT_WEAPONKEY EV_INT_impulse
#define M32_WEAPONKEY 10921831

#define weapon_m32venom "weapon_m3"
#define weapon_event "events/m3.sc"
#define weapon_old "models/w_m3.mdl"
#define CSW_BASE CSW_M3

// Attachment

#define MAX_CHANNEL 4
#define ATTACHMENT_CLASSNAME "venom_hit"
#define TASK_RELOADING 1335+19

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

new g_MyAttachment[33][MAX_CHANNEL+1]

new const FIRE_SOUND[][] = { "weapons/m32venom-1.wav" }
new const GRENADE_TRAIL[] = "sprites/laserbeam.spr"
new const GRENADE_EXPLOSION[] = "sprites/ef_m32_poison.spr"

const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_P90)|(1<<CSW_P90)|(1<<CSW_P90)|(1<<CSW_SG550)|(1<<CSW_P90)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_P90)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_M3)|(1<<CSW_P90)|(1<<CSW_AK47)|(1<<CSW_P90)

new in_zoom[33], g_reload[33], sTrail, sExplo, g_has_M32[33], getzoom[33]
new g_MsgWeaponList, g_MaxPlayers, g_orig_event_M32

new item
new item_name = "M32 Venom"
new item_cost = 7
new item_teams = 0
public plugin_init()
{
	register_plugin("m32_venom", "1.0", "Dias Remade Mellowzy")
	
	register_event("CurWeapon","CurrentWeapon","be","1=1")
	
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	
	register_think("venom_poison", "PoisonThink")
	register_think(ATTACHMENT_CLASSNAME, "fw_Think")
	
	RegisterHam(Ham_Item_AddToPlayer, weapon_m32venom, "fw_AddToPlayer", 1)
	RegisterHam(Ham_Item_Deploy,weapon_m32venom, "fw_Item_Deploy_Post", 1)
	RegisterHam(Ham_Weapon_Reload, weapon_m32venom, "fw_r")
	RegisterHam(Ham_Weapon_Reload, weapon_m32venom, "fw_reload")
	
	register_message(get_user_msgid("DeathMsg"), "Message_DeathMsg")
	
	g_MsgWeaponList = get_user_msgid("WeaponList")
	g_MaxPlayers = get_maxplayers()
	
	item = ze_register_item(item_name,item_cost,item_teams)
	register_clcmd("weapon_m32venom", "Hook_Select")
}
public ze_select_item_pre(id,itemid)
{
	// This not our item?
    if (itemid != item)
        return ZE_ITEM_AVAILABLE
   
	// Available for V.I.P only, So don't show it for others
   if (!(ze_get_vip_flags(id) & VIP_A))
        return ZE_ITEM_DONT_SHOW
	
	// Available for Humans only, So don't show it for zombies
   if (ze_is_user_zombie(id)
        return ZE_ITEM_DONT_SHOW
   
	// Finally return that it's available
    return ZE_ITEM_AVAILABLE
}
public ze_select_item_post(id,itemid)
{
	if(itemid != item)
		return
		
	Get_M32_Venom(id)
}	
public plugin_precache()
{
	precache_model(MODEL_V)
	precache_model(MODEL_P)
	precache_model(MODEL_W)
	precache_model(GRENADE_MODEL)
	precache_sound(FIRE_SOUND[0])	
	
	sTrail = precache_model(GRENADE_TRAIL)
	sExplo = precache_model(GRENADE_EXPLOSION)
	
	precache_model("sprites/ef_smoke_poison.spr")
	precache_model("sprites/head_poison.spr")
	
	// Extra Sound
	precache_sound("weapons/M32_after_reload.wav")
	precache_sound("weapons/M32_insert.wav")
	precache_sound("weapons/M32_start_reload.wav")
	precache_sound("weapons/m32venom_exp.wav")
	
	// WeaponList
	precache_generic("sprites/weapon_m32venom.txt")
	precache_generic("sprites/640hud177.spr")
	precache_generic("sprites/640hud18.spr")

	register_forward(FM_PrecacheEvent, "fwPrecacheEvent_Post", 1)
}

public Hook_Select(id)
{
	engclient_cmd(id, weapon_m32venom)
	return PLUGIN_HANDLED
}

public fwPrecacheEvent_Post(type, const name[])
{
	if (equal(weapon_event, name))
	{
		g_orig_event_M32 = get_orig_retval()
		return FMRES_HANDLED
	}
	
	return FMRES_IGNORED
}
public plugin_natives()
{
	register_native("get_m32venom", "Get_M32_Venom", 1)
	register_native("refill_m32venom", "Refill_M32_Venom", 1)
	register_native("remove_m32venom", "Remove_M32_Venom", 1)
}	
public Get_M32_Venom(id)
{
	if(!is_user_alive(id))return
	drop_weapons(id, 1)
	new iWep2 = give_item(id,weapon_m32venom)
	if(iWep2 > 0)
	{
		cs_set_weapon_ammo(iWep2, M32_CLIP)
		cs_set_user_bpammo(id, CSW_BASE, M32_BPAMMO)
	}

	if(in_zoom[id])
	{ 
		cs_set_user_zoom(id, CS_RESET_ZOOM, 1)
		in_zoom[id] = 0
	}
	
	message_begin(MSG_ONE_UNRELIABLE, g_MsgWeaponList, {0,0,0}, id)
	write_string("weapon_m32venom")
	write_byte(5)
	write_byte(32)
	write_byte(-1)
	write_byte(-1)
	write_byte(0)
	write_byte(5)
	write_byte(21)
	write_byte(0)
	message_end()
	
	Set_Player_Zoom(id, 0)
	getzoom[id] = 0
	g_reload[id] = 0
	g_has_M32[id] = true
}
public Refill_M32_Venom(id)
{
	if(!is_user_alive(id)) return
	if(cs_get_user_bpammo(id, CSW_BASE) < M32_BPAMMO)
		cs_set_user_bpammo(id, CSW_BASE, M32_BPAMMO)
		else return
}
public Remove_M32_Venom(id)
{
	g_has_M32[id] = false
	Set_Player_Zoom(id, 0)
	getzoom[id] = 0
	remove_task(id+TASK_RELOADING)
}
public fw_AddToPlayer(M32, id)
{
	if(!pev_valid(M32) || !is_user_alive(id)) return
        
	if(pev(M32, pev_impulse) == M32_WEAPONKEY)
	{
		g_has_M32[id] = true
		g_reload[id] = 0
		
		Set_Player_Zoom(id, 0)
		set_pev(M32, pev_impulse, 0)
		
		message_begin(MSG_ONE_UNRELIABLE, g_MsgWeaponList, {0,0,0}, id)
		write_string(g_has_M32[id] == 1 ? "weapon_m32venom" : weapon_m32venom)
		write_byte(5)
		write_byte(32)
		write_byte(-1)
		write_byte(-1)
		write_byte(0)
		write_byte(5)
		write_byte(21)
		write_byte(0)
		message_end()
	}
}
public fw_SetModel(ent, const model[])
{
	if(!pev_valid(ent))
		return FMRES_IGNORED
	
	static szClassName[33]
	entity_get_string(ent, EV_SZ_classname, szClassName, charsmax(szClassName))
	
	if(!equal(szClassName, "weaponbox"))
		return FMRES_IGNORED
	
	static id
	id = pev(ent, pev_owner)
	
	
	if(equal(model, weapon_old))
	{
		static Wpn
		Wpn = find_ent_by_owner(-1, weapon_m32venom, ent)
		
		if(!pev_valid(Wpn))
			return FMRES_IGNORED;
		
		if(g_has_M32[id])
		{
			set_pev(Wpn, pev_impulse, M32_WEAPONKEY)
			engfunc(EngFunc_SetModel, ent, MODEL_W)
			g_has_M32[id] = false
			g_reload[id] = 0
			getzoom[id] = 0
			Set_Player_Zoom(id, 0)
			
			return FMRES_SUPERCEDE
		}
	}
	
	return FMRES_IGNORED
}
public fw_Item_Deploy_Post(weapon_ent)
{
	new owner = pev(weapon_ent,pev_owner)
	if(is_user_alive(owner) && get_user_weapon(owner) == CSW_BASE)
		Set_Player_Zoom(owner, 0)
	
	static weaponid; weaponid = cs_get_weapon_id(weapon_ent)
	if(is_user_alive(owner)) replace_weapon_models(owner, weaponid)
}

public CurrentWeapon(id)
{
	if(read_data(2) != CSW_BASE) 
	{
		if(g_reload[id]) 
		{
			g_reload[id] = false
			remove_task(id + TASK_RELOADING)
		}
	}
	
	replace_weapon_models(id, read_data(2))
	remove_task(id)
} 
 
replace_weapon_models(id, weaponid)
{
	switch(weaponid)
	{
		case CSW_BASE:
		{
			if(g_has_M32[id] && is_user_alive(id))
			{

				set_pev(id, pev_viewmodel2, MODEL_V)
				set_pev(id, pev_weaponmodel2, MODEL_P)
			}
		}
	}
}
 
public fw_UpdateClientData_Post(Player, SendWeapons, CD_Handle)
{
	if(!is_user_alive(Player) || (get_user_weapon(Player) != CSW_BASE) || !g_has_M32[Player]) return FMRES_IGNORED
        
	set_cd(CD_Handle, CD_flNextAttack, halflife_time () + 0.00001)
	return FMRES_HANDLED
}
public fw_CmdStart(id) 
{
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
	static iClip; iClip = get_pdata_int(Ent, 51, 4)
	new ammo, clip, weapon = get_user_weapon(id, clip, ammo)
	if (!g_has_M32[id] || weapon != CSW_BASE || !is_user_alive(id))return
	if(get_pdata_float(Ent, 46, 4) > 0.0 || !iClip)return
	
	if(pev(id, pev_button) & IN_ATTACK)
	{
		if(g_reload[id])
		{
			UTIL_PlayWeaponAnimation(id, 4)
			set_pdata_float(id, 83, 1.0)
			remove_task(id + TASK_RELOADING)
			g_reload[id] = false
			return
		}

		UTIL_PlayWeaponAnimation(id,random_num(1,2))
		emit_sound(id, CHAN_WEAPON, FIRE_SOUND[0], 1.0, ATTN_NORM, 0, PITCH_NORM)
		FireGrenade(id)
		MakeRecoil(id)
		set_pdata_int(Ent, 51, iClip - 1, 4)
		set_pdata_float(Ent, 46, 1.0, 4)
		set_pdata_float(Ent, 48, 1.0, 4)
	}

	if((pev(id, pev_button) & IN_ATTACK2))
	{
		if(!getzoom[id])
			Set_Player_Zoom(id, 1)
			else Set_Player_Zoom(id, 0)
		
		set_pdata_float(Ent, 46, 0.5, 4)
		set_pdata_float(Ent, 48, 0.5, 4)
		
	}
}
public Remove_Entity(Ent)
{
	if(pev_valid(Ent)) remove_entity(Ent)
}
public MakeRecoil(id)
{
	if(!is_user_alive(id))
		return
	if(!g_has_M32[id])
		return;

	static Float:punchAngle[3];
	punchAngle[0] = float(random_num(-1 * 400, 400)) / 100.0;
	punchAngle[1] = float(random_num(-1 * 700, 700)) / 100.0;
	punchAngle[2] = 0.0;
	
	set_pev(id, pev_punchangle, punchAngle);
}

public FireGrenade(id)
{
	new Float:origin[3],Float:velocity[3],Float:angles[3]
	engfunc(EngFunc_GetAttachment, id, 0, origin,angles)
	pev(id,pev_angles,angles)
	new ent = create_entity("info_target") 
	set_pev(ent, pev_classname, "M32_grenade")
	set_pev(ent, pev_solid, SOLID_BBOX)
	set_pev(ent, pev_movetype, MOVETYPE_TOSS)
	set_pev(ent, pev_mins, { -0.1, -0.1, -0.1 })
	set_pev(ent, pev_maxs, { 0.1, 0.1, 0.1 })
	entity_set_model(ent, GRENADE_MODEL)
	set_pev(ent, pev_origin, origin)
	set_pev(ent, pev_angles, angles)
	set_pev(ent, pev_owner, id)
	velocity_by_aim(id, getzoom[id]? 1400 : 1000 , velocity)
	set_pev(ent, pev_velocity, velocity)
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMFOLLOW) // Temporary entity ID
	write_short(ent) // Entity
	write_short(sTrail) // Sprite index
	write_byte(10) // Life
	write_byte(2) // Line width
	write_byte(255) // Red
	write_byte(255) // Green
	write_byte(255) // Blue
	write_byte(255) // Alpha
	message_end() 
	return PLUGIN_CONTINUE
}	



// We hit something!!!
public pfn_touch(ptr, ptd)
{
	// If ent is valid
	if (pev_valid(ptr))
	{	
		// Get classnames
		static classname[32]
		pev(ptr, pev_classname, classname, 31)
		
		// Our ent
		if(equal(classname, "M32_grenade"))
		{
			// Get it's origin
			new Float:originF[3]
			pev(ptr, pev_origin, originF)
			// Draw explosion
			message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
			write_byte(TE_EXPLOSION) // Temporary entity ID
			engfunc(EngFunc_WriteCoord, originF[0]) // engfunc because float
			engfunc(EngFunc_WriteCoord, originF[1])
			engfunc(EngFunc_WriteCoord, originF[2]+30.0)
			write_short(sExplo) // Sprite index
			write_byte(20) // Scale
			write_byte(25) // Framerate
			write_byte(TE_EXPLFLAG_NODLIGHTS | TE_EXPLFLAG_NOSOUND | TE_EXPLFLAG_NOPARTICLES) // Flags
			message_end()
			
			emit_sound(ptd, CHAN_BODY, "weapons/m32venom_exp.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
			
			Create_Poison(ptr)
			
			// Get owner
			new pevAttacker = pev(ptr, pev_owner)
			Stock_DamageRadius(pevAttacker, CSW_BASE, originF, M32_RANGE, M32_DAMAGE_EXPLOSION, DMG_BULLET)
			set_pev(ptr, pev_flags, pev(ptr, pev_flags) | FL_KILLME)
		}
	}
		
}	
public Create_Poison(iEnt)
{
	if(!pev_valid(iEnt))return
	static Float:Origin[3]; pev(iEnt, pev_origin, Origin)
	
	Create_Poison_Onground(Origin, iEnt)
}

public Create_Poison_Onground(Float:Origin[3], iEnt)
{
	static id; id = pev(iEnt, pev_owner)
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
	if(!pev_valid(Ent)) return

	// Set info for ent
	set_pev(Ent, pev_movetype, MOVETYPE_PUSHSTEP)
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 100.0)
	set_pev(Ent, pev_scale, 3.0)
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
	set_pev(Ent, pev_owner, id)
	
	set_pev(Ent, pev_classname, "venom_poison")
	engfunc(EngFunc_SetModel, Ent, "sprites/ef_smoke_poison.spr")
	
	set_pev(Ent, pev_mins, Float:{-16.0, -16.0, -6.0})
	set_pev(Ent, pev_maxs, Float:{16.0, 16.0, 36.0})
	
	set_pev(Ent, pev_origin, Origin)
	set_pev(Ent, pev_iuser2, pev(iEnt, pev_iuser2))
	
	set_pev(Ent, pev_gravity, 1.0)
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	set_pev(Ent, pev_frame, 0.0)
}
public PoisonThink(iEnt)
{
	static Float:fFrame; pev(iEnt, pev_frame, fFrame)
	new pevAttacker = pev(iEnt, pev_owner);
	if(!is_user_connected(pevAttacker) || !is_user_alive(pevAttacker) || !g_has_M32[pevAttacker])
	{
		set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME)
		return
	}
	if(!pev_valid(iEnt)) return;
	if(pev(iEnt, pev_flags) & FL_KILLME) return;
	
	fFrame += 0.5
	if(fFrame >= 38.0) 
		set_pev(iEnt, pev_flags, pev(iEnt, pev_flags) | FL_KILLME)

	set_pev(iEnt, pev_frame, fFrame)
	set_pev(iEnt, pev_nextthink, halflife_time() + 0.05)
	
	if(get_gametime() >= pev(iEnt, pev_livetime))
	{
		static Float:Origin[3]
		pev(iEnt, pev_origin, Origin)
		Stock_DamageRadius(pevAttacker, CSW_BASE, Origin, M32_RANGE, M32_DAMAGE_POISON, DMG_POISON)
		set_pev(iEnt, pev_livetime, get_gametime())
		set_pev(iEnt, pev_owner, pevAttacker)
	}
}
public fw_Think(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Owner; Owner = pev(Ent, pev_user)
	if(!is_user_alive(Owner))
	{
		engfunc(EngFunc_RemoveEntity, Ent)
		return
	}
	if(get_gametime() >= pev(Ent, pev_livetime))
	{
		if(pev(Ent, pev_renderamt) > 0.0)
		{
			static Float:AMT; pev(Ent, pev_renderamt, AMT)
			static Float:RealAMT; 
			
			AMT -= 10.0
			RealAMT = float(max(floatround(AMT), 0))
			
			set_pev(Ent, pev_renderamt, RealAMT)
		} else {
			engfunc(EngFunc_RemoveEntity, Ent)
			return
		}
	}
	if(pev(Ent, pev_frame) >= pev(Ent, pev_totalframe)) 
		set_pev(Ent, pev_frame, 0.0)
	
	// Set Attachment
	static Float:Origin[3]; pev(Owner, pev_origin, Origin)
	
	if(!(pev(Owner, pev_flags) & FL_DUCKING)) Origin[2] += 36.0
	else Origin[2] += 26.0
	
	engfunc(EngFunc_SetOrigin, Ent, Origin)
	
	// Force Think
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}
public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if ((eventid != g_orig_event_M32)) return FMRES_IGNORED
	if (!(1 <= invoker <= g_MaxPlayers)) return FMRES_IGNORED

	playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
	return FMRES_SUPERCEDE
}


public Message_DeathMsg(msg_id, msg_dest, id)
{
	static szTruncatedWeapon[33], iAttacker, iVictim
        
	get_msg_arg_string(4, szTruncatedWeapon, charsmax(szTruncatedWeapon))
        
	iAttacker = get_msg_arg_int(1)
	iVictim = get_msg_arg_int(2)
        
	if(!is_user_connected(iAttacker) || iAttacker == iVictim) return PLUGIN_CONTINUE
        
	if(get_user_weapon(iAttacker) == CSW_BASE)
	{
		if(g_has_M32[iAttacker])
			set_msg_arg_string(4, "m32")
	}
                
	return PLUGIN_CONTINUE
}
 
stock UTIL_PlayWeaponAnimation(const Player, const Sequence)
{
	set_pev(Player, pev_weaponanim, Sequence)
        
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player)
	write_byte(Sequence)
	write_byte(2)
	message_end()
}

 
public fw_r(wpn) {
	if(g_has_M32[ pev(wpn, pev_owner) ]) {
		fw_reload(wpn)
		return HAM_SUPERCEDE
	}
	return HAM_IGNORED
}

public fw_reload(weapon) {
	new id = pev(weapon, pev_owner)
	new clip, bpammo
	get_user_weapon(id, clip, bpammo)
	if(g_has_M32[ id ] && clip < 6 && bpammo > 0) {
		if(!task_exists(id+TASK_RELOADING)) set_task(0.1, "reload", id+TASK_RELOADING)
		}
	if(in_zoom[id])
	{
		cs_set_user_zoom(id, CS_RESET_ZOOM, 1)
		in_zoom[id] = 0
	}
	return HAM_IGNORED
}

public reload(id) {
	id -= TASK_RELOADING
	new clip, bpammo, weapon = find_ent_by_owner(-1, "weapon_m3", id)
	get_user_weapon(id, clip, bpammo)
	Set_Player_Zoom(id, 0)
	if(!g_reload[id]) {
			Set_Player_Zoom(id, 0)
			UTIL_PlayWeaponAnimation(id, 5)
			g_reload[ id ] = 1
			set_pdata_float(id, 83, 1.0, 5)
			set_task(0.7, "reload", id+TASK_RELOADING)
			return
	}

	if(in_zoom[id])
	{
		cs_set_user_zoom(id, CS_RESET_ZOOM, 1)
		in_zoom[id] = 0
	}
	
	if(clip > 5 || bpammo < 1) {
		UTIL_PlayWeaponAnimation(id, 4)
		g_reload[ id ] = 0
		set_pdata_float(id, 83, 1.5, 5)
		return
	}
	cs_set_user_bpammo(id, CSW_BASE, bpammo - 1)
	cs_set_weapon_ammo(weapon, clip + 1)
	set_pdata_float(id, 83, 1.0, 5)
	UTIL_PlayWeaponAnimation(id, 3)
	set_task(0.7, "reload", id+TASK_RELOADING)
}
 
stock drop_weapons(id, dropwhat)
{
	static weapons[32], num, i, weaponid
	num = 0
	get_user_weapons(id, weapons, num)
	
	for (i = 0; i < num; i++)
	{
		weaponid = weapons[i]
		
		if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
		{
			static wname[32]
			get_weaponname(weaponid, wname, sizeof wname - 1)
			engclient_cmd(id, "drop", wname)
		}
	}
}


stock Set_Player_Zoom(id, type = 0)
{
	if(!is_user_alive(id))return
	if(type == 0 && getzoom[id] == 1)
	{
		cs_set_user_zoom(id, CS_RESET_ZOOM, 1)
		getzoom[id] = 0
	}
	if(type == 1 && getzoom[id] == 0)
	{
		cs_set_user_zoom(id, CS_SET_AUGSG552_ZOOM, 1)
		getzoom[id] = 1
	}
	
	emit_sound(id, CHAN_ITEM, "weapons/zoom.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}
stock Stock_DamageRadius(iPlayer, CSWID, Float:vOrigin[3], Float:fRadius, Float:fDamage, iDamageType = DMG_BULLET)
{
	new iCount, iVictim = FM_NULLENT
	new iEnt = fm_get_user_weapon_entity(iPlayer, CSWID)
	while((iVictim = find_ent_in_sphere(iVictim, vOrigin, fRadius)) != 0) 
	{
		if(iVictim == iPlayer) continue
		if(pev(iVictim, pev_takedamage) == DAMAGE_NO) continue
		if(pev(iVictim, pev_spawnflags) & SF_BREAK_TRIGGER_ONLY) continue
		if(is_user_alive(iVictim))
			if(get_user_team(iVictim) == get_user_team(iPlayer)) continue
		
		iCount ++
		ExecuteHamB(Ham_TakeDamage, iVictim, iEnt, iPlayer, fDamage, iDamageType)
		Show_Attachment(iVictim, "sprites/head_poison.spr", 3.0, 1.0, 1.0, 6)
	}
	return iCount
}
stock Show_Attachment(id, const Sprite[],  Float:Time, Float:Scale, Float:FrameRate, TotalFrame)
{
	if(!is_user_alive(id))
		return

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

	if (armorvalue > 0)
	{
		flDamage *= 0.5;
		armorvalue -= flDamage;
	}

	health -= flDamage;

	set_pev(victim, pev_health, health);
	set_pev(victim, pev_armorvalue, armorvalue);

	if (health < 0.0)
		death_message(attacker, victim, 1, type)
}
stock death_message(Killer, Victim, ScoreBoard, type)
{
	// Block death msg
	set_msg_block(get_user_msgid("DeathMsg"), BLOCK_SET)
	ExecuteHamB(Ham_Killed, Victim, Killer, type)
	set_msg_block(get_user_msgid("DeathMsg"), BLOCK_NOT)
	
	// Death
	make_deathmsg(Killer, Victim, 0, "m32")

	// Update score board
	if (ScoreBoard)
	{
		message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"))
		write_byte(Killer) // id
		write_short(pev(Killer, pev_frags)) // frags
		write_short(cs_get_user_deaths(Killer)) // deaths
		write_short(0) // class?
		write_short(get_user_team(Killer)) // team
		message_end()
		
		message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"))
		write_byte(Victim) // id
		write_short(pev(Victim, pev_frags)) // frags
		write_short(cs_get_user_deaths(Victim)) // deaths
		write_short(0) // class?
		write_short(get_user_team(Victim)) // team
		message_end()
	}
}*/
wait i converting others
Don't Say This Is Impossible , Because Nothing Impossible.

User avatar
Muhammet20
Senior Member
Senior Member
Turkey
Posts: 101
Joined: 7 Months Ago
Has thanked: 10 times
Been thanked: 1 time
Contact:

#4

Post by Muhammet20 » 2 Months Ago

Stracha Serar :
______________

Code: Select all

/* Plugin generated by AMXX-Studio */

#pragma compress 1


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

#define PLUGIN "Star Chaser AR"
#define VERSION "1.0"
#define AUTHOR "Bim Bim Cay"

// Models
#define v_model "models/csnz/v_starchaserar.mdl"
#define w_model "models/csnz/w_starchaserar.mdl"
#define p_model "models/csnz/p_starchaserar.mdl"

// Sounds
#define attack1_sound "weapons/starchaserar-1.wav"
#define attack2_sound "weapons/starchaserar-2.wav"
#define explode_sound "weapons/starchasersr_exp.wav"

// Sprites
#define muzzle_flash "sprites/muzzleflash76.spr"
#define ef_ball "sprites/ef_starchasersr_star.spr"
#define ef_line "sprites/ef_starchasersr_line.spr"
#define ef_explosion "sprites/ef_starchasersr_explosion.spr"

// Anims
#define ANIM_IDLE		0
#define ANIM_RELOAD		1
#define ANIM_DRAW		2
#define ANIM_SHOOT1		3
#define ANIM_SHOOT2		4
#define ANIM_SHOOT3		5

#define ANIM_EXTENSION 		"carbine"

// Entity Classname
#define BALL_CLASSNAME "StarChaserAREf_Ball"
#define MUZZLEFLASH_CLASSNAME "Muzzle_StarChaserAR"

// Configs
#define WEAPON_NAME 		"weapon_starchaserar"
#define WEAPON_BASE		"weapon_aug"

#define WEAPON_MAX_CLIP		35
#define WEAPON_DEFAULT_AMMO	90

#define WEAPON_SHOOT_DAMAGE	45.0
#define WEAPON_EXPLODE_DAMAGE	150.0
#define WEAPON_EXPLODE_RADIUS	100.0

#define WEAPON_TIME_NEXT_ATTACK 0.1
#define WEAPON_TIME_NEXT_ATTACKZ 0.135
#define AMMO_CHARGE 7

// 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

new g_iszWeaponKey
new g_iForwardDecalIndex
new g_Line_SprId, g_Explode_SprId

// Safety
new g_HamBot
new g_IsConnected, g_IsAlive

new item
new item_name = "Starcha Serar"
new item_cost = 7
new item_teams = 0

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(MUZZLEFLASH_CLASSNAME, "fw_MuzzleFlash_Think") 
	register_think(BALL_CLASSNAME, "fw_Ball_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_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")
	
	item = ze_register_item(item_name,item_cost,item_teams)
	
	
}
public ze_select_item_pre(id,itemid)
{
	// This not our item?
    if (itemid != item)
        return ZE_ITEM_AVAILABLE
   
	// Available for V.I.P only, So don't show it for others
   if (!(ze_get_vip_flags(id) & VIP_A))
        return ZE_ITEM_DONT_SHOW
	
	// Available for Humans only, So don't show it for zombies
   if (ze_is_user_zombie(id)
        return ZE_ITEM_DONT_SHOW
   
	// Finally return that it's available
    return ZE_ITEM_AVAILABLE
}
public ze_select_item_post(id,itemid)
{
	if(itemid != item)
		return
		
	Get_MyWeapon(id)
}	
public plugin_precache()
{
	precache_model(v_model)
	precache_model(w_model)
	precache_model(p_model)
	
	precache_model(ef_ball)
	precache_model(muzzle_flash)
	
	g_Line_SprId = precache_model(ef_line)
	g_Explode_SprId = precache_model(ef_explosion)
	
	precache_sound(attack1_sound)
	precache_sound(attack2_sound)
	precache_sound(explode_sound)
	
	g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
	g_iForwardDecalIndex = register_forward(FM_DecalIndex, "fw_DecalIndex_Post", 1)
}

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

//**********************************************
//* 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_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)	
	
	set_pev(iPlayer, pev_viewmodel2, v_model)
	set_pev(iPlayer, pev_weaponmodel2, p_model)
	
	Weapon_SendAnim(iPlayer, iItem, ANIM_DRAW)
	
	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)
	}	
	
	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)
	
	set_pdata_int(iItem, 51, iClip, 4)
	
	set_pdata_float(iPlayer, 83, 3.2, 5)
	set_pdata_float(iItem, 48, 3.2, 4)
	
	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, 10.0, 4)
	
	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 ShootAnim
	switch(random_num(0, 2))
	{
		case 0: ShootAnim = ANIM_SHOOT1
		case 1: ShootAnim = ANIM_SHOOT2
		case 2: ShootAnim = ANIM_SHOOT3
	}
		
	Weapon_SendAnim(iPlayer, iItem, ShootAnim)
	
	set_pdata_float(iItem, 48, 0.7, 4)
	
	if(pev(iPlayer, pev_fov) == 90)
	{
		set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK, 4)
		set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK, 4)
	}
	else
	{
		set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACKZ, 4)
		set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACKZ, 4)
	}
	
	pev(iPlayer, pev_velocity, Velocity)
	
	if(xs_vec_len(Velocity) > 0)
	{
		Weapon_KickBack(iItem, iPlayer, 1.0, 0.45, 0.275, 0.05, 4.0, 2.5, 7)
	}
	else if(!(iFlags & FL_ONGROUND))
	{
		Weapon_KickBack(iItem, iPlayer, 1.25, 0.45, 0.22, 0.18, 5.5, 4.0, 5)
	}
	else if(iFlags & FL_DUCKING)
	{
		Weapon_KickBack(iItem, iPlayer, 0.575, 0.325, 0.2, 0.011, 3.25, 2.0, 8)
	}
	else
	{
		Weapon_KickBack(iItem, iPlayer, 0.625, 0.375, 0.25, 0.0125, 3.5, 2.25, 8)
	}

	Make_MuzzleFlash(iPlayer)
	
	static AmmoCharge; AmmoCharge = get_pdata_int(iItem, 30, 4)
	
	if(AmmoCharge < AMMO_CHARGE)
	{
		set_pdata_int(iItem, 30, AmmoCharge + 1, 4)
		
		emit_sound(iPlayer, CHAN_WEAPON, attack1_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
	}
	else
	{
		set_pdata_int(iItem, 30, 0, 4)
		
		emit_sound(iPlayer, CHAN_WEAPON, attack2_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
		
		Create_Star(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 */ 
}

//**********************************************
//* Effects                                    *
//**********************************************
Make_MuzzleFlash(iPlayer)
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))

	set_pev(Ent, pev_classname, MUZZLEFLASH_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)
	
	engfunc(EngFunc_SetModel, Ent, muzzle_flash)
	
	set_pev(Ent, pev_scale, 0.04)
	set_pev(Ent, pev_frame, 0.0)
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 250.0)
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
}

public fw_MuzzleFlash_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 > 2.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 Create_Star(iPlayer)
{
	static Float:Origin[3]
	
	if(get_cvar_num("cl_righthand"))
	{
		Get_Position(iPlayer, 48.0, 10.0, -5.0, Origin)
	}
	else
	{
		Get_Position(iPlayer, 48.0, -10.0, -5.0, Origin)
	}

	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	if(!pev_valid(Ent)) 
		return
		
	engfunc(EngFunc_SetModel, Ent, ef_ball)	
	
	set_pev(Ent, pev_classname, BALL_CLASSNAME)
	set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
	set_pev(Ent, pev_owner, iPlayer)
	set_pev(Ent, pev_origin, Origin)
	
	set_pev(Ent, pev_solid, SOLID_SLIDEBOX)
	set_pev(Ent, pev_mins, {-1.0, -1.0, -1.0})
	set_pev(Ent, pev_maxs, {1.0, 1.0, 1.0})
	
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 255.0)
	set_pev(Ent, pev_scale, 0.075)
	set_pev(Ent, pev_frame, 0.0)
	
	// Create Velocity
	static Float:Velocity[3], Float:TargetOrigin[3]
	
	fm_get_aim_origin(iPlayer, TargetOrigin)
	get_speed_vector(Origin, TargetOrigin, 2500.0, Velocity)
	
	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
		
	new Float:fFrame
	pev(Ent, pev_frame, fFrame)
	
	// effect exp
	if(fFrame <= 14.0) 
	{
		fFrame += 1.0
		
	}
	else
	{
		fFrame = 0.0
	}
	
	set_pev(Ent, pev_frame, fFrame)
	
	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
	
	engfunc(EngFunc_MessageBegin, MSG_BROADCAST, SVC_TEMPENTITY, Origin, 0)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_Line_SprId)	// sprite index
	write_byte(3)	// scale in 3.4's
	write_byte(20)	// framerate
	write_byte(TE_FLAG)	// flags
	message_end()
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)	
}

public fw_Ball_Touch(Ent, Touch)
{
	if(!pev_valid(Ent)) 
		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
	
	engfunc(EngFunc_MessageBegin, MSG_BROADCAST, SVC_TEMPENTITY, Origin, 0)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_Explode_SprId)	// sprite index
	write_byte(7)	// scale in 3.4's
	write_byte(45)	// framerate
	write_byte(TE_FLAG)	// flags
	message_end()
	
	emit_sound(Ent, CHAN_BODY, explode_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	static Owner; Owner = pev(Ent, pev_owner)
	
	if(is_connected(Owner))
	{
		static Victim; Victim = -1
		while((Victim = find_ent_in_sphere(Victim, Origin, WEAPON_EXPLODE_RADIUS)) != 0)
		{
			if(is_alive(Victim))
			{
				if(Victim == Owner)
					continue
			}
			else
			{
				if(pev(Victim, pev_takedamage) == DAMAGE_NO)
					continue
			}
		
			ExecuteHamB(Ham_TakeDamage, Victim, Ent, Owner, WEAPON_EXPLODE_DAMAGE, DMG_BULLET)
		}
	}
	
	set_pev(Ent, pev_flags, FL_KILLME)
}

//**********************************************
//* 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, WEAPON_MAX_CLIP, 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)
		
		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
}
i converting others
Don't Say This Is Impossible , Because Nothing Impossible.

User avatar
Muhammet20
Senior Member
Senior Member
Turkey
Posts: 101
Joined: 7 Months Ago
Has thanked: 10 times
Been thanked: 1 time
Contact:

#5

Post by Muhammet20 » 2 Months Ago

Dual Chinese :
______________

Code: Select all

#include <fakemeta_util>
#include <cstrike>
#include <zombie_escape>
#include <ze_vip>

#define PLUGIN "Chinese Dual-Hand Gun"
#define VERSION "1.0"
#define AUTHOR "Dias"

#define V_MODEL "models/v_monkeywpnset2.mdl"
#define P_MODEL "models/p_monkeywpnset2.mdl"
#define W_MODEL "models/w_monkeywpnset2.mdl"

#define CSW_DI CSW_USP
#define weapon_di "weapon_usp"

#define ANIM_EXT "dualpistols_1"
#define WEAPON_SECRETCODE 1953

#define WEAPON_EVENT "events/usp.sc"
#define OLD_W_MODEL "models/w_usp.mdl"

#define DRAW_TIME 0.75
#define RELOAD_TIME 4.0

#define DAMAGEA 32
#define DAMAGEB 29
#define CLIP 36
#define BPAMMO 200

new const WeaponSounds[4][] = 
{
	"weapons/monkeyswpnset2-1.wav",
	"weapons/monkeyswpnset2_clipin.wav",
	"weapons/monkeyswpnset2_clipout.wav",
	"weapons/monkeyswpnset2_draw.wav"
}

enum
{
	ANIM_IDLE = 0,
	ANIM_IDLE2,
	ANIM_LEFT,
	ANIM_LEFT2,
	ANIM_RIGHT,
	ANIM_RIGHT2,
	ANIM_SLEFT,
	ANIM_SLEFT2,
	ANIM_SRIGHT,
	ANIM_SRIGHT2,
	ANIM_SLEFTL,
	ANIM_SRIGHTL,
	ANIM_RELOAD,
	ANIM_DRAW
}

new g_Had_DualChinesePistol, g_InSpecialShoot, g_InRapidShoot, g_Shooting, Float:g_LastShoot[33]
new g_OldWeapon[33], g_Clip[33], g_di_event, g_ShellId, g_ham_bot, g_smokepuff_id

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

new item
new item_name = "Chinese Dual-Hand Gun"
new item_cost = 7
new item_teams = 0
public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_CmdStart, "fw_CmdStart")		
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	RegisterHam(Ham_Item_PostFrame, weapon_di, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_di, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_di, "fw_Weapon_Reload_Post", 1)	
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_di, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_di, "fw_Weapon_PrimaryAttack_Post", 1)		
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_di, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Item_AddToPlayer, weapon_di, "fw_Item_AddToPlayer_Post", 1)
	
	item = ze_register_item(item_name,item_cost,item_teams)
}
public ze_select_item_pre(id,itemid)
{
	// This not our item?
    if (itemid != item)
        return ZE_ITEM_AVAILABLE
   
	// Available for V.I.P only, So don't show it for others
   if (!(ze_get_vip_flags(id) & VIP_A))
        return ZE_ITEM_DONT_SHOW
	
	// Available for Humans only, So don't show it for zombies
   if (ze_is_user_zombie(id)
        return ZE_ITEM_DONT_SHOW
   
	// Finally return that it's available
    return ZE_ITEM_AVAILABLE
}
public ze_select_item_post(id,itemid)
{
	if(itemid != item)
		return
		
	Get_DualChinesePistol(id)
}
public plugin_precache()
{
	engfunc(EngFunc_PrecacheModel, V_MODEL)
	engfunc(EngFunc_PrecacheModel, P_MODEL)
	engfunc(EngFunc_PrecacheModel, W_MODEL)
	
	for(new i = 0; i < sizeof(WeaponSounds); i++)
		engfunc(EngFunc_PrecacheSound, WeaponSounds[i])
	
	g_ShellId = engfunc(EngFunc_PrecacheModel, "models/pshell.mdl")
	g_smokepuff_id = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
	
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
}

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

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

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

public Get_DualChinesePistol(id)
{
	Set_BitVar(g_Had_DualChinesePistol, id)
	UnSet_BitVar(g_InSpecialShoot, id)
	UnSet_BitVar(g_InRapidShoot, id)
	UnSet_BitVar(g_Shooting, id)
	
	fm_give_item(id, weapon_di)
	
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_DI)
	if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, CLIP)
	
	cs_set_user_bpammo(id, CSW_DI, BPAMMO)
}

public Remove_DualChinesePistol(id)
{
	UnSet_BitVar(g_Had_DualChinesePistol, id)
	UnSet_BitVar(g_InSpecialShoot, id)
	UnSet_BitVar(g_InRapidShoot, id)
	UnSet_BitVar(g_Shooting, id)
}

public Event_CurWeapon(id)
{
	if(!is_user_alive(id))
		return
	
	static CSWID; CSWID = read_data(2)
	if(Get_BitVar(g_Had_DualChinesePistol, id) && (CSWID == CSW_DI && g_OldWeapon[id] != CSW_DI))
	{
		set_pev(id, pev_viewmodel2, V_MODEL)
		set_pev(id, pev_weaponmodel2, P_MODEL)
		
		// Draw Scene
		set_weapon_anim(id, ANIM_DRAW)
		
		set_weapon_timeidle(id, CSW_DI, DRAW_TIME)
		set_player_nextattack(id, DRAW_TIME)
		
		// Set Ext Anim
		set_pdata_string(id, (492) * 4, ANIM_EXT, -1 , 20)
	} else if(Get_BitVar(g_Had_DualChinesePistol, id) && CSWID == CSW_DI) {
		set_pev(id, pev_viewmodel2, V_MODEL)
	}
	
	g_OldWeapon[id] = CSWID
}

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

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_user_connected(invoker))
		return FMRES_IGNORED	
	if(get_user_weapon(invoker) != CSW_DI || !Get_BitVar(g_Had_DualChinesePistol, invoker))
		return FMRES_IGNORED
	
	if(eventid == g_di_event)
	{
		engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
		
		Set_BitVar(g_Shooting, invoker)
		Weapon_Attack(invoker)
		
		return FMRES_SUPERCEDE
	} 
	
	return FMRES_HANDLED
}

public Weapon_Attack(id)
{
	static iFlags, iAnimDesired, iWeaponState, iItem, szAnimation[64]
	
	#define WEAPONSTATE_ELITE_LEFT (1 << 3)
	
	iItem = fm_get_user_weapon_entity(id, CSW_DI)
	if(!pev_valid(iItem)) return
	
	iFlags = pev(id, pev_flags);
	iWeaponState = get_pdata_int(iItem, 74, 4)
	
	if(iWeaponState & WEAPONSTATE_ELITE_LEFT)
	{	
		iWeaponState &= ~ WEAPONSTATE_ELITE_LEFT;
		
		if(Get_BitVar(g_InSpecialShoot, id)) set_weapon_anim(id, ANIM_SLEFT)
		else set_weapon_anim(id, ANIM_LEFT)
		
		make_shell(id, 0)
		
		formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot_%s" : "ref_shoot_%s", ANIM_EXT);
	} else {
		iWeaponState |= WEAPONSTATE_ELITE_LEFT;
		
		if(Get_BitVar(g_InSpecialShoot, id)) set_weapon_anim(id, ANIM_SRIGHT)
		else set_weapon_anim(id, ANIM_RIGHT)
		make_shell(id, 1)
		
		formatex(szAnimation, charsmax(szAnimation), iFlags & FL_DUCKING ? "crouch_shoot2_%s" : "ref_shoot2_%s", ANIM_EXT);
	}
	
	if((iAnimDesired = lookup_sequence(id, szAnimation)) == -1)
		iAnimDesired = 0;
	
	set_pev(id, pev_sequence, iAnimDesired)
	set_pdata_int(iItem, 74, iWeaponState, 4)
	
	emit_sound(id, CHAN_WEAPON, WeaponSounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_LOW)
}

public Check_Recoil(id, Right)
{
	if(!Get_BitVar(g_InSpecialShoot, id))
	{
		static Float:Push[3]
		
		Push[0] = random_float(-0.5, -1.0)
		if(Right) Push[1] = random_float(0.1, 0.25)
		else Push[1] = random_float(-0.1, -0.25)

		set_pev(id, pev_punchangle, Push)
	} else {
		if(!Get_BitVar(g_InRapidShoot, id))
		{
			static Float:Push[3]
		
			Push[0] = random_float(-0.5, -1.0)
			if(Right) Push[1] = random_float(0.5, 1.0)
			else Push[1] = random_float(-0.5, -1.0)
			
			set_pev(id, pev_punchangle, Push)
		} else {
			static Float:Push[3]
		
			Push[0] = Push[1] = 0.0
			set_pev(id, pev_punchangle, Push)
		}
	}
}

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

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) != CSW_DI || !Get_BitVar(g_Had_DualChinesePistol, id))	
		return FMRES_IGNORED
		
	static NewButton; NewButton = get_uc(uc_handle, UC_Buttons)
	if(NewButton & IN_ATTACK)
	{
		UnSet_BitVar(g_InSpecialShoot, id)
		UnSet_BitVar(g_InRapidShoot, id)
	} else if(NewButton & IN_ATTACK2)
	{
		NewButton &= ~IN_ATTACK2
		set_uc(uc_handle, UC_Buttons, NewButton)
		
		UnSet_BitVar(g_InSpecialShoot, id)
		UnSet_BitVar(g_InRapidShoot, id)
		
		Checking_SpecialShoot(id, uc_handle)
	}
	
	return FMRES_IGNORED
}

public Checking_SpecialShoot(id, UCResult)
{
	if(get_pdata_float(id, 83, 5) > 0.0)
		return
		
	if(!(pev(id, pev_oldbuttons) & IN_ATTACK2))
	{
		if(get_gametime() - 0.01 > g_LastShoot[id])
		{
			Set_BitVar(g_InSpecialShoot, id)
			Set_BitVar(g_InRapidShoot, id)
			
			static Ent; Ent = fm_get_user_weapon_entity(id, CSW_DI)
			if(pev_valid(id)) ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
			
			g_LastShoot[id] = get_gametime()
		}
	} else {
		if(get_gametime() - 0.1 > g_LastShoot[id])
		{
			Set_BitVar(g_InSpecialShoot, id)
			UnSet_BitVar(g_InRapidShoot, id)
			
			static Ent; Ent = fm_get_user_weapon_entity(id, CSW_DI)
			if(pev_valid(id)) ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
			
			g_LastShoot[id] = get_gametime()
		}
	}
}

public fw_TraceAttack_World(ent, attacker, Float:Damage, Float:fDir[3], ptr, iDamageType)
{
	if(!is_user_alive(attacker))
		return HAM_IGNORED	
	if(get_user_weapon(attacker) != CSW_DI || !Get_BitVar(g_Had_DualChinesePistol, attacker))
		return HAM_IGNORED
		
	static Float:flEnd[3], Float:vecPlane[3]
	
	get_tr2(ptr, TR_vecEndPos, flEnd)
	get_tr2(ptr, TR_vecPlaneNormal, vecPlane)		
		
	make_bullet(attacker, flEnd)
	fake_smoke(attacker, ptr)
		
	SetHamParamFloat(3, !Get_BitVar(g_InSpecialShoot, attacker) ? float(DAMAGEA) : float(DAMAGEB))	

	return HAM_HANDLED
}

public fw_TraceAttack_Player(ent, attacker, Float:Damage, Float:fDir[3], ptr, iDamageType)
{
	if(!is_user_alive(attacker))
		return HAM_IGNORED	
	if(get_user_weapon(attacker) != CSW_DI || !Get_BitVar(g_Had_DualChinesePistol, attacker))
		return HAM_IGNORED
		
	SetHamParamFloat(3, !Get_BitVar(g_InSpecialShoot, attacker) ? float(DAMAGEA) : float(DAMAGEB))

	return HAM_HANDLED
}

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

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

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

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

public fw_Weapon_Reload_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_DualChinesePistol, id))
		return HAM_IGNORED
		
	if((get_pdata_int(ent, 54, 4) == 1))
	{ // Reload
		if(g_Clip[id] == -1)
			return HAM_IGNORED
		
		set_pdata_int(ent, 51, g_Clip[id], 4)
		
		set_weapon_anim(id, ANIM_RELOAD)
		
		set_weapon_timeidle(id, CSW_DI, RELOAD_TIME)
		set_player_nextattack(id, RELOAD_TIME)
	}
	
	return HAM_HANDLED
}

public fw_Weapon_PrimaryAttack(Ent)
{
	if(!pev_valid(Ent))
		return
	static Id; Id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_DualChinesePistol, Id))
		return

	if(!Get_BitVar(g_InSpecialShoot, Id)) set_pdata_float(Ent, 62, 0.9, 4)
	else set_pdata_float(Ent, 62, 0.9, 4)
}

public fw_Weapon_PrimaryAttack_Post(Ent)
{
	if(!pev_valid(Ent))
		return
	static id; id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_DualChinesePistol, id))
		return
	if(!Get_BitVar(g_Shooting, id))
		return
		
	UnSet_BitVar(g_Shooting, id)
	
	static iWeaponState
	iWeaponState = get_pdata_int(Ent, 74, 4)
	
	if(iWeaponState & WEAPONSTATE_ELITE_LEFT)
	{	
		Check_Recoil(id, 0)
	} else {
		Check_Recoil(id, 1)
	}
}

public fw_Weapon_WeaponIdle_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_DualChinesePistol, id))
		return HAM_IGNORED
		
	if(get_pdata_float(ent, 48, 4) <= 0.1) 
	{
		set_weapon_anim(id, ANIM_IDLE)
		set_pdata_float(ent, 48, 20.0, 4)
	}
	
	return HAM_IGNORED
}

public fw_Item_AddToPlayer_Post(ent, id)
{
	if(!pev_valid(ent))
		return HAM_IGNORED
		
	if(pev(ent, pev_impulse) == WEAPON_SECRETCODE)
	{
		Set_BitVar(g_Had_DualChinesePistol, id)
		set_pev(ent, pev_impulse, 0)
	}		

	return HAM_HANDLED	
}

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

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

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

	static angle; angle = random_num(0, 360)

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

stock make_bullet(id, Float:Origin[3])
{
	// Find target
	static decal; decal = random_num(41, 45)

	// Put decal on "world" (a wall)
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_WORLDDECAL)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_byte(decal)
	message_end()
	
	// Show sparcles
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_GUNSHOTDECAL)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(id)
	write_byte(decal)
	message_end()
}

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

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

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

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

stock set_weapon_timeidle(id, CSWID, Float:TimeIdle)
{
	static Ent; Ent = fm_get_user_weapon_entity(id, CSWID)
	if(!pev_valid(Ent)) 
		return
	
	set_pdata_float(Ent, 46, TimeIdle, 4)
	set_pdata_float(Ent, 47, TimeIdle, 4)
	set_pdata_float(Ent, 48, TimeIdle + 1.0, 4)
}

stock set_player_nextattack(id, Float:Time) set_pdata_float(id, 83, Time, 5)
stock set_weapon_anim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}
i converting the last
Don't Say This Is Impossible , Because Nothing Impossible.

User avatar
Muhammet20
Senior Member
Senior Member
Turkey
Posts: 101
Joined: 7 Months Ago
Has thanked: 10 times
Been thanked: 1 time
Contact:

#6

Post by Muhammet20 » 2 Months Ago

Last One : Poison Gun
_____________________

Code: Select all

#include <engine>
#include <fakemeta_util>
#include <cstrike>
#include <fun>
#include <zombie_escape>
#include <ze_vip>

#define PLUGIN "[CSO] Poison Gun"
#define VERSION "2015"
#define AUTHOR "Dias Pendragon Leon"

#define CSW_POISONGUN CSW_M249
#define weapon_poisongun "weapon_m249"

#define DAMAGE 38
#define FIRE_SPEED 960.0
#define RECOIL 0.0
#define CLIP 100
#define BPAMMO 200

#define AFTERPOISON_TIME 10.0
#define AFTERPOISON_DAMAGE 25

#define MODEL_V "models/v_poisongun.mdl"
#define MODEL_P "models/p_poisongun.mdl"
#define MODEL_W "models/w_poisongun.mdl"
#define DEFAULT_W_MODEL "models/w_m249.mdl"
#define POISON_CLASSNAME "poisonu"

new const WeaponSounds[7][] =
{
	"weapons/poisongun-1.wav",
	"weapons/poisongun-2.wav",
	"weapons/flamegun_draw.wav",
	"weapons/flamegun_clipin1.wav",
	"weapons/flamegun_clipin2.wav",
	"weapons/flamegun_clipout1.wav",
	"weapons/flamegun_clipout2.wav"
}

new const WeaponResources[5][] = 
{
	"sprites/ef_smoke_poison.spr", // Fire Effect
	"sprites/ef_smoke_poison.spr", // Burn Effect
	"sprites/weapon_poisongun.txt",
	"sprites/640hud7_2.spr",
	"sprites/640hud75_2.spr"
}

enum
{
	ANIM_IDLE = 0,
	ANIM_SHOOT,
	ANIM_SHOOT_END,
	ANIM_RELOAD,
	ANIM_DRAW
}

// Marcros
#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)));

// Vars
new g_PoisonGun
new g_Had_PoisonGun, g_WeaponEnt, Float:g_PunchAngles[33]
new g_MsgCurWeapon, g_MsgWeaponList

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

new item
new item_name = "Poison Gun"
new item_cost = 7
new item_teams = 0

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Your highness!
	Register_SafetyFunc()
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
	
	// Engine
	register_think(POISON_CLASSNAME, "fw_Fire_Think")
	register_touch(POISON_CLASSNAME, "*", "fw_Fire_Touch")
	register_think("afterpoison", "fw_FireBurn_Think")
	
	// Hams
	RegisterHam(Ham_Item_Deploy, weapon_poisongun, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_poisongun, "fw_Item_AddToPlayer_Post", 1)
	
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_poisongun, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_poisongun, "fw_Weapon_PrimaryAttack_Post", 1)
	
	g_MsgCurWeapon = get_user_msgid("CurWeapon")
	g_MsgWeaponList = get_user_msgid("WeaponList")
	
	item = ze_register_item(item_name,item_cost,item_teams)
	register_clcmd("weapon_poisongun", "Hook_Weapon")
}
public ze_select_item_pre(id,itemid)
{
	// This not our item?
    if (itemid != item)
        return ZE_ITEM_AVAILABLE
   
	// Available for V.I.P only, So don't show it for others
   if (!(ze_get_vip_flags(id) & VIP_A))
        return ZE_ITEM_DONT_SHOW
	
	// Available for Humans only, So don't show it for zombies
   if (ze_is_user_zombie(id)
        return ZE_ITEM_DONT_SHOW
   
	// Finally return that it's available
    return ZE_ITEM_AVAILABLE
}
public ze_select_item_post(id,itemid)
{
	if(itemid != item)
		return
		
	Get_PoisonGun(id)
}
public plugin_precache()
{
	precache_model(MODEL_V)
	precache_model(MODEL_P)
	precache_model(MODEL_W)
	
	for(new i = 0; i < sizeof(WeaponSounds); i++)
		precache_sound(WeaponSounds[i])
	for(new i = 0; i < sizeof(WeaponResources); i++)
	{
		if(i == 2) precache_generic(WeaponResources[i])
		else precache_model(WeaponResources[i])
	}
}

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

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

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

public zeli_base_register(Ent, Team)
{
	RegisterHamFromEntity(Ham_TraceAttack, Ent, "fw_TraceAttack")
}

public client_disconnect(id)
{
	Safety_Disconnected(id)
}

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

// public zeli_user_spawned -> Remove_AfterPoison(id)

public zeli_weapon_selected(id, ItemID, ClassID)
{
	if(ItemID == g_PoisonGun) Get_PoisonGun(id)
}

public zeli_weapon_removed(id, ItemID)
{
	if(ItemID == g_PoisonGun) Remove_PoisonGun(id)
}

public Get_PoisonGun(id)
{
	Set_BitVar(g_Had_PoisonGun, id)
	give_item(id, weapon_poisongun)
	
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_POISONGUN)
	if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, CLIP)
	
	message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
	write_byte(1)
	write_byte(CSW_POISONGUN)
	write_byte(CLIP)
	message_end()
	
	cs_set_user_bpammo(id, CSW_POISONGUN, BPAMMO)
}

public Remove_PoisonGun(id)
{
	UnSet_BitVar(g_Had_PoisonGun, id)
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_alive(id))
		return FMRES_IGNORED
	if(get_player_weapon(id) != CSW_POISONGUN || !Get_BitVar(g_Had_PoisonGun, id))
		return FMRES_IGNORED
	
	set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static szClassName[33]
	pev(entity, pev_classname, szClassName, charsmax(szClassName))
	
	if(!equal(szClassName, "weaponbox"))
		return FMRES_IGNORED
	
	static id
	id = pev(entity, pev_owner)
	
	if(equal(model, DEFAULT_W_MODEL))
	{
		static weapon; weapon = fm_find_ent_by_owner(-1, weapon_poisongun, entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED
		
		if(Get_BitVar(g_Had_PoisonGun, id))
		{
			set_pev(weapon, pev_impulse, 1562015)
			engfunc(EngFunc_SetModel, entity, MODEL_W)
			
			UnSet_BitVar(g_Had_PoisonGun, id)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if(!is_alive(invoker))
		return FMRES_IGNORED
	if(get_player_weapon(invoker) != CSW_POISONGUN || !Get_BitVar(g_Had_PoisonGun, invoker))
		return FMRES_IGNORED	
	if(eventid == g_WeaponEnt)
	{
		playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)	
		if(pev(invoker, pev_weaponanim) != ANIM_SHOOT) Set_WeaponAnim(invoker, ANIM_SHOOT)
		
		return FMRES_SUPERCEDE
	}
	
	return FMRES_HANDLED
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_alive(id))
		return FMRES_IGNORED
	if(get_player_weapon(id) != CSW_POISONGUN || !Get_BitVar(g_Had_PoisonGun, id))
		return FMRES_IGNORED
		
	static PressedButton
	PressedButton = get_uc(uc_handle, UC_Buttons)
	
	if(!(PressedButton & IN_ATTACK))
	{
		if((pev(id, pev_oldbuttons) & IN_ATTACK) && pev(id, pev_weaponanim) == ANIM_SHOOT)
		{
			static weapon; weapon = fm_get_user_weapon_entity(id, CSW_POISONGUN)
			if(pev_valid(weapon)) set_pdata_float(weapon, 48, 2.0, 4)
			
			Set_WeaponAnim(id, ANIM_SHOOT_END)
			emit_sound(id, CHAN_WEAPON, WeaponSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
	}
		
	return FMRES_HANDLED
}

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

public fw_Item_AddToPlayer_Post(Ent, id)
{
	if(!pev_valid(Ent))
		return HAM_IGNORED
		
	if(pev(Ent, pev_impulse) == 1562015)
	{
		Set_BitVar(g_Had_PoisonGun, id)
		set_pev(Ent, pev_impulse, 0)
	}
	
	if(Get_BitVar(g_Had_PoisonGun, id))
	{
		message_begin(MSG_ONE_UNRELIABLE, g_MsgWeaponList, _, id)
		write_string("weapon_poisongun")
		write_byte(3)
		write_byte(200)
		write_byte(-1)
		write_byte(-1)
		write_byte(0)
		write_byte(4)
		write_byte(CSW_POISONGUN)
		write_byte(0)
		message_end()	
	}
	
	return HAM_HANDLED	
}

public fw_TraceAttack(Ent, Attacker, Float:Damage, Float:Dir[3], ptr, DamageType)
{
	if(!is_alive(Attacker))
		return HAM_IGNORED
	if(get_player_weapon(Attacker) != CSW_POISONGUN || !Get_BitVar(g_Had_PoisonGun, Attacker))
		return HAM_IGNORED
	
	return HAM_SUPERCEDE
}

public CreateFire(id, Float:Speed)
{
	new iEnt = create_entity("env_sprite")
	if(!pev_valid(iEnt)) return
	
	static Float:vfAngle[3], Float:MyOrigin[3]
	static Float:Origin[3], Float:TargetOrigin[3], Float:Velocity[3]

	get_position(id, 40.0, 5.0, -5.0, Origin)
	get_position(id, 1024.0, 0.0, 0.0, TargetOrigin)
	
	pev(id, pev_angles, vfAngle)
	pev(id, pev_origin, MyOrigin)
	
	vfAngle[2] = float(random(18) * 20)

	// set info for ent
	set_pev(iEnt, pev_movetype, MOVETYPE_FLY)
	set_pev(iEnt, pev_rendermode, kRenderTransAdd)
	set_pev(iEnt, pev_renderamt, 160.0)
	set_pev(iEnt, pev_fuser1, get_gametime() + 1.0)	// time remove
	set_pev(iEnt, pev_scale, 0.25)
	set_pev(iEnt, pev_nextthink, get_gametime() + 0.05)
	
	entity_set_string(iEnt, EV_SZ_classname, POISON_CLASSNAME)
	engfunc(EngFunc_SetModel, iEnt, WeaponResources[0])
	set_pev(iEnt, pev_mins, Float:{-1.0, -1.0, -1.0})
	set_pev(iEnt, pev_maxs, Float:{1.0, 1.0, 1.0})
	set_pev(iEnt, pev_origin, Origin)
	set_pev(iEnt, pev_gravity, 0.01)
	set_pev(iEnt, pev_angles, vfAngle)
	set_pev(iEnt, pev_solid, SOLID_TRIGGER)
	set_pev(iEnt, pev_owner, id)	
	set_pev(iEnt, pev_frame, 0.0)
	set_pev(iEnt, pev_iuser2, get_user_team(id))

	get_speed_vector(Origin, TargetOrigin, Speed, Velocity)
	set_pev(iEnt, pev_velocity, Velocity)
	
	emit_sound(iEnt, CHAN_BODY, WeaponSounds[0], 1.0, ATTN_NORM, 0, PITCH_NORM)	
}

public fw_Fire_Think(iEnt)
{
	if(!pev_valid(iEnt)) 
		return
	
	static Float:fFrame, Float:fScale
	pev(iEnt, pev_frame, fFrame)
	pev(iEnt, pev_scale, fScale)

	// effect exp
	if(pev(iEnt, pev_movetype) == MOVETYPE_NONE)
	{
		fFrame += 1.5
		fScale += 0.1
		fScale = floatmin(fScale, 1.75)

		if(fFrame > 38.0)
		{
			engfunc(EngFunc_RemoveEntity, iEnt)
			return
		}
		
		set_pev(iEnt, pev_nextthink, get_gametime() + 0.025)
	} else {
		fFrame += 1.75
		fFrame = floatmin(38.0, fFrame)
		fScale += 0.15
		fScale = floatmin(fScale, 1.75)
		
		set_pev(iEnt, pev_nextthink, get_gametime() + 0.05)
	}

	set_pev(iEnt, pev_frame, fFrame)
	set_pev(iEnt, pev_scale, fScale)
	
	// time remove
	static Float:fTimeRemove
	pev(iEnt, pev_fuser1, fTimeRemove)
	if (get_gametime() >= fTimeRemove)
	{
		engfunc(EngFunc_RemoveEntity, iEnt)
		return;
	}
}

public fw_Fire_Touch(ent, id)
{
	if(!pev_valid(ent))
		return
		
	if(pev_valid(id))
	{
		static Classname[32]
		pev(id, pev_classname, Classname, sizeof(Classname))
		
		if(equal(Classname, POISON_CLASSNAME)) return
		else if(is_alive(id)) 
		{
			static EntTeam; EntTeam = pev(ent, pev_iuser2)
			if(get_user_team(id) != EntTeam)
			{
				static Attacker; Attacker = pev(ent, pev_owner)
				if(is_connected(Attacker))
				{
					ExecuteHamB(Ham_TakeDamage, id, 0, Attacker, float(DAMAGE), DMG_BULLET)
					if(is_alive(id)) Make_AfterPoison(id, Attacker, AFTERPOISON_TIME, AFTERPOISON_DAMAGE)
				}
			}
		}
	}
		
	set_pev(ent, pev_movetype, MOVETYPE_NONE)
	set_pev(ent, pev_solid, SOLID_NOT)
}

public Make_AfterPoison(id, attacker, Float:Time, Damage)
{
	static Ent; Ent = fm_find_ent_by_owner(-1, "afterpoison", id)
	if(!pev_valid(Ent))
	{
		new iEnt = create_entity("env_sprite")
		static Float:MyOrigin[3]
		
		pev(id, pev_origin, MyOrigin)
		
		// set info for ent
		set_pev(iEnt, pev_movetype, MOVETYPE_FLY)
		set_pev(iEnt, pev_rendermode, kRenderTransAdd)
		set_pev(iEnt, pev_renderamt, 250.0)
		set_pev(iEnt, pev_scale, 0.375)
		set_pev(iEnt, pev_fuser1, get_gametime() + Time)	// time remove
		set_pev(iEnt, pev_iuser1, Damage)
		
		entity_set_string(iEnt, EV_SZ_classname, "afterpoison")
		engfunc(EngFunc_SetModel, iEnt, WeaponResources[1])
		set_pev(iEnt, pev_origin, MyOrigin)
		set_pev(iEnt, pev_owner, id)
		set_pev(iEnt, pev_aiment, id)
		set_pev(iEnt, pev_frame, 0.0)
		set_pev(iEnt, pev_iuser4, attacker)
		
		set_pev(iEnt, pev_nextthink, get_gametime() + 0.05)
	} else {
		set_pev(Ent, pev_fuser1, get_gametime() + Time)	// time remove
		set_pev(Ent, pev_iuser1, Damage)
		
		set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
	}
}

public Remove_AfterPoison(id)
{
	static Ent; Ent = fm_find_ent_by_owner(-1, "afterpoison", id)
	if(pev_valid(Ent) == 2) 
	{
		set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
		set_pev(Ent, pev_flags, FL_KILLME)
	}
}

public fw_FireBurn_Think(iEnt)
{
	if(!pev_valid(iEnt)) 
		return
	
	static Float:fFrame
	pev(iEnt, pev_frame, fFrame)

	// effect exp
	fFrame += 1.0
	if(fFrame > 7.0) fFrame = 0.0

	set_pev(iEnt, pev_frame, fFrame)
	set_pev(iEnt, pev_nextthink, get_gametime() + 0.05)
	
	static id; id = pev(iEnt, pev_owner)
	static attacker; attacker = pev(iEnt, pev_iuser4)
	if(!is_alive(id))
	{
		engfunc(EngFunc_RemoveEntity, iEnt)
		return;
	}
	if(!is_connected(attacker))
	{
		engfunc(EngFunc_RemoveEntity, iEnt)
		return;
	}
	
	if(get_gametime() - 2.0 > pev(iEnt, pev_fuser2))
	{
		ExecuteHamB(Ham_TakeDamage, id, 0, attacker, 0.0, DMG_BURN)
		if((get_user_health(id) - pev(iEnt, pev_iuser1)) > 0) set_user_health(id, get_user_health(id) - pev(iEnt, pev_iuser1))
		else ExecuteHamB(Ham_TakeDamage, id, 0, attacker, pev(iEnt, pev_iuser1) * 10.0, DMG_BURN)
		set_pev(iEnt, pev_fuser2, get_gametime())
	}
	
	// time remove
	static Float:fTimeRemove
	pev(iEnt, pev_fuser1, fTimeRemove)
	if (get_gametime() >= fTimeRemove)
	{
		engfunc(EngFunc_RemoveEntity, iEnt)
		return;
	}
}

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

public fw_Weapon_PrimaryAttack_Post(ent)
{
	static id; id = pev(ent, pev_owner)

	if(get_player_weapon(id) == CSW_POISONGUN && Get_BitVar(g_Had_PoisonGun, id) && cs_get_weapon_ammo(ent) > 0)
	{
		static Float:push[3]
		pev(id, pev_punchangle, push)
		xs_vec_sub(push, g_PunchAngles[id], push)
		
		xs_vec_mul_scalar(push, RECOIL, push)
		xs_vec_add(push, g_PunchAngles[id], push)
		set_pev(id, pev_punchangle, push)
		
		CreateFire(id, FIRE_SPEED)
	} else {
		static Float:push[3]
		pev(id, pev_punchangle, push)
		xs_vec_sub(push, g_PunchAngles[id], push)
		
		xs_vec_mul_scalar(push, 0.0, push)
		xs_vec_add(push, g_PunchAngles[id], push)
		set_pev(id, pev_punchangle, push)
	}
	
	return HAM_IGNORED	
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return 1
}

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

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


// ===================== STOCK... =======================
// ======================================================
finally i finished
enjoy :)
Don't Say This Is Impossible , Because Nothing Impossible.

User avatar
sPe3doN
Senior Member
Senior Member
Algeria
Posts: 163
Joined: 2 Years Ago
Has thanked: 15 times
Been thanked: 3 times
Age: 19
Contact:

#7

Post by sPe3doN » 2 Months Ago

Good job, post them here: viewforum.php?f=14

[ Post made via Android ]

User avatar
Muhammet20
Senior Member
Senior Member
Turkey
Posts: 101
Joined: 7 Months Ago
Has thanked: 10 times
Been thanked: 1 time
Contact:

#8

Post by Muhammet20 » 2 Months Ago

sPe3doN wrote:
2 Months Ago
Good job, post them here: viewforum.php?f=14
sPe3doN wrote:
2 Months Ago
Good job
thanks bro
sPe3doN wrote:
2 Months Ago
post them here: viewforum.php?f=14
but i don't have the models , sprites and sounds
i just converted the codes
Don't Say This Is Impossible , Because Nothing Impossible.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest