Furien Weapons pe Credite (OutDated) - NO SUPORT!

Pluginuri pentru modul AmxModX.

Moderators: Moderatori ajutatori, Moderatori, Echipa eXtreamCS.com

Post Reply
User avatar
roberteeel
Membru eXtream
Membru eXtream
Posts: 4440
Joined: 05 Sep 2012, 10:39
Detinator Steam: Nu
Reputatie: Nick anterior: QAZW, Robert.ultrasFarul, CT 18 ROS
Restrictie schimbare nume
Fost moderator
Fost Membru Club eXtreamCS (doua luni)
Has thanked: 312 times
Been thanked: 357 times

26 Feb 2014, 19:25

The YONTU wrote:QAZW: Trebuie modificat accesu' din sursele armelor...
Si mi-l poate face cineva, va rog frumos?
Rapidserver
User avatar
YONTU
Moderator ajutator
Moderator ajutator
Posts: 2446
Joined: 10 May 2013, 13:25
Detinator Steam: Nu
CS Status: Everyone is looking at ur shoes
Reputatie: Moderator ajutator
Fost scripter eXtreamCS
Location: Gura Humorului
Has thanked: 255 times
Been thanked: 281 times
Contact:

26 Feb 2014, 19:36

QAZW wrote:
The YONTU wrote:QAZW: Trebuie modificat accesu' din sursele armelor...
Si mi-l poate face cineva, va rog frumos?
Da-ne sursele la armele la care zici tu ca au acces jucatorii !
„Peste douăzeci de ani vei fi dezamăgit din cauza lucrurilor pe care nu le-ai făcut, nu din cauza celor pe care le-ai făcut.” - Mark Twain
„Asa e si in viata, hotii castiga, prostii care invata pierd.” - Mihai Nemeș

discord: IonutC#5114

Vrei sa joci pe un server de biohazard clasic specific timpurilor 2008-2012?
CLICK | Afiseaza codul
89.44.246.14:27015 biohazard clasic
User avatar
roberteeel
Membru eXtream
Membru eXtream
Posts: 4440
Joined: 05 Sep 2012, 10:39
Detinator Steam: Nu
Reputatie: Nick anterior: QAZW, Robert.ultrasFarul, CT 18 ROS
Restrictie schimbare nume
Fost moderator
Fost Membru Club eXtreamCS (doua luni)
Has thanked: 312 times
Been thanked: 357 times

26 Feb 2014, 19:45

The YONTU wrote:
QAZW wrote:
The YONTU wrote:QAZW: Trebuie modificat accesu' din sursele armelor...
Si mi-l poate face cineva, va rog frumos?
Da-ne sursele la armele la care zici tu ca au acces jucatorii !
Din cate stiu eu, la gatling au sigur... la celelalate nu am incercat.

Fm_Gatling | Afiseaza codul
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>

#define PLUGIN "Gatling (Volcano)"
#define VERSION "1.0"
#define AUTHOR "Dias"

#define CSW_GATLING CSW_M3
#define weapon_gatling "weapon_m3"
#define WEAPON_ANIMEXT "m249"
#define DEFAULT_W_MODEL "models/w_m3.mdl"
#define WEAPON_SECRET_CODE 1942
#define old_event "events/m3.sc"

#define DAMAGE 30
#define SPEED 0.25
#define RECOIL 0.5
#define RELOAD_TIME 4.5
#define DEFAULT_CLIP 45
#define DEFAULT_BPAMMO 300

new const WeaponModel[3][] =
{
	"models/v_gatling.mdl", // V
	"models/p_gatling.mdl", // P
	"models/w_gatling.mdl" // W
}

new const WeaponSound[7][] =
{
	"weapons/gatling-1.wav",
	"weapons/gatling_boltpull.wav",
	"weapons/gatling_clipin1.wav",
	"weapons/gatling_clipin2.wav",
	"weapons/gatling_clipout1.wav",
	"weapons/gatling_clipout2.wav",
	"weapons/usas_draw.wav"
}

new const WeaponResource[4][] = 
{
	"sprites/weapon_gatling.txt",
	"sprites/640hud7_2.spr",
	"sprites/640hud55_2.spr",
	"sprites/640hud56_2.spr"
}

enum
{
	GATLING_ANIM_IDLE = 0,
	GATLING_ANIM_SHOOT1,
	GATLING_ANIM_SHOOT2,
	GATLING_ANIM_RELOAD,
	GATLING_ANIM_DRAW
}

const PDATA_SAFE = 2
const OFFSET_LINUX_WEAPONS = 4
const OFFSET_LINUX_PLAYER = 5
const OFFSET_WEAPONOWNER = 41
const m_iClip = 51
const m_fInReload = 54
const m_flNextAttack = 83
const m_szAnimExtention = 492

new g_had_gatling[33], Float:g_punchangles[33][3], g_gatling_event, g_smokepuff_id, m_iBlood[2], g_ham_bot

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")		
	
	RegisterHam(Ham_Item_Deploy, weapon_gatling, "fw_Item_Deploy_Post", 1)
	RegisterHam(Ham_Weapon_Reload, weapon_gatling, "fw_Weapon_Reload_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_gatling, "fw_Item_PostFrame")
	RegisterHam(Ham_Item_AddToPlayer, weapon_gatling, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_gatling, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_gatling, "fw_Weapon_PrimaryAttack_Post", 1)
	
	register_clcmd("weapon_gatling", "hook_weapon")
	register_clcmd("admin_get_gatling", "get_gatling", ADMIN_BAN)
}

public plugin_precache()
{
	new i
	
	for(i = 0; i < sizeof(WeaponModel); i++)
		engfunc(EngFunc_PrecacheModel, WeaponModel)
	for(i = 0; i < sizeof(WeaponSound); i++)
		engfunc(EngFunc_PrecacheSound, WeaponSound)
	for(new i = 0; i < sizeof(WeaponResource); i++)
	{
		if(i == 0) engfunc(EngFunc_PrecacheGeneric, WeaponResource)
		else engfunc(EngFunc_PrecacheModel, WeaponResource)
	}
	
	g_smokepuff_id = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
	m_iBlood[0] = engfunc(EngFunc_PrecacheModel, "sprites/blood.spr")
	m_iBlood[1] = engfunc(EngFunc_PrecacheModel, "sprites/bloodspray.spr")		
	
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)	
}

public plugin_natives()
{
	register_native("give_weapon_gatling", "native_give_weapon_add", 1)
}
public native_give_weapon_add(id)
{
	get_gatling(id)
}

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

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

public Do_Register_Ham(id)
{
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")	
}

public get_gatling(id)
{
	if(!is_user_alive(id))
		return
		
	drop_weapons(id, 1)
		
	g_had_gatling[id] = 1
	fm_give_item(id, weapon_gatling)
	
	// Set Clip
	static ent; ent = fm_get_user_weapon_entity(id, CSW_GATLING)
	if(pev_valid(ent)) cs_set_weapon_ammo(ent, DEFAULT_CLIP)
	
	// Set BpAmmo
	cs_set_user_bpammo(id, CSW_GATLING, DEFAULT_BPAMMO)
	
	// Update Ammo
	update_ammo(id, CSW_GATLING, DEFAULT_CLIP, DEFAULT_BPAMMO)
}

public remove_gatling(id)
{
	g_had_gatling[id] = 0
}

public hook_weapon(id)
{
	client_cmd(id, weapon_gatling)
	return PLUGIN_HANDLED
}

public Event_CurWeapon(id)
{
	if(!is_user_alive(id))
		return
	if(get_user_weapon(id) != CSW_GATLING || !g_had_gatling[id])
		return
		
	// Speed
	static ent; ent = fm_get_user_weapon_entity(id, CSW_GATLING)
	if(!pev_valid(ent)) 
		return
		
	set_pdata_float(ent, 46, get_pdata_float(ent, 46, OFFSET_LINUX_WEAPONS) * SPEED, OFFSET_LINUX_WEAPONS)
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_user_alive(id))
		return
	if(get_user_weapon(id) != CSW_GATLING || !g_had_gatling[id])
		return 

	static CurButton; CurButton = get_uc(uc_handle, UC_Buttons)

	if(CurButton & IN_RELOAD)
	{
		CurButton &= ~IN_RELOAD
		set_uc(uc_handle, UC_Buttons, CurButton)
		
		static ent; ent = fm_get_user_weapon_entity(id, CSW_GATLING)
		if(!pev_valid(ent)) return
		
		static fInReload; fInReload = get_pdata_int(ent, m_fInReload, OFFSET_LINUX_WEAPONS)
		static Float:flNextAttack; flNextAttack = get_pdata_float(id, m_flNextAttack, OFFSET_LINUX_PLAYER)
		
		if (flNextAttack > 0.0)
			return
			
		if (fInReload)
		{
			set_weapon_anim(id, GATLING_ANIM_IDLE)
			return
		}
		
		if(cs_get_weapon_ammo(ent) >= DEFAULT_CLIP)
		{
			set_weapon_anim(id, GATLING_ANIM_IDLE)
			return
		}
			
		fw_Weapon_Reload_Post(ent)
	}
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static szClassName[33]
	pev(entity, pev_classname, szClassName, charsmax(szClassName))
	
	if(!equal(szClassName, "weaponbox"))
		return FMRES_IGNORED
	
	static id
	id = pev(entity, pev_owner)
	
	if(equal(model, DEFAULT_W_MODEL))
	{
		static weapon
		weapon = fm_find_ent_by_owner(-1, weapon_gatling, entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED
		
		if(g_had_gatling[id])
		{
			set_pev(weapon, pev_impulse, WEAPON_SECRET_CODE)
			engfunc(EngFunc_SetModel, entity, WeaponModel[2])
			
			remove_gatling(id)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED
}

public fw_TraceAttack(ent, attacker, Float:Damage, Float:fDir[3], pentru, iDamageType)
{
	if(!is_user_alive(attacker))
		return HAM_IGNORED	
	if(get_user_weapon(attacker) != CSW_GATLING || !g_had_gatling[attacker])
		return HAM_IGNORED
		
	if(!is_user_alive(ent))
	{
		static Float:flEnd[3], Float:vecPlane[3]
	
		get_tr2(pentru, TR_vecEndPos, flEnd)
		get_tr2(pentru, TR_vecPlaneNormal, vecPlane)		
		
		make_bullet(attacker, flEnd)
		fake_smoke(attacker, pentru)
	}
		
	SetHamParamFloat(3, float(DAMAGE) / random_float(1.5, 2.5))	

	return HAM_HANDLED
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_user_alive(id) || !is_user_connected(id))
		return FMRES_IGNORED
	if(get_user_weapon(id) != CSW_GATLING || !g_had_gatling[id])
		return FMRES_IGNORED
		
	set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if(!is_user_connected(invoker))
		return FMRES_IGNORED	
		
	if(get_user_weapon(invoker) == CSW_GATLING && g_had_gatling[invoker] && eventid == g_gatling_event)
	{
		engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
		Event_Gatling_Shoot(invoker)	

		return FMRES_SUPERCEDE
	}
	
	return FMRES_HANDLED
}

public fw_Item_Deploy_Post(ent)
{
	static id; id = fm_cs_get_weapon_ent_owner(ent)
	if (!pev_valid(id))
		return
	
	static weaponid
	weaponid = cs_get_weapon_id(ent)
	
	if(weaponid != CSW_GATLING)
		return
	if(!g_had_gatling[id])
		return
		
	set_pev(id, pev_viewmodel2, WeaponModel[0])
	set_pev(id, pev_weaponmodel2, WeaponModel[1])
	
	set_weapon_anim(id, GATLING_ANIM_DRAW)
	set_pdata_string(id, m_szAnimExtention * 4, WEAPON_ANIMEXT, -1 , 20)
}

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

	if(g_had_gatling[id])
	{
		static CurBpAmmo; CurBpAmmo = cs_get_user_bpammo(id, CSW_GATLING)
		
		if(CurBpAmmo  <= 0)
			return HAM_IGNORED

		set_pdata_int(ent, 55, 0, OFFSET_LINUX_WEAPONS)
		set_pdata_float(id, 83, RELOAD_TIME, OFFSET_LINUX_PLAYER)
		set_pdata_float(ent, 48, RELOAD_TIME + 0.5, OFFSET_LINUX_WEAPONS)
		set_pdata_float(ent, 46, RELOAD_TIME + 0.25, OFFSET_LINUX_WEAPONS)
		set_pdata_float(ent, 47, RELOAD_TIME + 0.25, OFFSET_LINUX_WEAPONS)
		set_pdata_int(ent, m_fInReload, 1, OFFSET_LINUX_WEAPONS)
		
		set_weapon_anim(id, GATLING_ANIM_RELOAD)			
		
		return HAM_HANDLED
	}
	
	return HAM_IGNORED	
}

public fw_Item_PostFrame(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!g_had_gatling[id]) return

	static iBpAmmo ; iBpAmmo = get_pdata_int(id, 381, OFFSET_LINUX_PLAYER)
	static iClip ; iClip = get_pdata_int(ent, m_iClip, OFFSET_LINUX_WEAPONS)
	static iMaxClip ; iMaxClip = DEFAULT_CLIP

	if(get_pdata_int(ent, m_fInReload, OFFSET_LINUX_WEAPONS) && get_pdata_float(id, m_flNextAttack, OFFSET_LINUX_PLAYER) <= 0.0)
	{
		static j; j = min(iMaxClip - iClip, iBpAmmo)
		set_pdata_int(ent, m_iClip, iClip + j, OFFSET_LINUX_WEAPONS)
		set_pdata_int(id, 381, iBpAmmo-j, OFFSET_LINUX_PLAYER)
		
		set_pdata_int(ent, m_fInReload, 0, OFFSET_LINUX_WEAPONS)
		cs_set_weapon_ammo(ent, DEFAULT_CLIP)
	
		update_ammo(id, CSW_GATLING, cs_get_weapon_ammo(ent), cs_get_user_bpammo(id, CSW_GATLING))
	
		return
	}
}

public fw_Item_AddToPlayer_Post(ent, id)
{
	if(!pev_valid(ent))
		return HAM_IGNORED
		
	if(pev(ent, pev_impulse) == WEAPON_SECRET_CODE)
	{
		remove_gatling(id)
		g_had_gatling[id] = 1
		
		update_ammo(id, CSW_GATLING, cs_get_weapon_ammo(ent), cs_get_user_bpammo(id, CSW_GATLING))
	}
	
	message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("WeaponList"), _, id)
	write_string(g_had_gatling[id] == 1 ? "weapon_gatling" : "weapon_m3")
	write_byte(5)
	write_byte(200)
	write_byte(-1)
	write_byte(-1)
	write_byte(0)
	write_byte(5)
	write_byte(g_had_gatling[id] == 1 ? CSW_GATLING : CSW_M3)
	write_byte(0)
	message_end()			
		
	return HAM_IGNORED
}

public fw_Weapon_PrimaryAttack(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!g_had_gatling[id])
		return
		
	pev(id, pev_punchangle, g_punchangles[id])
}

public fw_Weapon_PrimaryAttack_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!g_had_gatling[id])
		return
		
	static Float:push[3]
	pev(id, pev_punchangle, push)
	xs_vec_sub(push, g_punchangles[id], push)
	
	xs_vec_mul_scalar(push, RECOIL, push)
	xs_vec_add(push, g_punchangles[id], push)
	set_pev(id, pev_punchangle, push)	
}

public update_ammo(id, csw_id, clip, bpammo)
{
	if(!is_user_alive(id))
		return
		
	message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("CurWeapon"), _, id)
	write_byte(1)
	write_byte(csw_id)
	write_byte(clip)
	message_end()
	
	message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("AmmoX"), _, id)
	write_byte(3)
	write_byte(bpammo)
	message_end()
}

public Event_Gatling_Shoot(id)
{
	set_weapon_anim(id, random_num(GATLING_ANIM_SHOOT1, GATLING_ANIM_SHOOT2))
	emit_sound(id, CHAN_WEAPON, WeaponSound[0], 1.0, ATTN_NORM, 0, PITCH_NORM)
}

stock fm_cs_get_weapon_ent_owner(ent)
{
	if (pev_valid(ent) != PDATA_SAFE)
		return -1
	
	return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS)
}

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

stock drop_weapons(id, dropwhat)
{
	static weapons[32], num, i, weaponid
	num = 0
	get_user_weapons(id, weapons, num)
	
	const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_MAC10)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_MAC10)|(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)
	
	for (i = 0; i < num; i++)
	{
		weaponid = weapons
		
		if (dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM))
		{
			static wname[32]
			get_weaponname(weaponid, wname, sizeof wname - 1)
			engclient_cmd(id, "drop", wname)
		}
	}
}


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

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

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

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{ 
	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 create_blood(const Float:origin[3])
{
	// Show some blood :)
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY) 
	write_byte(TE_BLOODSPRITE)
	engfunc(EngFunc_WriteCoord, origin[0])
	engfunc(EngFunc_WriteCoord, origin[1])
	engfunc(EngFunc_WriteCoord, origin[2])
	write_short(m_iBlood[1])
	write_short(m_iBlood[0])
	write_byte(75)
	write_byte(5)
	message_end()
}

Fm_PlasmaGun | Afiseaza codul
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>

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

// ================= Config =================

// Level 1 Config
#define V_MODEL "models/v_plasmagun2.mdl"
#define P_MODEL "models/p_plasmagun.mdl"
#define W_MODEL "models/w_plasmagun.mdl"

new const WeaponSounds[7][] =
{
	"weapons/plasmagun-1.wav",
	"weapons/plasmagun_exp.wav",
	"weapons/plasmagun_idle.wav",
	"weapons/plasmagun_draw.wav",
	"weapons/plasmagun_clipin1.wav",
	"weapons/plasmagun_clipin2.wav",
	"weapons/plasmagun_clipout.wav"
}

new const WeaponResources[3][] =
{
	"sprites/weapon_plasmagun.txt",
	"sprites/640hud3_2.spr",
	"sprites/640hud91_2.spr"
}

new const WeaponFiles[2][] =
{
	"sprites/plasmaball.spr",
	"sprites/plasmabomb.spr"
}

new const MuzzleFlash[] = "sprites/muzzleflash27.spr"

// Level 2 Config
#define DAMAGE 27
#define CLIP 45
#define BPAMMO 300
#define SPEED 1.5
#define RECOIL 0.75

#define PLASMA_SPEED 1400.0
#define PLASMA_RADIUS 200.0

// Level 3 Config
#define CSW_PLASMA CSW_AK47
#define weapon_plasma "weapon_ak47"

#define WEAPON_EVENT "events/ak47.sc"
#define WEAPON_ANIMEXT "carbine"
#define WEAPON_OLD_WMODEL "models/w_ak47.mdl"
#define WEAPON_SECRETCODE 1946

#define WEAPONANIM_SHOOT random_num(3, 5)
#define WEAPONANIM_RELOAD 1

#define WEAPONTIME_DRAW 0.75
#define WEAPONTIME_RELOAD 3.5

// Level 4 Config
#define PLASMABALL_CLASSNAME "plasmaball"
// ============== End of Config ==============

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

enum
{
	TEAM_T = 1,
	TEAM_CT
}

// Vars
new g_Had_Plasma, g_WeaponClip[33], Float:g_WeaponRecoil[33][3]
new g_Msg_WeaponList, g_Msg_CurWeapon, g_Msg_AmmoX
new g_MuzzleFlash_SprId, g_PlasmaExp_SprId, g_weapon_event, g_HamBot, g_MaxPlayers

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

	register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
	
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	register_forward(FM_SetModel, "fw_SetModel")		
	
	register_think(PLASMABALL_CLASSNAME, "fw_Think_Plasma")
	register_touch(PLASMABALL_CLASSNAME, "*", "fw_Touch_Plasma")
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_plasma, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_plasma, "fw_Weapon_PrimaryAttack_Post", 1)
	RegisterHam(Ham_Item_Deploy, weapon_plasma, "fw_Item_Deploy_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_plasma, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_plasma, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_plasma, "fw_Weapon_Reload_Post", 1)
	RegisterHam(Ham_Item_AddToPlayer, weapon_plasma, "fw_Item_AddToPlayer_Post", 1)
	
	g_Msg_WeaponList = get_user_msgid("WeaponList")
	g_Msg_CurWeapon = get_user_msgid("CurWeapon")
	g_Msg_AmmoX = get_user_msgid("AmmoX")
	g_MaxPlayers = get_maxplayers()
	
	register_clcmd("admin_get_plasmagun", "Get_Plasma", ADMIN_KICK)
	register_clcmd("weapon_plasmagun", "Hook_WeaponHud")
}

public plugin_precache()
{
	engfunc(EngFunc_PrecacheModel, V_MODEL)
	engfunc(EngFunc_PrecacheModel, P_MODEL)
	engfunc(EngFunc_PrecacheModel, W_MODEL)
	
	new i
	for(i = 0; i < sizeof(WeaponSounds); i++)
		engfunc(EngFunc_PrecacheSound, WeaponSounds)
	for(i = 0; i < sizeof(WeaponResources); i++)
	{
		if(i == 0) engfunc(EngFunc_PrecacheGeneric, WeaponResources)
		else engfunc(EngFunc_PrecacheModel, WeaponResources)
	}
	for(i = 0; i < sizeof(WeaponFiles); i++)
	{
		if(i == 1) g_PlasmaExp_SprId = engfunc(EngFunc_PrecacheModel, WeaponFiles)
		else engfunc(EngFunc_PrecacheModel, WeaponFiles)
	}
		
	g_MuzzleFlash_SprId = engfunc(EngFunc_PrecacheModel, MuzzleFlash)
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
}

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

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

public plugin_natives ()
{
	register_native("give_weapon_plasmagun", "native_give_weapon_add", 1)
}
public native_give_weapon_add(id)
{
	Get_Plasma(id)
}

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

public Get_Plasma(id)
{
	if(!is_user_alive(id))
		return
		
	Set_BitVar(g_Had_Plasma, id)
	fm_give_item(id, weapon_plasma)
	
	// Set Weapon
	engclient_cmd(id, weapon_plasma)
	
	set_pev(id, pev_viewmodel2, V_MODEL)
	set_pev(id, pev_weaponmodel2, P_MODEL)
	
	set_pdata_string(id, (492) * 4, WEAPON_ANIMEXT, -1 , 20)	
	
	// Set Weapon Base
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_PLASMA)
	if(!pev_valid(Ent)) return
	
	cs_set_weapon_ammo(Ent, CLIP)
	cs_set_user_bpammo(id, CSW_PLASMA, BPAMMO)
	
	Update_AmmoHud(id, CSW_PLASMA, CLIP, BPAMMO)
}

public Remove_Plasma(id)
{
	UnSet_BitVar(g_Had_Plasma, id)
}

public Hook_WeaponHud(id)
{
	engclient_cmd(id, weapon_plasma)
	return PLUGIN_HANDLED
}

public Event_NewRound() remove_entity_name(PLASMABALL_CLASSNAME)

public fw_Think_Plasma(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Float:RenderAmt; pev(Ent, pev_renderamt, RenderAmt)
	
	RenderAmt += 50.0
	RenderAmt = float(clamp(floatround(RenderAmt), 0, 255))
	
	set_pev(Ent, pev_renderamt, RenderAmt)
	set_pev(Ent, pev_nextthink, halflife_time() + 0.1)
}

public fw_Touch_Plasma(Ent, Id)
{
	if(!pev_valid(Ent))
		return
	if(pev(Ent, pev_movetype) == MOVETYPE_NONE)
		return
		
	// Exp Sprite
	static Float:Origin[3], TE_FLAG
	pev(Ent, pev_origin, Origin)
	
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, Origin[0])
	engfunc(EngFunc_WriteCoord, Origin[1])
	engfunc(EngFunc_WriteCoord, Origin[2])
	write_short(g_PlasmaExp_SprId)
	write_byte(7)
	write_byte(30)
	write_byte(TE_FLAG)
	message_end()	
	
	// Exp Sound
	emit_sound(Ent, CHAN_BODY, WeaponSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	// Damage
	Damage_Plasma(Ent, Id)
	
	// Remove Ent
	set_pev(Ent, pev_movetype, MOVETYPE_NONE)
	set_task(0.1, "Remove_PlasmaBall", Ent)
}

public Damage_Plasma(Ent, Id)
{
	static Owner; Owner = pev(Ent, pev_iuser1)
	static Attacker; 
	if(!is_user_alive(Owner)) 
	{
		Attacker = 0
		return
	} else Attacker = Owner
	
	if(is_user_alive(Id) && cs_get_user_team(Id) != Get_PlasmaTeam(Ent))
		ExecuteHamB(Ham_TakeDamage, Id, 0, Attacker, float(DAMAGE), DMG_ACID)
	
	for(new i = 0; i < g_MaxPlayers; i++)
	{
		if(!is_user_alive(i))
			continue
		if(entity_range(i, Ent) > PLASMA_RADIUS)
			continue
		if(cs_get_user_team(i) == Get_PlasmaTeam(Ent))
			continue
			
		ExecuteHamB(Ham_TakeDamage, i, 0, Attacker, float(DAMAGE) / random_float(1.25, 1.5), DMG_ACID)
	}
}

public Remove_PlasmaBall(Ent)
{
	if(!pev_valid(Ent)) return
	engfunc(EngFunc_RemoveEntity, Ent)
}

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

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_user_connected(invoker))
		return FMRES_IGNORED	
	if(get_user_weapon(invoker) != CSW_PLASMA || !Get_BitVar(g_Had_Plasma, invoker))
		return FMRES_IGNORED
	if(eventid != g_weapon_event)
		return FMRES_IGNORED
	
	engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
	
	return FMRES_SUPERCEDE
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[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, WEAPON_OLD_WMODEL))
	{
		static weapon; weapon = fm_find_ent_by_owner(-1, weapon_plasma, entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED;
		
		if(Get_BitVar(g_Had_Plasma, iOwner))
		{
			Remove_Plasma(iOwner)
			
			set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
			engfunc(EngFunc_SetModel, entity, W_MODEL)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_PLASMA || !Get_BitVar(g_Had_Plasma, Attacker))
		return HAM_IGNORED
	
	return HAM_SUPERCEDE
}

public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], pentru, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_PLASMA || !Get_BitVar(g_Had_Plasma, Attacker))
		return HAM_IGNORED
		
	return HAM_SUPERCEDE
}

public fw_Weapon_PrimaryAttack(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Id; Id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_Plasma, Id))
		return
	static Ammo; Ammo = cs_get_weapon_ammo(Ent)
	if(Ammo <= 0) return

	// Weapon Shoot
	Set_Weapon_Anim(Id, WEAPONANIM_SHOOT)
	emit_sound(Id, CHAN_WEAPON, WeaponSounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	// MuzzleFlash & Effect
	Make_Muzzleflash(Id)
	
	// Create Plasma Effect
	Create_PlasmaBall(Id)
	
	// Speed & Recoil
	pev(Ent, pev_punchangle, g_WeaponRecoil[Id])
}

public fw_Weapon_PrimaryAttack_Post(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Id; Id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_Plasma, Id))
		return
	static Ammo; Ammo = cs_get_weapon_ammo(Ent)
	if(Ammo <= 0) return
	
	// Speed & Recoil
	set_pdata_float(Ent, 46, get_pdata_float(Ent, 46, 4) * SPEED, 4)
	
	static Float:Push[3]; pev(Id, pev_punchangle, Push)
	
	xs_vec_sub(Push, g_WeaponRecoil[Id], Push)
	xs_vec_mul_scalar(Push, RECOIL, Push)
	xs_vec_add(Push,  g_WeaponRecoil[Id], Push)

	set_pev(Id, pev_punchangle, Push)
}

public fw_Item_Deploy_Post(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Id; Id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_Plasma, Id))
		return
		
	set_pev(Id, pev_viewmodel2, V_MODEL)
	set_pev(Id, pev_weaponmodel2, P_MODEL)
	
	set_pdata_string(Id, (492) * 4, WEAPON_ANIMEXT, -1 , 20)
	
	// Set Draw
	Set_Player_NextAttack(Id, WEAPONTIME_DRAW)
	Set_Weapon_TimeIdle(Id, CSW_PLASMA, WEAPONTIME_DRAW)
}

public fw_Item_PostFrame(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Id; Id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_Plasma, Id))
		return
	
	static Float:flNextAttack; flNextAttack = get_pdata_float(Id, 83, 5)
	static bpammo; bpammo = cs_get_user_bpammo(Id, CSW_PLASMA)
	static iClip; iClip = get_pdata_int(Ent, 51, 4)

	if(get_pdata_int(Ent, 54, 4) && flNextAttack <= 0.0)
	{
		static temp1; temp1 = min(CLIP - iClip, bpammo)

		set_pdata_int(Ent, 51, iClip + temp1, 4)
		cs_set_user_bpammo(Id, CSW_PLASMA, bpammo - temp1)		
		
		set_pdata_int(Ent, 54, 0, 4)
	}		
}

public fw_Weapon_Reload(Ent)
{
	if(!pev_valid(Ent))
		return HAM_IGNORED
		
	static Id; Id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_Plasma, Id))
		return HAM_IGNORED
		
	g_WeaponClip[Id] = -1
	
	static bpammo; bpammo = cs_get_user_bpammo(Id, CSW_PLASMA)
	static iClip; iClip = get_pdata_int(Ent, 51, 4)
	
	if(bpammo <= 0) return HAM_SUPERCEDE
	if(iClip >= CLIP) return HAM_SUPERCEDE
		
	g_WeaponClip[Id] = iClip
	return HAM_IGNORED
}

public fw_Weapon_Reload_Post(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Id; Id = pev(Ent, pev_owner)
	if(!Get_BitVar(g_Had_Plasma, Id))
		return
	if(g_WeaponClip[Id] == -1)
		return
	
	set_pdata_int(Ent, 51, g_WeaponClip[Id], 4)
	set_pdata_int(Ent, 54, 1, 4)
	
	Set_Weapon_Anim(Id, WEAPONANIM_RELOAD)
	set_pdata_float(Id, 83, WEAPONTIME_RELOAD, 5)
}

public fw_Item_AddToPlayer_Post(Ent, Id)
{
	if(!pev_valid(Ent))
		return
		
	if(pev(Ent, pev_impulse) == WEAPON_SECRETCODE)
	{
		Set_BitVar(g_Had_Plasma, Id)
		set_pev(Ent, pev_impulse, 0)
		
		set_task(0.01, "AddToPlayer_Delay", Id)
	}		

	message_begin(MSG_ONE_UNRELIABLE, g_Msg_WeaponList, _, Id)
	write_string(Get_BitVar(g_Had_Plasma, Id) ? "weapon_plasmagun" : "weapon_ak47")
	write_byte(2)
	write_byte(Get_BitVar(g_Had_Plasma, Id) ? 200 : 90)
	write_byte(-1)
	write_byte(-1)
	write_byte(0)
	write_byte(1)
	write_byte(Get_BitVar(g_Had_Plasma, Id) ? CSW_PLASMA : CSW_AK47)
	write_byte(0)
	message_end()			
	
	return
}

public AddToPlayer_Delay(Id)
{
	set_pev(Id, pev_viewmodel2, V_MODEL)
	set_pev(Id, pev_weaponmodel2, P_MODEL)
	
	set_pdata_string(Id, (492) * 4, WEAPON_ANIMEXT, -1 , 20)	
}
		
public Create_PlasmaBall(id)
{
	static Float:StartOrigin[3], Float:TargetOrigin[3], Float:MyVelocity[3], Float:VecLength
	
	get_position(id, 48.0, 10.0, -5.0, StartOrigin)
	get_position(id, 1024.0, 0.0, 0.0, TargetOrigin)
	
	pev(id, pev_velocity, MyVelocity)
	VecLength = vector_length(MyVelocity)
	
	if(VecLength) 
	{
		TargetOrigin[0] += random_float(-16.0, 16.0); TargetOrigin[1] += random_float(-16.0, 16.0); TargetOrigin[2] += random_float(-16.0, 16.0)
	} else {
		TargetOrigin[0] += random_float(-8.0, 8.0); TargetOrigin[1] += random_float(-8.0, 8.0); TargetOrigin[2] += random_float(-8.0, 8.0)
	}
	
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
	if(!pev_valid(Ent)) return
	
	// Set info for ent
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 10.0)
	set_pev(Ent, pev_iuser1, id) // Better than pev_owner
	set_pev(Ent, pev_iuser2, Get_SpecialTeam(id, cs_get_user_team(id)))
	set_pev(Ent, pev_fuser1, get_gametime() + 3.0)
	set_pev(Ent, pev_scale, random_float(0.1, 0.25))
	set_pev(Ent, pev_nextthink, halflife_time() + 0.1)
	
	entity_set_string(Ent, EV_SZ_classname, PLASMABALL_CLASSNAME)
	engfunc(EngFunc_SetModel, Ent, WeaponFiles[0])
	set_pev(Ent, pev_mins, Float:{-1.0, -1.0, -1.0})
	set_pev(Ent, pev_maxs, Float:{1.0, 1.0, 1.0})
	set_pev(Ent, pev_origin, StartOrigin)
	set_pev(Ent, pev_gravity, 0.01)
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	set_pev(Ent, pev_frame, 0.0)
	
	static Float:Velocity[3]
	get_speed_vector(StartOrigin, TargetOrigin, PLASMA_SPEED, Velocity)
	set_pev(Ent, pev_velocity, Velocity)
}

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 Update_AmmoHud(id, CSWID, Ammo, BpAmmo)
{
	message_begin(MSG_ONE_UNRELIABLE, g_Msg_CurWeapon, _, id)
	write_byte(1)
	write_byte(CSWID)
	write_byte(Ammo)
	message_end()
	
	message_begin(MSG_ONE_UNRELIABLE, g_Msg_AmmoX, _, id)
	write_byte(10)
	write_byte(BpAmmo)
	message_end()
}

public Get_SpecialTeam(Ent, CsTeams:Team)
{
	if(Team == CS_TEAM_T) return TEAM_T
	else if(Team == CS_TEAM_CT) return TEAM_CT
	
	return 0
}

public CsTeams:Get_PlasmaTeam(Ent)
{
	if(pev(Ent, pev_iuser2) == TEAM_T) return CS_TEAM_T
	else if(pev(Ent, pev_iuser2) == TEAM_CT) return CS_TEAM_CT
	
	return CS_TEAM_UNASSIGNED
}

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

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

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

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

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

Fm_Balrog11 | Afiseaza codul
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>

#define PLUGIN "Balrog-XI"
#define VERSION "1.0"
#define AUTHOR "Dias"

#define V_MODEL "models/v_balrog11_2.mdl"
#define P_MODEL "models/p_balrog11.mdl"
#define W_MODEL "models/w_balrog11.mdl"

#define CSW_BALROG11 CSW_XM1014
#define weapon_balrog11 "weapon_xm1014"

#define OLD_W_MODEL "models/w_xm1014.mdl"
#define OLD_EVENT "events/xm1014.sc"
#define WEAPON_SECRETCODE 1982

#define DRAW_TIME 1.0
#define DAMAGE 35
#define FIRE_DAMAGE 100
#define BPAMMO 200

#define CHARGE_COND_AMMO 4
#define MAX_SPECIAL_AMMO 11
#define SPECIALSHOOT_DELAY 0.20
#define FIRE_SPEED 750
#define FIRE_CLASSNAME "balrog11_fire"
#define SYSTEM_CLASSNAME "balrog11_firesystem"

// OFFSET
const PDATA_SAFE = 2
const OFFSET_LINUX_WEAPONS = 4
const OFFSET_WEAPONOWNER = 41
const m_flNextAttack = 83
const m_flNextPrimaryAttack	= 46
const m_flNextSecondaryAttack	= 47

// Weapon bitsums
const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
	
new const WeaponSounds[5][] = 
{
	"weapons/balrog11-1.wav",
	"weapons/balrog11-2.wav",
	"weapons/balrog11_draw.wav",
	"weapons/balrog11_insert.wav",
	"weapons/balrog11_charge.wav"
}

new const WeaponResources[4][] =
{
	"sprites/flame_puff01.spr",
	"sprites/weapon_balrog11.txt",
	"sprites/640hud3_2.spr",
	"sprites/640hud89_2.spr"
}

enum
{
	B11_ANIM_IDLE = 0,
	B11_ANIM_SHOOT,
	B11_ANIM_SHOOT_SPECIAL,
	B11_ANIM_INSERT,
	B11_ANIM_AFTER_RELOAD,
	B11_ANIM_START_RELOAD,
	B11_ANIM_DRAW
}

new g_had_balrog11[33], g_holding_attack[33], g_Shoot_Count[33], g_SpecialAmmo[33]
new g_old_weapon[33], g_event_balrog11, g_Msg_StatusIcon, g_smokepuff_id, g_ham_bot

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	register_forward(FM_Think, "fw_Think")
	register_forward(FM_Touch, "fw_Touch")
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_SetModel, "fw_SetModel")
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack")	
	
	RegisterHam(Ham_Item_AddToPlayer, weapon_balrog11, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_balrog11, "fw_Item_PostFrame")
	RegisterHam(Ham_Item_Deploy, weapon_balrog11, "fw_Item_Deploy_Post", 1)
	
	g_Msg_StatusIcon = get_user_msgid("StatusIcon")
	
	register_clcmd("admin_get_balrog11", "Get_Balrog11", ADMIN_BAN)
	register_clcmd("weapon_balrog11", "hook_weapon")
}

public plugin_precache()
{
	engfunc(EngFunc_PrecacheModel, V_MODEL)
	engfunc(EngFunc_PrecacheModel, P_MODEL)
	engfunc(EngFunc_PrecacheModel, W_MODEL)
	
	new i
	for(i = 0; i < sizeof(WeaponSounds); i++)
		engfunc(EngFunc_PrecacheSound, WeaponSounds[i])
	for(i = 0; i < sizeof(WeaponResources); i++)
	{
		if(i == 1) engfunc(EngFunc_PrecacheGeneric, WeaponResources[i])
		else engfunc(EngFunc_PrecacheModel, WeaponResources[i])
	}
	
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)	
	g_smokepuff_id = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
}

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

public plugin_natives ()
{
	register_native("give_weapon_balrog11", "native_give_weapon_add", 1)
}
public native_give_weapon_add(id)
{
	Get_Balrog11(id)
}

public do_register(id)
{
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
}

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

public Get_Balrog11(id)
{
	if(!is_user_alive(id))
		return
		
	drop_weapons(id, 1)
	Remove_Balrog11(id)
		
	g_had_balrog11[id] = 1
	g_old_weapon[id] = 0
	g_holding_attack[id] = 0
	g_Shoot_Count[id] = 0
	g_SpecialAmmo[id] = 0
	
	fm_give_item(id, weapon_balrog11)
	cs_set_user_bpammo(id, CSW_BALROG11, BPAMMO)
	
	update_ammo(id)
	update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
}

public Remove_Balrog11(id)
{
	if(!is_user_connected(id))
		return
		
	update_specialammo(id, g_SpecialAmmo[id], 0)
		
	g_had_balrog11[id] = 0
	g_old_weapon[id] = 0
	g_holding_attack[id] = 0
	g_Shoot_Count[id] = 0
	g_SpecialAmmo[id] = 0	
}

public hook_weapon(id)
{
	engclient_cmd(id, weapon_balrog11)
	return PLUGIN_HANDLED
}

public Event_CurWeapon(id)
{
	if(!is_user_alive(id))
		return	
	
	if(g_had_balrog11[id] && (get_user_weapon(id) == CSW_BALROG11 && g_old_weapon[id] != CSW_BALROG11))
	{ // Balrog Draw
		set_weapon_anim(id, B11_ANIM_DRAW)
		set_player_nextattack(id, DRAW_TIME)
		
		update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
	} else if(get_user_weapon(id) != CSW_BALROG11 && g_old_weapon[id] == CSW_BALROG11) {
		update_specialammo(id, g_SpecialAmmo[id], 0)
	}
	
	g_old_weapon[id] = get_user_weapon(id)
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_user_alive(id))
		return
	if(get_user_weapon(id) != CSW_BALROG11 || !g_had_balrog11[id])
		return
		
	static NewButton; NewButton = get_uc(uc_handle, UC_Buttons)
	static OldButton; OldButton = pev(id, pev_oldbuttons)
	
	if(NewButton & IN_ATTACK)
	{
		if(!g_holding_attack[id]) g_holding_attack[id] = 1
	} else if(NewButton & IN_ATTACK2) {
		SpecialShoot_Handle(id)
	} else {
		if(OldButton & IN_ATTACK)
		{
			if(g_holding_attack[id]) 
			{
				g_holding_attack[id] = 0
				g_Shoot_Count[id] = 0
			}
		}
	}
}

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

	return FMRES_IGNORED;
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_user_alive(id) || !is_user_connected(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_BALROG11 && g_had_balrog11[id])
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_user_connected(invoker))
		return FMRES_IGNORED		
	if(get_user_weapon(invoker) == CSW_BALROG11 && g_had_balrog11[invoker] && eventid == g_event_balrog11)
	{
		engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)	

		if(g_holding_attack[invoker]) g_Shoot_Count[invoker]++
		else g_Shoot_Count[invoker] = 0
		
		if(g_Shoot_Count[invoker] >= CHARGE_COND_AMMO)
		{
			g_Shoot_Count[invoker] = 0
			
			if(g_SpecialAmmo[invoker] < MAX_SPECIAL_AMMO) 
			{
				update_specialammo(invoker, g_SpecialAmmo[invoker], 0)
				g_SpecialAmmo[invoker]++
				update_specialammo(invoker, g_SpecialAmmo[invoker], 1)
				
				emit_sound(invoker, CHAN_ITEM, WeaponSounds[4], 1.0, ATTN_NORM, 0, PITCH_NORM)
			}
		}
		
		set_weapon_anim(invoker, B11_ANIM_SHOOT)
		emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], 1.0, ATTN_NORM, 0, PITCH_NORM)	

		return FMRES_SUPERCEDE
	}
	
	return FMRES_HANDLED
}

public fw_Think(ent)
{
	if(!pev_valid(ent))
		return
		
	static Classname[32]; pev(ent, pev_classname, Classname, sizeof(Classname))
	if(equal(Classname, FIRE_CLASSNAME))
	{	
		static Float:fFrame; pev(ent, pev_frame, fFrame)
	
		fFrame += 1.5
		fFrame = floatmin(21.0, fFrame)
	
		set_pev(ent, pev_frame, fFrame)
		set_pev(ent, pev_nextthink, get_gametime() + 0.05)
		
		// time remove
		static Float:fTimeRemove, Float:Amount
		pev(ent, pev_fuser1, fTimeRemove)
		pev(ent, pev_renderamt, Amount)
		
		if(get_gametime() >= fTimeRemove) 
		{
			Amount -= 10.0
			set_pev(ent, pev_renderamt, Amount)
			
			if(Amount <= 15.0) engfunc(EngFunc_RemoveEntity, ent)
		}
	} else if(equal(Classname, SYSTEM_CLASSNAME)) {
		
		static Float:Origin[3], Float:Scale
		
		pev(ent, pev_origin, Origin)
		pev(ent, pev_scale, Scale)
		
		Scale += 0.1 
		Scale = floatmin(1.5, Scale)
		set_pev(ent, pev_scale, Scale)

		Create_Fire(pev(ent, pev_owner), Origin, Scale, 0.0)
		
		set_pev(ent, pev_nextthink, get_gametime() + 0.05)
		
		// time remove
		static Float:fTimeRemove
		pev(ent, pev_fuser1, fTimeRemove)
		if(get_gametime() >= fTimeRemove) engfunc(EngFunc_RemoveEntity, ent)
	}
}

public fw_Touch(ent, id)
{
	if(!pev_valid(ent))
		return
		
	static Classname[32]
	pev(ent, pev_classname, Classname, sizeof(Classname))
		
	if(!equal(Classname, SYSTEM_CLASSNAME))
		return
		
	if(pev_valid(id))
	{
		static Classname2[32]
		pev(id, pev_classname, Classname2, sizeof(Classname2))
		
		if(equal(Classname2, SYSTEM_CLASSNAME) || equal(Classname2, FIRE_CLASSNAME)) return
		else if(is_user_alive(id))
		{
			if(pev(ent, pev_iuser3) == 1 && cs_get_user_team(id) != CS_TEAM_T) ExecuteHamB(Ham_TakeDamage, id, 0, pev(ent, pev_owner), float(FIRE_DAMAGE) / random_float(3.0, 5.0), DMG_BULLET)
			else if(pev(ent, pev_iuser3) == 2 && cs_get_user_team(id) != CS_TEAM_CT) ExecuteHamB(Ham_TakeDamage, id, 0, pev(ent, pev_owner), float(FIRE_DAMAGE) / random_float(3.0, 5.0), DMG_BULLET)
			
			return
		}
	}
		
	set_pev(ent, pev_movetype, MOVETYPE_NONE)
	set_pev(ent, pev_solid, SOLID_NOT)
}

public fw_TraceAttack(Ent, Attacker, Float:Damage, Float:Dir[3], pentru, DamageType)
{
	if(!is_user_alive(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_BALROG11 || !g_had_balrog11[Attacker])
		return HAM_IGNORED
		
	static Float:flEnd[3], Float:vecPlane[3]
	
	get_tr2(pentru, TR_vecEndPos, flEnd)
	get_tr2(pentru, TR_vecPlaneNormal, vecPlane)		
		
	if(!is_user_alive(Ent))
	{
		make_bullet(Attacker, flEnd)
		fake_smoke(Attacker, pentru)
	}
		
	SetHamParamFloat(3, float(DAMAGE) / random_float(1.5, 2.5))	

	return HAM_HANDLED	
}

public fw_Item_AddToPlayer_Post(ent, id)
{
	if(pev(ent, pev_impulse) == WEAPON_SECRETCODE)
	{
		g_had_balrog11[id] = 1
		
		set_pev(ent, pev_impulse, 0)
		g_SpecialAmmo[id] = pev(ent, pev_iuser4)
	}			
	
	message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("WeaponList"), _, id)
	write_string((g_had_balrog11[id] == 1 ? "weapon_balrog11" : "weapon_xm1014"))
	write_byte(5)
	write_byte(32)
	write_byte(-1)
	write_byte(-1)
	write_byte(0)
	write_byte(12)
	write_byte(CSW_BALROG11)
	write_byte(0)
	message_end()
}

public fw_Item_PostFrame(ent)
{
	static id; id = fm_cs_get_weapon_ent_owner(ent)
	if (!pev_valid(id))
		return

	if(!g_had_balrog11[id])
		return
		
	if(get_pdata_int(ent, 55, OFFSET_LINUX_WEAPONS) == 1) set_weapon_anim(id, B11_ANIM_INSERT)
}

public fw_Item_Deploy_Post(ent)
{
	static id; id = fm_cs_get_weapon_ent_owner(ent)
	if (!pev_valid(id))
		return

	if(!g_had_balrog11[id])
		return
		
	set_pev(id, pev_viewmodel2, V_MODEL)
	set_pev(id, pev_weaponmodel2, P_MODEL)
}

public update_ammo(id)
{
	if(!is_user_alive(id))
		return
	
	static weapon_ent; weapon_ent = fm_get_user_weapon_entity(id, CSW_BALROG11)
	if(!pev_valid(weapon_ent)) return
	
	engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, get_user_msgid("CurWeapon"), {0, 0, 0}, id)
	write_byte(1)
	write_byte(CSW_BALROG11)
	write_byte(cs_get_weapon_ammo(weapon_ent))
	message_end()
	
	message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("AmmoX"), _, id)
	write_byte(1)
	write_byte(cs_get_user_bpammo(id, CSW_BALROG11))
	message_end()
}

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

public SpecialShoot_Handle(id)
{
	if(get_pdata_float(id, 83, 5) > 0.0)
		return
	if(g_SpecialAmmo[id] <= 0)
		return		

	create_fake_attack(id)	
	
	// Shoot Handle
	set_player_nextattack(id, SPECIALSHOOT_DELAY)
	set_weapons_timeidle(id, CSW_BALROG11, SPECIALSHOOT_DELAY)
	
	update_specialammo(id, g_SpecialAmmo[id], 0)
	g_SpecialAmmo[id]--
	update_specialammo(id, g_SpecialAmmo[id], g_SpecialAmmo[id] > 0 ? 1 : 0)
	
	set_weapon_anim(id, B11_ANIM_SHOOT_SPECIAL)
	emit_sound(id, CHAN_WEAPON, WeaponSounds[1], 1.0, ATTN_NORM, 0, PITCH_NORM)
	
	Create_FireSystem(id)
}

public create_fake_attack(id)
{
	static weapon
	weapon = fm_find_ent_by_owner(-1, "weapon_knife", id)
	
	if(pev_valid(weapon)) ExecuteHamB(Ham_Weapon_PrimaryAttack, weapon)
}

public Create_FireSystem(id)
{
	static Float:StartOrigin[3], Float:EndOrigin[5][3]
	get_weapon_attachment(id, StartOrigin, 40.0)
	
	// Left
	get_position(id, 512.0, -140.0, 0.0, EndOrigin[0])
	get_position(id, 512.0, -70.0, 0.0, EndOrigin[1])
	
	// Center
	get_position(id, 512.0, 0.0, 0.0, EndOrigin[2])
	
	// Right
	get_position(id, 512.0, 70.0, 0.0, EndOrigin[3])
	get_position(id, 512.0, 140.0, 0.0, EndOrigin[4])	
	
	// Create Fire
	for(new i = 0; i < 5; i++) Create_System(id, StartOrigin, EndOrigin[i], float(FIRE_SPEED))
}

public Create_System(id, Float:StartOrigin[3], Float:EndOrigin[3], Float:Speed)
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
	
	// set info for ent
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 0.0)
	set_pev(Ent, pev_fuser1, get_gametime() + 0.75)	// time remove
	set_pev(Ent, pev_scale, 0.1)
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
	
	set_pev(Ent, pev_classname, SYSTEM_CLASSNAME)
	engfunc(EngFunc_SetModel, Ent, WeaponResources[0])
	set_pev(Ent, pev_mins, Float:{-16.0, -16.0, -16.0})
	set_pev(Ent, pev_maxs, Float:{16.0, 16.0, 16.0})
	set_pev(Ent, pev_origin, StartOrigin)
	set_pev(Ent, pev_gravity, 0.01)
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	set_pev(Ent, pev_owner, id)	
	static Team; 
	if(cs_get_user_team(id) == CS_TEAM_T) Team = 1
	else if(cs_get_user_team(id) == CS_TEAM_CT) Team = 2
	set_pev(Ent, pev_iuser3, Team)
	set_pev(Ent, pev_frame, 0.0)

	static Float:Velocity[3]
	
	get_speed_vector(StartOrigin, EndOrigin, Speed, Velocity)
	set_pev(Ent, pev_velocity, Velocity)		
}

public Create_Fire(id, Float:Origin[3], Float:Scale, Float:Frame)
{
	static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "env_sprite"))
	
	// set info for ent
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	set_pev(Ent, pev_rendermode, kRenderTransAdd)
	set_pev(Ent, pev_renderamt, 255.0)
	set_pev(Ent, pev_fuser1, get_gametime() + 0.1)	// time remove
	set_pev(Ent, pev_scale, Scale)
	set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
	
	set_pev(Ent, pev_classname, FIRE_CLASSNAME)
	engfunc(EngFunc_SetModel, Ent, WeaponResources[0])
	set_pev(Ent, pev_mins, Float:{-10.0, -10.0, -10.0})
	set_pev(Ent, pev_maxs, Float:{10.0, 10.0, 10.0})
	set_pev(Ent, pev_origin, Origin)
	set_pev(Ent, pev_gravity, 0.01)
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	set_pev(Ent, pev_owner, id)	
	set_pev(Ent, pev_frame, Frame)
}

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

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

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

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

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

stock fm_cs_get_weapon_ent_owner(ent)
{
	if (pev_valid(ent) != PDATA_SAFE)
		return -1
	
	return get_pdata_cbase(ent, OFFSET_WEAPONOWNER, OFFSET_LINUX_WEAPONS)
}

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

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, OFFSET_LINUX_WEAPONS)
	set_pdata_float(entwpn, 47, TimeIdle, OFFSET_LINUX_WEAPONS)
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, OFFSET_LINUX_WEAPONS)
}

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

stock get_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;
}

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

			// Player drops the weapon and looses his bpammo
			engclient_cmd(id, "drop", wname)
			cs_set_user_bpammo(id, weaponid, 0)
		}
	}
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/
User avatar
WHOAMI?
Super moderator
Super moderator
Posts: 903
Joined: 17 Dec 2013, 19:51
Detinator Steam: Da
Reputatie: Super Moderator
Fost Membru Club eXtreamCS (o luna)
Location: RO
Has thanked: 13 times
Been thanked: 9 times

26 Feb 2014, 20:24

frate am bagat sv se incarca la intrare modele si altele dar cand intru ep sv numi apara meniul am pus si pluginul de credite ala alui askadar sau sa scrie /weapons numi apare ma poti ajuta
User avatar
roberteeel
Membru eXtream
Membru eXtream
Posts: 4440
Joined: 05 Sep 2012, 10:39
Detinator Steam: Nu
Reputatie: Nick anterior: QAZW, Robert.ultrasFarul, CT 18 ROS
Restrictie schimbare nume
Fost moderator
Fost Membru Club eXtreamCS (doua luni)
Has thanked: 312 times
Been thanked: 357 times

27 Feb 2014, 09:34

Eu mi-am rezolvat problema, am sters register_clcmd admin_get_gatling din fiecare sursa.
User avatar
DaNNe.
Fost moderator
Fost moderator
Posts: 2808
Joined: 08 Nov 2013, 20:43
Detinator Steam: Da
CS Status: Activitate scăzută
SteamID: /id/FurienMaster
Reputatie: Nick anterior: DnD. Gold, Emrys
0.5/3
Fost moderator ajutator
Fost Membru Club eXtreamCS (doua luni)
Has thanked: 230 times
Been thanked: 128 times
Contact:

27 Feb 2014, 18:24

QAZW wrote:Eu mi-am rezolvat problema, am sters register_clcmd admin_get_gatling din fiecare sursa.
Exact asa trebuia rezolvat... am uitat de astea...
Contact: Activitate scazuta.
User avatar
LOLpgl
Membru, skill +3
Membru, skill +3
Posts: 1123
Joined: 16 Dec 2013, 21:01
Detinator Steam: Da
SteamID: ionutcruso
Location: Rm.Valcea
Has thanked: 19 times
Been thanked: 15 times

25 Mar 2014, 16:19

Te iubesc(NU,nu sunt kay)Cel mai misto plugin!
User avatar
n0talaMa.
Membru, skill 0
Membru, skill 0
Posts: 99
Joined: 06 Oct 2013, 16:47
Detinator Steam: Da
Detinator server CS: Nu
SteamID: boss1234538
Has thanked: 8 times
Been thanked: 5 times
Contact:

09 Apr 2014, 08:55

Frumos din partea ta :)
Mar1usica
Membru, skill 0
Membru, skill 0
Posts: 3
Joined: 07 Apr 2014, 17:36
Detinator Steam: Da
CS Status: htz
Detinator server CS: Da..

20 May 2014, 19:43

Am o problema ... cand pun plugin apar toate frumos in meniu , dar daca vreau sa iau arme hunter pot sa apas de 10000 de ori ca nu se deschide , doar itmele cu credite...
Dr.wHo;x
Membru, skill 0
Membru, skill 0
Posts: 74
Joined: 03 Feb 2014, 13:29
Detinator Steam: Nu
CS Status: Citesc forumul eXtreamCS.com...!
Has thanked: 10 times
Been thanked: 2 times
Contact:

30 May 2014, 14:51

Poti modifica armele de la vip ? Iti dau eu ce arme sa adaugi.. [ janus 7 / cross bow/ speargun si mai am :P ]. Daca poti te rog intra pe mess.
Off Shoot
Membru, skill 0
Membru, skill 0
Posts: 56
Joined: 08 Jul 2014, 11:26
Detinator Steam: Nu
CS Status: Citesc forumul eXtreamCS.com...!
Fond eXtream: 0
Has thanked: 3 times
Contact:

11 Jul 2014, 19:31

La mine nu merge pluginu , il bag si apare cel normal de la server cu armele normale...
User avatar
mR#ZOOMBI**
Utilizator neserios (tepar)
Utilizator neserios (tepar)
Posts: 636
Joined: 06 Jul 2014, 12:12
Detinator Steam: Da
CS Status: Frec MENTA>
SteamID: Privat.
Reputatie: Utilizator neserios ( tepar )
Fond eXtream: 0
Location: Lugoj
Has thanked: 7 times
Been thanked: 1 time
Contact:

16 Aug 2014, 18:07

Nu imi merge la compliere, imi zice /tmp/textUowyQA.sma(9) : fatal error 100: cannot read from file: "CC_ColorChat" daca puteti sa ma ajutati .
Post Reply

Return to “AmxModX”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests