Also, that is the worst rope mod ever.
Code:
#include <amxmodx>
#include <engine>
#define HOLD_T 8.0
#define ROPE_DELAY 0.5
#define TE_BEAMENTPOINT 1
#define TE_KILLBEAM 99
#define DELTA_T 0.1 // seconds
#define BEAMLIFE 1 // deciseconds
#define MOVEACCELERATION 150 // units per second^2
#define REELSPEED 200 // units per second
new beam
new hook_id[33]
public plugin_init()
{
register_plugin("NinjaRope", "1.17","Twilight Suzuka")
register_clcmd("+ninjarope","attach_hook")
register_clcmd("-ninjarope","detach_hook")
register_cvar("ninjarope_on","1")
register_cvar("ninjarope_r","255")
register_cvar("ninjarope_g","255")
register_cvar("ninjarope_b","255")
register_cvar("ninjarope_width","10")
register_think("ninja_hook","hook_think")
}
public plugin_precache()
{
beam = precache_model("sprites/zbeam4.spr")
precache_sound("weapons/xbow_hit2.wav")
}
public client_putinserver(id)
{
hook_id[id] = 0;
}
stock can_use_hook(id)
{
if(!get_cvar_num("ninjarope_on") || !is_user_alive(id) ) return 0;
return 1;
}
public attach_hook(id)
{
if(!can_use_hook(id) ) return client_print(id,print_chat,"[NINJA] You cannot use the rope at this time!")
new s_origin[3]
get_user_origin(id,s_origin,3)
new Float:f_origin[3]
IVecFVec(s_origin,f_origin)
create_hook(id,f_origin )
return PLUGIN_HANDLED;
}
public detach_hook(id)
{
delete_hook(id)
return PLUGIN_HANDLED;
}
public create_hook(id,Float:origin[3])
{
new hook = create_entity("info_target")
if(!hook) return;
entity_set_string(hook,EV_SZ_classname,"ninja_hook")
entity_set_origin(hook,origin)
hook_id[id] = hook;
entity_set_int(hook,EV_INT_iuser1,id)
entity_set_float(hook,EV_FL_fuser2,entity_range(id,hook) )
entity_set_float(hook,EV_FL_nextthink,get_gametime() + 0.0001 )
emit_sound(id, CHAN_STATIC, "weapons/xbow_hit2.wav", 1.0, ATTN_NORM, 0, PITCH_NORM)
}
public delete_hook(id)
{
remove_entity(hook_id[id])
hook_id[id] = 0;
kill_hook(id)
}
public hook_think(id)
{
new user = entity_get_int(id,EV_INT_iuser1)
if(!can_use_hook(user) ) detach_hook(user)
make_hook( user )
hook_effect(user,id)
entity_set_float(id,EV_FL_nextthink,get_gametime() + 0.01 )
}
public make_hook(id)
{
new Float:vec[3]
get_hook_vec(id,vec)
message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
write_byte( TE_BEAMENTPOINT )
write_short( id )
write_coord( floatround(vec[0]) )
write_coord( floatround(vec[1]) )
write_coord( floatround(vec[2]) )
write_short( beam ) // sprite index
write_byte( 0 ) // start frame
write_byte( 0 ) // framerate
write_byte( BEAMLIFE ) // life
write_byte( get_cvar_num("ninjarope_width") ) // width
write_byte( 2 ) // noise
write_byte( get_cvar_num("ninjarope_r") ) // r, g, b
write_byte( get_cvar_num("ninjarope_g") ) // r, g, b
write_byte( get_cvar_num("ninjarope_b") ) // r, g, b
write_byte( 150 ) // brightness
write_byte( 0 ) // speed
message_end( )
}
public kill_hook(id)
{
message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
write_byte( TE_KILLBEAM )
write_short( id )
message_end()
}
stock get_hook_vec(id,Float:vec[3])
{
new h_id = hook_id[id];
entity_get_vector(h_id, EV_VEC_origin,vec)
}
public hook_effect(id,hook)
{
new user_origin[3], user_look[3], user_direction[3], move_direction[3]
new Float:hook_length = entity_get_float(hook,EV_FL_fuser2)
new Float:hook_origin[3], hook_origin_i[3]
entity_get_vector(hook,EV_VEC_origin,hook_origin)
FVecIVec(hook_origin,hook_origin_i)
new A[3], D[3], buttonadjust[3]
new acceleration, velocity_TA, desired_velocity_TA
new velocity[3], null[3]
new Float:tmpVector[3]
null[0] = 0
null[1] = 0
null[2] = 0
get_user_origin(id, user_origin)
get_user_origin(id, user_look,2)
entity_get_vector(id, EV_VEC_velocity, tmpVector)
FVecIVec(tmpVector, velocity)
buttonadjust[0] = 0
buttonadjust[1] =0
new buttons = get_user_button(id)
if (buttons & IN_FORWARD)
{
buttonadjust[0]+=1
}
if (buttons & IN_BACK)
{
buttonadjust[0]-=1
}
if (buttons & IN_MOVERIGHT)
{
buttonadjust[1]+=1
}
if (buttons & IN_MOVELEFT)
{
buttonadjust[1]-=1
}
if (buttons & IN_JUMP)
{
buttonadjust[2] += 1
}
if (buttons & IN_DUCK)
{
buttonadjust[2] -= 1
}
if (buttonadjust[0] || buttonadjust[1])
{
user_direction[0] = user_look[0] - user_origin[0]
user_direction[1] = user_look[1] - user_origin[1]
move_direction[0] = buttonadjust[0] * user_direction[0] + user_direction[1]*buttonadjust[1]
move_direction[1] = buttonadjust[0] * user_direction[1] - user_direction[0]*buttonadjust[1]
move_direction[2] = 0
velocity[0] += floatround(move_direction[0] * MOVEACCELERATION * DELTA_T / get_distance(null,move_direction))
velocity[1] += floatround(move_direction[1] * MOVEACCELERATION * DELTA_T / get_distance(null,move_direction))
}
if (buttonadjust[2])
{
hook_length -= buttonadjust[2] * REELSPEED * DELTA_T
}
if (hook_length < 100.0)
{
(hook_length) = 100.0
}
A[0] = floatround(hook_origin[0]) - user_origin[0]
A[1] = floatround(hook_origin[1]) - user_origin[1]
A[2] = floatround(hook_origin[2]) - user_origin[2]
D[0] = A[0]*A[2] / get_distance(null,A)
D[1] = A[1]*A[2] / get_distance(null,A)
D[2] = -(A[1]*A[1] + A[0]*A[0]) / get_distance(null,A)
new aDistance = get_distance(null,D) ? get_distance(null,D) : 1
acceleration = - 800 * D[2] / aDistance
velocity_TA = (velocity[0] * A[0] + velocity[1] * A[1] + velocity[2] * A[2]) / get_distance(null,A)
desired_velocity_TA = (get_distance(user_origin,hook_origin_i) - floatround(hook_length) /*- 10*/) * 4
if (get_distance(null,D)>10)
{
velocity[0] += floatround((acceleration * DELTA_T * D[0]) / get_distance(null,D))
velocity[1] += floatround((acceleration * DELTA_T * D[1]) / get_distance(null,D))
velocity[2] += floatround((acceleration * DELTA_T * D[2]) / get_distance(null,D))
}
velocity[0] += ((desired_velocity_TA - velocity_TA) * A[0]) / get_distance(null,A)
velocity[1] += ((desired_velocity_TA - velocity_TA) * A[1]) / get_distance(null,A)
velocity[2] += ((desired_velocity_TA - velocity_TA) * A[2]) / get_distance(null,A)
IVecFVec(velocity, tmpVector)
entity_set_vector(id, EV_VEC_velocity, tmpVector)
entity_set_float(hook,EV_FL_fuser2,hook_length)
}