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")
}
註:非全部代碼 有些非重要部份我沒加