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

Annotation of /grab_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (view) (download)

1 : ian 1 /*
2 :     Grab+ v1.1
3 :     Copyright (C) 2007 Ian (Juan) Cammarata
4 :    
5 :     This program is free software; you can redistribute it and/or modify it under
6 :     the terms of the GNU General Public License as published by the Free Software
7 :     Foundation; either version 2 of the License, or (at your option) any later
8 :     version.
9 :    
10 :     This program is distributed in the hope that it will be useful, but WITHOUT ANY
11 :     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12 :     PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 :    
14 :     You should have received a copy of the GNU General Public License along with
15 :     this program; go to http://www.opensource.org/licenses/gpl-license.php
16 :     --------------------------------------------------------------------------------
17 :    
18 :     http://ian.cammarata.us/projects/grab_plus
19 :     Oct 16 21:03
20 :    
21 :    
22 :     Description:
23 :     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.
24 :    
25 :    
26 :     See it in Action:
27 :     http://www.game-monitor.com/search.php?search=grab_plus_version&type=variable&game=all&location=all
28 :    
29 :    
30 :     Features:
31 :     Multilingual
32 :     Screenfade to indicate grab activity instead of chat spam.
33 :     Can grab players off a ladder.
34 :     Automatically choke by holding down +pull while at min distance.
35 :     Choke with use key.
36 :     Throw with drop.
37 :     Can't have mutliple admins grabbing the same player.
38 :     Auto drop on death.
39 :     Grab entities other than players, such as bombs, weapons, and hostages.
40 :    
41 :    
42 :     Commands:
43 :    
44 :     +grab : Grab something for as long as you hold down the key.
45 :     grab_toggle : Same as +grab but toggles.
46 :     amx_grab <name> : Grab client by name or id and teleport them to you. Use +grab or grab_toggle key to release.
47 :    
48 :     +pull/+push (or invnext/invprev): Pulls/pushes the grabbed towards/away from you as you hold the button.
49 :    
50 :     +use : Chokes the grabbed (it damages the grabbed with 5 (cvar: gp_chokedmg) hp per 1.5 (cvar: gp_choketime) seconds)
51 :     drop - Throws the grabbed with 1500 velocity. (cvar: gp_throwforce)
52 :    
53 :    
54 :     Cvars (First value is default):
55 :     gp_enabled <1|0> Enables all plugin functionality.
56 :     gp_playersonly <0|1> Disables admins grabbing entities other than players.
57 :    
58 :     gp_min_dist <90|...> Min distance between the grabber and grabbed.
59 :     gp_grabforce <8|...> Sets the amount of force used when grabbing players.
60 :     gp_throwforce <1500|...> Sets the power used when throwing players.
61 :     gp_speed <5|...> How fast the grabbed moves when using push and pull.
62 :    
63 :     gp_choketime <1.5|...> Time frequency for choking.
64 :     gp_chokedmg <5|...> Amount of damage done with each choke.
65 :    
66 :     gp_glow_r <50|0-255> Sets red amount for glow.
67 :     gp_glow_g <0|0-255> Sets green amount for glow.
68 :     gp_glow_b <0|0-255> Sets blue amount for glow.
69 :    
70 :    
71 :     Notes:
72 :     Make sure you place the grab_plus.txt file in addons\amxmodx\data\lang
73 :    
74 :    
75 :     Credits:
76 : ian 5 Thanks to vittu for contributing code (changed all engine/fun module stuff to fakemeta).
77 :    
78 : ian 1 Thanks to all the coders who worked on the original Jedi Force Grab plugin for all their ideas:
79 :     SpaceDude
80 :     KCE
81 :     KRoTaL
82 :     BOB_SLAYER
83 :     kosmo111
84 :    
85 :    
86 :     Supported Languages:
87 :     1337 (100%) - Thanks to l337newb
88 :     Brazilian Portuguese (100%) - Thanks to Arion
89 :     Danish (100%) - Thanks to nellerbabz
90 :     Dutch (100%) - Thanks to BlackMilk
91 :     English (100%)
92 :     Finnish (100%) - Thanks to Pro Patria Finland
93 :     French (100%) - Thanks to connorr
94 :     German (100%) - Thanks to SchlumPF*
95 :     Russian (100%) - Thanks to `666
96 :     Spanish (100%) - Hope these don't suck.
97 :     Swedish (100%) - Thanks to Bend3r
98 :    
99 :    
100 :     Change Log:
101 :     Key (+ added | - removed | c changed | f fixed)
102 :    
103 : ian 5 v1.2 (Nov ??, 2007)
104 :     +: Cvars gp_screenfade and gp_glow to enable/disable these features.
105 :     +: Cvar gp_glow_a controls to control alpha of screenfade and glow.
106 :     c: Removed dependency of engine and fun modules. Thanks to vittu for doing all the work.
107 :     f: Fixed compile bug with amxx 1.8.0 (Compiles with 1.7x as well).
108 :    
109 : ian 1 v1.1 (Oct 16, 2007)
110 :     +: Grab a few types of entities other than players.
111 :     +: Cvar gp_playersonly.
112 :    
113 :     v1.0 (Oct 13, 2007)
114 :     !: Initial release
115 :    
116 :     */
117 :    
118 :     #include <amxmodx>
119 :     #include <amxmisc>
120 :     #include <fakemeta>
121 :    
122 : ian 7 #define VERSION "1.2b3"
123 : ian 1 #define ADMIN ADMIN_LEVEL_A
124 :    
125 :     #define TSK_CHKE 50
126 :    
127 : ian 5 #define SVC_DAMAGE 19
128 : ian 1 #define SF_FADEOUT 0
129 :    
130 :     new client_data[33][4]
131 :     #define GRABBED 0
132 :     #define GRABBER 1
133 :     #define GRAB_LEN 2
134 :     #define FLAGS 3
135 :    
136 :     #define CDF_IN_PUSH (1<<0)
137 :     #define CDF_IN_PULL (1<<1)
138 :     #define CDF_NO_CHOKE (1<<2)
139 :    
140 :     //Cvar Pointers
141 :     new p_enabled, p_playersonly
142 :     new p_throwforce, p_mindist, p_speed, p_grabforce
143 :     new p_choketime, p_chokedmg
144 : ian 5 new p_glow_r, p_glow_b, p_glow_g, p_glow_a
145 :     new p_fade, p_glow
146 : ian 1
147 :     //Pseudo Constants
148 :     new MAXPLAYERS
149 : ian 5 new SVC_SCREENFADE, SVC_SCREENSHAKE
150 : ian 1
151 :     public plugin_init( )
152 :     {
153 :     register_plugin( "Grab+", VERSION, "Ian Cammarata" )
154 :     register_cvar( "grab_plus_version", VERSION, FCVAR_SERVER )
155 :     set_cvar_string( "grab_plus_version", VERSION )
156 :    
157 :     p_enabled = register_cvar( "gp_enabled", "1" )
158 :     p_playersonly = register_cvar( "gp_playersonly", "0" )
159 :    
160 :     p_mindist = register_cvar ( "gp_min_dist", "90" )
161 :     p_throwforce = register_cvar( "gp_throwforce", "1500" )
162 :     p_grabforce = register_cvar( "gp_grabforce", "8" )
163 :     p_speed = register_cvar( "gp_speed", "5" )
164 :    
165 :     p_choketime = register_cvar( "gp_choketime", "1.5" )
166 :     p_chokedmg = register_cvar( "gp_chokedmg", "5" )
167 :    
168 :     p_glow_r = register_cvar( "gp_glow_r", "50" )
169 :     p_glow_g = register_cvar( "gp_glow_g", "0" )
170 :     p_glow_b = register_cvar( "gp_glow_b", "0" )
171 : ian 5 p_glow_a = register_cvar( "gp_glow_a", "200" )
172 : ian 1
173 : ian 5 p_fade = register_cvar( "gp_screenfade", "1" )
174 :     p_glow = register_cvar( "gp_glow", "1" )
175 :    
176 : ian 1 register_clcmd( "amx_grab", "force_grab", ADMIN, "Grab client & teleport to you." )
177 :     register_clcmd( "grab_toggle", "grab_toggle", ADMIN, "press once to grab and again to release" )
178 :     register_clcmd( "+grab", "grab", ADMIN, "bind a key to +grab" )
179 :     register_clcmd( "-grab", "unset_grabbed" )
180 :    
181 :     register_clcmd( "+push", "push", ADMIN, "bind a key to +push" )
182 :     register_clcmd( "-push", "push" )
183 :     register_clcmd( "+pull", "pull", ADMIN, "bind a key to +pull" )
184 :     register_clcmd( "-pull", "pull" )
185 :     register_clcmd( "push", "push2" )
186 :     register_clcmd( "pull", "pull2" )
187 :    
188 :     register_clcmd( "drop" ,"throw" )
189 :    
190 :     register_event( "DeathMsg", "DeathMsg", "a" )
191 :    
192 :     register_dictionary( "grab_plus.txt" )
193 :    
194 :     MAXPLAYERS = get_maxplayers()
195 :    
196 :     SVC_SCREENFADE = get_user_msgid( "ScreenFade" )
197 :     SVC_SCREENSHAKE = get_user_msgid( "ScreenShake" )
198 :    
199 :     return PLUGIN_CONTINUE
200 :     }
201 :    
202 :     public plugin_precache( )
203 :     {
204 :     precache_sound( "player/PL_PAIN2.WAV" )
205 :     return PLUGIN_CONTINUE
206 :     }
207 :    
208 :     public client_PreThink( id )
209 :     {
210 :     //Search for a target
211 :     if ( client_data[id][GRABBED] == -1 )
212 :     {
213 :     new Float:orig[3], Float:ret[3]
214 : ian 5 pev( id, pev_origin, orig )
215 :     pev( id, pev_view_ofs, ret )
216 : ian 1
217 :     for( new i = 0; i < 3; i++ ) orig[i] += ret[i]
218 : ian 5 engfunc( EngFunc_GetAimVector, id, 1, ret )
219 : ian 1 for( new i = 0; i < 3; i++ ) ret[i] = orig[i] + ( ret[i] * 9999 )
220 :    
221 : ian 7 engfunc( EngFunc_TraceLine, orig, ret, 0, id, 0 )
222 :     new target = get_tr2( 0, TR_pHit )
223 :     get_tr2( 0, TR_vecEndPos, ret )
224 : ian 1
225 :     if( 0 < target <= MAXPLAYERS )
226 :     {
227 :     if( is_grabbed( target, id ) ) return PLUGIN_CONTINUE
228 :     set_grabbed( id, target )
229 :     }
230 :     else if( !get_pcvar_num( p_playersonly ) )
231 :     {
232 :     new movetype
233 :     if( target )
234 :     {
235 :     movetype = pev( target, pev_movetype )
236 :     if( !( movetype == MOVETYPE_WALK || movetype == MOVETYPE_STEP || movetype == MOVETYPE_TOSS ) )
237 :     return PLUGIN_CONTINUE
238 :     }
239 :     else
240 :     {
241 : ian 5 new ent = engfunc( EngFunc_FindEntityInSphere, -1, ret, 12.0 )
242 : ian 1 while( !target && ent > 0 )
243 :     {
244 :     movetype = pev( ent, pev_movetype )
245 :     if( ( movetype == MOVETYPE_WALK || movetype == MOVETYPE_STEP || movetype == MOVETYPE_TOSS )
246 :     && ent != id )
247 :     target = ent
248 : ian 5 ent = engfunc( EngFunc_FindEntityInSphere, ent, ret, 12.0 )
249 : ian 1 }
250 :     }
251 :     if( target )
252 :     {
253 :     if( is_grabbed( target, id ) ) return PLUGIN_CONTINUE
254 :     set_grabbed( id, target )
255 :     }
256 :     }
257 :     }
258 :     //If they've grabbed something
259 :     if( client_data[id][GRABBED] > 0 )
260 :     {
261 :     new target = client_data[id][GRABBED]
262 :     if( !pev_valid( target ) || ( pev( target, pev_health ) < 1 && pev( target, pev_max_health ) ) )
263 :     {
264 :     unset_grabbed( id )
265 :     return PLUGIN_CONTINUE
266 :     }
267 :    
268 :     //Use key choke
269 :     if( pev( id, pev_button ) & IN_USE )
270 :     do_choke( id )
271 :    
272 :     //Push and pull
273 :     if ( client_data[id][FLAGS] & CDF_IN_PULL )
274 :     do_pull( id )
275 :     else if ( client_data[id][FLAGS] & CDF_IN_PUSH )
276 :     do_push( id )
277 :    
278 :     grab_think( id )
279 :     }
280 :     if( client_data[id][GRABBER] > 0 ) grab_think( client_data[id][GRABBER] )
281 :    
282 :     return PLUGIN_CONTINUE
283 :     }
284 :    
285 :     public grab_think ( id )
286 :     {
287 :     new target = client_data[id][GRABBED]
288 :    
289 :     //Keep grabbed clients from sticking to ladders
290 :     if( pev( target, pev_movetype ) == MOVETYPE_FLY && !(pev( target, pev_button ) & IN_JUMP ) ) client_cmd( target, "+jump;wait;-jump" )
291 :    
292 :     //Move targeted client
293 :     new Float:tmpvec[3], Float:tmpvec2[3], Float:dest[3], Float:torig[3], Float:tvel[3]
294 :     new len = client_data[id][GRAB_LEN]
295 :    
296 : ian 5 pev( id, pev_origin, dest )
297 :     pev( id, pev_view_ofs, tmpvec )
298 : ian 6 engfunc( EngFunc_GetAimVector, id, len, tmpvec2 )
299 : ian 1 torig = get_target_origin_f( target )
300 :    
301 :     new force = get_pcvar_num( p_grabforce )
302 :    
303 :     for( new i = 0; i < 3; i++ )
304 :     {
305 :     dest[i] += tmpvec[i] + tmpvec2[i]
306 :     tvel[i] = ( dest[i] - torig[i] ) * force
307 :     }
308 :    
309 : ian 5 set_pev( target, pev_velocity, tvel )
310 : ian 1 }
311 :    
312 :     stock Float:get_target_origin_f( id )
313 :     {
314 :     new Float:orig[3]
315 : ian 5 pev( id, pev_origin, orig )
316 : ian 1
317 :     //If grabbed is not a player, move origin to center
318 :     if( id > MAXPLAYERS )
319 :     {
320 :     new Float:mins[3], Float:maxs[3]
321 : ian 5 pev( id, pev_mins, mins )
322 :     pev( id, pev_maxs, maxs )
323 : ian 1
324 :     if( !mins[2] ) orig[2] += maxs[2] / 2
325 :     }
326 :    
327 :     return orig
328 :     }
329 :    
330 :     public grab_toggle( id, level, cid )
331 :     {
332 :     if( !client_data[id][GRABBED] ) grab( id, level, cid )
333 :     else unset_grabbed( id )
334 :    
335 :     return PLUGIN_HANDLED
336 :     }
337 :    
338 :     public grab( id, level, cid )
339 :     {
340 :     if( !cmd_access( id, level, cid, 1 ) || !get_pcvar_num( p_enabled ) ) return PLUGIN_HANDLED
341 :    
342 :     if ( !client_data[id][GRABBED] ) client_data[id][GRABBED] = -1
343 :     screenfade_in( id )
344 :    
345 :     return PLUGIN_HANDLED
346 :     }
347 :    
348 :     public screenfade_in( id )
349 :     {
350 : ian 5 if( get_pcvar_num( p_fade ) )
351 :     {
352 :     message_begin( MSG_ONE, SVC_SCREENFADE, _, id )
353 :     write_short( 10000 ) //duration
354 :     write_short( 0 ) //hold
355 :     write_short( SF_FADE_IN + SF_FADE_ONLYONE ) //flags
356 :     write_byte( get_pcvar_num( p_glow_r ) ) //r
357 :     write_byte( get_pcvar_num( p_glow_g ) ) //g
358 :     write_byte( get_pcvar_num( p_glow_b ) ) //b
359 :     write_byte( get_pcvar_num( p_glow_a ) / 2 ) //a
360 :     message_end( )
361 :     }
362 : ian 1 }
363 :    
364 :     public throw( id )
365 :     {
366 :     new target = client_data[id][GRABBED]
367 :     if( target > 0 )
368 :     {
369 :     new Float:pVelocity[3]
370 : ian 5 engfunc( EngFunc_GetAimVector, id, get_pcvar_num( p_throwforce ), pVelocity )
371 :     set_pev( target, pev_velocity, pVelocity )
372 : ian 1 unset_grabbed( id )
373 :     return PLUGIN_HANDLED
374 :     }
375 :     return PLUGIN_CONTINUE
376 :     }
377 :    
378 :     public unset_grabbed( id )
379 :     {
380 :     new target = client_data[id][GRABBED]
381 :     if( target > 0 && pev_valid( target ) )
382 :     {
383 : ian 5 set_pev( target, pev_renderfx, kRenderFxNone )
384 :     set_pev( target, pev_rendercolor, {255.0, 255.0, 255.0} )
385 :     set_pev( target, pev_rendermode, kRenderNormal )
386 :     set_pev( target, pev_renderamt, 16.0 )
387 :    
388 : ian 1 if( 0 < target <= MAXPLAYERS )
389 :     client_data[target][GRABBER] = 0
390 :     }
391 :     client_data[id][GRABBED] = 0
392 :    
393 : ian 5 if( get_pcvar_num( p_fade ) )
394 :     {
395 :     message_begin( MSG_ONE, SVC_SCREENFADE, _, id )
396 :     write_short( 10000 ) //duration
397 :     write_short( 0 ) //hold
398 :     write_short( SF_FADEOUT ) //flags
399 :     write_byte( get_pcvar_num( p_glow_r ) ) //r
400 :     write_byte( get_pcvar_num( p_glow_g ) ) //g
401 :     write_byte( get_pcvar_num( p_glow_b ) ) //b
402 :     write_byte( get_pcvar_num( p_glow_a ) / 2 ) //a
403 :     message_end( )
404 :     }
405 : ian 1 }
406 :    
407 :     //Grabs onto someone
408 :     public set_grabbed( id, target )
409 :     {
410 : ian 5 if( get_pcvar_num( p_glow ) )
411 :     {
412 :     new Float:color[3]
413 :     color[0] = get_pcvar_float( p_glow_r )
414 :     color[1] = get_pcvar_float( p_glow_g )
415 :     color[2] = get_pcvar_float( p_glow_b )
416 : ian 6 set_pev( target, pev_renderfx, kRenderFxGlowShell )
417 :     set_pev( target, pev_rendercolor, color )
418 :     set_pev( target, pev_rendermode, kRenderTransColor )
419 :     set_pev( target, pev_renderamt, get_pcvar_float( p_glow_a ) )
420 : ian 5 }
421 : ian 1
422 :     if( 0 < target <= MAXPLAYERS )
423 :     client_data[target][GRABBER] = id
424 :     client_data[id][FLAGS] = 0
425 :     client_data[id][GRABBED] = target
426 : ian 5 new Float:torig[3], Float:orig[3]
427 :     pev( target, pev_origin, torig )
428 :     pev( id, pev_origin, orig )
429 :     client_data[id][GRAB_LEN] = floatround( get_distance_f( torig, orig ) )
430 : ian 1 if( client_data[id][GRAB_LEN] < get_pcvar_num( p_mindist ) ) client_data[id][GRAB_LEN] = get_pcvar_num( p_mindist )
431 :     }
432 :    
433 :     public push( id )
434 :     {
435 :     client_data[id][FLAGS] ^= CDF_IN_PUSH
436 :     return PLUGIN_HANDLED
437 :     }
438 :    
439 :     public pull( id )
440 :     {
441 :     client_data[id][FLAGS] ^= CDF_IN_PULL
442 :     return PLUGIN_HANDLED
443 :     }
444 :    
445 :     public push2( id )
446 :     {
447 :     if( client_data[id][GRABBED] > 0 )
448 :     {
449 :     do_push( id )
450 :     return PLUGIN_HANDLED
451 :     }
452 :     return PLUGIN_CONTINUE
453 :     }
454 :    
455 :     public pull2( id )
456 :     {
457 :     if( client_data[id][GRABBED] > 0 )
458 :     {
459 :     do_pull( id )
460 :     return PLUGIN_HANDLED
461 :     }
462 :     return PLUGIN_CONTINUE
463 :     }
464 :    
465 :     public do_push( id )
466 :     if( client_data[id][GRAB_LEN] < 9999 )
467 :     client_data[id][GRAB_LEN] += get_pcvar_num( p_speed )
468 :    
469 :     public do_pull( id )
470 :     {
471 :     new mindist = get_pcvar_num( p_mindist )
472 :     new len = client_data[id][GRAB_LEN]
473 :    
474 :     if( len > mindist )
475 :     {
476 :     len -= get_pcvar_num( p_speed )
477 :     if( len < mindist ) len = mindist
478 :     client_data[id][GRAB_LEN] = len
479 :     }
480 :     else do_choke( id )
481 :     }
482 :    
483 :     public do_choke( id )
484 :     {
485 :     new target = client_data[id][GRABBED]
486 :     if( client_data[id][FLAGS] & CDF_NO_CHOKE || id == target || target > MAXPLAYERS) return
487 :    
488 :     new dmg = get_pcvar_num( p_chokedmg )
489 :     new Float:vec[3]
490 :     get_target_origin_f( target )
491 :    
492 :     message_begin( MSG_ONE, SVC_SCREENSHAKE, _, target )
493 :     write_short( 999999 ) //amount
494 :     write_short( 9999 ) //duration
495 :     write_short( 999 ) //frequency
496 :     message_end( )
497 :    
498 :     message_begin( MSG_ONE, SVC_SCREENFADE, _, target )
499 :     write_short( 9999 ) //duration
500 :     write_short( 100 ) //hold
501 :     write_short( SF_FADE_MODULATE ) //flags
502 :     write_byte( get_pcvar_num( p_glow_r ) ) //r
503 :     write_byte( get_pcvar_num( p_glow_g ) ) //g
504 :     write_byte( get_pcvar_num( p_glow_b ) ) //b
505 :     write_byte( 200 ) //a
506 :     message_end( )
507 :    
508 :     message_begin( MSG_ONE, SVC_DAMAGE, _, target )
509 :     write_byte( 0 ) //damage armor
510 :     write_byte( dmg ) //damage health
511 :     write_long( DMG_CRUSH ) //damage type
512 :     write_coord( floatround( vec[0] ) ) //origin[x]
513 :     write_coord( floatround( vec[1] ) ) //origin[y]
514 :     write_coord( floatround( vec[2] ) ) //origin[z]
515 :     message_end( )
516 :    
517 :     message_begin( MSG_BROADCAST, SVC_TEMPENTITY )
518 :     write_byte( TE_BLOODSTREAM )
519 :     write_coord( floatround( vec[0] ) ) //pos.x
520 :     write_coord( floatround( vec[1] ) ) //pos.y
521 :     write_coord( floatround( vec[2] ) + 15 ) //pos.z
522 :     write_coord( random_num( 0, 255 ) ) //vec.x
523 :     write_coord( random_num( 0, 255 ) ) //vec.y
524 :     write_coord( random_num( 0, 255 ) ) //vec.z
525 :     write_byte( 70 ) //col index
526 :     write_byte( random_num( 50, 250 ) ) //speed
527 :     message_end( )
528 :    
529 :     new health = pev( target, pev_health ) - dmg
530 :     set_pev( target, pev_health, float( health ) )
531 :     if( health < 1 ) dllfunc( DLLFunc_ClientKill, target )
532 :    
533 :     emit_sound( target, CHAN_BODY, "player/PL_PAIN2.WAV", VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
534 :    
535 :     client_data[id][FLAGS] ^= CDF_NO_CHOKE
536 :     set_task( get_pcvar_float( p_choketime ), "clear_no_choke", TSK_CHKE + id )
537 :     }
538 :    
539 :     public clear_no_choke( tskid )
540 :     {
541 :     new id = tskid - TSK_CHKE
542 :     client_data[id][FLAGS] ^= CDF_NO_CHOKE
543 :     }
544 :    
545 :     //Grabs the client and teleports them to the admin
546 :     public force_grab(id, level, cid)
547 :     {
548 :     if( !cmd_access( id, level, cid, 1 ) || !get_pcvar_num( p_enabled ) ) return PLUGIN_HANDLED
549 :    
550 :     new arg[33]
551 :     read_argv( 1, arg, 32 )
552 :    
553 :     new targetid = cmd_target( id, arg, 1 )
554 :    
555 :     if( is_grabbed( targetid, id ) ) return PLUGIN_HANDLED
556 :     if( !is_user_alive( targetid ) )
557 :     {
558 :     client_print( id, print_console, "[AMXX] %L", id, "COULDNT" )
559 :     return PLUGIN_HANDLED
560 :     }
561 :    
562 :     //Safe to tp target to aim spot?
563 :     new Float:tmpvec[3], Float:tmpvec2[3], Float:orig[3], Float:torig[3], Float:trace_ret[3]
564 :     new bool:safe = false, i
565 :    
566 : ian 5 pev( id, pev_origin, orig )
567 :     pev( id, pev_view_ofs, tmpvec )
568 : ian 1 for( i = 0; i < 3; i++ ) tmpvec[i] += orig[i]
569 : ian 5 engfunc( EngFunc_GetAimVector, id, get_pcvar_num( p_mindist ), tmpvec2 )
570 : ian 1
571 :     for( new j = 1; j < 11 && !safe; j++ )
572 :     {
573 :     for( i = 0; i < 3; i++ )
574 :     torig[i] = tmpvec[i] + tmpvec2[i] * j
575 : ian 5
576 : ian 7 engfunc( EngFunc_TraceLine, tmpvec, torig, 0, id, 0 )
577 :     get_tr2( 0, TR_vecEndPos, trace_ret )
578 :    
579 : ian 1 if( get_distance_f( trace_ret, torig ) ) break
580 : ian 5 if( !_trace_hull( torig, HULL_HUMAN ) ) safe = true
581 : ian 1 }
582 :    
583 :     //Still not safe? Then find another safe spot somewhere around the grabber
584 :     new try[3]
585 :     orig[2] += 2
586 :     while( try[2] < 3 && !safe )
587 :     {
588 :     for( i = 0; i < 3; i++ )
589 :     switch( try[i] )
590 :     {
591 :     case 0 : torig[i] = orig[i] + ( i == 2 ? 80 : 40 )
592 :     case 1 : torig[i] = orig[i]
593 :     case 2 : torig[i] = orig[i] - ( i == 2 ? 80 : 40 )
594 :     }
595 :    
596 : ian 7 engfunc( EngFunc_TraceLine, tmpvec, torig, 0, id, 0 )
597 :     get_tr2( 0, TR_vecEndPos, trace_ret )
598 : ian 1
599 : ian 5 if( !_trace_hull( torig, HULL_HUMAN ) && !get_distance_f( trace_ret, torig ) ) safe = true
600 :    
601 : ian 1 try[0]++
602 :     if( try[0] == 3 )
603 :     {
604 :     try[0] = 0
605 :     try[1]++
606 :     if( try[1] == 3 )
607 :     {
608 :     try[1] = 0
609 :     try[2]++
610 :     }
611 :     }
612 :     }
613 :    
614 :     if( safe )
615 :     {
616 : ian 5 set_pev( targetid, pev_origin, torig )
617 : ian 1 set_grabbed( id, targetid )
618 :     screenfade_in( id )
619 :     }
620 :     else client_print( id, print_chat, "[AMXX] %L", id, "COULDNT" )
621 :    
622 :     return PLUGIN_HANDLED
623 :     }
624 :    
625 :     public is_grabbed( target, grabber )
626 :     {
627 :     for( new i = 1; i <= MAXPLAYERS; i++ )
628 :     if( client_data[i][GRABBED] == target )
629 :     {
630 :     client_print( grabber, print_chat, "[AMXX] %L", grabber, "ALREADY" )
631 :     unset_grabbed( grabber )
632 :     return true
633 :     }
634 :     return false
635 :     }
636 :    
637 :     public DeathMsg( )
638 :     kill_grab( read_data( 2 ) )
639 :    
640 :     public client_disconnect( id )
641 :     {
642 :     kill_grab( id )
643 :     return PLUGIN_CONTINUE
644 :     }
645 :    
646 :     public kill_grab( id )
647 :     {
648 :     //If given client has grabbed, or has a grabber, unset it
649 :     if( client_data[id][GRABBED] )
650 :     unset_grabbed( id )
651 :     else if( client_data[id][GRABBER] )
652 :     unset_grabbed( client_data[id][GRABBER] )
653 :     }
654 : ian 5
655 :     //Complements of vittu
656 :     //Complements of fakemeta_util, cause i was too lazy to add this in as not a function
657 :     _trace_hull(const Float:origin[3], hull, ignoredent = 0, ignoremonsters = 0) {
658 :     new result = 0;
659 :     engfunc(EngFunc_TraceHull, origin, origin, ignoremonsters, hull, ignoredent > 0 ? ignoredent : 0, 0);
660 :    
661 :     if (get_tr2(0, TR_StartSolid))
662 :     result += 1;
663 :     if (get_tr2(0, TR_AllSolid))
664 :     result += 2;
665 :     if (!get_tr2(0, TR_InOpen))
666 :     result += 4;
667 :    
668 :     return result;
669 :     }

Contact
ViewVC Help
Powered by ViewVC 1.0.4