[Half-Life AMXX] / grab_plus.sma Repository:
ViewVC logotype

Diff of /grab_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10, Sun Nov 4 03:44:10 2007 UTC revision 28, Wed Nov 21 18:04:40 2007 UTC
# Line 1  Line 1 
1  /*  /*
2  Grab+ v1.2  Grab+ v1.2.3
3  Copyright (C) 2007 Ian (Juan) Cammarata  Copyright (C) 2007 Ian (Juan) Cammarata
4    
5  This program is free software; you can redistribute it and/or modify it under  This program is free software: you can redistribute it and/or modify
6  the terms of the GNU General Public License as published by the Free Software  it under the terms of the GNU Affero General Public License as
7  Foundation; either version 2 of the License, or (at your option) any later  published by the Free Software Foundation, either version 3 of the
8  version.  License, or (at your option) any later version.
9    
10  This program is distributed in the hope that it will be useful, but WITHOUT ANY  This program is distributed in the hope that it will be useful,
11  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  PARTICULAR PURPOSE. See the GNU General Public License for more details.  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU Affero General Public License for more details.
14    
15  You should have received a copy of the GNU General Public License along with  You should have received a copy of the GNU Affero General Public License
16  this program; go to http://www.opensource.org/licenses/gpl-license.php  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  --------------------------------------------------------------------------------  --------------------------------------------------------------------------------
18    
19  http://ian.cammarata.us/projects/grab_plus  http://ian.cammarata.us/projects/grab_plus
20  Nov 02 01:52  Nov 21 11:03
21    
22    
23  Description:  Description:
24  This is a remake from scratch of SpaceDude's Jedi Force Grab plugin.  It has many additional features and optimizations, is less spammy, multilingual and requires fewer binds.  This is a remake from scratch of SpaceDude's Jedi Force Grab plugin.  It has many additional features and optimizations, is less spammy, multilingual and requires fewer binds.
25    
26    
 See it in Action:  
 http://www.game-monitor.com/search.php?search=grab_plus_version&type=variable&game=all&location=all  
   
   
27  Features:  Features:
28  Multilingual  Multilingual
29  Screenfade to indicate grab activity instead of chat spam.  Screenfade to indicate grab activity instead of chat spam.
# Line 105  Line 102 
102  Change Log:  Change Log:
103  Key (+ added | - removed | c changed | f fixed)  Key (+ added | - removed | c changed | f fixed)
104    
105  v1.2 (Nov 02, 2007)  v1.2.3 (Nov 21, 2007)
106    c: A few more small optimizations.
107    f: Bloodstream for choke wasn't aligned with player.
108    f: Bad message disconnect error when players were choked. ( stupid SVC_DAMAGE define )
109    
110    v1.2.2 (Nov 16, 2007)
111    c: A few small code optimizations.
112    
113    v1.2.1 (Nov 12, 2007)
114    f: Eliminated two run time warnings in the player prethink function.
115    
116    v1.2 (Nov 06, 2007)
117  +: Cvars gp_screen_fade and gp_glow to enable/disable these features.  +: Cvars gp_screen_fade and gp_glow to enable/disable these features.
118  +: Cvar gp_glow_a controls to control alpha of screenfade and glow.  +: Cvar gp_glow_a controls to control alpha of screenfade and glow.
119  +: Cvar gp_auto_choke to enable/disable choking automatically with +pull command.  +: Cvar gp_auto_choke to enable/disable choking automatically with +pull command.
120  c: Removed dependency of engine and fun modules.  Thanks to vittu for doing all the work.  c: Removed dependency of engine and fun modules.  Thanks to vittu for doing most of the work.
121  c: Made cvar names more consistent by adding more underscores.  c: Made cvar names more consistent by adding more underscores.
122  f: Fixed compile bug with amxx 1.8.0 (Compiles with 1.7x as well).  f: Fixed compile bug with amxx 1.8.0 (Compiles with 1.7.x as well).
123    
124  v1.1 (Oct 16, 2007)  v1.1 (Oct 16, 2007)
125  +: Grab a few types of entities other than players.  +: Grab a few types of entities other than players.
# Line 126  Line 134 
134  #include <amxmisc>  #include <amxmisc>
135  #include <fakemeta>  #include <fakemeta>
136    
137  #define VERSION "1.2b6"  new const VERSION[ ] = "1.2.3"
138    new const TRKCVAR[ ] = "grab_plus_version"
139  #define ADMIN ADMIN_LEVEL_A  #define ADMIN ADMIN_LEVEL_A
140    
141  #define TSK_CHKE 50  #define TSK_CHKE 50
142    
 #define SVC_DAMAGE 19  
143  #define SF_FADEOUT 0  #define SF_FADEOUT 0
144    
145  new client_data[33][4]  new client_data[33][4]
# Line 153  Line 161 
161    
162  //Pseudo Constants  //Pseudo Constants
163  new MAXPLAYERS  new MAXPLAYERS
164  new SVC_SCREENFADE, SVC_SCREENSHAKE  new SVC_SCREENFADE, SVC_SCREENSHAKE, WTF_DAMAGE
165    
166  public plugin_init( )  public plugin_init( )
167  {  {
168          register_plugin( "Grab+", VERSION, "Ian Cammarata" )          register_plugin( "Grab+", VERSION, "Ian Cammarata" )
169          register_cvar( "grab_plus_version", VERSION, FCVAR_SERVER )          register_cvar( TRKCVAR, VERSION, FCVAR_SERVER )
170          set_cvar_string( "grab_plus_version", VERSION )          set_cvar_string( TRKCVAR, VERSION )
171    
172          p_enabled = register_cvar( "gp_enabled", "1" )          p_enabled = register_cvar( "gp_enabled", "1" )
173          p_players_only = register_cvar( "gp_players_only", "0" )          p_players_only = register_cvar( "gp_players_only", "0" )
# Line 205  Line 213 
213    
214          SVC_SCREENFADE = get_user_msgid( "ScreenFade" )          SVC_SCREENFADE = get_user_msgid( "ScreenFade" )
215          SVC_SCREENSHAKE = get_user_msgid( "ScreenShake" )          SVC_SCREENSHAKE = get_user_msgid( "ScreenShake" )
216            WTF_DAMAGE = get_user_msgid( "Damage" )
         return PLUGIN_CONTINUE  
217  }  }
218    
219  public plugin_precache( )  public plugin_precache( )
220  {  {
221          precache_sound( "player/PL_PAIN2.WAV" )          precache_sound( "player/PL_PAIN2.WAV" )
         return PLUGIN_CONTINUE  
222  }  }
223    
224  public fm_player_prethink( id )  public fm_player_prethink( id )
225  {  {
226            new target
227          //Search for a target          //Search for a target
228          if ( client_data[id][GRABBED] == -1 )          if ( client_data[id][GRABBED] == -1 )
229          {          {
230                  new Float:orig[3], Float:ret[3]                  new Float:orig[3], Float:ret[3]
231                  pev( id, pev_origin, orig )                  get_view_pos( id, orig )
232                  pev( id, pev_view_ofs, ret )                  ret = vel_by_aim( id, 9999 )
233    
234                  for( new i = 0; i < 3; i++ ) orig[i] += ret[i]                  ret[0] += orig[0]
235                  //velocity_by_aim( id, 1, ret )                  ret[1] += orig[1]
236                  pev( id, pev_v_angle, ret )                  ret[2] += orig[2]
237                  for( new i = 0; i < 3; i++ ) ret[i] = orig[i] + ( ret[i] * 9999 )  
238                    target = traceline( orig, ret, id, ret )
                 engfunc( EngFunc_TraceLine, orig, ret, 0, id, 0 )  
                 new target = get_tr2( 0, TR_pHit )  
                 get_tr2( 0, TR_vecEndPos, ret )  
239    
240                  if( 0 < target <= MAXPLAYERS )                  if( 0 < target <= MAXPLAYERS )
241                  {                  {
242                          if( is_grabbed( target, id ) ) return PLUGIN_CONTINUE                          if( is_grabbed( target, id ) ) return FMRES_IGNORED
243                          set_grabbed( id, target )                          set_grabbed( id, target )
244                  }                  }
245                  else if( !get_pcvar_num( p_players_only ) )                  else if( !get_pcvar_num( p_players_only ) )
246                  {                  {
247                          new movetype                          new movetype
248                          if( target )                          if( target && pev_valid( target ) )
249                          {                          {
250                                  movetype = pev( target, pev_movetype )                                  movetype = pev( target, pev_movetype )
251                                  if( !( movetype == MOVETYPE_WALK || movetype == MOVETYPE_STEP || movetype == MOVETYPE_TOSS ) )                                  if( !( movetype == MOVETYPE_WALK || movetype == MOVETYPE_STEP || movetype == MOVETYPE_TOSS ) )
252                                          return PLUGIN_CONTINUE                                          return FMRES_IGNORED
253                          }                          }
254                          else                          else
255                          {                          {
256                                    target = 0
257                                  new ent = engfunc( EngFunc_FindEntityInSphere, -1, ret, 12.0 )                                  new ent = engfunc( EngFunc_FindEntityInSphere, -1, ret, 12.0 )
258                                  while( !target && ent > 0 )                                  while( !target && ent > 0 )
259                                  {                                  {
# Line 261  Line 266 
266                          }                          }
267                          if( target )                          if( target )
268                          {                          {
269                                  if( is_grabbed( target, id ) ) return PLUGIN_CONTINUE                                  if( is_grabbed( target, id ) ) return FMRES_IGNORED
270                                  set_grabbed( id, target )                                  set_grabbed( id, target )
271                          }                          }
272                  }                  }
273          }          }
274    
275            target = client_data[id][GRABBED]
276          //If they've grabbed something          //If they've grabbed something
277          if( client_data[id][GRABBED] > 0 )          if( target > 0 )
278          {          {
                 new target = client_data[id][GRABBED]  
279                  if( !pev_valid( target ) || ( pev( target, pev_health ) < 1 && pev( target, pev_max_health ) ) )                  if( !pev_valid( target ) || ( pev( target, pev_health ) < 1 && pev( target, pev_max_health ) ) )
280                  {                  {
281                          unset_grabbed( id )                          unset_grabbed( id )
282                          return PLUGIN_CONTINUE                          return FMRES_IGNORED
283                  }                  }
284    
285                  //Use key choke                  //Use key choke
# Line 281  Line 287 
287                          do_choke( id )                          do_choke( id )
288    
289                  //Push and pull                  //Push and pull
290                  if ( client_data[id][FLAGS] & CDF_IN_PULL )                  new cdf = client_data[id][FLAGS]
291                    if ( cdf & CDF_IN_PULL )
292                          do_pull( id )                          do_pull( id )
293                  else if ( client_data[id][FLAGS] & CDF_IN_PUSH )                  else if ( cdf & CDF_IN_PUSH )
294                          do_push( id )                          do_push( id )
295    
296                  grab_think( id )                  if( target > MAXPLAYERS ) grab_think( id )
297          }          }
         if( client_data[id][GRABBER] > 0 ) grab_think( client_data[id][GRABBER] )  
298    
299          return PLUGIN_CONTINUE          //If they're grabbed
300            target = client_data[id][GRABBER]
301            if( target > 0 ) grab_think( target )
302    
303            return FMRES_IGNORED
304  }  }
305    
306  public grab_think ( id )  public grab_think( id ) //id of the grabber
307  {  {
308          new target = client_data[id][GRABBED]          new target = client_data[id][GRABBED]
309    
# Line 301  Line 311 
311          if( pev( target, pev_movetype ) == MOVETYPE_FLY && !(pev( target, pev_button ) & IN_JUMP ) ) client_cmd( target, "+jump;wait;-jump" )          if( pev( target, pev_movetype ) == MOVETYPE_FLY && !(pev( target, pev_button ) & IN_JUMP ) ) client_cmd( target, "+jump;wait;-jump" )
312    
313          //Move targeted client          //Move targeted client
314          new Float:tmpvec[3], Float:tmpvec2[3], Float:dest[3], Float:torig[3], Float:tvel[3]          new Float:tmpvec[3], Float:tmpvec2[3], Float:torig[3], Float:tvel[3]
         new len = client_data[id][GRAB_LEN]  
315    
316          pev( id, pev_origin, dest )          get_view_pos( id, tmpvec )
         pev( id, pev_view_ofs, tmpvec )  
317    
318          //velocity_by_aim( id, len, tmpvec2 )          tmpvec2 = vel_by_aim( id, client_data[id][GRAB_LEN] )
         pev( id, pev_v_angle, tmpvec2 )  
         for( new i = 0; i < 3; i++ ) tmpvec2[i] *= len  
319    
320          torig = get_target_origin_f( target )          torig = get_target_origin_f( target )
321    
322          new force = get_pcvar_num( p_grab_force )          new force = get_pcvar_num( p_grab_force )
323    
324          for( new i = 0; i < 3; i++ )          tvel[0] = ( ( tmpvec[0] + tmpvec2[0] ) - torig[0] ) * force
325          {          tvel[1] = ( ( tmpvec[1] + tmpvec2[1] ) - torig[1] ) * force
326                  dest[i] += tmpvec[i] + tmpvec2[i]          tvel[2] = ( ( tmpvec[2] + tmpvec2[2] ) - torig[2] ) * force
                 tvel[i] = ( dest[i] - torig[i] ) * force  
         }  
327    
328          set_pev( target, pev_velocity, tvel )          set_pev( target, pev_velocity, tvel )
329  }  }
# Line 381  Line 385 
385          new target = client_data[id][GRABBED]          new target = client_data[id][GRABBED]
386          if( target > 0 )          if( target > 0 )
387          {          {
388                  new Float:vel[3]                  set_pev( target, pev_velocity, vel_by_aim( id, get_pcvar_num(p_throw_force) ) )
                 new len = get_pcvar_num(p_throw_force)  
   
                 //velocity_by_aim( id, get_pcvar_num(p_throw_force), vel )  
                 pev( id, pev_v_angle, vel )  
                 for( new i = 0; i < 3; i++ ) vel[i] *= len  
   
                 set_pev( target, pev_velocity, vel )  
389                  unset_grabbed( id )                  unset_grabbed( id )
390                  return PLUGIN_HANDLED                  return PLUGIN_HANDLED
391          }          }
392    
393          return PLUGIN_CONTINUE          return PLUGIN_CONTINUE
394  }  }
395    
# Line 507  Line 505 
505          if( client_data[id][FLAGS] & CDF_NO_CHOKE || id == target || target > MAXPLAYERS) return          if( client_data[id][FLAGS] & CDF_NO_CHOKE || id == target || target > MAXPLAYERS) return
506    
507          new dmg = get_pcvar_num( p_choke_dmg )          new dmg = get_pcvar_num( p_choke_dmg )
508          new Float:vec[3]          new vec[3]
509          get_target_origin_f( target )          FVecIVec( get_target_origin_f( target ), vec )
510    
511          message_begin( MSG_ONE, SVC_SCREENSHAKE, _, target )          message_begin( MSG_ONE, SVC_SCREENSHAKE, _, target )
512          write_short( 999999 ) //amount          write_short( 999999 ) //amount
# Line 526  Line 524 
524          write_byte( 200 ) //a          write_byte( 200 ) //a
525          message_end( )          message_end( )
526    
527          message_begin( MSG_ONE, SVC_DAMAGE, _, target )          message_begin( MSG_ONE, WTF_DAMAGE, _, target )
528          write_byte( 0 ) //damage armor          write_byte( 0 ) //damage armor
529          write_byte( dmg ) //damage health          write_byte( dmg ) //damage health
530          write_long( DMG_CRUSH ) //damage type          write_long( DMG_CRUSH ) //damage type
531          write_coord( floatround( vec[0] ) ) //origin[x]          write_coord( vec[0] ) //origin[x]
532          write_coord( floatround( vec[1] ) ) //origin[y]          write_coord( vec[1] ) //origin[y]
533          write_coord( floatround( vec[2] ) ) //origin[z]          write_coord( vec[2] ) //origin[z]
534          message_end( )          message_end( )
535    
536          message_begin( MSG_BROADCAST, SVC_TEMPENTITY )          message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
537          write_byte( TE_BLOODSTREAM )          write_byte( TE_BLOODSTREAM )
538          write_coord( floatround( vec[0] ) ) //pos.x          write_coord( vec[0] ) //pos.x
539          write_coord( floatround( vec[1] ) ) //pos.y          write_coord( vec[1] ) //pos.y
540          write_coord( floatround( vec[2] ) + 15 ) //pos.z          write_coord( vec[2] + 15 ) //pos.z
541          write_coord( random_num( 0, 255 ) ) //vec.x          write_coord( random_num( 0, 255 ) ) //vec.x
542          write_coord( random_num( 0, 255 ) ) //vec.y          write_coord( random_num( 0, 255 ) ) //vec.y
543          write_coord( random_num( 0, 255 ) ) //vec.z          write_coord( random_num( 0, 255 ) ) //vec.z
# Line 581  Line 579 
579          }          }
580    
581          //Safe to tp target to aim spot?          //Safe to tp target to aim spot?
582          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]
583          new bool:safe = false, i          new bool:safe = false, i
584    
585          pev( id, pev_origin, orig )          get_view_pos( id, orig )
586          pev( id, pev_view_ofs, tmpvec )          tmpvec = vel_by_aim( id, get_pcvar_num( p_min_dist ) )
         for( i = 0; i < 3; i++ ) tmpvec[i] += orig[i]  
   
         //velocity_by_aim( id, get_pcvar_num( p_min_dist ), tmpvec2 )  
         new min_dist = get_pcvar_num( p_min_dist )  
         pev( id, pev_v_angle, tmpvec2 )  
         for( new i = 0; i < 3; i++ ) tmpvec2[i] *= min_dist  
587    
588          for( new j = 1; j < 11 && !safe; j++ )          for( new j = 1; j < 11 && !safe; j++ )
589          {          {
590                  for( i = 0; i < 3; i++ )                  torig[0] = orig[0] + tmpvec[i] * j
591                          torig[i] = tmpvec[i] + tmpvec2[i] * j                  torig[1] = orig[1] + tmpvec[i] * j
592                    torig[2] = orig[2] + tmpvec[i] * j
593    
594                  engfunc( EngFunc_TraceLine, tmpvec, torig, 0, id, 0 )                  traceline( tmpvec, torig, id, trace_ret )
                 get_tr2( 0, TR_vecEndPos, trace_ret )  
595    
596                  if( get_distance_f( trace_ret, torig ) ) break                  if( get_distance_f( trace_ret, torig ) ) break
597    
# Line 609  Line 601 
601          }          }
602    
603          //Still not safe? Then find another safe spot somewhere around the grabber          //Still not safe? Then find another safe spot somewhere around the grabber
604            pev( id, pev_origin, orig )
605          new try[3]          new try[3]
606          orig[2] += 2          orig[2] += 2
607          while( try[2] < 3 && !safe )          while( try[2] < 3 && !safe )
# Line 621  Line 614 
614                                  case 2 : torig[i] = orig[i] - ( i == 2 ? 80 : 40 )                                  case 2 : torig[i] = orig[i] - ( i == 2 ? 80 : 40 )
615                          }                          }
616    
617                  engfunc( EngFunc_TraceLine, tmpvec, torig, 0, id, 0 )                  traceline( tmpvec, torig, id, trace_ret )
                 get_tr2( 0, TR_vecEndPos, trace_ret )  
618    
619                  engfunc( EngFunc_TraceHull, torig, torig, 0, HULL_HUMAN, 0, 0 )                  engfunc( EngFunc_TraceHull, torig, torig, 0, HULL_HUMAN, 0, 0 )
620                  if ( !get_tr2( 0, TR_StartSolid ) && !get_tr2( 0, TR_AllSolid ) && get_tr2( 0, TR_InOpen )                  if ( !get_tr2( 0, TR_StartSolid ) && !get_tr2( 0, TR_AllSolid ) && get_tr2( 0, TR_InOpen )
# Line 681  Line 673 
673          else if( client_data[id][GRABBER] )          else if( client_data[id][GRABBER] )
674                  unset_grabbed( client_data[id][GRABBER] )                  unset_grabbed( client_data[id][GRABBER] )
675  }  }
676    
677    stock traceline( const Float:vStart[3], const Float:vEnd[3], const pIgnore, Float:vHitPos[3] )
678    {
679            engfunc( EngFunc_TraceLine, vStart, vEnd, 0, pIgnore, 0 )
680            get_tr2( 0, TR_vecEndPos, vHitPos )
681            return get_tr2( 0, TR_pHit )
682    }
683    
684    stock get_view_pos( const id, Float:vViewPos[3] )
685    {
686            new Float:vOfs[3]
687            pev( id, pev_origin, vViewPos )
688            pev( id, pev_view_ofs, vOfs )
689    
690            vViewPos[0] += vOfs[0]
691            vViewPos[1] += vOfs[1]
692            vViewPos[2] += vOfs[2]
693    }
694    
695    stock Float:vel_by_aim( id, speed = 1 )
696    {
697            new Float:v1[3], Float:vBlah[3]
698            pev( id, pev_v_angle, v1 )
699            engfunc( EngFunc_AngleVectors, v1, v1, vBlah, vBlah )
700    
701            v1[0] *= speed
702            v1[1] *= speed
703            v1[2] *= speed
704    
705            return v1
706    }

Legend:
Removed from v.10  
changed lines
  Added in v.28

Contact
ViewVC Help
Powered by ViewVC 1.0.4