1.
可以使用Ham_TraceAttack来解决 只要侦测是否为小刀并且攻击者非僵尸即可
2. 只要侦测攻击时是否按右键就行了
sma类似这样
复制程式
#include <amxmodx>
#include <hamsandwich>
#include <xs>
#include <zombieplague>
public plugin_init()
{
RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack")
}
public fw_TraceAttack(victim, attacker, Float:damage, Float:direction[3], tracehandle, damage_type)
{
// 自己对自己不会有击退
if (victim == attacker)
return HAM_IGNORED;
// 请勿残害队友(?
if (zp_get_user_zombie(attacker) == zp_get_user_zombie(victim))
return HAM_IGNORED;
// 攻击者非人类或被伤害者非僵尸
if (zp_get_user_zombie(attacker) || !zp_get_user_zombie(victim))
return HAM_IGNORED;
// 非小刀?
if (get_user_weapon(attacker) != CSW_KNIFE)
return HAM_IGNORED;
static Float:hit_direction[3]
hit_direction = direction
// Get knockback vector
static Float:knockback_vector
knockback_vector = 120.0 //击退力
xs_vec_mul_scalar(hit_direction, knockback_vector, hit_direction)
static button
button = pev(attacker, pev_button)
if (button & IN_ATTACK2) //右键攻击加包
zp_set_user_ammo_packs(attacker, zp_get_user_ammo_packs(attacker) + 1)
set_vector_change_angle2(hit_direction, 0.0, 15.0, hit_direction)
// 开始飞吧你
set_pev(victim, pev_velocity, hit_direction)
SetHamParamVector(4, Float:{0.0, 0.0, 0.0});
return HAM_IGNORED;
}
//以下这段是增加BOT支援用的
new bool:BotHasDebug = false
public client_putinserver(id)
{
if (!cvar_botquota || !is_user_bot(id) || BotHasDebug)
return;
new classname[32]
pev(id, pev_classname, classname, 31)
if (!equal(classname, "player"))
set_task(0.1, "_Debug", id)
}
public _Debug(id)
{
// Make sure it's a CZ bot and it's still connected
if (!get_pcvar_num(cvar_botquota) || !is_user_connected(id))
return;
BotHasDebug = true
RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack")
}
注:非全部代码 有些非重要部份我没加