Sign in to follow this  
Followers 0
ostaninsema

Ham_Weapon_PrimaryAttack

3 posts in this topic

помогите с оружием, при зажатии пкп работает как скорострелка (работает как автомат)

#include <amxmodx>
#include <cstrike>
#include <fakemeta_util>
#include <hamsandwich>

#define anim_shoot1 1
#define anim_shoot2 2
#define anim_reload 4
#define anim_draw 5

#define time_draw 1.0
#define time_reload 2.0

#define weapon_name "weapon_fiveseven"
#define weapon_new_name "weapon_406_infinitysr"

#define WEAPONKEY 4062

#define weapon_clip 15
#define weapon_ammo 100
#define weapon_damage 1.95

#define customitem(%0) (pev(%0, pev_impulse)==WEAPONKEY)
new const g_trace_attack[][] = {"func_breakable", "hostage_entity", "player"}
new const g_trace_attack_post[][] = {"func_breakable", "func_wall", "func_door", "func_plat", "func_rotating", "worldspawn"}
new g_viewmodel, g_weaponmodel

new const g_weapon_models[][] = 
{
	"models/406/v_infinitysr.mdl",
	"models/406/p_infinitysr.mdl",
	"models/406/w_infinitysr.mdl"
}

new const g_weapon_sounds[][] = 
{
	"weapons/infi-1.wav",
	"weapons/infis_clipin.wav",
	"weapons/infis_clipout.wav",
	"weapons/infis_draw.wav",
	"weapons/infis_foley1.wav",
	"weapons/infis_foley2.wav"
}

new const g_weapon_sprites[][] = 
{
	"sprites/406/640hud7.spr",
	"sprites/406/640hud47.spr",
	"sprites/406/640hud48.spr"
}

public plugin_init()
{
	register_plugin("[CS] Weapon Infinity Red", "1.0", "406")
	RegisterHam(Ham_Item_Deploy, weapon_name, "cs_item_deploy", 1)
	RegisterHam(Ham_Item_AddToPlayer, weapon_name, "cs_item_add_to_player", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_name, "cs_weapon_primary_attack", 0)
	RegisterHam(Ham_Item_PostFrame, weapon_name, "cs_item_post_frame", 0)
	RegisterHam(Ham_Weapon_Reload, weapon_name, "cs_weapon_reload", 0)
	for(new i = 0; i < sizeof g_trace_attack; i++)
	RegisterHam(Ham_TraceAttack, g_trace_attack[i], "cs_trace_attack")
	for(new i = 0; i < sizeof g_trace_attack_post; i++)
	RegisterHam(Ham_TraceAttack, g_trace_attack_post[i], "cs_trace_attack_post")
	register_forward(FM_SetModel, "cs_set_model")
	register_forward(FM_UpdateClientData, "cs_update_client_data", 1)
	g_viewmodel=engfunc(EngFunc_AllocString, g_weapon_models[0])
	g_weaponmodel=engfunc(EngFunc_AllocString, g_weapon_models[1])
	register_clcmd(weapon_new_name, "cs_weapon_hook")
	register_clcmd("say /infinitysr", "get_item_infinitysr")
}

public plugin_precache()
{
	for(new i = 0; i < sizeof g_weapon_models; i++)
	precache_model(g_weapon_models[i])
	for(new i = 0; i < sizeof g_weapon_sounds; i++)
	precache_sound(g_weapon_sounds[i])
	for(new i = 0; i < sizeof g_weapon_sprites; i++)
	precache_generic(g_weapon_sprites[i])
	new newspr[64]
	format(newspr, charsmax(newspr), "sprites/%s.txt", weapon_new_name)
	precache_generic(newspr)
}

public plugin_natives()
{
	register_library("cs_give_weapons")
	register_native("cs_give_infinitysr", "get_item_infinitysr", 1)
}

public get_item_infinitysr(id)
{
	if(is_user_alive(id))
	{
		weapon_drop(id, 2)
		new weapon=weapon_make()
		if(weapon<=0) return
		if(!ExecuteHamB(Ham_AddPlayerItem, id, weapon))
		{
			engfunc(EngFunc_RemoveEntity, weapon); return
		}
		ExecuteHam(Ham_Item_AttachToPlayer, weapon, id)
		new ammotype=376+get_pdata_int(weapon, 49, 4)
		new ammo=get_pdata_int(id, ammotype, 5)
		if(ammo<weapon_ammo) set_pdata_int(id, ammotype, weapon_ammo, 5)
		set_pdata_int(weapon, 51, weapon_clip, 4)
		emit_sound(id, CHAN_ITEM, "items/gunpickup2.wav", VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	}
}

public cs_weapon_hook(id) engclient_cmd(id, weapon_name)

public cs_set_model(ent)
{
	new i, classname[32], item; pev(ent, pev_classname, classname, 31)
	if(!equal(classname, "weaponbox")) return FMRES_IGNORED
	for(i=0; i<6; i++)
	{
		item=get_pdata_cbase(ent, 34+i, 4)
		if(item>0 && customitem(item))
		{
			engfunc(EngFunc_SetModel, ent, g_weapon_models[2])
			return FMRES_SUPERCEDE
		}
	}
	return FMRES_IGNORED
}

public cs_item_post_frame(ent)
{
	if(!customitem(ent)) return HAM_IGNORED
	new id; id=get_pdata_cbase(ent, 41, 4)
	if(get_pdata_int(ent, 54, 4))
	{
		new clip, ammotype, ammo, jam
		clip=get_pdata_int(ent, 51, 4)
		ammotype=376+get_pdata_int(ent, 49, 4)
		ammo=get_pdata_int(id, ammotype, 5)
		jam=min(weapon_clip-clip, ammo)
		set_pdata_int(ent, 51, clip+jam, 4)
		set_pdata_int(id, ammotype, ammo-jam, 5)
		set_pdata_int(ent, 54, 0, 4)
	}
	return HAM_IGNORED
}

public cs_weapon_reload(ent)
{
	if(!customitem(ent)) return HAM_IGNORED
	new clip; clip=get_pdata_int(ent, 51, 4)
	if(clip>=weapon_clip) return HAM_SUPERCEDE
	new id; id=get_pdata_cbase(ent, 41, 4)
	if(get_pdata_int(id, 376+get_pdata_int(ent, 49, 4), 5)<=0)
	return HAM_SUPERCEDE
	set_pdata_int(ent, 51, 0, 4)
	ExecuteHam(Ham_Weapon_Reload, ent)
	set_pdata_int(ent, 51, clip, 4)
	set_pdata_int(ent, 54, 1, 4)
	set_pdata_float(ent, 46, time_reload, 4)
	set_pdata_float(ent, 47, time_reload, 4)
	set_pdata_float(ent, 48, time_reload, 4)
	set_pdata_float(id, 83, time_reload, 5)
	weapon_anim(id, anim_reload)
	return HAM_SUPERCEDE
}

public cs_item_deploy(ent)
{
	if(!customitem(ent)) return HAM_IGNORED
	new id; id=get_pdata_cbase(ent, 41, 4)
	set_pev_string(id, pev_viewmodel2, g_viewmodel)
	set_pev_string(id, pev_weaponmodel2, g_weaponmodel)
	set_pdata_float(ent, 46, time_draw, 4)
	set_pdata_float(ent, 47, time_draw, 4)
	set_pdata_float(ent, 48, time_draw, 4)
	weapon_anim(id, anim_draw)
	return HAM_IGNORED
}

public cs_weapon_primary_attack(ent)
{
	if(!customitem(ent)||!cs_get_weapon_ammo(ent)) return HAM_IGNORED
	new id; id=get_pdata_cbase(ent, 41, 4)
	ExecuteHam(Ham_Weapon_PrimaryAttack, ent)
	set_pdata_float(id, 111, get_gametime(), 5)
	weapon_anim(id, random_num(anim_shoot1, anim_shoot2))
	emit_sound(id, CHAN_WEAPON, g_weapon_sounds[0], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	return HAM_SUPERCEDE
}

public cs_trace_attack(entity, attacker, Float:damage)
{
	if(!customitem(get_pdata_cbase(attacker, 373, 5))) return HAM_IGNORED
	SetHamParamFloat(3, damage * weapon_damage); return HAM_IGNORED
}

public cs_trace_attack_post(entity, attacker, Float:damage, Float:fDir[3], ptr, damagetype)
{
	if(!customitem(get_pdata_cbase(attacker, 373, 5))) return HAM_IGNORED
	new Float:vecEnd[3]; get_tr2(ptr, TR_vecEndPos, vecEnd)
	engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
	write_byte(TE_GUNSHOTDECAL); engfunc(EngFunc_WriteCoord, vecEnd[0])
	engfunc(EngFunc_WriteCoord, vecEnd[1]); engfunc(EngFunc_WriteCoord, vecEnd[2])
	write_short(entity); write_byte(random_num(41, 45))
	message_end(); return HAM_IGNORED
}

public cs_update_client_data(id, SendWeapons, CD_Handle)
{
	new item; item=get_pdata_cbase(id, 373, 5)
	if(item<=0||!customitem(item)) return FMRES_IGNORED
	set_cd(CD_Handle, CD_flNextAttack, 99999.0)
	return FMRES_HANDLED
}

public cs_item_add_to_player(ent, id)
{
	switch(pev(ent, pev_impulse))
	{
		case 0: cs_weapon_list(id, weapon_name, 7, 100, 1, 6, 11, 0)
		case WEAPONKEY: cs_weapon_list(id, weapon_new_name, 7, weapon_ammo, 1, 6, 11, 0)
	}
}

stock weapon_drop(id, slot)
{
	new entity; entity=get_pdata_cbase(id, (367+slot), 5)
	if(entity>0)
	{
		new next, szWeaponName[32]
		do
		{
			next=get_pdata_cbase(entity, 42, 4)
			if(get_weaponname(get_pdata_int(entity, 43, 4), szWeaponName, 31))
			engclient_cmd(id, "drop", szWeaponName)
		}
		while((entity=next)>0)
	}
}

stock cs_weapon_list(id, weaponlist[], int, int2, int3, int4, int5, int6)
{
	new weaplist; if(!weaplist) weaplist = get_user_msgid("WeaponList")
	message_begin(MSG_ONE, weaplist, _, id)
	write_string(weaponlist); write_byte(int); write_byte(int2); write_byte(-1); write_byte(-1)
	write_byte(int3); write_byte(int4); write_byte(int5); write_byte(int6); message_end()
}

stock weapon_make()
{
	new ent; new allocstring
	if(allocstring||(allocstring=engfunc(EngFunc_AllocString, weapon_name)))
	ent=engfunc(EngFunc_CreateNamedEntity, allocstring)
	else return 0
	if(ent<=0) return 0
	set_pev(ent, pev_spawnflags, SF_NORESPAWN)
	set_pev(ent, pev_impulse, WEAPONKEY)
	ExecuteHam(Ham_Spawn, ent); return ent
}

stock weapon_anim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, _, id)
	write_byte(anim); write_byte(0); message_end()
}

cs_weapon_infinitysr.sma

Edited by ostaninsema

Share this post


Link to post
Share on other sites

Возможно у тебя на сервере есть оружие с таким же "веапонкеем" которое на правую кнопку и совершает автоматическую стрельбу

замени число в "#define WEAPONKEY 4062" на любое другое, к примеру на 40621

Share this post


Link to post
Share on other sites

Чувак это инфинити... У них на ПКМ режим такой, стреляют быстро. Если ты хочешь чтобы по медленнее стреляли, то измени скорость стрельбы.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0