weapon menu

Unpaid Requests, Public Plugins
Post Reply
User avatar
sPe3doN
Senior Member
Senior Member
Bosnia & Herzegovina
Posts: 144
Joined: 1 Year Ago
Has thanked: 12 times
Been thanked: 2 times
Age: 19
Contact:

weapon menu

#1

Post by sPe3doN » 3 Weeks Ago

any one here can add native for this plugin i want add it to weapon menu

Code: Select all

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

#define ENG_NULLENT		-1
#define EV_INT_WEAPONKEY	EV_INT_impulse
#define RAILCANNON_WEAPONKEY 756144798
#define IsValidUser(%1) (1 <= %1 <= g_MaxPlayers)

#define SMOKE_CLASS "smokess"

#define ENABLE_KNOCKBACK 1

const USE_STOPPED = 0
const OFFSET_ACTIVE_ITEM = 373
const OFFSET_WEAPONOWNER = 41
const OFFSET_LINUX = 5
const OFFSET_LINUX_WEAPONS = 4

#if cellbits == 32
const OFFSET_CLIPAMMO = 51
#else
const OFFSET_CLIPAMMO = 65
#endif

#define WEAP_LINUX_XTRA_OFF		4
#define m_fKnown					44
#define m_flNextPrimaryAttack 		46
#define m_flNextSecondaryAttack 		47
#define m_flTimeWeaponIdle			48
#define m_iClip					51
#define m_fInReload				54
#define m_fInSpecialReload 			55
#define PLAYER_LINUX_XTRA_OFF	5
#define m_flNextAttack				83

#define RAILCANNON_DRAW			7

#define TASK_SOUND 2573+10
#define TASK_SETRUM2 2573+20

new gmsgWeaponList, sTrail

#define write_coord_f(%1)	engfunc(EngFunc_WriteCoord,%1)

new const Fire_Sounds[] = "weapons/railcanon-1.wav"
new const MuzzleFlash[] = "sprites/muzzleflash19.spr"

//////////// Change Here For Customize //////////////////////////

const Float:cvar_recoil_railcannon = 0.65
const cvar_clip_railcannon = 30
const cvar_railcannon_ammo = 300

const Float:damage_mode1 = 20.0
const Float:damage_mode2 = 35.0
const Float:damage_mode3 = 350.0

/////////////////////////////////////////////////////////////////
new RAILCANNON_V_MODEL[64] = "models/v_railcannon.mdl"
new RAILCANNON_P_MODEL[64] = "models/p_railcannon.mdl"
new RAILCANNON_W_MODEL[64] = "models/w_railcannon.mdl"

new const GUNSHOT_DECALS[] = { 41, 42, 43, 44, 45 }

new g_has_railcannon[33], g_Ham_Bot

new g_MaxPlayers, g_orig_event_railcannon, g_IsInPrimaryAttack, g_MuzzleFlash_SprId, g_rail, g_KnockBack
new Float:cl_pushangle[33][3], m_iBlood[2], zz[33], udah[33]
new g_clip_ammo[33], oldweap[33], g_reload[33], railcannon_mode[33], Float:StartOrigin2[3], g_SpecialAmmo[33]
const PRIMARY_WEAPONS_BIT_SUM = 
(1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<
CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
new const WEAPONENTNAMES[][] = { "", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10",
			"weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550",
			"weapon_mp5navy", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249",
			"weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552",
			"weapon_ak47", "weapon_knife", "weapon_p90" }

public plugin_init()
{
	register_plugin("[ZE]Rail Cannon", "1.0", "m4m3ts")
	register_cvar("rail_version", "m4m3ts", FCVAR_SERVER|FCVAR_SPONLY)
	register_event("CurWeapon","CurrentWeapon","be","1=1")
	register_think(SMOKE_CLASS, "fw_Fire_smoke")
	RegisterHam(Ham_Item_AddToPlayer, "weapon_m3", "fw_RAILCANNON_AddToPlayer")
	RegisterHam(Ham_Use, "func_tank", "fw_UseStationary_Post", 1)
	RegisterHam(Ham_Use, "func_tankmortar", "fw_UseStationary_Post", 1)
	RegisterHam(Ham_Use, "func_tankrocket", "fw_UseStationary_Post", 1)
	RegisterHam(Ham_Use, "func_tanklaser", "fw_UseStationary_Post", 1)
	
	for (new i = 1; i < sizeof WEAPONENTNAMES; i++)
		if (WEAPONENTNAMES[i][0]) RegisterHam(Ham_Item_Deploy, WEAPONENTNAMES[i], "fw_Item_Deploy_Post", 1)
	
	RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m3", "fw_RAIL_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m3", "fw_RAIL_PrimaryAttack_Post", 1)
	RegisterHam(Ham_Weapon_Reload, "weapon_m3", "RAILCANNON_Reload")
	RegisterHam(Ham_Weapon_Reload, "weapon_m3", "RAILCANNON_Reload_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle, "weapon_m3", "fw_railcannonidleanim", 1)
	
	RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
	
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fwPlaybackEvent")
	register_forward(FM_TraceLine,"fw_traceline",1)
	
	gmsgWeaponList = get_user_msgid("WeaponList")
	
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack", 1)
	RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack", 1)
	RegisterHam(Ham_TraceAttack, "func_wall", "fw_TraceAttack", 1)
	RegisterHam(Ham_TraceAttack, "func_door", "fw_TraceAttack", 1)
	RegisterHam(Ham_TraceAttack, "func_door_rotating", "fw_TraceAttack", 1)
	RegisterHam(Ham_TraceAttack, "func_plat", "fw_TraceAttack", 1)
	RegisterHam(Ham_TraceAttack, "func_rotating", "fw_TraceAttack", 1)
	
	g_KnockBack = ENABLE_KNOCKBACK
	g_MaxPlayers = get_maxplayers()
}

public plugin_precache()
{
	precache_model(RAILCANNON_V_MODEL)
	precache_model(RAILCANNON_P_MODEL)
	precache_model(RAILCANNON_W_MODEL)
	precache_sound(Fire_Sounds)	
		
	sTrail = precache_model("sprites/laserbeam.spr")
	
	precache_sound("weapons/railcanon_clipin.wav")
	precache_sound("weapons/railcanon_chage1_start.wav")
	precache_sound("weapons/railcanon_chage3_loop.wav")
	precache_sound("weapons/railcanon_draw.wav")
	precache_sound("weapons/railcanon_clipout.wav")
	precache_sound("weapons/railcanon-2.wav")
	
	g_MuzzleFlash_SprId = engfunc(EngFunc_PrecacheModel, MuzzleFlash)
	precache_generic("sprites/weapon_railcannon.txt")
	
	precache_generic("sprites/640hud112.spr")
	precache_generic("sprites/640hud13.spr")
		
	register_clcmd("weapon_railcannon", "weapon_hook")	
					
	m_iBlood[0] = precache_model("sprites/blood.spr")
	m_iBlood[1] = precache_model("sprites/bloodspray.spr")
	precache_model("sprites/wall_puff1.spr")

	register_forward(FM_PrecacheEvent, "fwPrecacheEvent_Post", 1)
}

public weapon_hook(id)
{
	engclient_cmd(id, "weapon_m3")
	return PLUGIN_HANDLED
}

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

public Do_RegisterHam_Bot(id)
{
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack", 1)
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
}

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

public ze_select_item_post(player, itemid)
{
    if (itemid != g_rail)
        return
	
    give_railcannon(player)
}

public ze_user_infected(id)
{
	update_specialammo(id, g_SpecialAmmo[id], 0)
	g_has_railcannon[id] = false
	g_SpecialAmmo[id] = 0
}

public fw_PlayerKilled(id)
{
	g_has_railcannon[id] = false
}

public fw_TraceAttack(iEnt, iAttacker, Float:flDamage, Float:fDir[3], ptr, iDamageType)
{
	if(!is_user_alive(iAttacker))
		return

	new g_currentweapon = get_user_weapon(iAttacker)

	if(g_currentweapon != CSW_M3 || !g_has_railcannon[iAttacker])
		return
	
	if(railcannon_mode[iAttacker] == 3) SetHamParamFloat(3, 60.0)
	if(railcannon_mode[iAttacker] == 2) SetHamParamFloat(3, 35.0)
	if(railcannon_mode[iAttacker] == 1) SetHamParamFloat(3, 20.0)
	
	static Float:flEnd[3], Float:test[3], Float:myOrigin[3]
	
	pev(iAttacker, pev_origin, myOrigin)
	get_tr2(ptr, TR_vecEndPos, flEnd)
		
	if(!is_user_alive(iEnt))
	{
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_DECAL)
		write_coord_f(flEnd[0])
		write_coord_f(flEnd[1])
		write_coord_f(flEnd[2])
		write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
		write_short(iEnt)
		message_end()

		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_WORLDDECAL)
		write_coord_f(flEnd[0])
		write_coord_f(flEnd[1])
		write_coord_f(flEnd[2])
		write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
		message_end()
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_GUNSHOTDECAL)
		write_coord_f(flEnd[0])
		write_coord_f(flEnd[1])
		write_coord_f(flEnd[2])
		write_short(iAttacker)
		write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
		message_end()
		
		fm_get_aim_origin(iAttacker, test)
		if(railcannon_mode[iAttacker] == 3) fake_smokes(iAttacker, test)
	}
	
	if(railcannon_mode[iAttacker] == 2)
	{
		get_position(iAttacker, 20.0, 0.0, 10.0, StartOrigin2)
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_BEAMPOINTS)
		engfunc(EngFunc_WriteCoord, StartOrigin2[0])
		engfunc(EngFunc_WriteCoord, StartOrigin2[1])
		engfunc(EngFunc_WriteCoord, StartOrigin2[2] - 10.0)
		engfunc(EngFunc_WriteCoord, flEnd[0])
		engfunc(EngFunc_WriteCoord, flEnd[1])
		engfunc(EngFunc_WriteCoord, flEnd[2])
		write_short(sTrail)
		write_byte(0) // start frame
		write_byte(0) // framerate
		write_byte(5) // life
		write_byte(5) // line width
		write_byte(0) // amplitude
		write_byte(220)
		write_byte(88)
		write_byte(0) // blue
		write_byte(255) // brightness
		write_byte(0) // speed
		message_end()
	}
	
	if(railcannon_mode[iAttacker] == 3)
	{
		get_position(iAttacker, 20.0, 5.0, 5.0, StartOrigin2)
		
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_BEAMPOINTS)
		engfunc(EngFunc_WriteCoord, StartOrigin2[0])
		engfunc(EngFunc_WriteCoord, StartOrigin2[1])
		engfunc(EngFunc_WriteCoord, StartOrigin2[2] - 10.0)
		engfunc(EngFunc_WriteCoord, flEnd[0])
		engfunc(EngFunc_WriteCoord, flEnd[1])
		engfunc(EngFunc_WriteCoord, flEnd[2])
		write_short(sTrail)
		write_byte(0) // start frame
		write_byte(0) // framerate
		write_byte(8) // life
		write_byte(8) // line width
		write_byte(0) // amplitude
		write_byte(220)
		write_byte(88)
		write_byte(0) // blue
		write_byte(50) // brightness
		write_byte(0) // speed
		message_end()
		
		if(!is_user_alive(iEnt))
			return
		
		if(ze_is_user_zombie(iEnt) && g_KnockBack == 1) knockback(iEnt, myOrigin, 42.0, 2)
	}
	
}

public fake_smokes(id, Float:Origin[3])
{
	new ent_test; ent_test = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
	
	engfunc(EngFunc_SetModel, ent_test, "sprites/wall_puff1.spr")
	entity_set_string(ent_test, EV_SZ_classname, SMOKE_CLASS)
	set_pev(ent_test, pev_nextthink, get_gametime() + 0.04)
	set_pev(ent_test, pev_movetype, MOVETYPE_NONE)
	set_pev(ent_test, pev_rendermode, kRenderTransAdd)
	set_pev(ent_test, pev_renderamt, 20.0)
	set_pev(ent_test, pev_scale, 1.0)
	set_pev(ent_test, pev_origin, Origin)
	set_pev(ent_test, pev_frame, 0.0)
	set_pev(ent_test, pev_iuser2, get_user_team(id))

	set_pev(ent_test, pev_solid, SOLID_NOT)
	dllfunc(DLLFunc_Spawn, ent_test)
}

public fw_Fire_smoke(iEnt)
{
	if(!pev_valid(iEnt)) 
		return
	
	new Float:fFrame
	pev(iEnt, pev_frame, fFrame)

	// effect exp
	fFrame += 1.0

	set_pev(iEnt, pev_frame, fFrame)
	set_pev(iEnt, pev_scale, 1.0)
	set_pev(iEnt, pev_nextthink, get_gametime() + 0.02)
	
	if(fFrame > 30.0) engfunc(EngFunc_RemoveEntity, iEnt)
}

public fw_traceline(Float:v1[3],Float:v2[3],noMonsters,id,ptr)
{
	if(!is_user_alive(id))
		return HAM_IGNORED	
	if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
		return HAM_IGNORED
	if(railcannon_mode[id] != 3)
		return HAM_IGNORED
	
	// get crosshair aim
	static Float:aim[3];
	get_aim(id,v1,aim);
	
	// do another trace to this spot
	new trace = create_tr2();
	engfunc(EngFunc_TraceLine,v1,aim,noMonsters,id,trace);
	
	// copy ints
	set_tr2(ptr,TR_AllSolid,get_tr2(trace,TR_AllSolid));
	set_tr2(ptr,TR_StartSolid,get_tr2(trace,TR_StartSolid));
	set_tr2(ptr,TR_InOpen,get_tr2(trace,TR_InOpen));
	set_tr2(ptr,TR_InWater,get_tr2(trace,TR_InWater));
	set_tr2(ptr,TR_pHit,get_tr2(trace,TR_pHit));
	set_tr2(ptr,TR_iHitgroup,get_tr2(trace,TR_iHitgroup));

	// copy floats
	get_tr2(trace,TR_flFraction,aim[0]);
	set_tr2(ptr,TR_flFraction,aim[0]);
	get_tr2(trace,TR_flPlaneDist,aim[0]);
	set_tr2(ptr,TR_flPlaneDist,aim[0]);
	
	// copy vecs
	get_tr2(trace,TR_vecEndPos,aim);
	set_tr2(ptr,TR_vecEndPos,aim);
	get_tr2(trace,TR_vecPlaneNormal,aim);
	set_tr2(ptr,TR_vecPlaneNormal,aim);

	// get rid of new trace
	free_tr2(trace);

	return FMRES_IGNORED;
}

get_aim(id,Float:source[3],Float:ret[3])
{
	static Float:vAngle[3], Float:pAngle[3], Float:dir[3], Float:temp[3];

	// get aiming direction from forward global based on view angle and punch angle
	pev(id,pev_v_angle,vAngle);
	pev(id,pev_punchangle,pAngle);
	xs_vec_add(vAngle,pAngle,temp);
	engfunc(EngFunc_MakeVectors,temp);
	global_get(glb_v_forward,dir);
	
	/* vecEnd = vecSrc + vecDir * flDistance; */
	xs_vec_mul_scalar(dir,8192.0,temp);
	xs_vec_add(source,temp,ret);
}

public fwPrecacheEvent_Post(type, const name[])
{
	if (equal("events/m3.sc", name))
	{
		g_orig_event_railcannon = get_orig_retval()
		return FMRES_HANDLED
	}
	return FMRES_IGNORED
}

public client_connect(id)
{
	g_has_railcannon[id] = false
}

public client_disconnect(id)
{
	g_has_railcannon[id] = false
}

public fw_SetModel(entity, model[])
{
	if(!is_valid_ent(entity))
		return FMRES_IGNORED
	
	static szClassName[33]
	entity_get_string(entity, EV_SZ_classname, szClassName, charsmax(szClassName))
		
	if(!equal(szClassName, "weaponbox"))
		return FMRES_IGNORED
	
	static iOwner
	
	iOwner = entity_get_edict(entity, EV_ENT_owner)
	
	if(equal(model, "models/w_m3.mdl"))
	{
		static iStoredAugID
		
		iStoredAugID = find_ent_by_owner(ENG_NULLENT, "weapon_m3", entity)
	
		if(!is_valid_ent(iStoredAugID))
			return FMRES_IGNORED
	
		if(g_has_railcannon[iOwner])
		{
			entity_set_int(iStoredAugID, EV_INT_WEAPONKEY, RAILCANNON_WEAPONKEY)
			
			g_has_railcannon[iOwner] = false
			
			entity_set_model(entity, RAILCANNON_W_MODEL)
			
			return FMRES_SUPERCEDE
		}
	}
	return FMRES_IGNORED
}

public give_railcannon(id)
{
	drop_weapons(id, 1)
	new iWep2 = give_item(id,"weapon_m3")
	if( iWep2 > 0 )
	{
		cs_set_weapon_ammo(iWep2, cvar_clip_railcannon)
		cs_set_user_bpammo (id, CSW_M3, cvar_railcannon_ammo)
		UTIL_PlayWeaponAnimation(id, RAILCANNON_DRAW)
		set_weapons_timeidle(id, CSW_M3, 1.0)
		set_player_nextattackx(id, 1.0)
		g_clip_ammo[id] = cs_get_weapon_ammo(iWep2)
	}
	g_has_railcannon[id] = true
	g_SpecialAmmo[id] = 0
	udah[id] = 0
	zz[id] = 0
	railcannon_mode[id] = 1
	update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
	message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
	write_string("weapon_railcannon")
	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_RAILCANNON_AddToPlayer(railcannon, id)
{
	if(!is_valid_ent(railcannon) || !is_user_connected(id))
		return HAM_IGNORED
	
	if(entity_get_int(railcannon, EV_INT_WEAPONKEY) == RAILCANNON_WEAPONKEY)
	{
		g_has_railcannon[id] = true
		
		message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
		write_string("weapon_railcannon")
		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()
		
		entity_set_int(railcannon, EV_INT_WEAPONKEY, 0)
		update_specialammo(id, g_SpecialAmmo[id], 0)
		g_SpecialAmmo[id] = 0

		return HAM_HANDLED
	}
	return HAM_IGNORED
}

public fw_UseStationary_Post(entity, caller, activator, use_type)
{
	if (use_type == USE_STOPPED && is_user_connected(caller))
		replace_weapon_models(caller, get_user_weapon(caller))
}

public fw_Item_Deploy_Post(weapon_ent)
{
	static owner
	owner = fm_cs_get_weapon_ent_owner(weapon_ent)
	
	static weaponid
	weaponid = cs_get_weapon_id(weapon_ent)
	
	update_specialammo(owner, g_SpecialAmmo[owner], 0)
	g_SpecialAmmo[owner] = 0
	
	replace_weapon_models(owner, weaponid)
}

public CurrentWeapon(id)
{
	if( read_data(2) != CSW_M3 ) {
		if( g_reload[id] ) {
			g_reload[id] = 0
			remove_task( id + 1331 )
		}
	}
	replace_weapon_models(id, read_data(2))
}

replace_weapon_models(id, weaponid)
{
	switch (weaponid)
	{
		case CSW_M3:
		{
			if(g_has_railcannon[id])
			{
				set_pev(id, pev_viewmodel2, RAILCANNON_V_MODEL)
				set_pev(id, pev_weaponmodel2, RAILCANNON_P_MODEL)
				if(oldweap[id] != CSW_M3) 
				{
					set_weapons_timeidle(id, CSW_M3, 1.0)
					set_player_nextattackx(id, 1.0)
					UTIL_PlayWeaponAnimation(id, RAILCANNON_DRAW)
					udah[id] = 0
					zz[id] = 0
					railcannon_mode[id] = 1
					remove_task(id+TASK_SOUND)
					remove_task(id)

					message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
					write_string("weapon_railcannon")
					write_byte(5)
					write_byte(32)
					write_byte(-1)
					write_byte(-1)
					write_byte(0)
					write_byte(5)
					write_byte(CSW_M3)
					message_end()
				}
			}
		}
	}
	oldweap[id] = weaponid
}

public fw_UpdateClientData_Post(Player, SendWeapons, CD_Handle)
{
	if(!is_user_alive(Player) || get_user_weapon(Player) != CSW_M3 || !g_has_railcannon[Player])
		return FMRES_IGNORED
	
	set_cd(CD_Handle, CD_flNextAttack, halflife_time () + 0.001)
	return FMRES_HANDLED
}

public fw_RAIL_PrimaryAttack(Weapon)
{
	new Player = get_pdata_cbase(Weapon, 41, 4)
	
	if (!g_has_railcannon[Player])
		return
	
	g_IsInPrimaryAttack = 1
	pev(Player,pev_punchangle,cl_pushangle[Player])
	
	g_clip_ammo[Player] = cs_get_weapon_ammo(Weapon)
	if(g_clip_ammo[Player]) Make_Muzzleflash(Player)
}

public fw_RAIL_PrimaryAttack_Post(Weapon)
{
	g_IsInPrimaryAttack = 0
	new Player = get_pdata_cbase(Weapon, 41, 4)
	
	new szClip, szAmmo
	get_user_weapon(Player, szClip, szAmmo)
	
	if(!is_user_alive(Player))
		return

	if(g_has_railcannon[Player])
	{
		if (!g_clip_ammo[Player] && railcannon_mode[Player] == 1)
			return
		
		g_reload[Player] = 0
		remove_task( Player + 1331 )
		new Float:push[3]
		pev(Player,pev_punchangle,push)
		xs_vec_sub(push,cl_pushangle[Player],push)
		xs_vec_mul_scalar(push,cvar_recoil_railcannon,push)
		xs_vec_add(push,cl_pushangle[Player],push)
		set_pev(Player,pev_punchangle,push)
		
		UTIL_PlayWeaponAnimation(Player,random_num(4,5))
		set_weapons_timeidle(Player, CSW_M3, 0.3)
		set_player_nextattackx(Player, 0.3)
		g_clip_ammo[Player] --
		
		if(railcannon_mode[Player] == 3) emit_sound(Player, CHAN_WEAPON, "weapons/railcanon-2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		else emit_sound(Player, CHAN_WEAPON, Fire_Sounds, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		
		railcannon_mode[Player] = 1
	}
}

public Make_Muzzleflash(id)
{
	static Float:Origin[3], TE_FLAG
	get_position(id, 32.0, 6.0, -15.0, Origin)
	
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, Origin, id)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_MuzzleFlash_SprId)
	write_byte(2)
	write_byte(30)
	write_byte(TE_FLAG)
	message_end()
}

public fw_CmdStart(id, uc_handle, seed) 
{
	new ammo, clip, weapon = get_user_weapon(id, clip, ammo)
	if (!g_has_railcannon[id] || weapon != CSW_M3 || !is_user_alive(id))
		return
	
	static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
		
	if(!pev_valid(ent))
		return
		
	static CurButton
	CurButton = get_uc(uc_handle, UC_Buttons)
	
	if(CurButton & IN_ATTACK)
	{
		new wpn = fm_get_user_weapon_entity(id, get_user_weapon(id))
		
		new Id = pev( wpn, pev_owner ), clip, bpammo
		get_user_weapon( Id, clip, bpammo )
		if( g_has_railcannon[ Id ] ) {
		if( clip >= 2 ) {
			if( g_reload[Id] ) {
				remove_task( Id + 1331 )
				g_reload[Id] = 0
			}
		}
		else if( clip == 1 )
		{
			if(get_pdata_float(Id, 83, 4) <= 0.3)
			{
				if( g_reload[Id] ) {
				remove_task( Id + 1331 )
				g_reload[Id] = 0
			}
			}
		}
	}
	}
	
	else if(CurButton & IN_ATTACK2)
	{
		if(!zz[id] && get_pdata_float(id, 83, 4) <= 0.0 && g_clip_ammo[id] >= 1)
		{
			set_weapons_timeidle(id, CSW_M3, 200.0)
			set_player_nextattackx(id, 200.0)
			UTIL_PlayWeaponAnimation(id, 1)
			emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage1_start.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
			set_task(0.6, "charge_idle2", id)
			zz[id] = 1
			udah[id] = 0
			railcannon_mode[id] = 2
			
			update_specialammo(id, g_SpecialAmmo[id], 0)
			g_SpecialAmmo[id] ++
			update_specialammo(id, g_SpecialAmmo[id], 1)
			
			new weapon = find_ent_by_owner( -1, "weapon_m3", id )
			cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
			g_clip_ammo[id] --
		}
	}
	
	else if(!(pev(id, pev_oldbuttons) & IN_ATTACK) && zz[id])
	{
		zz[id] = 0
		if(udah[id])
		{
			if(g_clip_ammo[id] >= 1)
			{
				ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
				set_weapons_timeidle(id, CSW_M3, 1.1)
				set_player_nextattackx(id, 1.1)
				udah[id] = 0
				remove_task(id+TASK_SOUND)
				
				update_specialammo(id, g_SpecialAmmo[id], 0)
				g_SpecialAmmo[id] = 0
				
				new weapon = find_ent_by_owner( -1, "weapon_m3", id )
				cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
				g_clip_ammo[id] ++
			}
			else
			{
				new weapon = find_ent_by_owner( -1, "weapon_m3", id )
				cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
				g_clip_ammo[id] ++
				
				ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
				set_weapons_timeidle(id, CSW_M3, 1.1)
				set_player_nextattackx(id, 1.1)
				udah[id] = 0
				remove_task(id+TASK_SOUND)
				
				update_specialammo(id, g_SpecialAmmo[id], 0)
				g_SpecialAmmo[id] = 0
			}
		}
	}
}

public charge_idle2(id)
{
	if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
		return
	if(zz[id])
	{
		if(g_clip_ammo[id] >= 1)
		{
			UTIL_PlayWeaponAnimation(id, 2)
			set_weapons_timeidle(id, CSW_M3, 200.0)
			set_player_nextattackx(id, 200.0)
			set_task(0.6, "charge_idle3", id)
			
			update_specialammo(id, g_SpecialAmmo[id], 0)
			g_SpecialAmmo[id] ++
			update_specialammo(id, g_SpecialAmmo[id], 1)
			
			new weapon = find_ent_by_owner( -1, "weapon_m3", id )
			cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
			g_clip_ammo[id] --
		}
		else
		{
			static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
		
			if(!pev_valid(ent))
				return
			
			new weapon = find_ent_by_owner( -1, "weapon_m3", id )
			cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
			g_clip_ammo[id] ++
			
			ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
			set_weapons_timeidle(id, CSW_M3, 1.1)
			set_player_nextattackx(id, 1.1)
			
			update_specialammo(id, g_SpecialAmmo[id], 0)
			g_SpecialAmmo[id] = 0
		}
	}
	else
	{
		static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
		
		if(!pev_valid(ent))
			return
		ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
		set_weapons_timeidle(id, CSW_M3, 1.1)
		set_player_nextattackx(id, 1.1)
		
		update_specialammo(id, g_SpecialAmmo[id], 0)
		g_SpecialAmmo[id] = 0
		
		new weapon = find_ent_by_owner( -1, "weapon_m3", id )
		cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
		g_clip_ammo[id] ++
	}
}

public charge_idle3(id)
{
	if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
		return
	if(zz[id])
	{
		if(g_clip_ammo[id] >= 1)
		{
			UTIL_PlayWeaponAnimation(id, 3)
			emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage3_loop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
			set_task(0.794, "play_sound", id+TASK_SOUND,_,_,"b")
			udah[id] = 1
			railcannon_mode[id] = 3
			set_weapons_timeidle(id, CSW_M3, 200.0)
			set_player_nextattackx(id, 200.0)
			
			update_specialammo(id, g_SpecialAmmo[id], 0)
			g_SpecialAmmo[id] ++
			update_specialammo(id, g_SpecialAmmo[id], 1)
			
			new weapon = find_ent_by_owner( -1, "weapon_m3", id )
			cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
			g_clip_ammo[id] --
		}
		else
		{
			static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
		
			if(!pev_valid(ent))
				return
			new weapon = find_ent_by_owner( -1, "weapon_m3", id )
			cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
			g_clip_ammo[id] ++
			
			ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
			set_weapons_timeidle(id, CSW_M3, 1.1)
			set_player_nextattackx(id, 1.1)
			
			update_specialammo(id, g_SpecialAmmo[id], 0)
			g_SpecialAmmo[id] = 0
		}
	}
	else
	{
		static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
		
		if(!pev_valid(ent))
			return
		ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
		set_weapons_timeidle(id, CSW_M3, 1.1)
		set_player_nextattackx(id, 1.1)
		
		update_specialammo(id, g_SpecialAmmo[id], 0)
		g_SpecialAmmo[id] = 0
		
		new weapon = find_ent_by_owner( -1, "weapon_m3", id )
		cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
		g_clip_ammo[id] ++
	}
}

public play_sound(id)
{
	id -= TASK_SOUND
	
	if(!is_user_alive(id) || get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
		return
	
	emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage3_loop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}

public fw_railcannonidleanim(Weapon)
{
	new id = get_pdata_cbase(Weapon, 41, 4)

	if(!is_user_alive(id) || !g_has_railcannon[id] || get_user_weapon(id) != CSW_M3)
		return HAM_IGNORED;
	
	if(railcannon_mode[id] == 1 && get_pdata_float(Weapon, 48, 4) <= 0.25)
	{
		UTIL_PlayWeaponAnimation(id, 0)
		set_pdata_float(Weapon, 48, 20.0, 4)
		return HAM_SUPERCEDE;
	}
	
	if(railcannon_mode[id] == 3 && get_pdata_float(Weapon, 48, 4) <= 0.01)
	{
		UTIL_PlayWeaponAnimation(id, 3)
		set_pdata_float(Weapon, 48, 1.7, 4)
		return HAM_SUPERCEDE;
	}

	return HAM_IGNORED;
}

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

public fwPlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if ((eventid != g_orig_event_railcannon) || !g_IsInPrimaryAttack)
		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 RAILCANNON_Reload( wpn ) {
	if(railcannon_mode[pev( wpn, pev_owner )] == 3)
	      return HAM_SUPERCEDE
		  
	if( g_has_railcannon[ pev( wpn, pev_owner ) ] ) {
		RAILCANNON_Reload_Post( wpn )
		return HAM_SUPERCEDE
	}
	return HAM_IGNORED
}

public RAILCANNON_Reload_Post(weapon) {
	new id = pev( weapon, pev_owner )
	if(railcannon_mode[id] == 3 || g_reload[id])
	      return HAM_SUPERCEDE
	new clip, bpammo
	get_user_weapon(id, clip, bpammo )
	if( g_has_railcannon[ id ] && clip < cvar_clip_railcannon && bpammo > 0 ) {
		if(!task_exists( id+1331 )) set_task( 0.1, "reload", id+1331 )
		}
	return HAM_IGNORED
}

public reload( id ) {
	id -= 1331
	set_weapons_timeidle(id, CSW_M3, 3.0)
	set_player_nextattackx(id, 3.0)
	UTIL_PlayWeaponAnimation(id, 6)
	g_reload[id] = 1
	set_task(3.0, "isi", id)
}

public isi(id)
{
	if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
		return
	
	if(!g_reload[id])
		return
	
	new clip, pluru, pengurang, bpammo, weapon = find_ent_by_owner( -1, "weapon_m3", id )
	get_user_weapon(id, clip, bpammo )
	pengurang = cvar_clip_railcannon - clip
	pluru = bpammo - pengurang
	cs_set_user_bpammo( id, CSW_M3, pluru )
	
	if(bpammo <= pengurang) cs_set_weapon_ammo( weapon, clip + bpammo)
	else cs_set_weapon_ammo( weapon, cvar_clip_railcannon)
	
	g_clip_ammo[id] = cvar_clip_railcannon
}

stock knockback(ent, Float:VicOrigin[3], Float:speed, type)
{
	static Float:fl_Velocity[3]
	static Float:EntOrigin[3]
	static Float:EntVelocity[3]
	
	pev(ent, pev_velocity, EntVelocity)
	pev(ent, pev_origin, EntOrigin)
	static Float:distance_f
	distance_f = get_distance_f(EntOrigin, VicOrigin)
	
	static Float:fl_Time; fl_Time = distance_f / speed
	
	if(type == 1)
	{
		fl_Velocity[0] = ((VicOrigin[0] - EntOrigin[0]) / fl_Time) * 1.5
		fl_Velocity[1] = ((VicOrigin[1] - EntOrigin[1]) / fl_Time) * 1.5
		fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time		
		} else if(type == 2) {
		fl_Velocity[0] = ((EntOrigin[0] - VicOrigin[0]) / fl_Time) * 1.5
		fl_Velocity[1] = ((EntOrigin[1] - VicOrigin[1]) / fl_Time) * 1.5
		fl_Velocity[2] = (EntOrigin[2] - VicOrigin[2]) / fl_Time
	}
	
	xs_vec_add(EntVelocity, fl_Velocity, fl_Velocity)
	set_pev(ent, pev_velocity, fl_Velocity)
}

stock fm_cs_get_current_weapon_ent(id)
{
	return get_pdata_cbase(id, OFFSET_ACTIVE_ITEM, OFFSET_LINUX)
}

stock fm_set_weapon_ammo(entity, amount)
{
	set_pdata_int(entity, OFFSET_CLIPAMMO, amount, OFFSET_LINUX_WEAPONS);
}

stock fm_cs_get_weapon_ent_owner(ent)
{
	return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS)
}

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(pev(Player, pev_body))
	message_end()
}

stock set_player_nextattackx(id, Float:nexttime)
{
	if(!is_user_alive(id))
		return
		
	set_pdata_float(id, m_flNextAttack, nexttime, 5)
}

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

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

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


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

[ Post made via Android ]
Last edited by sPe3doN on 30 Nov 2018, 16:05, edited 2 times in total.

User avatar
sPe3doN
Senior Member
Senior Member
Bosnia & Herzegovina
Posts: 144
Joined: 1 Year Ago
Has thanked: 12 times
Been thanked: 2 times
Age: 19
Contact:

#2

Post by sPe3doN » 1 Week Ago

upp

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

#3

Post by Raheem » 1 Week Ago

  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <fakemeta_util>
  4. #include <fun>
  5. #include <xs>
  6. #include <cstrike>
  7.  
  8. #define ENG_NULLENT     -1
  9. #define EV_INT_WEAPONKEY    EV_INT_impulse
  10. #define RAILCANNON_WEAPONKEY 756144798
  11. #define IsValidUser(%1) (1 <= %1 <= g_MaxPlayers)
  12.  
  13. #define SMOKE_CLASS "smokess"
  14.  
  15. #define ENABLE_KNOCKBACK 1
  16.  
  17. const USE_STOPPED = 0
  18. const OFFSET_ACTIVE_ITEM = 373
  19. const OFFSET_WEAPONOWNER = 41
  20. const OFFSET_LINUX = 5
  21. const OFFSET_LINUX_WEAPONS = 4
  22.  
  23. #if cellbits == 32
  24. const OFFSET_CLIPAMMO = 51
  25. #else
  26. const OFFSET_CLIPAMMO = 65
  27. #endif
  28.  
  29. #define WEAP_LINUX_XTRA_OFF     4
  30. #define m_fKnown                    44
  31. #define m_flNextPrimaryAttack       46
  32. #define m_flNextSecondaryAttack         47
  33. #define m_flTimeWeaponIdle          48
  34. #define m_iClip                 51
  35. #define m_fInReload             54
  36. #define m_fInSpecialReload          55
  37. #define PLAYER_LINUX_XTRA_OFF   5
  38. #define m_flNextAttack              83
  39.  
  40. #define RAILCANNON_DRAW         7
  41.  
  42. #define TASK_SOUND 2573+10
  43. #define TASK_SETRUM2 2573+20
  44.  
  45. new gmsgWeaponList, sTrail
  46.  
  47. #define write_coord_f(%1)   engfunc(EngFunc_WriteCoord,%1)
  48.  
  49. new const Fire_Sounds[] = "weapons/railcanon-1.wav"
  50. new const MuzzleFlash[] = "sprites/muzzleflash19.spr"
  51.  
  52. //////////// Change Here For Customize //////////////////////////
  53.  
  54. const Float:cvar_recoil_railcannon = 0.65
  55. const cvar_clip_railcannon = 30
  56. const cvar_railcannon_ammo = 300
  57.  
  58. const Float:damage_mode1 = 20.0
  59. const Float:damage_mode2 = 35.0
  60. const Float:damage_mode3 = 350.0
  61.  
  62. /////////////////////////////////////////////////////////////////
  63. new RAILCANNON_V_MODEL[64] = "models/v_railcannon.mdl"
  64. new RAILCANNON_P_MODEL[64] = "models/p_railcannon.mdl"
  65. new RAILCANNON_W_MODEL[64] = "models/w_railcannon.mdl"
  66.  
  67. new const GUNSHOT_DECALS[] = { 41, 42, 43, 44, 45 }
  68.  
  69. new g_has_railcannon[33], g_Ham_Bot
  70.  
  71. new g_MaxPlayers, g_orig_event_railcannon, g_IsInPrimaryAttack, g_MuzzleFlash_SprId, g_KnockBack
  72. new Float:cl_pushangle[33][3], m_iBlood[2], zz[33], udah[33]
  73. new g_clip_ammo[33], oldweap[33], g_reload[33], railcannon_mode[33], Float:StartOrigin2[3], g_SpecialAmmo[33]
  74. const PRIMARY_WEAPONS_BIT_SUM =
  75. (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<
  76. CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
  77. new const WEAPONENTNAMES[][] = { "", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10",
  78.             "weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550",
  79.             "weapon_mp5navy", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249",
  80.             "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552",
  81.             "weapon_ak47", "weapon_knife", "weapon_p90" }
  82.  
  83. public plugin_init()
  84. {
  85.     register_plugin("[ZE]Rail Cannon", "1.0", "m4m3ts")
  86.     register_cvar("rail_version", "m4m3ts", FCVAR_SERVER|FCVAR_SPONLY)
  87.     register_event("CurWeapon","CurrentWeapon","be","1=1")
  88.     register_think(SMOKE_CLASS, "fw_Fire_smoke")
  89.     RegisterHam(Ham_Item_AddToPlayer, "weapon_m3", "fw_RAILCANNON_AddToPlayer")
  90.     RegisterHam(Ham_Use, "func_tank", "fw_UseStationary_Post", 1)
  91.     RegisterHam(Ham_Use, "func_tankmortar", "fw_UseStationary_Post", 1)
  92.     RegisterHam(Ham_Use, "func_tankrocket", "fw_UseStationary_Post", 1)
  93.     RegisterHam(Ham_Use, "func_tanklaser", "fw_UseStationary_Post", 1)
  94.    
  95.     for (new i = 1; i < sizeof WEAPONENTNAMES; i++)
  96.         if (WEAPONENTNAMES[i][0]) RegisterHam(Ham_Item_Deploy, WEAPONENTNAMES[i], "fw_Item_Deploy_Post", 1)
  97.    
  98.     RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m3", "fw_RAIL_PrimaryAttack")
  99.     RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m3", "fw_RAIL_PrimaryAttack_Post", 1)
  100.     RegisterHam(Ham_Weapon_Reload, "weapon_m3", "RAILCANNON_Reload")
  101.     RegisterHam(Ham_Weapon_Reload, "weapon_m3", "RAILCANNON_Reload_Post", 1)
  102.     RegisterHam(Ham_Weapon_WeaponIdle, "weapon_m3", "fw_railcannonidleanim", 1)
  103.    
  104.     RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  105.    
  106.     register_forward(FM_CmdStart, "fw_CmdStart")
  107.     register_forward(FM_SetModel, "fw_SetModel")
  108.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  109.     register_forward(FM_PlaybackEvent, "fwPlaybackEvent")
  110.     register_forward(FM_TraceLine,"fw_traceline",1)
  111.    
  112.     gmsgWeaponList = get_user_msgid("WeaponList")
  113.    
  114.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
  115.     RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack", 1)
  116.     RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack", 1)
  117.     RegisterHam(Ham_TraceAttack, "func_wall", "fw_TraceAttack", 1)
  118.     RegisterHam(Ham_TraceAttack, "func_door", "fw_TraceAttack", 1)
  119.     RegisterHam(Ham_TraceAttack, "func_door_rotating", "fw_TraceAttack", 1)
  120.     RegisterHam(Ham_TraceAttack, "func_plat", "fw_TraceAttack", 1)
  121.     RegisterHam(Ham_TraceAttack, "func_rotating", "fw_TraceAttack", 1)
  122.    
  123.     g_KnockBack = ENABLE_KNOCKBACK
  124.     g_MaxPlayers = get_maxplayers()
  125. }
  126.  
  127. public plugin_precache()
  128. {
  129.     precache_model(RAILCANNON_V_MODEL)
  130.     precache_model(RAILCANNON_P_MODEL)
  131.     precache_model(RAILCANNON_W_MODEL)
  132.     precache_sound(Fire_Sounds)
  133.        
  134.     sTrail = precache_model("sprites/laserbeam.spr")
  135.    
  136.     precache_sound("weapons/railcanon_clipin.wav")
  137.     precache_sound("weapons/railcanon_chage1_start.wav")
  138.     precache_sound("weapons/railcanon_chage3_loop.wav")
  139.     precache_sound("weapons/railcanon_draw.wav")
  140.     precache_sound("weapons/railcanon_clipout.wav")
  141.     precache_sound("weapons/railcanon-2.wav")
  142.    
  143.     g_MuzzleFlash_SprId = engfunc(EngFunc_PrecacheModel, MuzzleFlash)
  144.     precache_generic("sprites/weapon_railcannon.txt")
  145.    
  146.     precache_generic("sprites/640hud112.spr")
  147.     precache_generic("sprites/640hud13.spr")
  148.        
  149.     register_clcmd("weapon_railcannon", "weapon_hook") 
  150.                    
  151.     m_iBlood[0] = precache_model("sprites/blood.spr")
  152.     m_iBlood[1] = precache_model("sprites/bloodspray.spr")
  153.     precache_model("sprites/wall_puff1.spr")
  154.  
  155.     register_forward(FM_PrecacheEvent, "fwPrecacheEvent_Post", 1)
  156. }
  157.  
  158. public plugin_natives()
  159. {
  160.     register_native("give_railcanon", "native_give_railcanon", 1)
  161. }
  162.  
  163. public native_give_railcanon(id)
  164. {
  165.     give_railcannon(id)
  166. }
  167.  
  168. public weapon_hook(id)
  169. {
  170.     engclient_cmd(id, "weapon_m3")
  171.     return PLUGIN_HANDLED
  172. }
  173.  
  174. public client_putinserver(id)
  175. {
  176.     if(!g_Ham_Bot && is_user_bot(id))
  177.     {
  178.         g_Ham_Bot = 1
  179.         set_task(0.1, "Do_RegisterHam_Bot", id)
  180.     }
  181. }
  182.  
  183. public Do_RegisterHam_Bot(id)
  184. {
  185.     RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack", 1)
  186.     RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
  187. }
  188.  
  189. public ze_user_infected(id)
  190. {
  191.     update_specialammo(id, g_SpecialAmmo[id], 0)
  192.     g_has_railcannon[id] = false
  193.     g_SpecialAmmo[id] = 0
  194. }
  195.  
  196. public fw_PlayerKilled(id)
  197. {
  198.     g_has_railcannon[id] = false
  199. }
  200.  
  201. public fw_TraceAttack(iEnt, iAttacker, Float:flDamage, Float:fDir[3], ptr, iDamageType)
  202. {
  203.     if(!is_user_alive(iAttacker))
  204.         return
  205.  
  206.     new g_currentweapon = get_user_weapon(iAttacker)
  207.  
  208.     if(g_currentweapon != CSW_M3 || !g_has_railcannon[iAttacker])
  209.         return
  210.    
  211.     if(railcannon_mode[iAttacker] == 3) SetHamParamFloat(3, 60.0)
  212.     if(railcannon_mode[iAttacker] == 2) SetHamParamFloat(3, 35.0)
  213.     if(railcannon_mode[iAttacker] == 1) SetHamParamFloat(3, 20.0)
  214.    
  215.     static Float:flEnd[3], Float:test[3], Float:myOrigin[3]
  216.    
  217.     pev(iAttacker, pev_origin, myOrigin)
  218.     get_tr2(ptr, TR_vecEndPos, flEnd)
  219.        
  220.     if(!is_user_alive(iEnt))
  221.     {
  222.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  223.         write_byte(TE_DECAL)
  224.         write_coord_f(flEnd[0])
  225.         write_coord_f(flEnd[1])
  226.         write_coord_f(flEnd[2])
  227.         write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
  228.         write_short(iEnt)
  229.         message_end()
  230.  
  231.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  232.         write_byte(TE_WORLDDECAL)
  233.         write_coord_f(flEnd[0])
  234.         write_coord_f(flEnd[1])
  235.         write_coord_f(flEnd[2])
  236.         write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
  237.         message_end()
  238.        
  239.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  240.         write_byte(TE_GUNSHOTDECAL)
  241.         write_coord_f(flEnd[0])
  242.         write_coord_f(flEnd[1])
  243.         write_coord_f(flEnd[2])
  244.         write_short(iAttacker)
  245.         write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
  246.         message_end()
  247.        
  248.         fm_get_aim_origin(iAttacker, test)
  249.         if(railcannon_mode[iAttacker] == 3) fake_smokes(iAttacker, test)
  250.     }
  251.    
  252.     if(railcannon_mode[iAttacker] == 2)
  253.     {
  254.         get_position(iAttacker, 20.0, 0.0, 10.0, StartOrigin2)
  255.        
  256.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  257.         write_byte(TE_BEAMPOINTS)
  258.         engfunc(EngFunc_WriteCoord, StartOrigin2[0])
  259.         engfunc(EngFunc_WriteCoord, StartOrigin2[1])
  260.         engfunc(EngFunc_WriteCoord, StartOrigin2[2] - 10.0)
  261.         engfunc(EngFunc_WriteCoord, flEnd[0])
  262.         engfunc(EngFunc_WriteCoord, flEnd[1])
  263.         engfunc(EngFunc_WriteCoord, flEnd[2])
  264.         write_short(sTrail)
  265.         write_byte(0) // start frame
  266.         write_byte(0) // framerate
  267.         write_byte(5) // life
  268.         write_byte(5) // line width
  269.         write_byte(0) // amplitude
  270.         write_byte(220)
  271.         write_byte(88)
  272.         write_byte(0) // blue
  273.         write_byte(255) // brightness
  274.         write_byte(0) // speed
  275.         message_end()
  276.     }
  277.    
  278.     if(railcannon_mode[iAttacker] == 3)
  279.     {
  280.         get_position(iAttacker, 20.0, 5.0, 5.0, StartOrigin2)
  281.        
  282.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  283.         write_byte(TE_BEAMPOINTS)
  284.         engfunc(EngFunc_WriteCoord, StartOrigin2[0])
  285.         engfunc(EngFunc_WriteCoord, StartOrigin2[1])
  286.         engfunc(EngFunc_WriteCoord, StartOrigin2[2] - 10.0)
  287.         engfunc(EngFunc_WriteCoord, flEnd[0])
  288.         engfunc(EngFunc_WriteCoord, flEnd[1])
  289.         engfunc(EngFunc_WriteCoord, flEnd[2])
  290.         write_short(sTrail)
  291.         write_byte(0) // start frame
  292.         write_byte(0) // framerate
  293.         write_byte(8) // life
  294.         write_byte(8) // line width
  295.         write_byte(0) // amplitude
  296.         write_byte(220)
  297.         write_byte(88)
  298.         write_byte(0) // blue
  299.         write_byte(50) // brightness
  300.         write_byte(0) // speed
  301.         message_end()
  302.        
  303.         if(!is_user_alive(iEnt))
  304.             return
  305.        
  306.         if(ze_is_user_zombie(iEnt) && g_KnockBack == 1) knockback(iEnt, myOrigin, 42.0, 2)
  307.     }
  308.    
  309. }
  310.  
  311. public fake_smokes(id, Float:Origin[3])
  312. {
  313.     new ent_test; ent_test = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
  314.    
  315.     engfunc(EngFunc_SetModel, ent_test, "sprites/wall_puff1.spr")
  316.     entity_set_string(ent_test, EV_SZ_classname, SMOKE_CLASS)
  317.     set_pev(ent_test, pev_nextthink, get_gametime() + 0.04)
  318.     set_pev(ent_test, pev_movetype, MOVETYPE_NONE)
  319.     set_pev(ent_test, pev_rendermode, kRenderTransAdd)
  320.     set_pev(ent_test, pev_renderamt, 20.0)
  321.     set_pev(ent_test, pev_scale, 1.0)
  322.     set_pev(ent_test, pev_origin, Origin)
  323.     set_pev(ent_test, pev_frame, 0.0)
  324.     set_pev(ent_test, pev_iuser2, get_user_team(id))
  325.  
  326.     set_pev(ent_test, pev_solid, SOLID_NOT)
  327.     dllfunc(DLLFunc_Spawn, ent_test)
  328. }
  329.  
  330. public fw_Fire_smoke(iEnt)
  331. {
  332.     if(!pev_valid(iEnt))
  333.         return
  334.    
  335.     new Float:fFrame
  336.     pev(iEnt, pev_frame, fFrame)
  337.  
  338.     // effect exp
  339.     fFrame += 1.0
  340.  
  341.     set_pev(iEnt, pev_frame, fFrame)
  342.     set_pev(iEnt, pev_scale, 1.0)
  343.     set_pev(iEnt, pev_nextthink, get_gametime() + 0.02)
  344.    
  345.     if(fFrame > 30.0) engfunc(EngFunc_RemoveEntity, iEnt)
  346. }
  347.  
  348. public fw_traceline(Float:v1[3],Float:v2[3],noMonsters,id,ptr)
  349. {
  350.     if(!is_user_alive(id))
  351.         return HAM_IGNORED 
  352.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  353.         return HAM_IGNORED
  354.     if(railcannon_mode[id] != 3)
  355.         return HAM_IGNORED
  356.    
  357.     // get crosshair aim
  358.     static Float:aim[3];
  359.     get_aim(id,v1,aim);
  360.    
  361.     // do another trace to this spot
  362.     new trace = create_tr2();
  363.     engfunc(EngFunc_TraceLine,v1,aim,noMonsters,id,trace);
  364.    
  365.     // copy ints
  366.     set_tr2(ptr,TR_AllSolid,get_tr2(trace,TR_AllSolid));
  367.     set_tr2(ptr,TR_StartSolid,get_tr2(trace,TR_StartSolid));
  368.     set_tr2(ptr,TR_InOpen,get_tr2(trace,TR_InOpen));
  369.     set_tr2(ptr,TR_InWater,get_tr2(trace,TR_InWater));
  370.     set_tr2(ptr,TR_pHit,get_tr2(trace,TR_pHit));
  371.     set_tr2(ptr,TR_iHitgroup,get_tr2(trace,TR_iHitgroup));
  372.  
  373.     // copy floats
  374.     get_tr2(trace,TR_flFraction,aim[0]);
  375.     set_tr2(ptr,TR_flFraction,aim[0]);
  376.     get_tr2(trace,TR_flPlaneDist,aim[0]);
  377.     set_tr2(ptr,TR_flPlaneDist,aim[0]);
  378.    
  379.     // copy vecs
  380.     get_tr2(trace,TR_vecEndPos,aim);
  381.     set_tr2(ptr,TR_vecEndPos,aim);
  382.     get_tr2(trace,TR_vecPlaneNormal,aim);
  383.     set_tr2(ptr,TR_vecPlaneNormal,aim);
  384.  
  385.     // get rid of new trace
  386.     free_tr2(trace);
  387.  
  388.     return FMRES_IGNORED;
  389. }
  390.  
  391. get_aim(id,Float:source[3],Float:ret[3])
  392. {
  393.     static Float:vAngle[3], Float:pAngle[3], Float:dir[3], Float:temp[3];
  394.  
  395.     // get aiming direction from forward global based on view angle and punch angle
  396.     pev(id,pev_v_angle,vAngle);
  397.     pev(id,pev_punchangle,pAngle);
  398.     xs_vec_add(vAngle,pAngle,temp);
  399.     engfunc(EngFunc_MakeVectors,temp);
  400.     global_get(glb_v_forward,dir);
  401.    
  402.     /* vecEnd = vecSrc + vecDir * flDistance; */
  403.     xs_vec_mul_scalar(dir,8192.0,temp);
  404.     xs_vec_add(source,temp,ret);
  405. }
  406.  
  407. public fwPrecacheEvent_Post(type, const name[])
  408. {
  409.     if (equal("events/m3.sc", name))
  410.     {
  411.         g_orig_event_railcannon = get_orig_retval()
  412.         return FMRES_HANDLED
  413.     }
  414.     return FMRES_IGNORED
  415. }
  416.  
  417. public client_connect(id)
  418. {
  419.     g_has_railcannon[id] = false
  420. }
  421.  
  422. public client_disconnected(id)
  423. {
  424.     g_has_railcannon[id] = false
  425. }
  426.  
  427. public fw_SetModel(entity, model[])
  428. {
  429.     if(!is_valid_ent(entity))
  430.         return FMRES_IGNORED
  431.    
  432.     static szClassName[33]
  433.     entity_get_string(entity, EV_SZ_classname, szClassName, charsmax(szClassName))
  434.        
  435.     if(!equal(szClassName, "weaponbox"))
  436.         return FMRES_IGNORED
  437.    
  438.     static iOwner
  439.    
  440.     iOwner = entity_get_edict(entity, EV_ENT_owner)
  441.    
  442.     if(equal(model, "models/w_m3.mdl"))
  443.     {
  444.         static iStoredAugID
  445.        
  446.         iStoredAugID = find_ent_by_owner(ENG_NULLENT, "weapon_m3", entity)
  447.    
  448.         if(!is_valid_ent(iStoredAugID))
  449.             return FMRES_IGNORED
  450.    
  451.         if(g_has_railcannon[iOwner])
  452.         {
  453.             entity_set_int(iStoredAugID, EV_INT_WEAPONKEY, RAILCANNON_WEAPONKEY)
  454.            
  455.             g_has_railcannon[iOwner] = false
  456.            
  457.             entity_set_model(entity, RAILCANNON_W_MODEL)
  458.            
  459.             return FMRES_SUPERCEDE
  460.         }
  461.     }
  462.     return FMRES_IGNORED
  463. }
  464.  
  465. public give_railcannon(id)
  466. {
  467.     drop_weapons(id, 1)
  468.     new iWep2 = give_item(id,"weapon_m3")
  469.     if( iWep2 > 0 )
  470.     {
  471.         cs_set_weapon_ammo(iWep2, cvar_clip_railcannon)
  472.         cs_set_user_bpammo (id, CSW_M3, cvar_railcannon_ammo)
  473.         UTIL_PlayWeaponAnimation(id, RAILCANNON_DRAW)
  474.         set_weapons_timeidle(id, CSW_M3, 1.0)
  475.         set_player_nextattackx(id, 1.0)
  476.         g_clip_ammo[id] = cs_get_weapon_ammo(iWep2)
  477.     }
  478.     g_has_railcannon[id] = true
  479.     g_SpecialAmmo[id] = 0
  480.     udah[id] = 0
  481.     zz[id] = 0
  482.     railcannon_mode[id] = 1
  483.     update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
  484.     message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
  485.     write_string("weapon_railcannon")
  486.     write_byte(5)
  487.     write_byte(32)
  488.     write_byte(-1)
  489.     write_byte(-1)
  490.     write_byte(0)
  491.     write_byte(5)
  492.     write_byte(21)
  493.     write_byte(0)
  494.     message_end()
  495. }
  496.  
  497. public fw_RAILCANNON_AddToPlayer(railcannon, id)
  498. {
  499.     if(!is_valid_ent(railcannon) || !is_user_connected(id))
  500.         return HAM_IGNORED
  501.    
  502.     if(entity_get_int(railcannon, EV_INT_WEAPONKEY) == RAILCANNON_WEAPONKEY)
  503.     {
  504.         g_has_railcannon[id] = true
  505.        
  506.         message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
  507.         write_string("weapon_railcannon")
  508.         write_byte(5)
  509.         write_byte(32)
  510.         write_byte(-1)
  511.         write_byte(-1)
  512.         write_byte(0)
  513.         write_byte(5)
  514.         write_byte(21)
  515.         write_byte(0)
  516.         message_end()
  517.        
  518.         entity_set_int(railcannon, EV_INT_WEAPONKEY, 0)
  519.         update_specialammo(id, g_SpecialAmmo[id], 0)
  520.         g_SpecialAmmo[id] = 0
  521.  
  522.         return HAM_HANDLED
  523.     }
  524.     return HAM_IGNORED
  525. }
  526.  
  527. public fw_UseStationary_Post(entity, caller, activator, use_type)
  528. {
  529.     if (use_type == USE_STOPPED && is_user_connected(caller))
  530.         replace_weapon_models(caller, get_user_weapon(caller))
  531. }
  532.  
  533. public fw_Item_Deploy_Post(weapon_ent)
  534. {
  535.     static owner
  536.     owner = fm_cs_get_weapon_ent_owner(weapon_ent)
  537.    
  538.     static weaponid
  539.     weaponid = cs_get_weapon_id(weapon_ent)
  540.    
  541.     update_specialammo(owner, g_SpecialAmmo[owner], 0)
  542.     g_SpecialAmmo[owner] = 0
  543.    
  544.     replace_weapon_models(owner, weaponid)
  545. }
  546.  
  547. public CurrentWeapon(id)
  548. {
  549.     if( read_data(2) != CSW_M3 ) {
  550.         if( g_reload[id] ) {
  551.             g_reload[id] = 0
  552.             remove_task( id + 1331 )
  553.         }
  554.     }
  555.     replace_weapon_models(id, read_data(2))
  556. }
  557.  
  558. replace_weapon_models(id, weaponid)
  559. {
  560.     switch (weaponid)
  561.     {
  562.         case CSW_M3:
  563.         {
  564.             if(g_has_railcannon[id])
  565.             {
  566.                 set_pev(id, pev_viewmodel2, RAILCANNON_V_MODEL)
  567.                 set_pev(id, pev_weaponmodel2, RAILCANNON_P_MODEL)
  568.                 if(oldweap[id] != CSW_M3)
  569.                 {
  570.                     set_weapons_timeidle(id, CSW_M3, 1.0)
  571.                     set_player_nextattackx(id, 1.0)
  572.                     UTIL_PlayWeaponAnimation(id, RAILCANNON_DRAW)
  573.                     udah[id] = 0
  574.                     zz[id] = 0
  575.                     railcannon_mode[id] = 1
  576.                     remove_task(id+TASK_SOUND)
  577.                     remove_task(id)
  578.  
  579.                     message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
  580.                     write_string("weapon_railcannon")
  581.                     write_byte(5)
  582.                     write_byte(32)
  583.                     write_byte(-1)
  584.                     write_byte(-1)
  585.                     write_byte(0)
  586.                     write_byte(5)
  587.                     write_byte(CSW_M3)
  588.                     message_end()
  589.                 }
  590.             }
  591.         }
  592.     }
  593.     oldweap[id] = weaponid
  594. }
  595.  
  596. public fw_UpdateClientData_Post(Player, SendWeapons, CD_Handle)
  597. {
  598.     if(!is_user_alive(Player) || get_user_weapon(Player) != CSW_M3 || !g_has_railcannon[Player])
  599.         return FMRES_IGNORED
  600.    
  601.     set_cd(CD_Handle, CD_flNextAttack, halflife_time () + 0.001)
  602.     return FMRES_HANDLED
  603. }
  604.  
  605. public fw_RAIL_PrimaryAttack(Weapon)
  606. {
  607.     new Player = get_pdata_cbase(Weapon, 41, 4)
  608.    
  609.     if (!g_has_railcannon[Player])
  610.         return
  611.    
  612.     g_IsInPrimaryAttack = 1
  613.     pev(Player,pev_punchangle,cl_pushangle[Player])
  614.    
  615.     g_clip_ammo[Player] = cs_get_weapon_ammo(Weapon)
  616.     if(g_clip_ammo[Player]) Make_Muzzleflash(Player)
  617. }
  618.  
  619. public fw_RAIL_PrimaryAttack_Post(Weapon)
  620. {
  621.     g_IsInPrimaryAttack = 0
  622.     new Player = get_pdata_cbase(Weapon, 41, 4)
  623.    
  624.     new szClip, szAmmo
  625.     get_user_weapon(Player, szClip, szAmmo)
  626.    
  627.     if(!is_user_alive(Player))
  628.         return
  629.  
  630.     if(g_has_railcannon[Player])
  631.     {
  632.         if (!g_clip_ammo[Player] && railcannon_mode[Player] == 1)
  633.             return
  634.        
  635.         g_reload[Player] = 0
  636.         remove_task( Player + 1331 )
  637.         new Float:push[3]
  638.         pev(Player,pev_punchangle,push)
  639.         xs_vec_sub(push,cl_pushangle[Player],push)
  640.         xs_vec_mul_scalar(push,cvar_recoil_railcannon,push)
  641.         xs_vec_add(push,cl_pushangle[Player],push)
  642.         set_pev(Player,pev_punchangle,push)
  643.        
  644.         UTIL_PlayWeaponAnimation(Player,random_num(4,5))
  645.         set_weapons_timeidle(Player, CSW_M3, 0.3)
  646.         set_player_nextattackx(Player, 0.3)
  647.         g_clip_ammo[Player] --
  648.        
  649.         if(railcannon_mode[Player] == 3) emit_sound(Player, CHAN_WEAPON, "weapons/railcanon-2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  650.         else emit_sound(Player, CHAN_WEAPON, Fire_Sounds, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  651.        
  652.         railcannon_mode[Player] = 1
  653.     }
  654. }
  655.  
  656. public Make_Muzzleflash(id)
  657. {
  658.     static Float:Origin[3], TE_FLAG
  659.     get_position(id, 32.0, 6.0, -15.0, Origin)
  660.    
  661.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  662.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
  663.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  664.    
  665.     engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, Origin, id)
  666.     write_byte(TE_EXPLOSION)
  667.     engfunc(EngFunc_WriteCoord, Origin[0])
  668.     engfunc(EngFunc_WriteCoord, Origin[1])
  669.     engfunc(EngFunc_WriteCoord, Origin[2])
  670.     write_short(g_MuzzleFlash_SprId)
  671.     write_byte(2)
  672.     write_byte(30)
  673.     write_byte(TE_FLAG)
  674.     message_end()
  675. }
  676.  
  677. public fw_CmdStart(id, uc_handle, seed)
  678. {
  679.     new ammo, clip, weapon = get_user_weapon(id, clip, ammo)
  680.     if (!g_has_railcannon[id] || weapon != CSW_M3 || !is_user_alive(id))
  681.         return
  682.    
  683.     static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  684.        
  685.     if(!pev_valid(ent))
  686.         return
  687.        
  688.     static CurButton
  689.     CurButton = get_uc(uc_handle, UC_Buttons)
  690.    
  691.     if(CurButton & IN_ATTACK)
  692.     {
  693.         new wpn = fm_get_user_weapon_entity(id, get_user_weapon(id))
  694.        
  695.         new Id = pev( wpn, pev_owner ), clip, bpammo
  696.         get_user_weapon( Id, clip, bpammo )
  697.         if( g_has_railcannon[ Id ] ) {
  698.         if( clip >= 2 ) {
  699.             if( g_reload[Id] ) {
  700.                 remove_task( Id + 1331 )
  701.                 g_reload[Id] = 0
  702.             }
  703.         }
  704.         else if( clip == 1 )
  705.         {
  706.             if(get_pdata_float(Id, 83, 4) <= 0.3)
  707.             {
  708.                 if( g_reload[Id] ) {
  709.                 remove_task( Id + 1331 )
  710.                 g_reload[Id] = 0
  711.             }
  712.             }
  713.         }
  714.     }
  715.     }
  716.    
  717.     else if(CurButton & IN_ATTACK2)
  718.     {
  719.         if(!zz[id] && get_pdata_float(id, 83, 4) <= 0.0 && g_clip_ammo[id] >= 1)
  720.         {
  721.             set_weapons_timeidle(id, CSW_M3, 200.0)
  722.             set_player_nextattackx(id, 200.0)
  723.             UTIL_PlayWeaponAnimation(id, 1)
  724.             emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage1_start.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  725.             set_task(0.6, "charge_idle2", id)
  726.             zz[id] = 1
  727.             udah[id] = 0
  728.             railcannon_mode[id] = 2
  729.            
  730.             update_specialammo(id, g_SpecialAmmo[id], 0)
  731.             g_SpecialAmmo[id] ++
  732.             update_specialammo(id, g_SpecialAmmo[id], 1)
  733.            
  734.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  735.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
  736.             g_clip_ammo[id] --
  737.         }
  738.     }
  739.    
  740.     else if(!(pev(id, pev_oldbuttons) & IN_ATTACK) && zz[id])
  741.     {
  742.         zz[id] = 0
  743.         if(udah[id])
  744.         {
  745.             if(g_clip_ammo[id] >= 1)
  746.             {
  747.                 ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  748.                 set_weapons_timeidle(id, CSW_M3, 1.1)
  749.                 set_player_nextattackx(id, 1.1)
  750.                 udah[id] = 0
  751.                 remove_task(id+TASK_SOUND)
  752.                
  753.                 update_specialammo(id, g_SpecialAmmo[id], 0)
  754.                 g_SpecialAmmo[id] = 0
  755.                
  756.                 new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  757.                 cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  758.                 g_clip_ammo[id] ++
  759.             }
  760.             else
  761.             {
  762.                 new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  763.                 cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  764.                 g_clip_ammo[id] ++
  765.                
  766.                 ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  767.                 set_weapons_timeidle(id, CSW_M3, 1.1)
  768.                 set_player_nextattackx(id, 1.1)
  769.                 udah[id] = 0
  770.                 remove_task(id+TASK_SOUND)
  771.                
  772.                 update_specialammo(id, g_SpecialAmmo[id], 0)
  773.                 g_SpecialAmmo[id] = 0
  774.             }
  775.         }
  776.     }
  777. }
  778.  
  779. public charge_idle2(id)
  780. {
  781.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  782.         return
  783.     if(zz[id])
  784.     {
  785.         if(g_clip_ammo[id] >= 1)
  786.         {
  787.             UTIL_PlayWeaponAnimation(id, 2)
  788.             set_weapons_timeidle(id, CSW_M3, 200.0)
  789.             set_player_nextattackx(id, 200.0)
  790.             set_task(0.6, "charge_idle3", id)
  791.            
  792.             update_specialammo(id, g_SpecialAmmo[id], 0)
  793.             g_SpecialAmmo[id] ++
  794.             update_specialammo(id, g_SpecialAmmo[id], 1)
  795.            
  796.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  797.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
  798.             g_clip_ammo[id] --
  799.         }
  800.         else
  801.         {
  802.             static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  803.        
  804.             if(!pev_valid(ent))
  805.                 return
  806.            
  807.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  808.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  809.             g_clip_ammo[id] ++
  810.            
  811.             ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  812.             set_weapons_timeidle(id, CSW_M3, 1.1)
  813.             set_player_nextattackx(id, 1.1)
  814.            
  815.             update_specialammo(id, g_SpecialAmmo[id], 0)
  816.             g_SpecialAmmo[id] = 0
  817.         }
  818.     }
  819.     else
  820.     {
  821.         static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  822.        
  823.         if(!pev_valid(ent))
  824.             return
  825.         ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  826.         set_weapons_timeidle(id, CSW_M3, 1.1)
  827.         set_player_nextattackx(id, 1.1)
  828.        
  829.         update_specialammo(id, g_SpecialAmmo[id], 0)
  830.         g_SpecialAmmo[id] = 0
  831.        
  832.         new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  833.         cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  834.         g_clip_ammo[id] ++
  835.     }
  836. }
  837.  
  838. public charge_idle3(id)
  839. {
  840.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  841.         return
  842.     if(zz[id])
  843.     {
  844.         if(g_clip_ammo[id] >= 1)
  845.         {
  846.             UTIL_PlayWeaponAnimation(id, 3)
  847.             emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage3_loop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  848.             set_task(0.794, "play_sound", id+TASK_SOUND,_,_,"b")
  849.             udah[id] = 1
  850.             railcannon_mode[id] = 3
  851.             set_weapons_timeidle(id, CSW_M3, 200.0)
  852.             set_player_nextattackx(id, 200.0)
  853.            
  854.             update_specialammo(id, g_SpecialAmmo[id], 0)
  855.             g_SpecialAmmo[id] ++
  856.             update_specialammo(id, g_SpecialAmmo[id], 1)
  857.            
  858.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  859.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
  860.             g_clip_ammo[id] --
  861.         }
  862.         else
  863.         {
  864.             static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  865.        
  866.             if(!pev_valid(ent))
  867.                 return
  868.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  869.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  870.             g_clip_ammo[id] ++
  871.            
  872.             ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  873.             set_weapons_timeidle(id, CSW_M3, 1.1)
  874.             set_player_nextattackx(id, 1.1)
  875.            
  876.             update_specialammo(id, g_SpecialAmmo[id], 0)
  877.             g_SpecialAmmo[id] = 0
  878.         }
  879.     }
  880.     else
  881.     {
  882.         static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  883.        
  884.         if(!pev_valid(ent))
  885.             return
  886.         ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  887.         set_weapons_timeidle(id, CSW_M3, 1.1)
  888.         set_player_nextattackx(id, 1.1)
  889.        
  890.         update_specialammo(id, g_SpecialAmmo[id], 0)
  891.         g_SpecialAmmo[id] = 0
  892.        
  893.         new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  894.         cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  895.         g_clip_ammo[id] ++
  896.     }
  897. }
  898.  
  899. public play_sound(id)
  900. {
  901.     id -= TASK_SOUND
  902.    
  903.     if(!is_user_alive(id) || get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  904.         return
  905.    
  906.     emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage3_loop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  907. }
  908.  
  909. public fw_railcannonidleanim(Weapon)
  910. {
  911.     new id = get_pdata_cbase(Weapon, 41, 4)
  912.  
  913.     if(!is_user_alive(id) || !g_has_railcannon[id] || get_user_weapon(id) != CSW_M3)
  914.         return HAM_IGNORED;
  915.    
  916.     if(railcannon_mode[id] == 1 && get_pdata_float(Weapon, 48, 4) <= 0.25)
  917.     {
  918.         UTIL_PlayWeaponAnimation(id, 0)
  919.         set_pdata_float(Weapon, 48, 20.0, 4)
  920.         return HAM_SUPERCEDE;
  921.     }
  922.    
  923.     if(railcannon_mode[id] == 3 && get_pdata_float(Weapon, 48, 4) <= 0.01)
  924.     {
  925.         UTIL_PlayWeaponAnimation(id, 3)
  926.         set_pdata_float(Weapon, 48, 1.7, 4)
  927.         return HAM_SUPERCEDE;
  928.     }
  929.  
  930.     return HAM_IGNORED;
  931. }
  932.  
  933. public update_specialammo(id, Ammo, On)
  934. {
  935.     static AmmoSprites[33]
  936.     format(AmmoSprites, sizeof(AmmoSprites), "number_%d", Ammo)
  937.    
  938.     message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("StatusIcon"), {0,0,0}, id)
  939.     write_byte(On)
  940.     write_string(AmmoSprites)
  941.     write_byte(42) // red
  942.     write_byte(255) // green
  943.     write_byte(42) // blue
  944.     message_end()
  945. }
  946.  
  947. public fwPlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  948. {
  949.     if ((eventid != g_orig_event_railcannon) || !g_IsInPrimaryAttack)
  950.         return FMRES_IGNORED
  951.        
  952.     if (!(1 <= invoker <= g_MaxPlayers))
  953.         return FMRES_IGNORED
  954.  
  955.     playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
  956.     return FMRES_SUPERCEDE
  957. }
  958.  
  959. public RAILCANNON_Reload( wpn ) {
  960.     if(railcannon_mode[pev( wpn, pev_owner )] == 3)
  961.           return HAM_SUPERCEDE
  962.          
  963.     if( g_has_railcannon[ pev( wpn, pev_owner ) ] ) {
  964.         RAILCANNON_Reload_Post( wpn )
  965.         return HAM_SUPERCEDE
  966.     }
  967.     return HAM_IGNORED
  968. }
  969.  
  970. public RAILCANNON_Reload_Post(weapon) {
  971.     new id = pev( weapon, pev_owner )
  972.     if(railcannon_mode[id] == 3 || g_reload[id])
  973.           return HAM_SUPERCEDE
  974.     new clip, bpammo
  975.     get_user_weapon(id, clip, bpammo )
  976.     if( g_has_railcannon[ id ] && clip < cvar_clip_railcannon && bpammo > 0 ) {
  977.         if(!task_exists( id+1331 )) set_task( 0.1, "reload", id+1331 )
  978.         }
  979.     return HAM_IGNORED
  980. }
  981.  
  982. public reload( id ) {
  983.     id -= 1331
  984.     set_weapons_timeidle(id, CSW_M3, 3.0)
  985.     set_player_nextattackx(id, 3.0)
  986.     UTIL_PlayWeaponAnimation(id, 6)
  987.     g_reload[id] = 1
  988.     set_task(3.0, "isi", id)
  989. }
  990.  
  991. public isi(id)
  992. {
  993.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  994.         return
  995.    
  996.     if(!g_reload[id])
  997.         return
  998.    
  999.     new clip, pluru, pengurang, bpammo, weapon = find_ent_by_owner( -1, "weapon_m3", id )
  1000.     get_user_weapon(id, clip, bpammo )
  1001.     pengurang = cvar_clip_railcannon - clip
  1002.     pluru = bpammo - pengurang
  1003.     cs_set_user_bpammo( id, CSW_M3, pluru )
  1004.    
  1005.     if(bpammo <= pengurang) cs_set_weapon_ammo( weapon, clip + bpammo)
  1006.     else cs_set_weapon_ammo( weapon, cvar_clip_railcannon)
  1007.    
  1008.     g_clip_ammo[id] = cvar_clip_railcannon
  1009. }
  1010.  
  1011. stock knockback(ent, Float:VicOrigin[3], Float:speed, type)
  1012. {
  1013.     static Float:fl_Velocity[3]
  1014.     static Float:EntOrigin[3]
  1015.     static Float:EntVelocity[3]
  1016.    
  1017.     pev(ent, pev_velocity, EntVelocity)
  1018.     pev(ent, pev_origin, EntOrigin)
  1019.     static Float:distance_f
  1020.     distance_f = get_distance_f(EntOrigin, VicOrigin)
  1021.    
  1022.     static Float:fl_Time; fl_Time = distance_f / speed
  1023.    
  1024.     if(type == 1)
  1025.     {
  1026.         fl_Velocity[0] = ((VicOrigin[0] - EntOrigin[0]) / fl_Time) * 1.5
  1027.         fl_Velocity[1] = ((VicOrigin[1] - EntOrigin[1]) / fl_Time) * 1.5
  1028.         fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time       
  1029.         } else if(type == 2) {
  1030.         fl_Velocity[0] = ((EntOrigin[0] - VicOrigin[0]) / fl_Time) * 1.5
  1031.         fl_Velocity[1] = ((EntOrigin[1] - VicOrigin[1]) / fl_Time) * 1.5
  1032.         fl_Velocity[2] = (EntOrigin[2] - VicOrigin[2]) / fl_Time
  1033.     }
  1034.    
  1035.     xs_vec_add(EntVelocity, fl_Velocity, fl_Velocity)
  1036.     set_pev(ent, pev_velocity, fl_Velocity)
  1037. }
  1038.  
  1039. stock fm_cs_get_current_weapon_ent(id)
  1040. {
  1041.     return get_pdata_cbase(id, OFFSET_ACTIVE_ITEM, OFFSET_LINUX)
  1042. }
  1043.  
  1044. stock fm_set_weapon_ammo(entity, amount)
  1045. {
  1046.     set_pdata_int(entity, OFFSET_CLIPAMMO, amount, OFFSET_LINUX_WEAPONS);
  1047. }
  1048.  
  1049. stock fm_cs_get_weapon_ent_owner(ent)
  1050. {
  1051.     return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS)
  1052. }
  1053.  
  1054. stock UTIL_PlayWeaponAnimation(const Player, const Sequence)
  1055. {
  1056.     set_pev(Player, pev_weaponanim, Sequence)
  1057.    
  1058.     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player)
  1059.     write_byte(Sequence)
  1060.     write_byte(pev(Player, pev_body))
  1061.     message_end()
  1062. }
  1063.  
  1064. stock set_player_nextattackx(id, Float:nexttime)
  1065. {
  1066.     if(!is_user_alive(id))
  1067.         return
  1068.        
  1069.     set_pdata_float(id, m_flNextAttack, nexttime, 5)
  1070. }
  1071.  
  1072. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
  1073. {
  1074.     new Float:vfEnd[3], viEnd[3]
  1075.     get_user_origin(id, viEnd, 3)  
  1076.     IVecFVec(viEnd, vfEnd)
  1077.    
  1078.     new Float:fOrigin[3], Float:fAngle[3]
  1079.    
  1080.     pev(id, pev_origin, fOrigin)
  1081.     pev(id, pev_view_ofs, fAngle)
  1082.    
  1083.     xs_vec_add(fOrigin, fAngle, fOrigin)
  1084.    
  1085.     new Float:fAttack[3]
  1086.    
  1087.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1088.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1089.    
  1090.     new Float:fRate
  1091.    
  1092.     fRate = fDis / vector_length(fAttack)
  1093.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
  1094.    
  1095.     xs_vec_add(fOrigin, fAttack, output)
  1096. }
  1097.  
  1098. stock set_weapons_timeidle(id, WeaponId ,Float:TimeIdle)
  1099. {
  1100.     if(!is_user_alive(id))
  1101.         return
  1102.        
  1103.     static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
  1104.     if(!pev_valid(entwpn))
  1105.         return
  1106.        
  1107.     set_pdata_float(entwpn, 46, TimeIdle, WEAP_LINUX_XTRA_OFF)
  1108.     set_pdata_float(entwpn, 47, TimeIdle, WEAP_LINUX_XTRA_OFF)
  1109.     set_pdata_float(entwpn, 48, TimeIdle + 1.0, WEAP_LINUX_XTRA_OFF)
  1110. }
  1111.  
  1112. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
  1113. {
  1114.     new_velocity[0] = origin2[0] - origin1[0]
  1115.     new_velocity[1] = origin2[1] - origin1[1]
  1116.     new_velocity[2] = origin2[2] - origin1[2]
  1117.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  1118.     new_velocity[0] *= num
  1119.     new_velocity[1] *= num
  1120.     new_velocity[2] *= num
  1121.    
  1122.     return 1;
  1123. }
  1124.  
  1125. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
  1126. {
  1127.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  1128.    
  1129.     pev(id, pev_origin, vOrigin)
  1130.     pev(id, pev_view_ofs, vUp) //for player
  1131.     xs_vec_add(vOrigin, vUp, vOrigin)
  1132.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
  1133.    
  1134.     angle_vector(vAngle,ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
  1135.     angle_vector(vAngle,ANGLEVECTOR_RIGHT, vRight)
  1136.     angle_vector(vAngle,ANGLEVECTOR_UP, vUp)
  1137.    
  1138.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  1139.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  1140.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  1141. }
  1142.  
  1143.  
  1144. stock drop_weapons(id, dropwhat)
  1145. {
  1146.     static weapons[32], num, i, weaponid
  1147.     num = 0
  1148.     get_user_weapons(id, weapons, num)
  1149.      
  1150.     for (i = 0; i < num; i++)
  1151.     {
  1152.         weaponid = weapons[i]
  1153.          
  1154.         if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
  1155.         {
  1156.             static wname[32]
  1157.             get_weaponname(weaponid, wname, sizeof wname - 1)
  1158.             engclient_cmd(id, "drop", wname)
  1159.         }
  1160.     }
  1161. }
You don't know? Learn and you will know.

User avatar
sPe3doN
Senior Member
Senior Member
Bosnia & Herzegovina
Posts: 144
Joined: 1 Year Ago
Has thanked: 12 times
Been thanked: 2 times
Age: 19
Contact:

#4

Post by sPe3doN » 1 Week Ago

Raheem wrote:
1 Week Ago
  1. #include <zombie_escape>
  2. #include <engine>
  3. #include <fakemeta_util>
  4. #include <fun>
  5. #include <xs>
  6. #include <cstrike>
  7.  
  8. #define ENG_NULLENT     -1
  9. #define EV_INT_WEAPONKEY    EV_INT_impulse
  10. #define RAILCANNON_WEAPONKEY 756144798
  11. #define IsValidUser(%1) (1 <= %1 <= g_MaxPlayers)
  12.  
  13. #define SMOKE_CLASS "smokess"
  14.  
  15. #define ENABLE_KNOCKBACK 1
  16.  
  17. const USE_STOPPED = 0
  18. const OFFSET_ACTIVE_ITEM = 373
  19. const OFFSET_WEAPONOWNER = 41
  20. const OFFSET_LINUX = 5
  21. const OFFSET_LINUX_WEAPONS = 4
  22.  
  23. #if cellbits == 32
  24. const OFFSET_CLIPAMMO = 51
  25. #else
  26. const OFFSET_CLIPAMMO = 65
  27. #endif
  28.  
  29. #define WEAP_LINUX_XTRA_OFF     4
  30. #define m_fKnown                    44
  31. #define m_flNextPrimaryAttack       46
  32. #define m_flNextSecondaryAttack         47
  33. #define m_flTimeWeaponIdle          48
  34. #define m_iClip                 51
  35. #define m_fInReload             54
  36. #define m_fInSpecialReload          55
  37. #define PLAYER_LINUX_XTRA_OFF   5
  38. #define m_flNextAttack              83
  39.  
  40. #define RAILCANNON_DRAW         7
  41.  
  42. #define TASK_SOUND 2573+10
  43. #define TASK_SETRUM2 2573+20
  44.  
  45. new gmsgWeaponList, sTrail
  46.  
  47. #define write_coord_f(%1)   engfunc(EngFunc_WriteCoord,%1)
  48.  
  49. new const Fire_Sounds[] = "weapons/railcanon-1.wav"
  50. new const MuzzleFlash[] = "sprites/muzzleflash19.spr"
  51.  
  52. //////////// Change Here For Customize //////////////////////////
  53.  
  54. const Float:cvar_recoil_railcannon = 0.65
  55. const cvar_clip_railcannon = 30
  56. const cvar_railcannon_ammo = 300
  57.  
  58. const Float:damage_mode1 = 20.0
  59. const Float:damage_mode2 = 35.0
  60. const Float:damage_mode3 = 350.0
  61.  
  62. /////////////////////////////////////////////////////////////////
  63. new RAILCANNON_V_MODEL[64] = "models/v_railcannon.mdl"
  64. new RAILCANNON_P_MODEL[64] = "models/p_railcannon.mdl"
  65. new RAILCANNON_W_MODEL[64] = "models/w_railcannon.mdl"
  66.  
  67. new const GUNSHOT_DECALS[] = { 41, 42, 43, 44, 45 }
  68.  
  69. new g_has_railcannon[33], g_Ham_Bot
  70.  
  71. new g_MaxPlayers, g_orig_event_railcannon, g_IsInPrimaryAttack, g_MuzzleFlash_SprId, g_KnockBack
  72. new Float:cl_pushangle[33][3], m_iBlood[2], zz[33], udah[33]
  73. new g_clip_ammo[33], oldweap[33], g_reload[33], railcannon_mode[33], Float:StartOrigin2[3], g_SpecialAmmo[33]
  74. const PRIMARY_WEAPONS_BIT_SUM =
  75. (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<
  76. CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
  77. new const WEAPONENTNAMES[][] = { "", "weapon_p228", "", "weapon_scout", "weapon_hegrenade", "weapon_xm1014", "weapon_c4", "weapon_mac10",
  78.             "weapon_aug", "weapon_smokegrenade", "weapon_elite", "weapon_fiveseven", "weapon_ump45", "weapon_sg550",
  79.             "weapon_mp5navy", "weapon_famas", "weapon_usp", "weapon_glock18", "weapon_awp", "weapon_mp5navy", "weapon_m249",
  80.             "weapon_m3", "weapon_m4a1", "weapon_tmp", "weapon_g3sg1", "weapon_flashbang", "weapon_deagle", "weapon_sg552",
  81.             "weapon_ak47", "weapon_knife", "weapon_p90" }
  82.  
  83. public plugin_init()
  84. {
  85.     register_plugin("[ZE]Rail Cannon", "1.0", "m4m3ts")
  86.     register_cvar("rail_version", "m4m3ts", FCVAR_SERVER|FCVAR_SPONLY)
  87.     register_event("CurWeapon","CurrentWeapon","be","1=1")
  88.     register_think(SMOKE_CLASS, "fw_Fire_smoke")
  89.     RegisterHam(Ham_Item_AddToPlayer, "weapon_m3", "fw_RAILCANNON_AddToPlayer")
  90.     RegisterHam(Ham_Use, "func_tank", "fw_UseStationary_Post", 1)
  91.     RegisterHam(Ham_Use, "func_tankmortar", "fw_UseStationary_Post", 1)
  92.     RegisterHam(Ham_Use, "func_tankrocket", "fw_UseStationary_Post", 1)
  93.     RegisterHam(Ham_Use, "func_tanklaser", "fw_UseStationary_Post", 1)
  94.    
  95.     for (new i = 1; i < sizeof WEAPONENTNAMES; i++)
  96.         if (WEAPONENTNAMES[i][0]) RegisterHam(Ham_Item_Deploy, WEAPONENTNAMES[i], "fw_Item_Deploy_Post", 1)
  97.    
  98.     RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m3", "fw_RAIL_PrimaryAttack")
  99.     RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_m3", "fw_RAIL_PrimaryAttack_Post", 1)
  100.     RegisterHam(Ham_Weapon_Reload, "weapon_m3", "RAILCANNON_Reload")
  101.     RegisterHam(Ham_Weapon_Reload, "weapon_m3", "RAILCANNON_Reload_Post", 1)
  102.     RegisterHam(Ham_Weapon_WeaponIdle, "weapon_m3", "fw_railcannonidleanim", 1)
  103.    
  104.     RegisterHam(Ham_Killed, "player", "fw_PlayerKilled")
  105.    
  106.     register_forward(FM_CmdStart, "fw_CmdStart")
  107.     register_forward(FM_SetModel, "fw_SetModel")
  108.     register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
  109.     register_forward(FM_PlaybackEvent, "fwPlaybackEvent")
  110.     register_forward(FM_TraceLine,"fw_traceline",1)
  111.    
  112.     gmsgWeaponList = get_user_msgid("WeaponList")
  113.    
  114.     RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
  115.     RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack", 1)
  116.     RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack", 1)
  117.     RegisterHam(Ham_TraceAttack, "func_wall", "fw_TraceAttack", 1)
  118.     RegisterHam(Ham_TraceAttack, "func_door", "fw_TraceAttack", 1)
  119.     RegisterHam(Ham_TraceAttack, "func_door_rotating", "fw_TraceAttack", 1)
  120.     RegisterHam(Ham_TraceAttack, "func_plat", "fw_TraceAttack", 1)
  121.     RegisterHam(Ham_TraceAttack, "func_rotating", "fw_TraceAttack", 1)
  122.    
  123.     g_KnockBack = ENABLE_KNOCKBACK
  124.     g_MaxPlayers = get_maxplayers()
  125. }
  126.  
  127. public plugin_precache()
  128. {
  129.     precache_model(RAILCANNON_V_MODEL)
  130.     precache_model(RAILCANNON_P_MODEL)
  131.     precache_model(RAILCANNON_W_MODEL)
  132.     precache_sound(Fire_Sounds)
  133.        
  134.     sTrail = precache_model("sprites/laserbeam.spr")
  135.    
  136.     precache_sound("weapons/railcanon_clipin.wav")
  137.     precache_sound("weapons/railcanon_chage1_start.wav")
  138.     precache_sound("weapons/railcanon_chage3_loop.wav")
  139.     precache_sound("weapons/railcanon_draw.wav")
  140.     precache_sound("weapons/railcanon_clipout.wav")
  141.     precache_sound("weapons/railcanon-2.wav")
  142.    
  143.     g_MuzzleFlash_SprId = engfunc(EngFunc_PrecacheModel, MuzzleFlash)
  144.     precache_generic("sprites/weapon_railcannon.txt")
  145.    
  146.     precache_generic("sprites/640hud112.spr")
  147.     precache_generic("sprites/640hud13.spr")
  148.        
  149.     register_clcmd("weapon_railcannon", "weapon_hook") 
  150.                    
  151.     m_iBlood[0] = precache_model("sprites/blood.spr")
  152.     m_iBlood[1] = precache_model("sprites/bloodspray.spr")
  153.     precache_model("sprites/wall_puff1.spr")
  154.  
  155.     register_forward(FM_PrecacheEvent, "fwPrecacheEvent_Post", 1)
  156. }
  157.  
  158. public plugin_natives()
  159. {
  160.     register_native("give_railcanon", "native_give_railcanon", 1)
  161. }
  162.  
  163. public native_give_railcanon(id)
  164. {
  165.     give_railcannon(id)
  166. }
  167.  
  168. public weapon_hook(id)
  169. {
  170.     engclient_cmd(id, "weapon_m3")
  171.     return PLUGIN_HANDLED
  172. }
  173.  
  174. public client_putinserver(id)
  175. {
  176.     if(!g_Ham_Bot && is_user_bot(id))
  177.     {
  178.         g_Ham_Bot = 1
  179.         set_task(0.1, "Do_RegisterHam_Bot", id)
  180.     }
  181. }
  182.  
  183. public Do_RegisterHam_Bot(id)
  184. {
  185.     RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack", 1)
  186.     RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
  187. }
  188.  
  189. public ze_user_infected(id)
  190. {
  191.     update_specialammo(id, g_SpecialAmmo[id], 0)
  192.     g_has_railcannon[id] = false
  193.     g_SpecialAmmo[id] = 0
  194. }
  195.  
  196. public fw_PlayerKilled(id)
  197. {
  198.     g_has_railcannon[id] = false
  199. }
  200.  
  201. public fw_TraceAttack(iEnt, iAttacker, Float:flDamage, Float:fDir[3], ptr, iDamageType)
  202. {
  203.     if(!is_user_alive(iAttacker))
  204.         return
  205.  
  206.     new g_currentweapon = get_user_weapon(iAttacker)
  207.  
  208.     if(g_currentweapon != CSW_M3 || !g_has_railcannon[iAttacker])
  209.         return
  210.    
  211.     if(railcannon_mode[iAttacker] == 3) SetHamParamFloat(3, 60.0)
  212.     if(railcannon_mode[iAttacker] == 2) SetHamParamFloat(3, 35.0)
  213.     if(railcannon_mode[iAttacker] == 1) SetHamParamFloat(3, 20.0)
  214.    
  215.     static Float:flEnd[3], Float:test[3], Float:myOrigin[3]
  216.    
  217.     pev(iAttacker, pev_origin, myOrigin)
  218.     get_tr2(ptr, TR_vecEndPos, flEnd)
  219.        
  220.     if(!is_user_alive(iEnt))
  221.     {
  222.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  223.         write_byte(TE_DECAL)
  224.         write_coord_f(flEnd[0])
  225.         write_coord_f(flEnd[1])
  226.         write_coord_f(flEnd[2])
  227.         write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
  228.         write_short(iEnt)
  229.         message_end()
  230.  
  231.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  232.         write_byte(TE_WORLDDECAL)
  233.         write_coord_f(flEnd[0])
  234.         write_coord_f(flEnd[1])
  235.         write_coord_f(flEnd[2])
  236.         write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
  237.         message_end()
  238.        
  239.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  240.         write_byte(TE_GUNSHOTDECAL)
  241.         write_coord_f(flEnd[0])
  242.         write_coord_f(flEnd[1])
  243.         write_coord_f(flEnd[2])
  244.         write_short(iAttacker)
  245.         write_byte(GUNSHOT_DECALS[random_num (0, sizeof GUNSHOT_DECALS -1)])
  246.         message_end()
  247.        
  248.         fm_get_aim_origin(iAttacker, test)
  249.         if(railcannon_mode[iAttacker] == 3) fake_smokes(iAttacker, test)
  250.     }
  251.    
  252.     if(railcannon_mode[iAttacker] == 2)
  253.     {
  254.         get_position(iAttacker, 20.0, 0.0, 10.0, StartOrigin2)
  255.        
  256.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  257.         write_byte(TE_BEAMPOINTS)
  258.         engfunc(EngFunc_WriteCoord, StartOrigin2[0])
  259.         engfunc(EngFunc_WriteCoord, StartOrigin2[1])
  260.         engfunc(EngFunc_WriteCoord, StartOrigin2[2] - 10.0)
  261.         engfunc(EngFunc_WriteCoord, flEnd[0])
  262.         engfunc(EngFunc_WriteCoord, flEnd[1])
  263.         engfunc(EngFunc_WriteCoord, flEnd[2])
  264.         write_short(sTrail)
  265.         write_byte(0) // start frame
  266.         write_byte(0) // framerate
  267.         write_byte(5) // life
  268.         write_byte(5) // line width
  269.         write_byte(0) // amplitude
  270.         write_byte(220)
  271.         write_byte(88)
  272.         write_byte(0) // blue
  273.         write_byte(255) // brightness
  274.         write_byte(0) // speed
  275.         message_end()
  276.     }
  277.    
  278.     if(railcannon_mode[iAttacker] == 3)
  279.     {
  280.         get_position(iAttacker, 20.0, 5.0, 5.0, StartOrigin2)
  281.        
  282.         message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  283.         write_byte(TE_BEAMPOINTS)
  284.         engfunc(EngFunc_WriteCoord, StartOrigin2[0])
  285.         engfunc(EngFunc_WriteCoord, StartOrigin2[1])
  286.         engfunc(EngFunc_WriteCoord, StartOrigin2[2] - 10.0)
  287.         engfunc(EngFunc_WriteCoord, flEnd[0])
  288.         engfunc(EngFunc_WriteCoord, flEnd[1])
  289.         engfunc(EngFunc_WriteCoord, flEnd[2])
  290.         write_short(sTrail)
  291.         write_byte(0) // start frame
  292.         write_byte(0) // framerate
  293.         write_byte(8) // life
  294.         write_byte(8) // line width
  295.         write_byte(0) // amplitude
  296.         write_byte(220)
  297.         write_byte(88)
  298.         write_byte(0) // blue
  299.         write_byte(50) // brightness
  300.         write_byte(0) // speed
  301.         message_end()
  302.        
  303.         if(!is_user_alive(iEnt))
  304.             return
  305.        
  306.         if(ze_is_user_zombie(iEnt) && g_KnockBack == 1) knockback(iEnt, myOrigin, 42.0, 2)
  307.     }
  308.    
  309. }
  310.  
  311. public fake_smokes(id, Float:Origin[3])
  312. {
  313.     new ent_test; ent_test = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
  314.    
  315.     engfunc(EngFunc_SetModel, ent_test, "sprites/wall_puff1.spr")
  316.     entity_set_string(ent_test, EV_SZ_classname, SMOKE_CLASS)
  317.     set_pev(ent_test, pev_nextthink, get_gametime() + 0.04)
  318.     set_pev(ent_test, pev_movetype, MOVETYPE_NONE)
  319.     set_pev(ent_test, pev_rendermode, kRenderTransAdd)
  320.     set_pev(ent_test, pev_renderamt, 20.0)
  321.     set_pev(ent_test, pev_scale, 1.0)
  322.     set_pev(ent_test, pev_origin, Origin)
  323.     set_pev(ent_test, pev_frame, 0.0)
  324.     set_pev(ent_test, pev_iuser2, get_user_team(id))
  325.  
  326.     set_pev(ent_test, pev_solid, SOLID_NOT)
  327.     dllfunc(DLLFunc_Spawn, ent_test)
  328. }
  329.  
  330. public fw_Fire_smoke(iEnt)
  331. {
  332.     if(!pev_valid(iEnt))
  333.         return
  334.    
  335.     new Float:fFrame
  336.     pev(iEnt, pev_frame, fFrame)
  337.  
  338.     // effect exp
  339.     fFrame += 1.0
  340.  
  341.     set_pev(iEnt, pev_frame, fFrame)
  342.     set_pev(iEnt, pev_scale, 1.0)
  343.     set_pev(iEnt, pev_nextthink, get_gametime() + 0.02)
  344.    
  345.     if(fFrame > 30.0) engfunc(EngFunc_RemoveEntity, iEnt)
  346. }
  347.  
  348. public fw_traceline(Float:v1[3],Float:v2[3],noMonsters,id,ptr)
  349. {
  350.     if(!is_user_alive(id))
  351.         return HAM_IGNORED 
  352.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  353.         return HAM_IGNORED
  354.     if(railcannon_mode[id] != 3)
  355.         return HAM_IGNORED
  356.    
  357.     // get crosshair aim
  358.     static Float:aim[3];
  359.     get_aim(id,v1,aim);
  360.    
  361.     // do another trace to this spot
  362.     new trace = create_tr2();
  363.     engfunc(EngFunc_TraceLine,v1,aim,noMonsters,id,trace);
  364.    
  365.     // copy ints
  366.     set_tr2(ptr,TR_AllSolid,get_tr2(trace,TR_AllSolid));
  367.     set_tr2(ptr,TR_StartSolid,get_tr2(trace,TR_StartSolid));
  368.     set_tr2(ptr,TR_InOpen,get_tr2(trace,TR_InOpen));
  369.     set_tr2(ptr,TR_InWater,get_tr2(trace,TR_InWater));
  370.     set_tr2(ptr,TR_pHit,get_tr2(trace,TR_pHit));
  371.     set_tr2(ptr,TR_iHitgroup,get_tr2(trace,TR_iHitgroup));
  372.  
  373.     // copy floats
  374.     get_tr2(trace,TR_flFraction,aim[0]);
  375.     set_tr2(ptr,TR_flFraction,aim[0]);
  376.     get_tr2(trace,TR_flPlaneDist,aim[0]);
  377.     set_tr2(ptr,TR_flPlaneDist,aim[0]);
  378.    
  379.     // copy vecs
  380.     get_tr2(trace,TR_vecEndPos,aim);
  381.     set_tr2(ptr,TR_vecEndPos,aim);
  382.     get_tr2(trace,TR_vecPlaneNormal,aim);
  383.     set_tr2(ptr,TR_vecPlaneNormal,aim);
  384.  
  385.     // get rid of new trace
  386.     free_tr2(trace);
  387.  
  388.     return FMRES_IGNORED;
  389. }
  390.  
  391. get_aim(id,Float:source[3],Float:ret[3])
  392. {
  393.     static Float:vAngle[3], Float:pAngle[3], Float:dir[3], Float:temp[3];
  394.  
  395.     // get aiming direction from forward global based on view angle and punch angle
  396.     pev(id,pev_v_angle,vAngle);
  397.     pev(id,pev_punchangle,pAngle);
  398.     xs_vec_add(vAngle,pAngle,temp);
  399.     engfunc(EngFunc_MakeVectors,temp);
  400.     global_get(glb_v_forward,dir);
  401.    
  402.     /* vecEnd = vecSrc + vecDir * flDistance; */
  403.     xs_vec_mul_scalar(dir,8192.0,temp);
  404.     xs_vec_add(source,temp,ret);
  405. }
  406.  
  407. public fwPrecacheEvent_Post(type, const name[])
  408. {
  409.     if (equal("events/m3.sc", name))
  410.     {
  411.         g_orig_event_railcannon = get_orig_retval()
  412.         return FMRES_HANDLED
  413.     }
  414.     return FMRES_IGNORED
  415. }
  416.  
  417. public client_connect(id)
  418. {
  419.     g_has_railcannon[id] = false
  420. }
  421.  
  422. public client_disconnected(id)
  423. {
  424.     g_has_railcannon[id] = false
  425. }
  426.  
  427. public fw_SetModel(entity, model[])
  428. {
  429.     if(!is_valid_ent(entity))
  430.         return FMRES_IGNORED
  431.    
  432.     static szClassName[33]
  433.     entity_get_string(entity, EV_SZ_classname, szClassName, charsmax(szClassName))
  434.        
  435.     if(!equal(szClassName, "weaponbox"))
  436.         return FMRES_IGNORED
  437.    
  438.     static iOwner
  439.    
  440.     iOwner = entity_get_edict(entity, EV_ENT_owner)
  441.    
  442.     if(equal(model, "models/w_m3.mdl"))
  443.     {
  444.         static iStoredAugID
  445.        
  446.         iStoredAugID = find_ent_by_owner(ENG_NULLENT, "weapon_m3", entity)
  447.    
  448.         if(!is_valid_ent(iStoredAugID))
  449.             return FMRES_IGNORED
  450.    
  451.         if(g_has_railcannon[iOwner])
  452.         {
  453.             entity_set_int(iStoredAugID, EV_INT_WEAPONKEY, RAILCANNON_WEAPONKEY)
  454.            
  455.             g_has_railcannon[iOwner] = false
  456.            
  457.             entity_set_model(entity, RAILCANNON_W_MODEL)
  458.            
  459.             return FMRES_SUPERCEDE
  460.         }
  461.     }
  462.     return FMRES_IGNORED
  463. }
  464.  
  465. public give_railcannon(id)
  466. {
  467.     drop_weapons(id, 1)
  468.     new iWep2 = give_item(id,"weapon_m3")
  469.     if( iWep2 > 0 )
  470.     {
  471.         cs_set_weapon_ammo(iWep2, cvar_clip_railcannon)
  472.         cs_set_user_bpammo (id, CSW_M3, cvar_railcannon_ammo)
  473.         UTIL_PlayWeaponAnimation(id, RAILCANNON_DRAW)
  474.         set_weapons_timeidle(id, CSW_M3, 1.0)
  475.         set_player_nextattackx(id, 1.0)
  476.         g_clip_ammo[id] = cs_get_weapon_ammo(iWep2)
  477.     }
  478.     g_has_railcannon[id] = true
  479.     g_SpecialAmmo[id] = 0
  480.     udah[id] = 0
  481.     zz[id] = 0
  482.     railcannon_mode[id] = 1
  483.     update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
  484.     message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
  485.     write_string("weapon_railcannon")
  486.     write_byte(5)
  487.     write_byte(32)
  488.     write_byte(-1)
  489.     write_byte(-1)
  490.     write_byte(0)
  491.     write_byte(5)
  492.     write_byte(21)
  493.     write_byte(0)
  494.     message_end()
  495. }
  496.  
  497. public fw_RAILCANNON_AddToPlayer(railcannon, id)
  498. {
  499.     if(!is_valid_ent(railcannon) || !is_user_connected(id))
  500.         return HAM_IGNORED
  501.    
  502.     if(entity_get_int(railcannon, EV_INT_WEAPONKEY) == RAILCANNON_WEAPONKEY)
  503.     {
  504.         g_has_railcannon[id] = true
  505.        
  506.         message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
  507.         write_string("weapon_railcannon")
  508.         write_byte(5)
  509.         write_byte(32)
  510.         write_byte(-1)
  511.         write_byte(-1)
  512.         write_byte(0)
  513.         write_byte(5)
  514.         write_byte(21)
  515.         write_byte(0)
  516.         message_end()
  517.        
  518.         entity_set_int(railcannon, EV_INT_WEAPONKEY, 0)
  519.         update_specialammo(id, g_SpecialAmmo[id], 0)
  520.         g_SpecialAmmo[id] = 0
  521.  
  522.         return HAM_HANDLED
  523.     }
  524.     return HAM_IGNORED
  525. }
  526.  
  527. public fw_UseStationary_Post(entity, caller, activator, use_type)
  528. {
  529.     if (use_type == USE_STOPPED && is_user_connected(caller))
  530.         replace_weapon_models(caller, get_user_weapon(caller))
  531. }
  532.  
  533. public fw_Item_Deploy_Post(weapon_ent)
  534. {
  535.     static owner
  536.     owner = fm_cs_get_weapon_ent_owner(weapon_ent)
  537.    
  538.     static weaponid
  539.     weaponid = cs_get_weapon_id(weapon_ent)
  540.    
  541.     update_specialammo(owner, g_SpecialAmmo[owner], 0)
  542.     g_SpecialAmmo[owner] = 0
  543.    
  544.     replace_weapon_models(owner, weaponid)
  545. }
  546.  
  547. public CurrentWeapon(id)
  548. {
  549.     if( read_data(2) != CSW_M3 ) {
  550.         if( g_reload[id] ) {
  551.             g_reload[id] = 0
  552.             remove_task( id + 1331 )
  553.         }
  554.     }
  555.     replace_weapon_models(id, read_data(2))
  556. }
  557.  
  558. replace_weapon_models(id, weaponid)
  559. {
  560.     switch (weaponid)
  561.     {
  562.         case CSW_M3:
  563.         {
  564.             if(g_has_railcannon[id])
  565.             {
  566.                 set_pev(id, pev_viewmodel2, RAILCANNON_V_MODEL)
  567.                 set_pev(id, pev_weaponmodel2, RAILCANNON_P_MODEL)
  568.                 if(oldweap[id] != CSW_M3)
  569.                 {
  570.                     set_weapons_timeidle(id, CSW_M3, 1.0)
  571.                     set_player_nextattackx(id, 1.0)
  572.                     UTIL_PlayWeaponAnimation(id, RAILCANNON_DRAW)
  573.                     udah[id] = 0
  574.                     zz[id] = 0
  575.                     railcannon_mode[id] = 1
  576.                     remove_task(id+TASK_SOUND)
  577.                     remove_task(id)
  578.  
  579.                     message_begin(MSG_ONE, gmsgWeaponList, {0,0,0}, id)
  580.                     write_string("weapon_railcannon")
  581.                     write_byte(5)
  582.                     write_byte(32)
  583.                     write_byte(-1)
  584.                     write_byte(-1)
  585.                     write_byte(0)
  586.                     write_byte(5)
  587.                     write_byte(CSW_M3)
  588.                     message_end()
  589.                 }
  590.             }
  591.         }
  592.     }
  593.     oldweap[id] = weaponid
  594. }
  595.  
  596. public fw_UpdateClientData_Post(Player, SendWeapons, CD_Handle)
  597. {
  598.     if(!is_user_alive(Player) || get_user_weapon(Player) != CSW_M3 || !g_has_railcannon[Player])
  599.         return FMRES_IGNORED
  600.    
  601.     set_cd(CD_Handle, CD_flNextAttack, halflife_time () + 0.001)
  602.     return FMRES_HANDLED
  603. }
  604.  
  605. public fw_RAIL_PrimaryAttack(Weapon)
  606. {
  607.     new Player = get_pdata_cbase(Weapon, 41, 4)
  608.    
  609.     if (!g_has_railcannon[Player])
  610.         return
  611.    
  612.     g_IsInPrimaryAttack = 1
  613.     pev(Player,pev_punchangle,cl_pushangle[Player])
  614.    
  615.     g_clip_ammo[Player] = cs_get_weapon_ammo(Weapon)
  616.     if(g_clip_ammo[Player]) Make_Muzzleflash(Player)
  617. }
  618.  
  619. public fw_RAIL_PrimaryAttack_Post(Weapon)
  620. {
  621.     g_IsInPrimaryAttack = 0
  622.     new Player = get_pdata_cbase(Weapon, 41, 4)
  623.    
  624.     new szClip, szAmmo
  625.     get_user_weapon(Player, szClip, szAmmo)
  626.    
  627.     if(!is_user_alive(Player))
  628.         return
  629.  
  630.     if(g_has_railcannon[Player])
  631.     {
  632.         if (!g_clip_ammo[Player] && railcannon_mode[Player] == 1)
  633.             return
  634.        
  635.         g_reload[Player] = 0
  636.         remove_task( Player + 1331 )
  637.         new Float:push[3]
  638.         pev(Player,pev_punchangle,push)
  639.         xs_vec_sub(push,cl_pushangle[Player],push)
  640.         xs_vec_mul_scalar(push,cvar_recoil_railcannon,push)
  641.         xs_vec_add(push,cl_pushangle[Player],push)
  642.         set_pev(Player,pev_punchangle,push)
  643.        
  644.         UTIL_PlayWeaponAnimation(Player,random_num(4,5))
  645.         set_weapons_timeidle(Player, CSW_M3, 0.3)
  646.         set_player_nextattackx(Player, 0.3)
  647.         g_clip_ammo[Player] --
  648.        
  649.         if(railcannon_mode[Player] == 3) emit_sound(Player, CHAN_WEAPON, "weapons/railcanon-2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  650.         else emit_sound(Player, CHAN_WEAPON, Fire_Sounds, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
  651.        
  652.         railcannon_mode[Player] = 1
  653.     }
  654. }
  655.  
  656. public Make_Muzzleflash(id)
  657. {
  658.     static Float:Origin[3], TE_FLAG
  659.     get_position(id, 32.0, 6.0, -15.0, Origin)
  660.    
  661.     TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
  662.     TE_FLAG |= TE_EXPLFLAG_NOSOUND
  663.     TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
  664.    
  665.     engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, Origin, id)
  666.     write_byte(TE_EXPLOSION)
  667.     engfunc(EngFunc_WriteCoord, Origin[0])
  668.     engfunc(EngFunc_WriteCoord, Origin[1])
  669.     engfunc(EngFunc_WriteCoord, Origin[2])
  670.     write_short(g_MuzzleFlash_SprId)
  671.     write_byte(2)
  672.     write_byte(30)
  673.     write_byte(TE_FLAG)
  674.     message_end()
  675. }
  676.  
  677. public fw_CmdStart(id, uc_handle, seed)
  678. {
  679.     new ammo, clip, weapon = get_user_weapon(id, clip, ammo)
  680.     if (!g_has_railcannon[id] || weapon != CSW_M3 || !is_user_alive(id))
  681.         return
  682.    
  683.     static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  684.        
  685.     if(!pev_valid(ent))
  686.         return
  687.        
  688.     static CurButton
  689.     CurButton = get_uc(uc_handle, UC_Buttons)
  690.    
  691.     if(CurButton & IN_ATTACK)
  692.     {
  693.         new wpn = fm_get_user_weapon_entity(id, get_user_weapon(id))
  694.        
  695.         new Id = pev( wpn, pev_owner ), clip, bpammo
  696.         get_user_weapon( Id, clip, bpammo )
  697.         if( g_has_railcannon[ Id ] ) {
  698.         if( clip >= 2 ) {
  699.             if( g_reload[Id] ) {
  700.                 remove_task( Id + 1331 )
  701.                 g_reload[Id] = 0
  702.             }
  703.         }
  704.         else if( clip == 1 )
  705.         {
  706.             if(get_pdata_float(Id, 83, 4) <= 0.3)
  707.             {
  708.                 if( g_reload[Id] ) {
  709.                 remove_task( Id + 1331 )
  710.                 g_reload[Id] = 0
  711.             }
  712.             }
  713.         }
  714.     }
  715.     }
  716.    
  717.     else if(CurButton & IN_ATTACK2)
  718.     {
  719.         if(!zz[id] && get_pdata_float(id, 83, 4) <= 0.0 && g_clip_ammo[id] >= 1)
  720.         {
  721.             set_weapons_timeidle(id, CSW_M3, 200.0)
  722.             set_player_nextattackx(id, 200.0)
  723.             UTIL_PlayWeaponAnimation(id, 1)
  724.             emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage1_start.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  725.             set_task(0.6, "charge_idle2", id)
  726.             zz[id] = 1
  727.             udah[id] = 0
  728.             railcannon_mode[id] = 2
  729.            
  730.             update_specialammo(id, g_SpecialAmmo[id], 0)
  731.             g_SpecialAmmo[id] ++
  732.             update_specialammo(id, g_SpecialAmmo[id], 1)
  733.            
  734.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  735.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
  736.             g_clip_ammo[id] --
  737.         }
  738.     }
  739.    
  740.     else if(!(pev(id, pev_oldbuttons) & IN_ATTACK) && zz[id])
  741.     {
  742.         zz[id] = 0
  743.         if(udah[id])
  744.         {
  745.             if(g_clip_ammo[id] >= 1)
  746.             {
  747.                 ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  748.                 set_weapons_timeidle(id, CSW_M3, 1.1)
  749.                 set_player_nextattackx(id, 1.1)
  750.                 udah[id] = 0
  751.                 remove_task(id+TASK_SOUND)
  752.                
  753.                 update_specialammo(id, g_SpecialAmmo[id], 0)
  754.                 g_SpecialAmmo[id] = 0
  755.                
  756.                 new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  757.                 cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  758.                 g_clip_ammo[id] ++
  759.             }
  760.             else
  761.             {
  762.                 new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  763.                 cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  764.                 g_clip_ammo[id] ++
  765.                
  766.                 ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  767.                 set_weapons_timeidle(id, CSW_M3, 1.1)
  768.                 set_player_nextattackx(id, 1.1)
  769.                 udah[id] = 0
  770.                 remove_task(id+TASK_SOUND)
  771.                
  772.                 update_specialammo(id, g_SpecialAmmo[id], 0)
  773.                 g_SpecialAmmo[id] = 0
  774.             }
  775.         }
  776.     }
  777. }
  778.  
  779. public charge_idle2(id)
  780. {
  781.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  782.         return
  783.     if(zz[id])
  784.     {
  785.         if(g_clip_ammo[id] >= 1)
  786.         {
  787.             UTIL_PlayWeaponAnimation(id, 2)
  788.             set_weapons_timeidle(id, CSW_M3, 200.0)
  789.             set_player_nextattackx(id, 200.0)
  790.             set_task(0.6, "charge_idle3", id)
  791.            
  792.             update_specialammo(id, g_SpecialAmmo[id], 0)
  793.             g_SpecialAmmo[id] ++
  794.             update_specialammo(id, g_SpecialAmmo[id], 1)
  795.            
  796.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  797.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
  798.             g_clip_ammo[id] --
  799.         }
  800.         else
  801.         {
  802.             static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  803.        
  804.             if(!pev_valid(ent))
  805.                 return
  806.            
  807.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  808.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  809.             g_clip_ammo[id] ++
  810.            
  811.             ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  812.             set_weapons_timeidle(id, CSW_M3, 1.1)
  813.             set_player_nextattackx(id, 1.1)
  814.            
  815.             update_specialammo(id, g_SpecialAmmo[id], 0)
  816.             g_SpecialAmmo[id] = 0
  817.         }
  818.     }
  819.     else
  820.     {
  821.         static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  822.        
  823.         if(!pev_valid(ent))
  824.             return
  825.         ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  826.         set_weapons_timeidle(id, CSW_M3, 1.1)
  827.         set_player_nextattackx(id, 1.1)
  828.        
  829.         update_specialammo(id, g_SpecialAmmo[id], 0)
  830.         g_SpecialAmmo[id] = 0
  831.        
  832.         new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  833.         cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  834.         g_clip_ammo[id] ++
  835.     }
  836. }
  837.  
  838. public charge_idle3(id)
  839. {
  840.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  841.         return
  842.     if(zz[id])
  843.     {
  844.         if(g_clip_ammo[id] >= 1)
  845.         {
  846.             UTIL_PlayWeaponAnimation(id, 3)
  847.             emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage3_loop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  848.             set_task(0.794, "play_sound", id+TASK_SOUND,_,_,"b")
  849.             udah[id] = 1
  850.             railcannon_mode[id] = 3
  851.             set_weapons_timeidle(id, CSW_M3, 200.0)
  852.             set_player_nextattackx(id, 200.0)
  853.            
  854.             update_specialammo(id, g_SpecialAmmo[id], 0)
  855.             g_SpecialAmmo[id] ++
  856.             update_specialammo(id, g_SpecialAmmo[id], 1)
  857.            
  858.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  859.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] - 1)
  860.             g_clip_ammo[id] --
  861.         }
  862.         else
  863.         {
  864.             static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  865.        
  866.             if(!pev_valid(ent))
  867.                 return
  868.             new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  869.             cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  870.             g_clip_ammo[id] ++
  871.            
  872.             ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  873.             set_weapons_timeidle(id, CSW_M3, 1.1)
  874.             set_player_nextattackx(id, 1.1)
  875.            
  876.             update_specialammo(id, g_SpecialAmmo[id], 0)
  877.             g_SpecialAmmo[id] = 0
  878.         }
  879.     }
  880.     else
  881.     {
  882.         static ent; ent = fm_get_user_weapon_entity(id, CSW_M3)
  883.        
  884.         if(!pev_valid(ent))
  885.             return
  886.         ExecuteHamB(Ham_Weapon_PrimaryAttack, ent)
  887.         set_weapons_timeidle(id, CSW_M3, 1.1)
  888.         set_player_nextattackx(id, 1.1)
  889.        
  890.         update_specialammo(id, g_SpecialAmmo[id], 0)
  891.         g_SpecialAmmo[id] = 0
  892.        
  893.         new weapon = find_ent_by_owner( -1, "weapon_m3", id )
  894.         cs_set_weapon_ammo( weapon, g_clip_ammo[id] + 1)
  895.         g_clip_ammo[id] ++
  896.     }
  897. }
  898.  
  899. public play_sound(id)
  900. {
  901.     id -= TASK_SOUND
  902.    
  903.     if(!is_user_alive(id) || get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  904.         return
  905.    
  906.     emit_sound(id, CHAN_WEAPON, "weapons/railcanon_chage3_loop.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
  907. }
  908.  
  909. public fw_railcannonidleanim(Weapon)
  910. {
  911.     new id = get_pdata_cbase(Weapon, 41, 4)
  912.  
  913.     if(!is_user_alive(id) || !g_has_railcannon[id] || get_user_weapon(id) != CSW_M3)
  914.         return HAM_IGNORED;
  915.    
  916.     if(railcannon_mode[id] == 1 && get_pdata_float(Weapon, 48, 4) <= 0.25)
  917.     {
  918.         UTIL_PlayWeaponAnimation(id, 0)
  919.         set_pdata_float(Weapon, 48, 20.0, 4)
  920.         return HAM_SUPERCEDE;
  921.     }
  922.    
  923.     if(railcannon_mode[id] == 3 && get_pdata_float(Weapon, 48, 4) <= 0.01)
  924.     {
  925.         UTIL_PlayWeaponAnimation(id, 3)
  926.         set_pdata_float(Weapon, 48, 1.7, 4)
  927.         return HAM_SUPERCEDE;
  928.     }
  929.  
  930.     return HAM_IGNORED;
  931. }
  932.  
  933. public update_specialammo(id, Ammo, On)
  934. {
  935.     static AmmoSprites[33]
  936.     format(AmmoSprites, sizeof(AmmoSprites), "number_%d", Ammo)
  937.    
  938.     message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("StatusIcon"), {0,0,0}, id)
  939.     write_byte(On)
  940.     write_string(AmmoSprites)
  941.     write_byte(42) // red
  942.     write_byte(255) // green
  943.     write_byte(42) // blue
  944.     message_end()
  945. }
  946.  
  947. public fwPlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
  948. {
  949.     if ((eventid != g_orig_event_railcannon) || !g_IsInPrimaryAttack)
  950.         return FMRES_IGNORED
  951.        
  952.     if (!(1 <= invoker <= g_MaxPlayers))
  953.         return FMRES_IGNORED
  954.  
  955.     playback_event(flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
  956.     return FMRES_SUPERCEDE
  957. }
  958.  
  959. public RAILCANNON_Reload( wpn ) {
  960.     if(railcannon_mode[pev( wpn, pev_owner )] == 3)
  961.           return HAM_SUPERCEDE
  962.          
  963.     if( g_has_railcannon[ pev( wpn, pev_owner ) ] ) {
  964.         RAILCANNON_Reload_Post( wpn )
  965.         return HAM_SUPERCEDE
  966.     }
  967.     return HAM_IGNORED
  968. }
  969.  
  970. public RAILCANNON_Reload_Post(weapon) {
  971.     new id = pev( weapon, pev_owner )
  972.     if(railcannon_mode[id] == 3 || g_reload[id])
  973.           return HAM_SUPERCEDE
  974.     new clip, bpammo
  975.     get_user_weapon(id, clip, bpammo )
  976.     if( g_has_railcannon[ id ] && clip < cvar_clip_railcannon && bpammo > 0 ) {
  977.         if(!task_exists( id+1331 )) set_task( 0.1, "reload", id+1331 )
  978.         }
  979.     return HAM_IGNORED
  980. }
  981.  
  982. public reload( id ) {
  983.     id -= 1331
  984.     set_weapons_timeidle(id, CSW_M3, 3.0)
  985.     set_player_nextattackx(id, 3.0)
  986.     UTIL_PlayWeaponAnimation(id, 6)
  987.     g_reload[id] = 1
  988.     set_task(3.0, "isi", id)
  989. }
  990.  
  991. public isi(id)
  992. {
  993.     if(get_user_weapon(id) != CSW_M3 || !g_has_railcannon[id])
  994.         return
  995.    
  996.     if(!g_reload[id])
  997.         return
  998.    
  999.     new clip, pluru, pengurang, bpammo, weapon = find_ent_by_owner( -1, "weapon_m3", id )
  1000.     get_user_weapon(id, clip, bpammo )
  1001.     pengurang = cvar_clip_railcannon - clip
  1002.     pluru = bpammo - pengurang
  1003.     cs_set_user_bpammo( id, CSW_M3, pluru )
  1004.    
  1005.     if(bpammo <= pengurang) cs_set_weapon_ammo( weapon, clip + bpammo)
  1006.     else cs_set_weapon_ammo( weapon, cvar_clip_railcannon)
  1007.    
  1008.     g_clip_ammo[id] = cvar_clip_railcannon
  1009. }
  1010.  
  1011. stock knockback(ent, Float:VicOrigin[3], Float:speed, type)
  1012. {
  1013.     static Float:fl_Velocity[3]
  1014.     static Float:EntOrigin[3]
  1015.     static Float:EntVelocity[3]
  1016.    
  1017.     pev(ent, pev_velocity, EntVelocity)
  1018.     pev(ent, pev_origin, EntOrigin)
  1019.     static Float:distance_f
  1020.     distance_f = get_distance_f(EntOrigin, VicOrigin)
  1021.    
  1022.     static Float:fl_Time; fl_Time = distance_f / speed
  1023.    
  1024.     if(type == 1)
  1025.     {
  1026.         fl_Velocity[0] = ((VicOrigin[0] - EntOrigin[0]) / fl_Time) * 1.5
  1027.         fl_Velocity[1] = ((VicOrigin[1] - EntOrigin[1]) / fl_Time) * 1.5
  1028.         fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time       
  1029.         } else if(type == 2) {
  1030.         fl_Velocity[0] = ((EntOrigin[0] - VicOrigin[0]) / fl_Time) * 1.5
  1031.         fl_Velocity[1] = ((EntOrigin[1] - VicOrigin[1]) / fl_Time) * 1.5
  1032.         fl_Velocity[2] = (EntOrigin[2] - VicOrigin[2]) / fl_Time
  1033.     }
  1034.    
  1035.     xs_vec_add(EntVelocity, fl_Velocity, fl_Velocity)
  1036.     set_pev(ent, pev_velocity, fl_Velocity)
  1037. }
  1038.  
  1039. stock fm_cs_get_current_weapon_ent(id)
  1040. {
  1041.     return get_pdata_cbase(id, OFFSET_ACTIVE_ITEM, OFFSET_LINUX)
  1042. }
  1043.  
  1044. stock fm_set_weapon_ammo(entity, amount)
  1045. {
  1046.     set_pdata_int(entity, OFFSET_CLIPAMMO, amount, OFFSET_LINUX_WEAPONS);
  1047. }
  1048.  
  1049. stock fm_cs_get_weapon_ent_owner(ent)
  1050. {
  1051.     return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS)
  1052. }
  1053.  
  1054. stock UTIL_PlayWeaponAnimation(const Player, const Sequence)
  1055. {
  1056.     set_pev(Player, pev_weaponanim, Sequence)
  1057.    
  1058.     message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player)
  1059.     write_byte(Sequence)
  1060.     write_byte(pev(Player, pev_body))
  1061.     message_end()
  1062. }
  1063.  
  1064. stock set_player_nextattackx(id, Float:nexttime)
  1065. {
  1066.     if(!is_user_alive(id))
  1067.         return
  1068.        
  1069.     set_pdata_float(id, m_flNextAttack, nexttime, 5)
  1070. }
  1071.  
  1072. stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
  1073. {
  1074.     new Float:vfEnd[3], viEnd[3]
  1075.     get_user_origin(id, viEnd, 3)  
  1076.     IVecFVec(viEnd, vfEnd)
  1077.    
  1078.     new Float:fOrigin[3], Float:fAngle[3]
  1079.    
  1080.     pev(id, pev_origin, fOrigin)
  1081.     pev(id, pev_view_ofs, fAngle)
  1082.    
  1083.     xs_vec_add(fOrigin, fAngle, fOrigin)
  1084.    
  1085.     new Float:fAttack[3]
  1086.    
  1087.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1088.     xs_vec_sub(vfEnd, fOrigin, fAttack)
  1089.    
  1090.     new Float:fRate
  1091.    
  1092.     fRate = fDis / vector_length(fAttack)
  1093.     xs_vec_mul_scalar(fAttack, fRate, fAttack)
  1094.    
  1095.     xs_vec_add(fOrigin, fAttack, output)
  1096. }
  1097.  
  1098. stock set_weapons_timeidle(id, WeaponId ,Float:TimeIdle)
  1099. {
  1100.     if(!is_user_alive(id))
  1101.         return
  1102.        
  1103.     static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
  1104.     if(!pev_valid(entwpn))
  1105.         return
  1106.        
  1107.     set_pdata_float(entwpn, 46, TimeIdle, WEAP_LINUX_XTRA_OFF)
  1108.     set_pdata_float(entwpn, 47, TimeIdle, WEAP_LINUX_XTRA_OFF)
  1109.     set_pdata_float(entwpn, 48, TimeIdle + 1.0, WEAP_LINUX_XTRA_OFF)
  1110. }
  1111.  
  1112. stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
  1113. {
  1114.     new_velocity[0] = origin2[0] - origin1[0]
  1115.     new_velocity[1] = origin2[1] - origin1[1]
  1116.     new_velocity[2] = origin2[2] - origin1[2]
  1117.     new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
  1118.     new_velocity[0] *= num
  1119.     new_velocity[1] *= num
  1120.     new_velocity[2] *= num
  1121.    
  1122.     return 1;
  1123. }
  1124.  
  1125. stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
  1126. {
  1127.     static Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
  1128.    
  1129.     pev(id, pev_origin, vOrigin)
  1130.     pev(id, pev_view_ofs, vUp) //for player
  1131.     xs_vec_add(vOrigin, vUp, vOrigin)
  1132.     pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
  1133.    
  1134.     angle_vector(vAngle,ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
  1135.     angle_vector(vAngle,ANGLEVECTOR_RIGHT, vRight)
  1136.     angle_vector(vAngle,ANGLEVECTOR_UP, vUp)
  1137.    
  1138.     vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
  1139.     vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
  1140.     vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
  1141. }
  1142.  
  1143.  
  1144. stock drop_weapons(id, dropwhat)
  1145. {
  1146.     static weapons[32], num, i, weaponid
  1147.     num = 0
  1148.     get_user_weapons(id, weapons, num)
  1149.      
  1150.     for (i = 0; i < num; i++)
  1151.     {
  1152.         weaponid = weapons[i]
  1153.          
  1154.         if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
  1155.         {
  1156.             static wname[32]
  1157.             get_weaponname(weaponid, wname, sizeof wname - 1)
  1158.             engclient_cmd(id, "drop", wname)
  1159.         }
  1160.     }
  1161. }
thx raheem can you add for this 2 i try to add for them but when i join to game weapon menu plugin stopped

Code: Select all

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


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

// Data Config
#define MODEL_V "models/v_buffak.mdl"
#define MODEL_P "models/p_buffak.mdl"
#define MODEL_W "models/w_buffak.mdl"
#define MODEL_W_OLD "models/w_ak47.mdl"

#define CSW_BASE CSW_AK47
#define weapon_base "weapon_ak47"

#define SUBMODEL -1 // can -1
#define WEAPON_CODE 2692015
#define WEAPON_EVENT "events/ak47.sc"

#define ANIME_SHOOT 3
#define ANIME_RELOAD 1 // can -1
#define ANIME_DRAW 2 // can -1
#define ANIME_IDLE 0 // can -1

new const WeaponSounds[5][] =
{
	"weapons/ak47buff-1.wav",
	"weapons/ak47buff-2.wav",
	"weapons/ak47buff_idle.wav",
	"weapons/ak47buff_draw.wav",
	"weapons/ak47buff_reload.wav"
}

// Weapon Config
#define DAMAGE_A 33 // 66 for Zombie
#define DAMAGE_B 61 // 360 for Zombie
#define ACCURACY 70 // 0 - 100 ; -1 Default
#define CLIP 50
#define BPAMMO 250
#define SPEED_A 0.0775
#define SPEED_B 0.5
#define RECOIL 0.75
#define RELOAD_TIME 2.0
#define RANGE_SHOCK 96.0

// Muzzleflash
#define MUZZLEFLASH1 "sprites/muzzleflash40.spr"
#define MUZZLEFLASH2 "sprites/muzzleflash41.spr"

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

//new g_Base
new g_Had_Base, g_Clip[33], g_OldWeapon[33], Float:g_Recoil[33][3]
new g_Event_Base, g_SmokePuff_SprId, g_MsgCurWeapon, g_Hit_SprID, g_MaxPlayers
new g_Muzzleflash_Ent, g_Muzzleflash
new g_Muzzleflash_Ent2, g_Muzzleflash2

// Safety
new g_HamBot
new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
new  g_iItemID
public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Safety
	Register_SafetyFunc()
	
	// Event
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	g_iItemID = ze_register_item("Ak47 Paladin", 50, 0) 
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	register_forward(FM_SetModel, "fw_SetModel")	
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_AddToFullPack, "fw_AddToFullPack_Post", 1)
	register_forward(FM_CheckVisibility, "fw_CheckVisibility")
	
	// Ham
	RegisterHam(Ham_Item_Deploy, weapon_base, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_base, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_base, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_base, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload_Post", 1)	
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack_Post", 1)
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	// Cache
	g_MsgCurWeapon = get_user_msgid("CurWeapon")
	g_MaxPlayers = get_maxplayers()
	
	
}

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])
	
	g_Hit_SprID = precache_model("sprites/ef_buffak_hit.spr")
	g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
	
	// Muzzleflash
	g_Muzzleflash_Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	g_Muzzleflash_Ent2 = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	precache_model(MUZZLEFLASH1)
	precache_model(MUZZLEFLASH2)
	
	engfunc(EngFunc_SetModel, g_Muzzleflash_Ent, MUZZLEFLASH1)
	engfunc(EngFunc_SetModel, g_Muzzleflash_Ent2, MUZZLEFLASH2)
	
	set_pev(g_Muzzleflash_Ent, pev_scale, 0.075)
	set_pev(g_Muzzleflash_Ent2, pev_scale, 0.1)
	
	set_pev(g_Muzzleflash_Ent, pev_rendermode, kRenderTransTexture)
	set_pev(g_Muzzleflash_Ent, pev_renderamt, 0.0)
	set_pev(g_Muzzleflash_Ent2, pev_rendermode, kRenderTransTexture)
	set_pev(g_Muzzleflash_Ent2, pev_renderamt, 0.0)
}

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

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

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

public Mileage_WeaponRemove(id, ItemID)
{
	if(ItemID == g_Base) Remove_Base(id)
}*/

public Get_Base(id)
{
	Set_BitVar(g_Had_Base, id)
	give_item(id, weapon_base)
	
	// Clip & Ammo
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
	if(!pev_valid(Ent)) return
	
	cs_set_weapon_ammo(Ent, CLIP)
	cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
	
	message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
	write_byte(1)
	write_byte(CSW_BASE)
	write_byte(CLIP)
	message_end()
	
	cs_set_weapon_silen(Ent, 0, 0)
}

public ze_user_infected(id) 
{
	Remove_Base(id)
}

public ze_user_humanized(id)
{ 
	Remove_Base(id)
}
public ze_select_item_pre(id, itemid) 
{
    // This not our item?
    if (itemid != g_iItemID)
        return ZE_ITEM_AVAILABLE
   
    // Available for Humans only, So don't show it for zombies
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
   
    // Finally return that it's available
    return ZE_ITEM_AVAILABLE
} 

public ze_select_item_post(id, itemid)
{
    // This is not our item, Block it here and don't execute the blew code
    if (itemid != g_iItemID)
        return
	
    Get_Base(id);        
}
public Remove_Base(id)
{
	UnSet_BitVar(g_Had_Base, id)
}

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

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

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

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

	Set_WeaponAnim(invoker, ANIME_SHOOT)
	if(cs_get_user_zoom(invoker) != CS_SET_AUGSG552_ZOOM) emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
	else {
		emit_sound(invoker, CHAN_WEAPON, WeaponSounds[1], 1.0, 0.4, 0, 94 + random_num(0, 15))
		Shock_Damage(invoker)
	}
	
	return FMRES_SUPERCEDE
}

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

	return FMRES_IGNORED;
}

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

public fw_AddToFullPack_Post(esState, iE, iEnt, iHost, iHostFlags, iPlayer, pSet)
{
	if(iEnt == g_Muzzleflash_Ent)
	{
		if(Get_BitVar(g_Muzzleflash, iHost))
		{
			set_es(esState, ES_Frame, float(random_num(0, 2)))
				
			set_es(esState, ES_RenderMode, kRenderTransAdd)
			set_es(esState, ES_RenderAmt, 255.0)
			
			UnSet_BitVar(g_Muzzleflash, iHost)
			//remove_task(iHost+WEAPON_CODE)
			set_task(0.001, "Set_NextMuzzleflash", iHost+WEAPON_CODE)
		}
			
		set_es(esState, ES_Skin, iHost)
		set_es(esState, ES_Body, 1)
		set_es(esState, ES_AimEnt, iHost)
		set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
	} else if(iEnt == g_Muzzleflash_Ent2) {
		if(Get_BitVar(g_Muzzleflash2, iHost))
		{
			set_es(esState, ES_Frame, float(random_num(0, 2)))
				
			set_es(esState, ES_RenderMode, kRenderTransAdd)
			set_es(esState, ES_RenderAmt, 255.0)
			
			UnSet_BitVar(g_Muzzleflash2, iHost)
		}
			
		set_es(esState, ES_Skin, iHost)
		set_es(esState, ES_Body, 1)
		set_es(esState, ES_AimEnt, iHost)
		set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
	}
}

public Set_NextMuzzleflash(id) Set_BitVar(g_Muzzleflash2, id-WEAPON_CODE)

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

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

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

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

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

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

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

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

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

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

	if(cs_get_user_zoom(Attacker) != CS_SET_AUGSG552_ZOOM) SetHamParamFloat(3, float(DAMAGE_A))
	else SetHamParamFloat(3, float(DAMAGE_B))
	
	return HAM_HANDLED
}

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_BASE || !Get_BitVar(g_Had_Base, Attacker))
		return HAM_IGNORED

	static Float:flEnd[3]
	get_tr2(Ptr, TR_vecEndPos, flEnd)	
		
	if(cs_get_user_zoom(Attacker) != CS_SET_AUGSG552_ZOOM) SetHamParamFloat(3, float(DAMAGE_A))
	else SetHamParamFloat(3, float(DAMAGE_B))
	
	return HAM_HANDLED
}


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

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

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

	static Float:Push[3]
	pev(id, pev_punchangle, Push)
	xs_vec_sub(Push, g_Recoil[id], Push)
	
	xs_vec_mul_scalar(Push, RECOIL, Push)
	xs_vec_add(Push, g_Recoil[id], Push)
	
	set_pev(id, pev_punchangle, Push)
	Set_BitVar(g_Muzzleflash, id)
	
	// Acc
	static Accena; Accena = ACCURACY
	if(Accena != -1)
	{
		static Float:Accuracy
		Accuracy = (float(100 - ACCURACY) * 1.5) / 100.0

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

public Shock_Damage(id)
{
	static Float:Origin[3]; fm_get_aim_origin(id, Origin)
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_Hit_SprID)
	write_byte(6)
	write_byte(15)
	write_byte(TE_EXPLFLAG_NODLIGHTS | TE_EXPLFLAG_NOPARTICLES | TE_EXPLFLAG_NOSOUND)
	message_end()
	
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_AK47)
	if(!pev_valid(Ent)) return
	
	static Float:Origin2[3]
	
	for(new i = 0; i < g_MaxPlayers; i++)
	{
		if(!is_alive(i))
			continue
		if(id == i)
			continue
		pev(i, pev_origin, Origin2)
		if(get_distance_f(Origin, Origin2) > RANGE_SHOCK)
			continue
		
		ExecuteHamB(Ham_TakeDamage, i, Ent, id, float(DAMAGE_B), DMG_BULLET)
	}
}

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

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

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

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

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

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

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

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

	return 1
}

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

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

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

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

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

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

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

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

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

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

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

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

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

Code: Select all

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

#define PLUGIN "[CSO] M4A1 Dark Knight"
#define VERSION "1.0"
#define AUTHOR "Dias Pendragon"

// Data Config
#define MODEL_V "models/v_buffm4.mdl"
#define MODEL_P "models/p_buffm4.mdl"
#define MODEL_W "models/w_buffm4.mdl"
#define MODEL_W_OLD "models/w_m4a1.mdl"

#define CSW_BASE CSW_M4A1
#define weapon_base "weapon_m4a1"

#define SUBMODEL -1 // can -1
#define WEAPON_CODE 2692015
#define WEAPON_EVENT "events/m4a1.sc"

#define ANIME_SHOOT 3
#define ANIME_RELOAD 1 // can -1
#define ANIME_DRAW 2 // can -1
#define ANIME_IDLE 0 // can -1

new const WeaponSounds[6][] =
{
	"weapons/m4a1buff-1.wav",
	"weapons/m4a1buff-2.wav",
	"weapons/m4a1buff_idle.wav",
	"weapons/m4a1buff_clipin1.wav",
	"weapons/m4a1buff_clipin2.wav",
	"weapons/m4a1buff_clipout.wav"
}

// Weapon Config
#define DAMAGE_A 30 // 60 for Zombie
#define DAMAGE_B 43 // 200 for Zombie
#define ACCURACY 70 // 0 - 100 ; -1 Default
#define CLIP 50
#define BPAMMO 250
#define SPEED_A 0.0875
#define SPEED_B 0.25
#define RECOIL 0.75
#define RELOAD_TIME 2.0

// Muzzleflash
#define MUZZLEFLASH1 "sprites/muzzleflash43.spr"
#define MUZZLEFLASH2 "sprites/muzzleflash44.spr"

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

//new g_Base
new g_Had_Base, g_Clip[33], g_OldWeapon[33], Float:g_Recoil[33][3]
new g_Event_Base, g_SmokePuff_SprId, g_MsgCurWeapon, m_spriteTexture
new g_Muzzleflash_Ent, g_Muzzleflash
new g_Muzzleflash_Ent2, g_Muzzleflash2

// Safety
new g_HamBot
new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
new  g_iItemID
public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	// Safety
	Register_SafetyFunc()
	
	// Event
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	g_iItemID = ze_register_item("M4a1 Darknight", 50, 0) 
	
	// Forward
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
	register_forward(FM_SetModel, "fw_SetModel")	
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_AddToFullPack, "fw_AddToFullPack_Post", 1)
	register_forward(FM_CheckVisibility, "fw_CheckVisibility")
	
	// Ham
	RegisterHam(Ham_Item_Deploy, weapon_base, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_base, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_base, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_base, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_base, "fw_Weapon_Reload_Post", 1)	
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_base, "fw_Weapon_PrimaryAttack_Post", 1)
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	// Cache
	g_MsgCurWeapon = get_user_msgid("CurWeapon")
	
	// Get
	
}

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])
	
	m_spriteTexture = precache_model( "sprites/lgtning.spr" )
	g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
	
	// Muzzleflash
	g_Muzzleflash_Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	g_Muzzleflash_Ent2 = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
	
	precache_model(MUZZLEFLASH1)
	precache_model(MUZZLEFLASH2)
	
	engfunc(EngFunc_SetModel, g_Muzzleflash_Ent, MUZZLEFLASH1)
	engfunc(EngFunc_SetModel, g_Muzzleflash_Ent2, MUZZLEFLASH2)
	
	set_pev(g_Muzzleflash_Ent, pev_scale, 0.075)
	set_pev(g_Muzzleflash_Ent2, pev_scale, 0.1)
	
	set_pev(g_Muzzleflash_Ent, pev_rendermode, kRenderTransTexture)
	set_pev(g_Muzzleflash_Ent, pev_renderamt, 0.0)
	set_pev(g_Muzzleflash_Ent2, pev_rendermode, kRenderTransTexture)
	set_pev(g_Muzzleflash_Ent2, pev_renderamt, 0.0)
}

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

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

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

public Mileage_WeaponRemove(id, ItemID)
{
	if(ItemID == g_Base) Remove_Base(id)
}*/

public Get_Base(id)
{
	Set_BitVar(g_Had_Base, id)
	give_item(id, weapon_base)
	
	// Clip & Ammo
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_BASE)
	if(!pev_valid(Ent)) return
	
	cs_set_weapon_ammo(Ent, CLIP)
	cs_set_user_bpammo(id, CSW_BASE, BPAMMO)
	
	message_begin(MSG_ONE_UNRELIABLE, g_MsgCurWeapon, _, id)
	write_byte(1)
	write_byte(CSW_BASE)
	write_byte(CLIP)
	message_end()
	
	cs_set_weapon_silen(Ent, 0, 0)
}

public ze_user_infected(id) 
{
	Remove_Base(id)
}

public ze_user_humanized(id)
{ 
	Remove_Base(id)
}
public ze_select_item_pre(id, itemid) 
{
    // This not our item?
    if (itemid != g_iItemID)
        return ZE_ITEM_AVAILABLE
   
    // Available for Humans only, So don't show it for zombies
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
   
    // Finally return that it's available
    return ZE_ITEM_AVAILABLE
} 

public ze_select_item_post(id, itemid)
{
    // This is not our item, Block it here and don't execute the blew code
    if (itemid != g_iItemID)
        return
	
    Get_Base(id);        
}

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

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

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

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

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

	Set_WeaponAnim(invoker, ANIME_SHOOT)
	if(cs_get_user_zoom(invoker) != CS_SET_AUGSG552_ZOOM) emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
	else emit_sound(invoker, CHAN_WEAPON, WeaponSounds[1], 1.0, 0.4, 0, 94 + random_num(0, 15))
	
	return FMRES_SUPERCEDE
}

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

	return FMRES_IGNORED;
}

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

public fw_AddToFullPack_Post(esState, iE, iEnt, iHost, iHostFlags, iPlayer, pSet)
{
	if(iEnt == g_Muzzleflash_Ent)
	{
		if(Get_BitVar(g_Muzzleflash, iHost))
		{
			set_es(esState, ES_Frame, float(random_num(0, 2)))
				
			set_es(esState, ES_RenderMode, kRenderTransAdd)
			set_es(esState, ES_RenderAmt, 255.0)
			
			UnSet_BitVar(g_Muzzleflash, iHost)
			//remove_task(iHost+WEAPON_CODE)
			set_task(0.001, "Set_NextMuzzleflash", iHost+WEAPON_CODE)
		}
			
		set_es(esState, ES_Skin, iHost)
		set_es(esState, ES_Body, 1)
		set_es(esState, ES_AimEnt, iHost)
		set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
	} else if(iEnt == g_Muzzleflash_Ent2) {
		if(Get_BitVar(g_Muzzleflash2, iHost))
		{
			set_es(esState, ES_Frame, float(random_num(0, 2)))
				
			set_es(esState, ES_RenderMode, kRenderTransAdd)
			set_es(esState, ES_RenderAmt, 255.0)
			
			UnSet_BitVar(g_Muzzleflash2, iHost)
		}
			
		set_es(esState, ES_Skin, iHost)
		set_es(esState, ES_Body, 1)
		set_es(esState, ES_AimEnt, iHost)
		set_es(esState, ES_MoveType, MOVETYPE_FOLLOW)
	}
}

public Set_NextMuzzleflash(id) Set_BitVar(g_Muzzleflash2, id-WEAPON_CODE)

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

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

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

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

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

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

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

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

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

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

	if(cs_get_user_zoom(Attacker) != CS_SET_AUGSG552_ZOOM) SetHamParamFloat(3, float(DAMAGE_A))
	else {
		SetHamParamFloat(3, float(DAMAGE_B))
		Create_Tracer(Attacker, flEnd)
	}
	
	return HAM_HANDLED
}

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_BASE || !Get_BitVar(g_Had_Base, Attacker))
		return HAM_IGNORED

	static Float:flEnd[3]
	get_tr2(Ptr, TR_vecEndPos, flEnd)	
		
	if(cs_get_user_zoom(Attacker) != CS_SET_AUGSG552_ZOOM) SetHamParamFloat(3, float(DAMAGE_A))
	else {
		SetHamParamFloat(3, float(DAMAGE_B))
		Create_Tracer(Attacker, flEnd)
	}
	
	return HAM_HANDLED
}

public Create_Tracer(id, Float:Target[3])
{
	static Float:Start[3]; 
	Get_Position(id, 48.0, 6.0, -6.0, Start)
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_BEAMPOINTS)
	write_coord(Start[0]) 
	write_coord(Start[1]) 
	write_coord(Start[2]) 
	write_coord(Target[0]) 
	write_coord(Target[1]) 
	write_coord(Target[2]) 
	write_short(m_spriteTexture)
	write_byte(0) // framerate
	write_byte(0) // framerate
	write_byte(5) // life
	write_byte(2)  // width
	write_byte(0)   // noise
	write_byte(255)   // r, g, b
	write_byte(255)   // r, g, b
	write_byte(255)   // r, g, b
	write_byte(175)	// brightness
	write_byte(1)		// speed
	message_end()
}

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

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

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

	static Float:Push[3]
	pev(id, pev_punchangle, Push)
	xs_vec_sub(Push, g_Recoil[id], Push)
	
	xs_vec_mul_scalar(Push, RECOIL, Push)
	xs_vec_add(Push, g_Recoil[id], Push)
	
	set_pev(id, pev_punchangle, Push)
	Set_BitVar(g_Muzzleflash, id)
	
	// Acc
	static Accena; Accena = ACCURACY
	if(Accena != -1)
	{
		static Float:Accuracy
		Accuracy = (float(100 - ACCURACY) * 1.5) / 100.0

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

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

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

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

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

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

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

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

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

	return 1
}

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

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

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

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

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

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

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

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

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

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

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

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

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest