Advertisement
crywolfy

manual_unstuck.sma

Oct 14th, 2014
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.06 KB | None | 0 0
  1. /*  AMX Mod X
  2. *   UnStuck Plugin
  3. *
  4. *   by the AMX Mod X Development Team
  5. *
  6. *   This file is part of AMX Mod X.
  7. *  
  8. *  
  9. *   This program is free software; you can redistribute it and/or modify it
  10. *   under the terms of the GNU General Public License as published by the
  11. *   Free Software Foundation; either version 2 of the License, or (at
  12. *   your option) any later version.
  13. *  
  14. *   This program is distributed in the hope that it will be useful, but
  15. *   WITHOUT ANY WARRANTY; without even the implied warranty of
  16. *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. *   General Public License for more details.
  18. *  
  19. *   You should have received a copy of the GNU General Public License
  20. *   along with this program; if not, write to the Free Software Foundation,
  21. *   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *  
  23. *   In addition, as a special exception, the author gives permission to
  24. *   link the code of this program with the Half-Life Game Engine ("HL
  25. *   Engine") and Modified Game Libraries ("MODs") developed by Valve,
  26. *   L.L.C ("Valve"). You must obey the GNU General Public License in all
  27. *   respects for all of the code used other than the HL Engine and MODs
  28. *   from Valve. If you modify this file, you may extend this exception
  29. *   to your version of the file, but you are not obligated to do so. If
  30. *   you do not wish to do so, delete this exception statement from your
  31. *   version.
  32. *
  33. *   Official Release Link and Changelog
  34. *   http://www.extreamcs.com/forum/pluginuri-extream/amxx-untuck-t265448.html
  35. *  
  36. */
  37.  
  38. #include < amxmodx >
  39. #include < fakemeta >
  40.  
  41. // Defines should be first
  42. #define MAX_CLIENTS     32
  43. #define START_DISTANCE  32
  44. #define MAX_ATTEMPTS    128
  45. #define GetPlayerHullSize(%1)  ( ( pev ( %1, pev_flags ) & FL_DUCKING ) ? HULL_HEAD : HULL_HUMAN )
  46.  
  47. // Globals needed
  48. new
  49.     g_MsgSync;
  50.  
  51. // pCvars begins
  52. new
  53.     pCvar_Function,
  54.     pCvar_UnstEff,
  55.     pCvar_UnstWait,
  56.     pCvar_Announce [ 5 ];
  57.  
  58. new Float:gf_LastCmdTime [ MAX_CLIENTS + 1 ];
  59.  
  60. enum Coord_e
  61. {
  62.     Float:x,
  63.     Float:y,
  64.     Float:z
  65. };
  66.  
  67. /************************************************************************************/
  68. // If you use a Zombie Mod and don't want zombies to cheat using untuck command
  69. // Uncomment the Mod you Use
  70.  
  71. // Default NO Mod
  72. #define USE_DEFAULT
  73.  
  74. // Zombie Plague 4.3 and 5.0
  75. // #define USE_ZPMOD
  76.  
  77. // Biohazard [ALL Version]
  78. // #define USE_BIOMOD
  79.  
  80. // Don't touch
  81. #if defined USE_ZPMOD
  82.     #tryinclude < zombieplague >
  83. #endif
  84.  
  85. #if defined USE_BIOMOD
  86.     #tryinclude < biohazard >
  87. #endif
  88. /************************************************************************************/
  89.  
  90.  
  91. // Plugins begins
  92. public plugin_init ( )
  93. {
  94.     register_plugin ( "AMXX Unstuck", "1.7.2", "AMXX Dev Builder" );    // & CryWolf
  95.    
  96.     // Main plugin
  97.     pCvar_Function  = register_cvar ( "amx_unstuck", "1" );
  98.     pCvar_UnstEff   = register_cvar ( "amx_autounstuckeffects", "1" );
  99.     pCvar_UnstWait  = register_cvar ( "amx_autounstuckwait", "7.0" );
  100.    
  101.     // Message pCvars
  102.     pCvar_Announce [ 0 ]    = register_cvar ( "amx_unst_announce", "1" );
  103.     pCvar_Announce [ 1 ]    = register_cvar ( "amx_ann_time", "120" );
  104.     pCvar_Announce [ 2 ]    = register_cvar ( "amx_ann_type", "1" );
  105.     pCvar_Announce [ 3 ]    = register_cvar ( "amx_ann_hold", "15.0" );
  106.     pCvar_Announce [ 4 ]    = register_cvar ( "amx_ann_effects", "0" );
  107.    
  108.     // Chat commands
  109.     register_clcmd ( "say /unstuck", "FunC_CheckStuck", -1 );
  110.     register_clcmd ( "say /stuck", "FunC_CheckStuck", -1 );
  111.     register_clcmd ( "say /unblock", "FunC_CheckStuck", -1 );
  112.    
  113.    
  114.     if ( get_pcvar_num ( pCvar_Announce [ 0 ] ) )
  115.     {
  116.         g_MsgSync = CreateHudSyncObj ( );
  117.         set_task ( get_pcvar_float ( pCvar_Announce [ 1 ] ), "ShowMessage", 0, _, _, "b", _ );
  118.     }
  119. }
  120.  
  121. public ShowMessage ( )
  122. {
  123.     switch ( get_pcvar_num ( pCvar_Announce [ 2 ] ) )
  124.     {
  125.         case 1:
  126.         {
  127.             client_print ( 0, print_chat, "[Unstuck] If you are stucked type /unstuck in chat to unstuck" );
  128.         }
  129.         case 2:
  130.         {
  131.             set_hudmessage ( 170, 255, 127, 0.02, 0.17, get_pcvar_num ( pCvar_Announce [ 4 ] ), 6.0, get_pcvar_float ( pCvar_Announce [ 3 ] ) );
  132.             ShowSyncHudMsg ( 0, g_MsgSync, "If you are stucked type /unstuck in chat to unstuck" );
  133.         }
  134.         default: return;
  135.     }
  136. }
  137.            
  138.            
  139. public FunC_CheckStuck ( const iPlayer)
  140. {
  141.     if ( !get_pcvar_num ( pCvar_Function ) )
  142.         return 1;
  143.    
  144.     new Float:f_MinFrequency    = get_pcvar_float ( pCvar_UnstWait );
  145.     new Float:f_ElapsedCmdTime  = get_gametime ( ) - gf_LastCmdTime [ iPlayer ];
  146.        
  147.     if ( f_ElapsedCmdTime < f_MinFrequency )
  148.     {
  149.         client_print ( iPlayer, print_chat, "[AMXX] You must wait %.1f seconds before trying to free yourself.", f_MinFrequency - f_ElapsedCmdTime );
  150.         return 1;
  151.     }
  152.    
  153.     gf_LastCmdTime [ iPlayer ] = get_gametime ( );
  154.     new i_Value;
  155.    
  156.     if ( ( i_Value = UnstuckPlayer ( iPlayer, START_DISTANCE, MAX_ATTEMPTS ) ) != 1 )
  157.     {
  158.         switch ( i_Value )
  159.         {
  160.             case 0  : {
  161.                 client_print ( iPlayer, print_chat, "[Unstuck] Couldn't find a free spot to move you too" );
  162.             }
  163.             case -1 : {
  164.                 client_print ( iPlayer, print_chat, "[Unstuck] You cannot free yourself as dead player" );
  165.             }
  166.         }
  167.     }
  168.    
  169.     return 1;
  170. }
  171.  
  172. public UnstuckPlayer ( const id, const i_StartDistance, const i_MaxAttempts )
  173. {  
  174.     #if defined USE_DEFAULT
  175.     if ( is_user_alive ( id ) )
  176.     {
  177.     #endif
  178.    
  179.     #if defined USE_ZPMOD
  180.     if ( is_user_alive ( id ) && !zp_get_user_zombie ( id ) )
  181.     {
  182.     #endif
  183.    
  184.     #if defined USE_BIOMOD
  185.     if ( is_user_alive ( id ) && !is_user_zombie ( id ) )
  186.     {
  187.     #endif
  188.         static Float:vf_OriginalOrigin [ Coord_e ], Float:vf_NewOrigin [ Coord_e ];
  189.         static i_Attempts, i_Distance;
  190.        
  191.         pev ( id, pev_origin, vf_OriginalOrigin );
  192.         i_Distance = i_StartDistance;
  193.        
  194.         while ( i_Distance < 1000 )
  195.         {
  196.             i_Attempts = i_MaxAttempts;
  197.        
  198.             while ( i_Attempts-- )
  199.             {
  200.                 vf_NewOrigin [ x ] = random_float ( vf_OriginalOrigin [ x ] - i_Distance, vf_OriginalOrigin [ x ] + i_Distance );
  201.                 vf_NewOrigin [ y ] = random_float ( vf_OriginalOrigin [ y ] - i_Distance, vf_OriginalOrigin [ y ] + i_Distance );
  202.                 vf_NewOrigin [ z ] = random_float ( vf_OriginalOrigin [ z ] - i_Distance, vf_OriginalOrigin [ z ] + i_Distance );
  203.                
  204.                 engfunc ( EngFunc_TraceHull, vf_NewOrigin, vf_NewOrigin, DONT_IGNORE_MONSTERS, GetPlayerHullSize ( id ), id, 0 );
  205.                
  206.                 if ( get_tr2 ( 0, TR_InOpen ) && !get_tr2 ( 0, TR_AllSolid ) && !get_tr2 ( 0, TR_StartSolid ) )
  207.                 {
  208.                     engfunc ( EngFunc_SetOrigin, id, vf_NewOrigin );
  209.                     effects ( id );
  210.                     client_print ( id, print_chat, "[Unstuck] You have been teleported to a new location." );
  211.                    
  212.                     return 1;
  213.                 }
  214.             }
  215.             i_Distance += i_StartDistance;
  216.         }
  217.     }
  218.         return 0;
  219. }
  220.    
  221. public effects ( id )
  222. {
  223.     if ( get_pcvar_num ( pCvar_UnstEff ) )
  224.     {
  225.         message_begin ( MSG_ONE_UNRELIABLE, 105, { 0, 0, 0 }, id );    
  226.         write_short(1<<10);     // fade lasts this long duration
  227.         write_short(1<<10);     // fade lasts this long hold time
  228.         write_short(1<<1);      // fade type (in / out)
  229.         write_byte(20);         // fade red
  230.         write_byte(255);        // fade green
  231.         write_byte(255);        // fade blue
  232.         write_byte(255);        // fade alpha
  233.         message_end ( );
  234.         client_cmd ( id, "spk fvox/blip.wav" );
  235.     }
  236. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement