圖 1.
new PLUGIN_VERSION[4] =
{
49, 46, 48, 0
}
new g_attacking[33];
new g_maxplayers;
new cvar_kf1;
new cvar_kf2;
xs_vec_add(Float:in1[], Float:in2[], Float:out[])
{
out[0] = in1[0] + in2[0];
out[1] = in1[1] + in2[1];
out[2] = in1[2] + in2[2];
return 0;
}
xs_vec_mul_scalar(Float:vec[], Float:scalar, Float:out[])
{
out[0] = vec[0] * scalar;
out[1] = vec[1] * scalar;
out[2] = vec[2] * scalar;
return 0;
}
public plugin_precache()
{
register_plugin("Custom Knife Distance", "1.0", "Fai & Shardow");
return 0;
}
public plugin_init()
{
register_event("HLTV", "event_round_start", "a", "1=0", "2=0");
RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "fw_PrimaryAttack", 0);
RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "fw_SecondaryAttack", 0);
RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "fw_PrimaryAttack_Post", 1);
RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_knife", "fw_SecondaryAttack_Post", 1);
register_forward(FM_TraceLine, "fw_TraceLine", 0);
register_forward(FM_TraceHull, "fw_TraceHull", 0);
cvar_kf1 = register_cvar("knife_distance1", "32.0", 0, 0.00);
cvar_kf2 = register_cvar("knife_distance2", "48.0", 0, 0.00);
g_maxplayers = get_maxplayers();
return 0;
}
public event_round_start()
{
colored_print(0, "\4[FxG]\3 FxG 伺服 IP: fxg1.nets.hk:27017 | fxg1.nets.hk:27016", get_pcvar_float(cvar_kf1), get_pcvar_float(cvar_kf2));
colored_print(0, "\4[FxG]\3 本伺服正在運行 \"Custom Knife Distance\" 版本: %d 作者: Fai & Shardow", PLUGIN_VERSION);
colored_print(0, "\4[FxG]\3 小刀輕砍有效距離: %1.f 小刀重砍有效距離: %1.f", get_pcvar_float(cvar_kf1), get_pcvar_float(cvar_kf2));
set_hudmessage(255, 0, 0, 0.60, 0.80, 1, 0.00, 5.00, 1.00, 1.00, -1);
show_hudmessage(0, "\4[FxG]\3 本伺服正在運行 \"Custom Knife Distance\"\n版本: %d 作者: 泥鰍大哥 & 史來姆");
return 0;
}
public fw_PrimaryAttack(weapon_ent)
{
if (!pev_valid(weapon_ent))
{
return 0;
}
if (g_maxplayers >= var2 & 1 <= var2 && is_user_connected(owner))
{
return 0;
}
g_attacking[owner] = 1;
return 0;
}
public fw_SecondaryAttack(weapon_ent)
{
if (!pev_valid(weapon_ent))
{
return 0;
}
if (g_maxplayers >= var2 & 1 <= var2 && is_user_connected(owner))
{
return 0;
}
g_attacking[owner] = 2;
return 0;
}
public fw_PrimaryAttack_Post(weapon_ent)
{
if (!pev_valid(weapon_ent))
{
return 0;
}
if (g_maxplayers >= var2 & 1 <= var2 && is_user_connected(owner))
{
return 0;
}
g_attacking[owner] = 0;
return 0;
}
public fw_SecondaryAttack_Post(weapon_ent)
{
if (!pev_valid(weapon_ent))
{
return 0;
}
if (g_maxplayers >= var2 & 1 <= var2 && is_user_connected(owner))
{
return 0;
}
g_attacking[owner] = 0;
return 0;
}
public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
{
if (g_maxplayers >= var2 & 1 <= var2 && is_user_connected(id))
{
return 1;
}
if (!is_user_alive(id))
{
return 1;
}
if (get_user_weapon(id, 0, 0) != 29)
{
return 1;
}
if (!g_attacking[id][0][0])
{
return 1;
}
pev(id, pev_v_angle, vector_end);
angle_vector(vector_end, 1, vector_end);
if (g_attacking[id][0][0] == 1)
{
xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf1), vector_end);
}
else
{
xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf2), vector_end);
}
xs_vec_add(vector_start, vector_end, vector_end);
engfunc(EngFunc_TraceLine, vector_start, vector_end, ignored_monster, id, handle);
return 4;
}
public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
{
if (g_maxplayers >= var2 & 1 <= var2 && is_user_connected(id))
{
return 1;
}
if (!is_user_alive(id))
{
return 1;
}
if (get_user_weapon(id, 0, 0) != 29)
{
return 1;
}
if (!g_attacking[id][0][0])
{
return 1;
}
pev(id, pev_v_angle, vector_end);
angle_vector(vector_end, 1, vector_end);
if (g_attacking[id][0][0] == 1)
{
xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf1), vector_end);
}
else
{
xs_vec_mul_scalar(vector_end, get_pcvar_float(cvar_kf2), vector_end);
}
xs_vec_add(vector_start, vector_end, vector_end);
engfunc(EngFunc_TraceHull, vector_start, vector_end, ignored_monster, hull, id, handle);
return 4;
}
colored_print(target, String:message[])
{
static g_msgSayText;
static argscount;
static i;
static buffer[512];
argscount = numargs();
g_msgSayText = get_user_msgid("SayText");
if (!target)
{
static player;
player = 1;
while (player <= g_maxplayers)
{
if (is_user_connected(player))
{
static changedcount;
static changed[5];
changedcount = 0;
i = 2;
while (i < argscount)
{
if (getarg(i, 0) == -1)
{
setarg(i, 0, player);
changed[changedcount] = i;
changedcount += 1;
i += 1;
}
i += 1;
}
vformat(buffer, 511, message, 3);
message_begin(MSG_ONE_UNRELIABLE, g_msgSayText, 4692, player);
write_byte(player);
write_string("");
message_end();
i = 0;
while (i < changedcount)
{
setarg(changed[i][0][0], 0, -1);
i += 1;
}
}
player += 1;
}
}
else
{
vformat(buffer, 511, message, 3);
message_begin(MSG_ONE, g_msgSayText, 4692, target);
write_byte(target);
write_string("");
message_end();
}
return 0;
}