Advertisement
eyal282

[CS:GO] Instant Defuse

Jan 22nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sourcemod>
  2. #include <sdkhooks>
  3. #include <sdktools>
  4. #include <cstrike>
  5.  
  6. new const String:PLUGIN_VERSION[] = "1.1";
  7.  
  8. new Handle:hcv_NoobMargin = INVALID_HANDLE;
  9.  
  10. new Handle:hcv_InfernoDuration = INVALID_HANDLE;
  11. new Handle:hcv_InfernoDistance = INVALID_HANDLE;
  12.  
  13. new Handle:hTimer_MolotovThreatEnd = INVALID_HANDLE;
  14.  
  15. public Plugin:myinfo =
  16. {
  17.     name = "Instant Defuse",
  18.     author = "Eyal282",
  19.     description = "Allows you to instantly defuse the bomb when all T are dead and nothing can stop the defuse.",
  20.     version = PLUGIN_VERSION,
  21.     url = ""
  22. }
  23.  
  24. public OnPluginStart()
  25. {
  26.     HookEvent("bomb_begindefuse", Event_BombBeginDefuse, EventHookMode_Post);
  27.     HookEvent("molotov_detonate", Event_MolotovDetonate);
  28.     HookEvent("hegrenade_detonate", Event_AttemptInstantDefuse, EventHookMode_Post);
  29.  
  30.     HookEvent("player_death", Event_AttemptInstantDefuse, EventHookMode_PostNoCopy);
  31.     HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  32.    
  33.     hcv_NoobMargin = CreateConVar("instant_defuse_noob_margin", "5.2", "To prevent noobs from instantly running for their lives when instant defuse fails, instant defuse won't activate if defuse may be uncertain to the player.");
  34.    
  35.     hcv_InfernoDuration = CreateConVar("instant_defuse_inferno_duration", "7.0", "If Valve ever changed the duration of molotov, this cvar should change with it.");
  36.     hcv_InfernoDistance = CreateConVar("instant_defuse_inferno_distance", "225.0", "If Valve ever changed the maximum distance spread of molotov, this cvar should change with it.");
  37. }
  38.  
  39. public OnMapStart()
  40. {
  41.     hTimer_MolotovThreatEnd = INVALID_HANDLE;
  42. }
  43.  
  44. public Action:Event_RoundStart(Handle:hEvent, const String:Name[], bool:dontBroadcast)
  45. {
  46.     if(hTimer_MolotovThreatEnd != INVALID_HANDLE)
  47.     {
  48.         CloseHandle(hTimer_MolotovThreatEnd);
  49.         hTimer_MolotovThreatEnd = INVALID_HANDLE;
  50.     }
  51. }
  52.  
  53. public Action:Event_BombBeginDefuse(Handle:hEvent, const String:Name[], bool:dontBroadcast)
  54. {  
  55.     RequestFrame(Event_BombBeginDefusePlusFrame, GetEventInt(hEvent, "userid"));
  56.    
  57.     return Plugin_Continue;
  58. }
  59.  
  60. public Event_BombBeginDefusePlusFrame(UserId)
  61. {
  62.     new client = GetClientOfUserId(UserId);
  63.    
  64.     if(client == 0)
  65.         return;
  66.        
  67.     AttemptInstantDefuse(client);
  68. }
  69.  
  70. stock AttemptInstantDefuse(client, exemptNade = 0)
  71. {
  72.     if(!GetEntProp(client, Prop_Send, "m_bIsDefusing"))
  73.         return;
  74.        
  75.     new StartEnt = MaxClients + 1;
  76.        
  77.     new c4 = FindEntityByClassname(StartEnt, "planted_c4");
  78.    
  79.     if(c4 == -1)
  80.         return;
  81.        
  82.     else if(FindAlivePlayer(CS_TEAM_T) != 0)
  83.         return;
  84.    
  85.     else if(GetEntPropFloat(c4, Prop_Send, "m_flC4Blow") - GetConVarFloat(hcv_NoobMargin) < GetEntPropFloat(c4, Prop_Send, "m_flDefuseCountDown"))
  86.     {
  87.         PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Defuse not certain enough, Good luck defusing!", "Insta-Defuse");
  88.         return;
  89.     }
  90.  
  91.     new ent
  92.     if((ent = FindEntityByClassname(StartEnt, "hegrenade_projectile")) != -1 || (ent = FindEntityByClassname(StartEnt, "molotov_projectile")) != -1)
  93.     {
  94.         if(ent != exemptNade)
  95.         {
  96.             PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 There is a live nade somewhere, Good luck defusing!", "Insta-Defuse");
  97.             return;
  98.         }
  99.     }  
  100.     else if(hTimer_MolotovThreatEnd != INVALID_HANDLE)
  101.     {
  102.         PrintToChatAll("\x01 \x09[\x04%s\x09]\x01 Molotov too close to bomb, Good luck defusing!", "Insta-Defuse");
  103.         return;
  104.     }
  105.        
  106.     SetEntPropFloat(c4, Prop_Send, "m_flDefuseCountDown", 0.0);
  107.     SetEntPropFloat(c4, Prop_Send, "m_flDefuseLength", 0.0);
  108.     SetEntProp(client, Prop_Send, "m_iProgressBarDuration", 0);
  109. }
  110.  
  111. public Action:Event_AttemptInstantDefuse(Handle:hEvent, const String:Name[], bool:dontBroadcast)
  112. {
  113.     new defuser = FindDefusingPlayer();
  114.    
  115.    
  116.     new ent = 0;
  117.    
  118.     if(StrContains(Name, "detonate") != -1)
  119.         ent = GetEventInt(hEvent, "entityid");
  120.        
  121.     if(defuser != 0)
  122.         AttemptInstantDefuse(defuser, ent);
  123. }
  124. public Action:Event_MolotovDetonate(Handle:hEvent, const String:Name[], bool:dontBroadcast)
  125. {
  126.     new Float:Origin[3];
  127.     Origin[0] = GetEventFloat(hEvent, "x");
  128.     Origin[1] = GetEventFloat(hEvent, "y");
  129.     Origin[2] = GetEventFloat(hEvent, "z");
  130.    
  131.     new c4 = FindEntityByClassname(MaxClients + 1, "planted_c4");
  132.    
  133.     if(c4 == -1)
  134.         return;
  135.    
  136.     new Float:C4Origin[3];
  137.     GetEntPropVector(c4, Prop_Data, "m_vecOrigin", C4Origin);
  138.    
  139.     if(GetVectorDistance(Origin, C4Origin, false) > GetConVarFloat(hcv_InfernoDistance))
  140.         return;
  141.  
  142.     if(hTimer_MolotovThreatEnd != INVALID_HANDLE)
  143.     {
  144.         CloseHandle(hTimer_MolotovThreatEnd);
  145.         hTimer_MolotovThreatEnd = INVALID_HANDLE;
  146.     }
  147.    
  148.     hTimer_MolotovThreatEnd = CreateTimer(GetConVarFloat(hcv_InfernoDuration), Timer_MolotovThreatEnd, _, TIMER_FLAG_NO_MAPCHANGE);
  149. }
  150.  
  151. public Action:Timer_MolotovThreatEnd(Handle:hTimer)
  152. {
  153.     hTimer_MolotovThreatEnd = INVALID_HANDLE;
  154.    
  155.     new defuser = FindDefusingPlayer();
  156.    
  157.     if(defuser != 0)
  158.         AttemptInstantDefuse(defuser);
  159. }
  160.  
  161. stock FindDefusingPlayer()
  162. {
  163.     for(new i=1;i <= MaxClients;i++)
  164.     {
  165.         if(!IsClientInGame(i))
  166.             continue;
  167.            
  168.         else if(!IsPlayerAlive(i))
  169.             continue;
  170.            
  171.         else if(!GetEntProp(i, Prop_Send, "m_bIsDefusing"))
  172.             continue;
  173.            
  174.         return i;
  175.     }
  176.    
  177.     return 0;
  178. }
  179.  
  180. stock FindAlivePlayer(Team)
  181. {
  182.     for(new i=1;i <= MaxClients;i++)
  183.     {
  184.         if(!IsClientInGame(i))
  185.             continue;
  186.            
  187.         else if(!IsPlayerAlive(i))
  188.             continue;
  189.            
  190.         else if(GetClientTeam(i) != Team)
  191.             continue;
  192.            
  193.         return i;
  194.     }
  195.    
  196.     return 0;
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement