Raised This Month: $12 Target: $400
 3% 

Solved How to Add Double Shot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hellmonja
Senior Member
Join Date: Oct 2015
Old 10-21-2015 , 21:04   How to Add Double Shot
Reply With Quote #1

I want to give a double shot function to a shotgun I added when I right-click. But I don't really have any idea how to. I've read this thread:

https://forums.alliedmods.net/showthread.php?t=269892

but I really can't understand anything. The guys there have far greater scripting knowledge than I have.

I confess I don't have in-depth AMX know-how but please help me, or at least give some insight or examples of code, or an existing weapon that uses a double shot function that I can study.

I had 2 threads here asking for help that no one even replied to but i hope you guys could pull through for me on this one. Thanks in advance...

Last edited by hellmonja; 06-25-2017 at 04:26. Reason: Solved...
hellmonja is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-25-2015 , 07:43   Re: [HELP] How to Add Double Shot
Reply With Quote #2

Do you just want double damage, or do you want the gun to fire twice with one right-click?
__________________
Bugsy is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 10-25-2015 , 10:25   Re: [HELP] How to Add Double Shot
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
Do you just want double damage, or do you want the gun to fire twice with one right-click?
well, it is a shotgun and you would notice how much buckshot would hit the wall. so firing twice, although i imagine would be tougher, would look cooler so that would be my choice...
hellmonja is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 10-25-2015 , 13:39   Re: [HELP] How to Add Double Shot
Reply With Quote #4

i would suggest you to take weapon balance mod, and look inside it, but i doubt you will understand anything from it...
Depresie is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 10-26-2015 , 05:12   Re: [HELP] How to Add Double Shot
Reply With Quote #5

How about hooking +attack .. checking if its shotgun and force fire +attack;wait;+attack ?
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !

#RespectList ANTICHRISTUS fysiks Bugsy

Most Common Errors You Can Encounter Every Now and Then
devilicioux is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 10-29-2015 , 12:00   Re: [HELP] How to Add Double Shot
Reply With Quote #6

Hi there! Sorry if I took so long to get back here. Was busy with work and all. And I didn't want to post again after I've actually done something.

OK, so devilicioux's wasn't actually what I was looking for. The two shells need to exit the gun at the same time. Then again, thank you for the suggestion. I did what Depresie suggested and he was right: Weapon Balance was just too complicated for me. But I did notice that Numb actually never did a Double Shot but only multiplied the damage by 2. Bearing that in mind, I tried my noobish attempt to make one, and here it is. Will post what I did for others like me.

So what did I do? Basically I started in "CmdStart" and forced the player to shoot when the RMB (right mouse button) is clicked. Then I check if the shotgun has 2 or more shells. If there's only 1, it fires normally. If 2 or more are in while RMB is clicked, then several things happen:
  • "DblShot" is set to true.
  • If DblShot is true, clip is reduced by 2.
  • Damage is multiplied by 150% (I did 200% first but it was way OP. It could pick someone from afar.)
  • Recoil is substituted to a bigger value.
  • A new, louder firing sound is emitted.
  • If LMB is clicked, DblShot is then set to false.
  • Also when there's only 1 shell and RMB is clicked, DblShot is set to false.


That's it. Here's the whole code. I don't really have that deep of an understanding of Pawn so you might see some "unoptimized" stuff here and there. Anyway, thanks for helping.

Code:
#include <amxmodx>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <cstrike>
#include <fun>

#define PLUGIN "Sawed-off Double Barrel Shotgun"
#define VERSION "1.0"
#define AUTHOR "Sneaky.amxx, MeRcyLeZZ, Arkshine"

#define V_MODEL "models/v_sawedoff.mdl"
#define P_MODEL "models/p_sawedoff.mdl"
#define W_MODEL "models/w_sawedoff.mdl"

#define CSW_SAWEDOFF CSW_M3
#define weapon_sawedoff "weapon_m3"

#define DAMAGE 30
#define CLIP 2
#define BPAMMO 32
#define RATEOFIRE 0.5
#define RECOIL 1.7
#define DBLRECOIL 2.5
#define RELOAD_TIME 1.75
#define TEAM 1		// 1-T, 2-CT, 0-Both
#define WALKSPEED 5
#define PRICE 2100

#define SHOOT_ANIM random_num(1, 2)
#define DRAW_ANIM 6
#define RELOAD_ANIM 7

#define BODY_NUM 0

#define WEAPON_SECRETCODE 852345
#define WEAPON_EVENT "events/m3.sc"
#define OLD_W_MODEL "models/w_m3.mdl"

#define FIRE_SOUND "weapons/sawedoff-1.wav"
#define DOUBLESHOT "weapons/sawedoff-2.wav"

new MsgIndexWeaponList, g_allowedteam, DblShot[33]
new g_Had_Weapon, g_Old_Weapon[33], Float:g_Recoil[33][3], g_Clip[33]
new g_weapon_event, g_ShellId, g_SmokePuff_SprId
new g_HamBot, g_Msg_CurWeapon, g_msgMoney, g_msgBlinkAcct
const PLAYER_IN_BUYZONE = (1<<0)
const OFFSET_CSMONEY = 115
const OFFSET_MAPZONE = 235
const OFFSET_CSTEAMS = 114

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

public plugin_init()
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
	
	register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	register_forward(FM_SetModel, "fw_SetModel")	
	register_forward(FM_CmdStart, "fw_CmdStart")
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_sawedoff, "fw_Weapon_PrimaryAttack")
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_sawedoff, "fw_Weapon_PrimaryAttack_Post", 1)
	RegisterHam(Ham_Item_AddToPlayer, weapon_sawedoff, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Weapon_Reload, weapon_sawedoff, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_sawedoff, "fw_Weapon_Reload_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_sawedoff, "fw_Item_PostFrame")		
	
	MsgIndexWeaponList = get_user_msgid("WeaponList");  
	g_Msg_CurWeapon = get_user_msgid("CurWeapon")
	g_msgMoney = get_user_msgid("Money")
	g_msgBlinkAcct = get_user_msgid("BlinkAcct")
	register_clcmd("weapon_sawedoff", "ClientCommand_SelectWeapon"); 
	register_concmd("sawedoff", "Get_Weapon")
	register_clcmd("say /sawedoff", "Get_Weapon")
}

public plugin_precache()
{
	precache_generic("sprites/weapon_sawedoff.txt");
	precache_generic("sprites/640hudap01.spr");
	precache_generic("sprites/640hudap01_s.spr");
	precache_generic("sprites/ap-rounds01.spr");
	
	engfunc(EngFunc_PrecacheModel, V_MODEL)
	engfunc(EngFunc_PrecacheModel, P_MODEL)
	engfunc(EngFunc_PrecacheModel, W_MODEL)
	engfunc(EngFunc_PrecacheSound, FIRE_SOUND)
	engfunc(EngFunc_PrecacheSound, DOUBLESHOT)
	
	g_SmokePuff_SprId = engfunc(EngFunc_PrecacheModel, "sprites/wall_puff1.spr")
	g_ShellId = engfunc(EngFunc_PrecacheModel, "models/rshell.mdl")	
	
	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 Do_RegisterHam(id)
{
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")	
}

public Get_Weapon(id)
{
	if(!is_user_alive(id)) return
	if (!fm_get_user_buyzone(id)) return

	// Check if the player is on a restricted team
	g_allowedteam = TEAM
	if (g_allowedteam > 0 && g_allowedteam != fm_get_user_team(id))
	{
		return
	}
	
	// Check that player has the money
	if (fm_get_user_money(id) < PRICE)
	{
		client_print(id, print_center, "#Cstrike_TitlesTXT_Not_Enough_Money")
		
		// Blink money
		message_begin(MSG_ONE_UNRELIABLE, g_msgBlinkAcct, _, id)
		write_byte(2) // times
		message_end()
		return
	}
	
	// Player tries to buy the same gun
	if(get_user_weapon(id) == CSW_SAWEDOFF)
	{
		client_print(id, print_center, "#Cstrike_Already_Own_Weapon")
		return
	}

	// Drop Other Weapons on Purchase
	if(get_user_weapon(id) != CSW_SAWEDOFF)
	{
		if (user_has_weapon(id, CSW_XM1014)) client_cmd(id, "drop weapon_xm1014"); else
		if (user_has_weapon(id, CSW_TMP)) client_cmd(id, "drop weapon_tmp"); else
		if (user_has_weapon(id, CSW_MAC10)) client_cmd(id, "drop weapon_mac10"); else
		if (user_has_weapon(id, CSW_MP5NAVY)) client_cmd(id, "drop weapon_mp5navy"); else
		if (user_has_weapon(id, CSW_UMP45)) client_cmd(id, "drop weapon_ump45"); else
		if (user_has_weapon(id, CSW_P90)) client_cmd(id, "drop weapon_p90"); else
		if (user_has_weapon(id, CSW_GALIL)) client_cmd(id, "drop weapon_galil"); else
		if (user_has_weapon(id, CSW_FAMAS)) client_cmd(id, "drop weapon_famas"); else
		if (user_has_weapon(id, CSW_AK47)) client_cmd(id, "drop weapon_ak47"); else
		if (user_has_weapon(id, CSW_M4A1)) client_cmd(id, "drop weapon_m4a1"); else
		if (user_has_weapon(id, CSW_AUG)) client_cmd(id, "drop weapon_aug"); else
		if (user_has_weapon(id, CSW_SG552)) client_cmd(id, "drop weapon_sg552"); else
		if (user_has_weapon(id, CSW_SCOUT)) client_cmd(id, "drop weapon_scout"); else
		if (user_has_weapon(id, CSW_AWP)) client_cmd(id, "drop weapon_awp"); else
		if (user_has_weapon(id, CSW_SG550)) client_cmd(id, "drop weapon_sg550"); else
		if (user_has_weapon(id, CSW_G3SG1)) client_cmd(id, "drop weapon_g3sg1"); else
		if (user_has_weapon(id, CSW_M249)) client_cmd(id, "drop weapon_m249");
		client_cmd(id, "drop weapon_shield");
	}

	Set_BitVar(g_Had_Weapon, id)
	fm_give_item(id, weapon_sawedoff)	
	
	// Set Ammo
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_SAWEDOFF)
	if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, CLIP)
	
	engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, g_Msg_CurWeapon, {0, 0, 0}, id)
	write_byte(1)
	write_byte(CSW_SAWEDOFF)
	write_byte(CLIP)
	message_end()
	
	// Calculate new money amount
	static newmoney
	newmoney = fm_get_user_money(id) - PRICE
	
	// Update money offset
	fm_set_user_money(id, newmoney)
	
	// Update money on HUD
	message_begin(MSG_ONE, g_msgMoney, _, id)
	write_long(newmoney) // amount
	write_byte(1) // flash
	message_end()


}

public Remove_Weapon(id)
{
	UnSet_BitVar(g_Had_Weapon, id)
}

public ClientCommand_SelectWeapon(id)  
{  
	engclient_cmd(id, weapon_sawedoff);
	return PLUGIN_HANDLED
} 

public Event_CurWeapon(id)
{
	if(!is_user_alive(id))
		return
		
	static CSWID; CSWID = read_data(2)
	
	if((CSWID == CSW_SAWEDOFF && g_Old_Weapon[id] != CSW_SAWEDOFF) && Get_BitVar(g_Had_Weapon, id))
	{
		set_pev(id, pev_viewmodel2, V_MODEL)
		set_pev(id, pev_weaponmodel2, "")
		
		set_weapon_anim(id, DRAW_ANIM)
		Draw_NewWeapon(id, CSWID)
		set_user_maxspeed(id, get_user_maxspeed(id)-WALKSPEED);
	} else if((CSWID == CSW_SAWEDOFF && g_Old_Weapon[id] == CSW_SAWEDOFF) && Get_BitVar(g_Had_Weapon, id)) {
		static Ent; Ent = fm_get_user_weapon_entity(id, CSW_SAWEDOFF)
		if(!pev_valid(Ent))
		{
			g_Old_Weapon[id] = get_user_weapon(id)
			return
		}
		
		set_pdata_float(Ent, 46, get_pdata_float(Ent, 46, 4) * RATEOFIRE, 4)
	} else if(CSWID != CSW_SAWEDOFF && g_Old_Weapon[id] == CSW_SAWEDOFF) Draw_NewWeapon(id, CSWID)
	
	g_Old_Weapon[id] = get_user_weapon(id)
}

public Draw_NewWeapon(id, CSW_ID)
{
	if(CSW_ID == CSW_SAWEDOFF)
	{
		static ent
		ent = fm_get_user_weapon_entity(id, CSW_SAWEDOFF)
		
		if(pev_valid(ent) && Get_BitVar(g_Had_Weapon, id))
		{
			set_pev(ent, pev_effects, pev(ent, pev_effects) &~ EF_NODRAW) 
			engfunc(EngFunc_SetModel, ent, P_MODEL)	
			set_pev(ent, pev_body, BODY_NUM)
		}
	} else {
		static ent
		ent = fm_get_user_weapon_entity(id, CSW_SAWEDOFF)
		
		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_user_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_SAWEDOFF && Get_BitVar(g_Had_Weapon, 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_SAWEDOFF || !Get_BitVar(g_Had_Weapon, 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)
	
	set_weapon_anim(invoker, SHOOT_ANIM)
	
	if(DblShot[invoker])
		emit_sound(invoker, CHAN_WEAPON, DOUBLESHOT, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	if(!DblShot[invoker])
		emit_sound(invoker, CHAN_WEAPON, FIRE_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	
	Eject_Shell(invoker, g_ShellId, 0.0)
		
	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, OLD_W_MODEL))
	{
		static weapon; weapon = fm_find_ent_by_owner(-1, weapon_sawedoff, entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED;
		
		if(Get_BitVar(g_Had_Weapon, iOwner))
		{
			Remove_Weapon(iOwner)
			
			set_pev(weapon, pev_impulse, WEAPON_SECRETCODE)
			engfunc(EngFunc_SetModel, entity, W_MODEL)
			set_pev(entity, pev_body, BODY_NUM)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_user_alive(id))
		return
	if(!Get_BitVar(g_Had_Weapon, id) || get_user_weapon(id) != CSW_SAWEDOFF)
		return
		
	static NewButton; NewButton = get_uc(uc_handle, UC_Buttons)
	if(NewButton & IN_ATTACK2) 
	{
		new ammoclip = cs_get_weapon_ammo(get_pdata_cbase(id, 373)/* m_pActiveItem */)
		if(ammoclip >= 2)
		{
			DblShot[id] = true
			client_cmd(id, "+attack;wait;-attack");
		}
		else
		{
			DblShot[id] = false
			client_cmd(id, "+attack;wait;-attack");
		}
	}
}

public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_SAWEDOFF || !Get_BitVar(g_Had_Weapon, 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)

	new dmg
	if(DblShot[Attacker]) 
	{
		dmg = 45
		static Ent; Ent = fm_get_user_weapon_entity(Attacker, CSW_SAWEDOFF)
		if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, 0)
	}
	else dmg = DAMAGE
	
	SetHamParamFloat(3, float(dmg))
	
	return HAM_IGNORED
}

public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_SAWEDOFF || !Get_BitVar(g_Had_Weapon, Attacker))
		return HAM_IGNORED

	new dmg
	if(DblShot[Attacker]) 
	{
		dmg = 45
		static Ent; Ent = fm_get_user_weapon_entity(Attacker, CSW_SAWEDOFF)
		if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, 0)
	}
	else dmg = DAMAGE
	
	SetHamParamFloat(3, float(dmg))

	return HAM_IGNORED
}

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

public fw_Weapon_PrimaryAttack_Post(Ent)
{
	static id; id = pev(Ent, pev_owner)
	
	new Float:r
	if(Get_BitVar(g_Had_Weapon, id))
		{
			if(DblShot[id]) r = DBLRECOIL
			else r = RECOIL
			static Float:Push[3]
			pev(id, pev_punchangle, Push)
			xs_vec_sub(Push, g_Recoil[id], Push)
		
			xs_vec_mul_scalar(Push, r, Push)
			xs_vec_add(Push, g_Recoil[id], Push)
			set_pev(id, pev_punchangle, Push)
		}
}

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

	message_begin( MSG_ONE, MsgIndexWeaponList, .player = id);
	write_string(g_Had_Weapon ? "weapon_sawedoff" : "weapon_m3"); // WeaponName  
	write_byte(5);		// PrimaryAmmoID
	write_byte(BPAMMO);	// PrimaryAmmoMaxAmount  
	write_byte(-1);		// SecondaryAmmoID  
	write_byte(-1);		// SecondaryAmmoMaxAmount  
	write_byte(0);		// SlotID (0...N)  
	write_byte(5);		// NumberInSlot (1...N)  
	write_byte(g_Had_Weapon ? CSW_SAWEDOFF : CSW_M3); // WeaponID  
	write_byte(0);		// Flags  
	message_end();
	
	return HAM_HANDLED	
}

public fw_Item_PostFrame(ent)
{
	if(!pev_valid(ent))
		return HAM_IGNORED
	
	static id
	id = pev(ent, pev_owner)
	
	if(is_user_alive(id) && Get_BitVar(g_Had_Weapon, id))
	{	
		static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
		static bpammo; bpammo = cs_get_user_bpammo(id, CSW_SAWEDOFF)
		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_SAWEDOFF, 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_Weapon, id))
		return HAM_IGNORED
	
	g_Clip[id] = -1
	
	static bpammo; bpammo = cs_get_user_bpammo(id, CSW_SAWEDOFF)
	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_Weapon, id))
		return HAM_IGNORED

	if (g_Clip[id] == -1)
		return HAM_IGNORED
	
	set_pdata_int(ent, 51, g_Clip[id], 4)
	set_pdata_int(ent, 54, 1, 4)
	
	set_weapon_anim(id, RELOAD_ANIM)
	set_pdata_float(id, 83, RELOAD_TIME, 5)

	return HAM_HANDLED
}

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

public 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 hook_ent2(ent, Float:VicOrigin[3], Float:speed, Float:multi, 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
	static Float:fl_Time2; fl_Time2 = distance_f / (speed * multi)
	
	if(type == 1)
	{
		fl_Velocity[0] = ((VicOrigin[0] - EntOrigin[0]) / fl_Time2) * 1.5
		fl_Velocity[1] = ((VicOrigin[1] - EntOrigin[1]) / fl_Time2) * 1.5
		fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time		
	} else if(type == 2) {
		fl_Velocity[0] = ((EntOrigin[0] - VicOrigin[0]) / fl_Time2) * 1.5
		fl_Velocity[1] = ((EntOrigin[1] - VicOrigin[1]) / fl_Time2) * 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 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 Eject_Shell(id, Shell_ModelIndex, Float:Time) // By Dias
{
	static Ent; Ent = get_pdata_cbase(id, 373, 5)
	if(!pev_valid(Ent))
		return

        set_pdata_int(Ent, 57, Shell_ModelIndex, 4)
        set_pdata_float(id, 111, get_gametime() + Time)
}

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, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

// Get User Money
stock fm_get_user_money(id)
{
	return get_pdata_int(id, OFFSET_CSMONEY);
}

// Set User Money
stock fm_set_user_money(id, amount)
{
	set_pdata_int(id, OFFSET_CSMONEY, amount);
}

// Returns whether user is in a buyzone
stock fm_get_user_buyzone(id)
{
	if (get_pdata_int(id, OFFSET_MAPZONE) & PLAYER_IN_BUYZONE)
		return 1;
	
	return 0;
}

// Get User Team
stock fm_get_user_team(id)
{
	return get_pdata_int(id, OFFSET_CSTEAMS);
}

Last edited by hellmonja; 10-29-2015 at 12:04. Reason: typos
hellmonja is offline
devilicioux
Veteran Member
Join Date: Jun 2013
Location: Delhi,India
Old 10-30-2015 , 00:26   Re: [HELP] How to Add Double Shot
Reply With Quote #7

Firstly .. Really G(0.o)d J0b with the plugin

Haven't run it yet .. but a top level observation..

IIRC This way is too unreliable and players can easily bypass it by setting alias for dropping weapons.. rather you can use engclient_cmd which is more reliable in this case..
I feel this is too inefficient..

PHP Code:
// Drop Other Weapons on Purchase
    
if(get_user_weapon(id) != CSW_SAWEDOFF)
    {
        if (
user_has_weapon(idCSW_XM1014)) client_cmd(id"drop weapon_xm1014"); else
        if (
user_has_weapon(idCSW_TMP)) client_cmd(id"drop weapon_tmp"); else
        if (
user_has_weapon(idCSW_MAC10)) client_cmd(id"drop weapon_mac10"); else
        if (
user_has_weapon(idCSW_MP5NAVY)) client_cmd(id"drop weapon_mp5navy"); else
        if (
user_has_weapon(idCSW_UMP45)) client_cmd(id"drop weapon_ump45"); else
        if (
user_has_weapon(idCSW_P90)) client_cmd(id"drop weapon_p90"); else
        if (
user_has_weapon(idCSW_GALIL)) client_cmd(id"drop weapon_galil"); else
        if (
user_has_weapon(idCSW_FAMAS)) client_cmd(id"drop weapon_famas"); else
        if (
user_has_weapon(idCSW_AK47)) client_cmd(id"drop weapon_ak47"); else
        if (
user_has_weapon(idCSW_M4A1)) client_cmd(id"drop weapon_m4a1"); else
        if (
user_has_weapon(idCSW_AUG)) client_cmd(id"drop weapon_aug"); else
        if (
user_has_weapon(idCSW_SG552)) client_cmd(id"drop weapon_sg552"); else
        if (
user_has_weapon(idCSW_SCOUT)) client_cmd(id"drop weapon_scout"); else
        if (
user_has_weapon(idCSW_AWP)) client_cmd(id"drop weapon_awp"); else
        if (
user_has_weapon(idCSW_SG550)) client_cmd(id"drop weapon_sg550"); else
        if (
user_has_weapon(idCSW_G3SG1)) client_cmd(id"drop weapon_g3sg1"); else
        if (
user_has_weapon(idCSW_M249)) client_cmd(id"drop weapon_m249");
        
client_cmd(id"drop weapon_shield");
    } 
why not rather just strip all weapons in one go ?
PHP Code:
strip_user_weapons(id
Or if you still just want to force them drop other weapons
PHP Code:
stock drop_user_weapon(id){
    new 
szWeaponName[32], iWeapon get_user_weapon(id)
    
get_weaponname(iWeaponszWeaponName31)
    
engclient_cmd(id"drop"szWeaponName)

Update #1

Also i feel you will require more "wait"s in such commands

PHP Code:
client_cmd(id"+attack;wait;-attack"); 
to
PHP Code:
client_cmd(id"+attack;wait;wait;wait;-attack"); 
__________________
You keep bringing ANTICHRISTUS down .. He will rise again and kick asses !

#RespectList ANTICHRISTUS fysiks Bugsy

Most Common Errors You Can Encounter Every Now and Then

Last edited by devilicioux; 10-30-2015 at 00:38. Reason: added info
devilicioux is offline
hellmonja
Senior Member
Join Date: Oct 2015
Old 11-03-2015 , 16:04   Re: [HELP] How to Add Double Shot
Reply With Quote #8

sorry it took so long to get back here again. still with work now that Christmas is coming. Anyways...

Quote:
Firstly .. Really G(0.o)d J0b with the plugin
I hope meant how I mashed my DoubleShot code into the plugin, because this is actually Sneaky.amxx's plugin that he uploaded in Gamebanana. I just keep re-editing it to make more weapons. That's why I didn't put my name as "author."

Quote:
I feel this is too inefficient..
I knew that part of the code somehow had problems! I could feel it. Will try what you suggested but will your methods drop my other gear as well? All I need is to drop the primary weapon on purchase (shield included and it's base weapon, which is the M3, that I'm finding hard to get around to).

Quote:
Also i feel you will require more "wait"s in such commands
You might be surprised to know that the Double Shot works perfectly. Actually it, the Sawed-off I added is now my favorite shotgun so I've been using the Double Shot quite often and works great. I'm using the CSO Sawed-off Double Barrel Shotgun which is, by now, in every Zombie mod pack for 1.6, if you wanna try out the plugin.

Thanks for the help, devilicioux...
hellmonja is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode