--- grab_plus.sma 2007/11/02 01:14:09 9 +++ grab_plus.sma 2007/11/06 18:25:29 11 @@ -16,7 +16,7 @@ -------------------------------------------------------------------------------- http://ian.cammarata.us/projects/grab_plus -Nov 01 04:16 +Nov 06 11:21 Description: @@ -47,23 +47,24 @@ +pull/+push (or invnext/invprev): Pulls/pushes the grabbed towards/away from you as you hold the button. -+use : Chokes the grabbed (it damages the grabbed with 5 (cvar: gp_chokedmg) hp per 1.5 (cvar: gp_choketime) seconds) -drop - Throws the grabbed with 1500 velocity. (cvar: gp_throwforce) ++use : Chokes the grabbed (it damages the grabbed with 5 (cvar: gp_choke_dmg) hp per 1.5 (cvar: gp_choke_time) seconds) +drop - Throws the grabbed with 1500 velocity. (cvar: gp_throw_force) Cvars (First value is default): gp_enabled <1|0> Enables all plugin functionality. -gp_playersonly <0|1> Disables admins grabbing entities other than players. +gp_players_only <0|1> Disables admins grabbing entities other than players. gp_min_dist <90|...> Min distance between the grabber and grabbed. -gp_grabforce <8|...> Sets the amount of force used when grabbing players. -gp_throwforce <1500|...> Sets the power used when throwing players. +gp_grab_force <8|...> Sets the amount of force used when grabbing players. +gp_throw_force <1500|...> Sets the power used when throwing players. gp_speed <5|...> How fast the grabbed moves when using push and pull. -gp_choketime <1.5|...> Time frequency for choking. -gp_chokedmg <5|...> Amount of damage done with each choke. +gp_choke_time <1.5|...> Time frequency for choking. +gp_choke_dmg <5|...> Amount of damage done with each choke. +gp_auto_choke <1|0> Enable/disable choking automatically with +pull command. -gp_screenfade <1|0> Enables/disables screenfade when grabbing. +gp_screen_fade <1|0> Enables/disables screenfade when grabbing. gp_glow <1|0> Enables/disables glowing for grabbed objects. gp_glow_r <50|0-255> Sets red amount for glow and screenfade. @@ -104,15 +105,17 @@ Change Log: Key (+ added | - removed | c changed | f fixed) -v1.2 (Nov ??, 2007) -+: Cvars gp_screenfade and gp_glow to enable/disable these features. +v1.2 (Nov 06, 2007) ++: Cvars gp_screen_fade and gp_glow to enable/disable these features. +: Cvar gp_glow_a controls to control alpha of screenfade and glow. -c: Removed dependency of engine and fun modules. Thanks to vittu for doing all the work. -f: Fixed compile bug with amxx 1.8.0 (Compiles with 1.7x as well). ++: Cvar gp_auto_choke to enable/disable choking automatically with +pull command. +c: Removed dependency of engine and fun modules. Thanks to vittu for doing most of the work. +c: Made cvar names more consistent by adding more underscores. +f: Fixed compile bug with amxx 1.8.0 (Compiles with 1.7.x as well). v1.1 (Oct 16, 2007) +: Grab a few types of entities other than players. -+: Cvar gp_playersonly. ++: Cvar gp_players_only. v1.0 (Oct 13, 2007) !: Initial release @@ -123,7 +126,7 @@ #include #include -#define VERSION "1.2b5" +#define VERSION "1.2" #define ADMIN ADMIN_LEVEL_A #define TSK_CHKE 50 @@ -142,9 +145,9 @@ #define CDF_NO_CHOKE (1<<2) //Cvar Pointers -new p_enabled, p_playersonly -new p_throwforce, p_mindist, p_speed, p_grabforce -new p_choketime, p_chokedmg +new p_enabled, p_players_only +new p_throw_force, p_min_dist, p_speed, p_grab_force +new p_choke_time, p_choke_dmg, p_auto_choke new p_glow_r, p_glow_b, p_glow_g, p_glow_a new p_fade, p_glow @@ -159,22 +162,23 @@ set_cvar_string( "grab_plus_version", VERSION ) p_enabled = register_cvar( "gp_enabled", "1" ) - p_playersonly = register_cvar( "gp_playersonly", "0" ) + p_players_only = register_cvar( "gp_players_only", "0" ) - p_mindist = register_cvar ( "gp_min_dist", "90" ) - p_throwforce = register_cvar( "gp_throwforce", "1500" ) - p_grabforce = register_cvar( "gp_grabforce", "8" ) + p_min_dist = register_cvar ( "gp_min_dist", "90" ) + p_throw_force = register_cvar( "gp_throw_force", "1500" ) + p_grab_force = register_cvar( "gp_grab_force", "8" ) p_speed = register_cvar( "gp_speed", "5" ) - p_choketime = register_cvar( "gp_choketime", "1.5" ) - p_chokedmg = register_cvar( "gp_chokedmg", "5" ) + p_choke_time = register_cvar( "gp_choke_time", "1.5" ) + p_choke_dmg = register_cvar( "gp_choke_dmg", "5" ) + p_auto_choke = register_cvar( "gp_auto_choke", "1" ) p_glow_r = register_cvar( "gp_glow_r", "50" ) p_glow_g = register_cvar( "gp_glow_g", "0" ) p_glow_b = register_cvar( "gp_glow_b", "0" ) p_glow_a = register_cvar( "gp_glow_a", "200" ) - p_fade = register_cvar( "gp_screenfade", "1" ) + p_fade = register_cvar( "gp_screen_fade", "1" ) p_glow = register_cvar( "gp_glow", "1" ) register_clcmd( "amx_grab", "force_grab", ADMIN, "Grab client & teleport to you." ) @@ -217,23 +221,18 @@ if ( client_data[id][GRABBED] == -1 ) { new Float:orig[3], Float:ret[3] - pev( id, pev_origin, orig ) - pev( id, pev_view_ofs, ret ) + get_view_pos( id, orig ) + ret = vel_by_aim( id, 9999 ) - for( new i = 0; i < 3; i++ ) orig[i] += ret[i] - velocity_by_aim( id, 1, ret ) - for( new i = 0; i < 3; i++ ) ret[i] = orig[i] + ( ret[i] * 9999 ) - - engfunc( EngFunc_TraceLine, orig, ret, 0, id, 0 ) - new target = get_tr2( 0, TR_pHit ) - get_tr2( 0, TR_vecEndPos, ret ) + for( new i = 0; i < 3; i++ ) ret[i] = orig[i] + ret[i] + new target = traceline( orig, ret, id, ret ) if( 0 < target <= MAXPLAYERS ) { if( is_grabbed( target, id ) ) return PLUGIN_CONTINUE set_grabbed( id, target ) } - else if( !get_pcvar_num( p_playersonly ) ) + else if( !get_pcvar_num( p_players_only ) ) { new movetype if( target ) @@ -296,21 +295,26 @@ if( pev( target, pev_movetype ) == MOVETYPE_FLY && !(pev( target, pev_button ) & IN_JUMP ) ) client_cmd( target, "+jump;wait;-jump" ) //Move targeted client - new Float:tmpvec[3], Float:tmpvec2[3], Float:dest[3], Float:torig[3], Float:tvel[3] - new len = client_data[id][GRAB_LEN] + new Float:tmpvec[3], Float:tmpvec2[3], /*Float:dest[3],*/ Float:torig[3], Float:tvel[3] + + //pev( id, pev_origin, dest ) + //pev( id, pev_view_ofs, tmpvec ) + get_view_pos( id, tmpvec ) + + //velocity_by_aim( id, len, tmpvec2 ) + //for( new i = 0; i < 3; i++ ) tmpvec2[i] *= len + tmpvec2 = vel_by_aim( id, client_data[id][GRAB_LEN] ) - pev( id, pev_origin, dest ) - pev( id, pev_view_ofs, tmpvec ) - velocity_by_aim( id, len, tmpvec2 ) torig = get_target_origin_f( target ) - new force = get_pcvar_num( p_grabforce ) + new force = get_pcvar_num( p_grab_force ) for( new i = 0; i < 3; i++ ) - { - dest[i] += tmpvec[i] + tmpvec2[i] + tvel[i] = ( ( tmpvec[i] + tmpvec2[i] ) - torig[i] ) * force + /*{ + dest[i] = tmpvec[i] + tmpvec2[i] tvel[i] = ( dest[i] - torig[i] ) * force - } + }*/ set_pev( target, pev_velocity, tvel ) } @@ -372,12 +376,11 @@ new target = client_data[id][GRABBED] if( target > 0 ) { - new Float:pVelocity[3] - velocity_by_aim( id, get_pcvar_num(p_throwforce), pVelocity ) - set_pev( target, pev_velocity, pVelocity ) + set_pev( target, pev_velocity, vel_by_aim( id, get_pcvar_num(p_throw_force) ) ) unset_grabbed( id ) return PLUGIN_HANDLED } + return PLUGIN_CONTINUE } @@ -433,7 +436,7 @@ pev( target, pev_origin, torig ) pev( id, pev_origin, orig ) client_data[id][GRAB_LEN] = floatround( get_distance_f( torig, orig ) ) - if( client_data[id][GRAB_LEN] < get_pcvar_num( p_mindist ) ) client_data[id][GRAB_LEN] = get_pcvar_num( p_mindist ) + if( client_data[id][GRAB_LEN] < get_pcvar_num( p_min_dist ) ) client_data[id][GRAB_LEN] = get_pcvar_num( p_min_dist ) } public push( id ) @@ -474,7 +477,7 @@ public do_pull( id ) { - new mindist = get_pcvar_num( p_mindist ) + new mindist = get_pcvar_num( p_min_dist ) new len = client_data[id][GRAB_LEN] if( len > mindist ) @@ -483,7 +486,8 @@ if( len < mindist ) len = mindist client_data[id][GRAB_LEN] = len } - else do_choke( id ) + else if( get_pcvar_num( p_auto_choke ) ) + do_choke( id ) } public do_choke( id ) @@ -491,7 +495,7 @@ new target = client_data[id][GRABBED] if( client_data[id][FLAGS] & CDF_NO_CHOKE || id == target || target > MAXPLAYERS) return - new dmg = get_pcvar_num( p_chokedmg ) + new dmg = get_pcvar_num( p_choke_dmg ) new Float:vec[3] get_target_origin_f( target ) @@ -539,7 +543,7 @@ emit_sound( target, CHAN_BODY, "player/PL_PAIN2.WAV", VOL_NORM, ATTN_NORM, 0, PITCH_NORM ) client_data[id][FLAGS] ^= CDF_NO_CHOKE - set_task( get_pcvar_float( p_choketime ), "clear_no_choke", TSK_CHKE + id ) + set_task( get_pcvar_float( p_choke_time ), "clear_no_choke", TSK_CHKE + id ) } public clear_no_choke( tskid ) @@ -566,21 +570,16 @@ } //Safe to tp target to aim spot? - new Float:tmpvec[3], Float:tmpvec2[3], Float:orig[3], Float:torig[3], Float:trace_ret[3] + new Float:tmpvec[3], Float:orig[3], Float:torig[3], Float:trace_ret[3] new bool:safe = false, i - pev( id, pev_origin, orig ) - pev( id, pev_view_ofs, tmpvec ) - for( i = 0; i < 3; i++ ) tmpvec[i] += orig[i] - velocity_by_aim( id, get_pcvar_num( p_mindist ), tmpvec2 ) + get_view_pos( id, orig ) + tmpvec = vel_by_aim( id, get_pcvar_num( p_min_dist ) ) for( new j = 1; j < 11 && !safe; j++ ) { - for( i = 0; i < 3; i++ ) - torig[i] = tmpvec[i] + tmpvec2[i] * j - - engfunc( EngFunc_TraceLine, tmpvec, torig, 0, id, 0 ) - get_tr2( 0, TR_vecEndPos, trace_ret ) + for( i = 0; i < 3; i++ ) torig[i] = orig[i] + tmpvec[i] * j + traceline( tmpvec, torig, id, trace_ret ) if( get_distance_f( trace_ret, torig ) ) break @@ -590,6 +589,7 @@ } //Still not safe? Then find another safe spot somewhere around the grabber + pev( id, pev_origin, orig ) new try[3] orig[2] += 2 while( try[2] < 3 && !safe ) @@ -602,8 +602,7 @@ case 2 : torig[i] = orig[i] - ( i == 2 ? 80 : 40 ) } - engfunc( EngFunc_TraceLine, tmpvec, torig, 0, id, 0 ) - get_tr2( 0, TR_vecEndPos, trace_ret ) + traceline( tmpvec, torig, id, trace_ret ) engfunc( EngFunc_TraceHull, torig, torig, 0, HULL_HUMAN, 0, 0 ) if ( !get_tr2( 0, TR_StartSolid ) && !get_tr2( 0, TR_AllSolid ) && get_tr2( 0, TR_InOpen ) @@ -662,3 +661,27 @@ else if( client_data[id][GRABBER] ) unset_grabbed( client_data[id][GRABBER] ) } + +stock traceline( const Float:vStart[3], const Float:vEnd[3], const pIgnore, Float:vHitPos[3] ) +{ + engfunc( EngFunc_TraceLine, vStart, vEnd, 0, pIgnore, 0 ) + get_tr2( 0, TR_vecEndPos, vHitPos ) + return get_tr2( 0, TR_pHit ) +} + +stock get_view_pos( const id, Float:vViewPos[3] ) +{ + new Float:ofs[3] + pev( id, pev_origin, vViewPos ) + pev( id, pev_view_ofs, ofs ) + for( new i = 0; i < 3; i++ ) vViewPos[i] += ofs[i] +} + +stock Float:vel_by_aim( id, speed = 1 ) +{ + new Float:v1[3], Float:vBlah[3] + pev( id, pev_v_angle, v1 ) + engfunc( EngFunc_AngleVectors, v1, v1, vBlah, vBlah ) + for( new i = 0; i < 3; i++ ) v1[i] *= speed + return v1 +}