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

Annotation of /grab_plus.sma

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (view) (download)

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

Contact
ViewVC Help
Powered by ViewVC 1.0.4