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

Annotation of /grab_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (view) (download)

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

Contact
ViewVC Help
Powered by ViewVC 1.0.4