I've made my own grappling hook which pulls people towards me. I'm just having problems removing the hook once the person is right next to me or touches me when they are still hooked...
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
new model[] = "models/crossbow_bolt.mdl"
new sprite
new bool: g_hooked[33]
public plugin_init()
{
register_plugin("Hook grab","1.0","Mazza")
register_forward(FM_Touch, "fw_Touch")
}
public client_putinserver(id)
{
g_hooked[id] = false
}
public plugin_precache()
{
engfunc(EngFunc_PrecacheModel, model);
sprite = precache_model("sprites/zbeam4.spr");
}
public client_impulse(id, impulse)
{
if(impulse == 100)
{
create_hook(id)
return PLUGIN_HANDLED_MAIN
}
return PLUGIN_CONTINUE
}
public create_hook(id)
{
if (!is_user_alive(id))
return
static Float: Origin[3], Float: Velocity[3], MinBox[3], MaxBox[3]
pev(id, pev_origin, Origin)
pev(id, pev_velocity, Velocity)
static ent ; ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
set_pev(ent, pev_classname, "ent")
engfunc(EngFunc_SetModel, ent, model)
MinBox = { -1.900000, -0.140000, -1.910000 }
MaxBox = { 1.900000, 25.000000, 1.910000 }
engfunc(EngFunc_SetSize, ent, MinBox, MaxBox)
engfunc(EngFunc_SetOrigin, ent, Origin)
set_pev(ent, pev_movetype, MOVETYPE_FLY)
set_pev(ent, pev_solid, SOLID_TRIGGER)
set_pev(ent, pev_owner, id)
velocity_by_aim(id, 1500, Velocity)
set_pev(ent, pev_velocity, Velocity)
// Create a beam between two entities
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_BEAMENTS)
write_short(id | 0x1000)
write_short(ent)
write_short(sprite) // sprite index
write_byte(0) // start frame
write_byte(0) // framerate
write_byte(200) // life
write_byte(7) // width
write_byte(1) // noise
write_byte(50) // r, g, b
write_byte(50) // r, g, b
write_byte(50) // r, g, b
write_byte(100) // brightness
write_byte(10) // speed
message_end()
}
public fw_Touch(pToucher, pTouched)
{
if ( pev_valid(pToucher))
{
static className[32], className2[32], attacker
pev(pToucher, pev_classname, className, 31)
if ( pev_valid(pTouched)) pev(pTouched, pev_classname, className2, 31)
attacker = pev(pToucher, pev_owner)
if ( equal(className, "ent"))
{
if ( pev_valid(pTouched))
{
if ( equal(className2, "player") && is_user_connected(pTouched))
{
static Float:fl_Velocity[3]
static attacker_origin[3], victim_origin[3]
get_user_origin(attacker, attacker_origin)
get_user_origin(pTouched, victim_origin)
static CsTeams:team[2]
team[0] = cs_get_user_team(pTouched), team[1] = cs_get_user_team(attacker)
if (attacker == pTouched)
return FMRES_SUPERCEDE
if (!get_cvar_num("mp_friendlyfire") && team[0] == team[1])
return FMRES_SUPERCEDE
set_pev(pToucher, pev_aiment, pTouched)
set_pev(pToucher, pev_movetype, MOVETYPE_FOLLOW)
g_hooked[pTouched] = true
static distance
distance = get_distance(attacker_origin, victim_origin)
if ( distance > 5 )
{
new Float:fl_Time = distance / 2000.0
fl_Velocity[0] = (attacker_origin[0] - victim_origin[0]) / fl_Time
fl_Velocity[1] = (attacker_origin[1] - victim_origin[1]) / fl_Time
fl_Velocity[2] = (attacker_origin[2] - victim_origin[2]) / fl_Time
}
else
{
fl_Velocity[0] = 0.0
fl_Velocity[1] = 0.0
fl_Velocity[2] = 0.0
}
set_pev(pTouched, pev_velocity, fl_Velocity)
}
else
remove_hook(pToucher)
}
else
remove_hook(pToucher)
}
}
return FMRES_IGNORED
}
remove_hook(index)
{
engfunc(EngFunc_RemoveEntity, index)
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_KILLBEAM)
write_short(index)
message_end()
}