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

Annotation of /grab_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (view) (download)

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

Contact
ViewVC Help
Powered by ViewVC 1.0.4