Advertisement
DeathChaos25

[L4D2] Mighty Stomp Foot

Sep 9th, 2015
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.56 KB | None | 0 0
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <sdktools>
  4. #include <sdkhooks>
  5. #include <l4d2_direct>
  6. #define PLUGIN_VERSION                        "1.0.1"
  7.  
  8. #define TEST_DEBUG                             0
  9. #define TEST_DEBUG_LOG                         0
  10. static bool:g_bIsBusy[MAXPLAYERS + 1] = false;
  11.  
  12. #define     CLASS_STRINGLENGHT                32
  13. static const L4D2_MAX_PLAYERS               = 32;
  14.  
  15. static const ANIM_SEQUENCES_DOWNED_BEGIN    = 128;
  16. static const ANIM_SEQUENCES_DOWNED_END      = 132;
  17. static const ANIM_SEQUENCE_WALLED           = 138;
  18. static const Float:DOWNED_ANIM_MIN_CYCLE    = 0.27;
  19. static const Float:DOWNED_ANIM_MAX_CYCLE    = 0.53;
  20. static const Float:STOMP_MOVE_PENALTY       = 0.25;
  21.  
  22. static const String:STOMP_SOUND_PATH[]      = "player/survivor/hit/rifle_swing_hit_infected9.wav";
  23. static const String:CLASSNAME_INFECTED[]    = "infected";
  24. static const String:ENTPROP_ANIM_SEQUENCE[] = "m_nSequence";
  25. static const String:ENTPROP_ANIM_CYCLE[]    = "m_flCycle";
  26. static const String:ENT_INPUT_TO_KILL[]     = "BecomeRagdoll";
  27. static const String:SPEED_MODIFY_ENTPROP[]  = "m_flVelocityModifier";
  28.  
  29. static      Handle:cvarSlowSurvivor         = INVALID_HANDLE;
  30.  
  31.  
  32. public Plugin:myinfo =
  33. {
  34.     name = "L4D2 Mighty Stomp Foot",
  35.     author = "AtomicStryker (Edited by:DeathChaos25",
  36.     description = "Crush downed Commons",
  37.     version = PLUGIN_VERSION,
  38.     url = "http://forums.alliedmods.net/showthread.php?p=1185478"
  39. };
  40.  
  41. public OnPluginStart()
  42. {
  43.     decl String:game_name[CLASS_STRINGLENGHT];
  44.     GetGameFolderName(game_name, sizeof(game_name));
  45.     if (StrContains(game_name, "left4dead", false) < 0)
  46.     {
  47.         SetFailState("Plugin supports L4D2 only.");
  48.     }
  49.  
  50.     CreateConVar("l4d2_mightystompfoot_version", PLUGIN_VERSION, "L4D2 Mighty Stomp Foot Version", FCVAR_PLUGIN|FCVAR_REPLICATED|FCVAR_DONTRECORD);
  51.    
  52.     cvarSlowSurvivor = CreateConVar("l4d2_mightystompfoot_stompslow", "0", " Does Stomping slow down Survivors momentarily ", FCVAR_PLUGIN|FCVAR_NOTIFY);
  53. }
  54.  
  55. public OnClientPostAdminCheck(client)
  56. {
  57.     SDKHook(client, SDKHook_StartTouch, _MF_Touch);
  58.     SDKHook(client, SDKHook_Touch,      _MF_Touch);
  59. }
  60.  
  61. public Action:_MF_Touch(entity, other)
  62. {
  63.     if (other < L4D2_MAX_PLAYERS || !IsValidEdict(other)) return Plugin_Continue;
  64.    
  65.     decl String:classname[CLASS_STRINGLENGHT];
  66.     GetEdictClassname(other, classname, sizeof(classname));
  67.    
  68.     if (StrEqual(classname, CLASSNAME_INFECTED))
  69.     {
  70.         new i = GetEntProp(other, Prop_Data, ENTPROP_ANIM_SEQUENCE);
  71.         new Float:f = GetEntPropFloat(other, Prop_Data, ENTPROP_ANIM_CYCLE);
  72.         DebugPrintToAll("Touch fired on Infected, Sequence %i, Cycle %f", i, f);
  73.        
  74.         if ((i >= ANIM_SEQUENCES_DOWNED_BEGIN && i <= ANIM_SEQUENCES_DOWNED_END) || i == ANIM_SEQUENCE_WALLED)
  75.         {
  76.             if (f >= DOWNED_ANIM_MIN_CYCLE && f <= DOWNED_ANIM_MAX_CYCLE)
  77.             {
  78.                 DebugPrintToAll("Infected found downed. STOMPING HIM!!!");
  79.                 CreateTimer(0.42, SMASH, other);
  80.                 L4D2Direct_DoAnimationEvent(entity, 37);
  81.                 g_bIsBusy[entity] = true;
  82.                 CreateTimer(1.0, RESETBUSY, entity);
  83.                 GotoThirdPerson(entity);
  84.                 if (GetConVarBool(cvarSlowSurvivor))
  85.                 {
  86.                     SetEntPropFloat(entity, Prop_Data, SPEED_MODIFY_ENTPROP, GetEntPropFloat(entity, Prop_Data, SPEED_MODIFY_ENTPROP) - STOMP_MOVE_PENALTY);
  87.                 }
  88.             }
  89.         }
  90.     }
  91.    
  92.     return Plugin_Continue;
  93. }
  94.  
  95. static SmashInfected(any:zombie)
  96. {
  97.     for (new j = 1; j <= MaxClients; j++)
  98.     {
  99.         if (IsClientInGame(j) && !IsFakeClient(j))
  100.         {
  101.             EmitSoundToClient(j, STOMP_SOUND_PATH, zombie, SNDCHAN_AUTO, SNDLEVEL_GUNFIRE);
  102.         }
  103.     }
  104.  
  105.     AcceptEntityInput(zombie, ENT_INPUT_TO_KILL);
  106. }
  107.  
  108. public Action:SMASH(Handle:Timer, any:other)
  109. {
  110.     SmashInfected(other);
  111. }
  112. public Action:RESETBUSY(Handle:Timer, any:client)
  113. {
  114.     g_bIsBusy[client] = false;
  115.     GotoFirstPerson(client);
  116. }
  117. public Action:OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:ang[3], &weapon)
  118. {
  119.     if (IsSurvivor(client) && IsPlayerAlive(client) && g_bIsBusy[client])
  120.         return Plugin_Handled;
  121.     return Plugin_Continue;
  122. }
  123. stock DebugPrintToAll(const String:format[], any:...)
  124. {
  125.     #if TEST_DEBUG  || TEST_DEBUG_LOG
  126.     decl String:buffer[192];
  127.    
  128.     VFormat(buffer, sizeof(buffer), format, 2);
  129.    
  130.     #if TEST_DEBUG
  131.     PrintToChatAll("[STOMP] %s", buffer);
  132.     PrintToConsole(0, "[STOMP] %s", buffer);
  133.     #endif
  134.    
  135.     LogMessage("%s", buffer);
  136.     #else
  137.     //suppress "format" never used warning
  138.     if(format[0])
  139.         return;
  140.     else
  141.         return;
  142.     #endif
  143. }
  144. stock bool:IsSurvivor(client)
  145. {
  146.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
  147. }
  148.  
  149. GotoThirdPerson(client)
  150. {
  151.     SetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView", 99999.3);
  152. }
  153.  
  154. GotoFirstPerson(client)
  155. {
  156.     SetEntPropFloat(client, Prop_Send, "m_TimeForceExternalView", 0.0);
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement