DeathChaos25

[L4D2] L4D1 Special Infected AI restore & other SI AI improv

Aug 16th, 2015
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 22.56 KB | None | 0 0
  1. // download https://drive.google.com/open?id=0B0rPMDhb3gbhN3FLN2E0Q2ZjM1k
  2. #pragma semicolon 1
  3.  
  4. /* Globals */
  5. #define DEBUG 1 /* Change this to 0 to disable debug info to be printed */
  6. #define DEBUG_TAG "SI Manipulation"
  7. #define DEBUG_PRINT_FORMAT "[%s] %s"
  8.  
  9. #define PLUGIN_VERSION "1.0"
  10.  
  11. #include <sourcemod>
  12. #include <sdktools>
  13. #include <l4d2_aidetours>
  14.  
  15. static g_hunteraitype;
  16. static g_jockeyaitype;
  17. static g_chargeraitype;
  18. static g_spitteraitype;
  19. static g_smokeraitype;
  20. static g_boomeraitype;
  21.  
  22. public Plugin:myinfo =
  23. {
  24.     name = "[L4D2] L4D1 Special Infected AI restore & other SI AI improvements",
  25.     author = "DeathChaos25",
  26.     description = " ",
  27.     version = PLUGIN_VERSION,
  28.     url = " "
  29. };
  30.  
  31. public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
  32. {
  33.     decl String:s_GameFolder[32];
  34.     GetGameFolderName(s_GameFolder, sizeof(s_GameFolder));
  35.     if (!StrEqual(s_GameFolder, "left4dead2", false))
  36.     {
  37.         strcopy(error, err_max, "This plugin is for Left 4 Dead 2 Only!");
  38.         return APLRes_Failure;
  39.     }
  40.     return APLRes_Success;
  41. }
  42.  
  43. public OnPluginStart()
  44. {
  45.     new Handle:HunterAIType = CreateConVar("hunter_ai_type", "1", "What Kind of AI do we enforce on the hunters (0 = default AI, 1 = L4D1 Hunter AI, 2 = Prioritize Incapped Survivors, 3 = Prioritize Survivor with lowest hp, 4 = Prioritize Survivor with higest hp)", FCVAR_PLUGIN, true, 0.0, true, 4.0);
  46.     HookConVarChange(HunterAIType, ConVarHunterAIType);
  47.     g_hunteraitype = GetConVarInt(HunterAIType);
  48.    
  49.     new Handle:JockeyAIType = CreateConVar("jockey_ai_type", "1", "What Kind of AI do we enforce on the jockeys (0 = default AI, 1 = Prioritize Survivor with lowest hp, 2 = Prioritize Survivor with higest hp)", FCVAR_PLUGIN, true, 0.0, true, 2.0);
  50.     HookConVarChange(JockeyAIType, ConVarJockeyAIType);
  51.     g_jockeyaitype = GetConVarInt(JockeyAIType);
  52.    
  53.     new Handle:ChargerAIType = CreateConVar("charger_ai_type", "1", "What Kind of AI do we enforce on the chargers (0 = default AI, 1 = Prioritize Survivor with lowest hp, 2 = Prioritize Survivor with higest hp)", FCVAR_PLUGIN, true, 0.0, true, 2.0);
  54.     HookConVarChange(ChargerAIType, ConVarChargerAIType);
  55.     g_chargeraitype = GetConVarInt(ChargerAIType);
  56.    
  57.     new Handle:BoomerAIType = CreateConVar("boomer_ai_type", "1", "What Kind of AI do we enforce on the boomers (0 = default AI, 1 = Prioritize Survivor with lowest hp, 2 = Prioritize Survivor with higest hp)", FCVAR_PLUGIN, true, 0.0, true, 2.0);
  58.     HookConVarChange(BoomerAIType, ConVarBoomerAIType);
  59.     g_boomeraitype = GetConVarInt(BoomerAIType);
  60.    
  61.     new Handle:SpitterAIType = CreateConVar("spitter_ai_type", "1", "What Kind of AI do we enforce on the spitters (0 = default AI, 1 = Prioritize Survivor with lowest hp, 2 = Prioritize Survivor with higest hp)", FCVAR_PLUGIN, true, 0.0, true, 2.0);
  62.     HookConVarChange(SpitterAIType, ConVarSpitterAIType);
  63.     g_spitteraitype = GetConVarInt(SpitterAIType);
  64.    
  65.     new Handle:SmokerAIType = CreateConVar("smoker_ai_type", "1", "What Kind of AI do we enforce on the smokers (0 = default AI, 1 = Prioritize Survivor with lowest hp, 2 = Prioritize Survivor with higest hp)", FCVAR_PLUGIN, true, 0.0, true, 2.0);
  66.     HookConVarChange(SmokerAIType, ConVarSmokerAIType);
  67.     g_smokeraitype = GetConVarInt(SmokerAIType);
  68.    
  69.     AutoExecConfig(true, "l4d2_si_ai_manipulation");
  70. }
  71.  
  72. // Tank AI Manipulation
  73. // Here, we force the Tank to prioritize incapped survivors
  74. public Action:L4D2_OnTankAttackUpdate(tank, &victim)
  75. {
  76.     if (IsInfected(tank) && IsTank(tank) && IsPlayerAlive(tank)) //Is this a valid tank?
  77.     {
  78.         for (new target = 1; target <= MaxClients; target++)
  79.         {
  80.             // Is our new target alive? incapped? not pinned by another si? not too far away?
  81.             if (IsSurvivor(target) && IsPlayerAlive(target) && IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(tank, target, 150.0))
  82.             {
  83.                 #if DEBUG
  84.                 Debug_PrintText("Tank (%i, %N) has changed targets to Survivor %N! (id:%i)", tank, tank, target, target);
  85.                 #endif
  86.                 // he is now the Tank's target
  87.                 victim = GetEntData(target, L4D2_RefEntityHandle());
  88.                 return Plugin_Changed;
  89.             }
  90.         }
  91.     }
  92.     return Plugin_Continue;
  93. }
  94.  
  95. // Hunter AI Manipulation
  96. public Action:L4D2_OnHunterAttackUpdate(hunter, &victim)
  97. {
  98.     if (IsInfected(hunter) && IsPlayerAlive(hunter))
  99.     {
  100.         new nearestclient, Float:lastdistance = 1000000.0;
  101.         if (g_hunteraitype == 1) //1 = L4D1 Hunter AI
  102.         {
  103.             for (new client = 1; client <= MaxClients; client++)
  104.             {
  105.                 new Float:Origin[3], Float:TOrigin[3];
  106.                 if (IsSurvivor(client) && IsPlayerAlive(client) && !IsPlayerHeld(client))
  107.                 {
  108.                     GetEntPropVector(client, Prop_Send, "m_vecOrigin", Origin);
  109.                     GetEntPropVector(hunter, Prop_Send, "m_vecOrigin", TOrigin);
  110.                    
  111.                     new Float:distance = GetVectorDistance(TOrigin, Origin);
  112.                     if (lastdistance > distance)
  113.                     {
  114.                         lastdistance = distance;
  115.                         nearestclient = client;
  116.                     }
  117.                 }
  118.             }
  119.             if (IsSurvivor(nearestclient))
  120.             {
  121.                 #if DEBUG
  122.                 Debug_PrintText("Hunter (%i, %N) has changed targets to Survivor %N! (id:%i)", hunter, hunter, nearestclient, nearestclient);
  123.                 #endif
  124.                
  125.                 victim = GetEntData(nearestclient, L4D2_RefEntityHandle());
  126.                 return Plugin_Changed;
  127.             }
  128.         }
  129.         else if (g_hunteraitype == 2) //2 = Prioritize Incapped Survivors
  130.         {
  131.             for (new target = 1; target <= MaxClients; target++)
  132.             {
  133.                 // Is our new target alive? incapped? not pinned by another si? not too far away?
  134.                 if (IsSurvivor(target) && IsPlayerAlive(target) && IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(hunter, target, 400.0))
  135.                 {
  136.                     #if DEBUG
  137.                     Debug_PrintText("Hunter (%i, %N) has changed targets to Survivor %N! (id:%i)", hunter, hunter, target, target);
  138.                     #endif
  139.                     // he is now the Hunter's target
  140.                     victim = GetEntData(target, L4D2_RefEntityHandle());
  141.                     return Plugin_Changed;
  142.                 }
  143.             }
  144.         }
  145.         else if (g_hunteraitype == 3) //3 = Prioritize Survivor with lowest hp (EXCLUDING INCAPS)
  146.         {
  147.             new weakestclient, leasthp = 100, mostincaps = 0;
  148.             for (new target = 1; target <= MaxClients; target++)
  149.             {
  150.                 // Is our new target alive? not incapped? not pinned by another si? not too far away?
  151.                 if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(hunter, target, 400.0))
  152.                 {
  153.                     if (GetEntProp(target, Prop_Send, "m_currentReviveCount") >= mostincaps)
  154.                     {
  155.                         if (GetClientHealth(target) + GetPlayerTempHealth(target) <= leasthp)
  156.                         {
  157.                             mostincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  158.                             leasthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  159.                             weakestclient = target;
  160.                         }
  161.                     }
  162.                 }
  163.             }
  164.             #if DEBUG
  165.             Debug_PrintText("Hunter (%i, %N) has changed targets to Survivor %N! (id:%i)", hunter, hunter, weakestclient, weakestclient);
  166.             #endif
  167.             // he is now the Hunter's target
  168.             victim = GetEntData(weakestclient, L4D2_RefEntityHandle());
  169.             return Plugin_Changed;
  170.         }
  171.         else if (g_hunteraitype == 4) //4 = Prioritize Survivor with higest hp (EXCLUDING INCAPS)
  172.         {
  173.             new healthiestclient, mosthp = 0, leastincaps = 5;
  174.             for (new target = 1; target <= MaxClients; target++)
  175.             {
  176.                 // Is our new target alive? not incapped? not pinned by another si? not too far away?
  177.                 if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(hunter, target, 400.0))
  178.                 {
  179.                     if (GetEntProp(target, Prop_Send, "m_currentReviveCount") <= leastincaps)
  180.                     {
  181.                         if (GetClientHealth(target) + GetPlayerTempHealth(target) >= mosthp)
  182.                         {
  183.                             leastincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  184.                             mosthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  185.                             healthiestclient = target;
  186.                         }
  187.                     }
  188.                 }
  189.             }
  190.             #if DEBUG
  191.             Debug_PrintText("Hunter (%i, %N) has changed targets to Survivor %N! (id:%i)", hunter, hunter, healthiestclient, healthiestclient);
  192.             #endif
  193.             // he is now the Hunter's target
  194.             victim = GetEntData(healthiestclient, L4D2_RefEntityHandle());
  195.             return Plugin_Changed;
  196.         }
  197.     }
  198.     return Plugin_Continue;
  199. }
  200.  
  201. public Action:L4D2_OnJockeyAttackUpdate(jockey, &victim)
  202. {
  203.     if (g_jockeyaitype == 1) //1 = Prioritize Survivor with lowest hp (EXCLUDING INCAPS)
  204.     {
  205.         new weakestclient, leasthp = 100, mostincaps = 0;
  206.         for (new target = 1; target <= MaxClients; target++)
  207.         {
  208.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  209.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(jockey, target, 400.0))
  210.             {
  211.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") >= mostincaps)
  212.                 {
  213.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) <= leasthp)
  214.                     {
  215.                         mostincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  216.                         leasthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  217.                         weakestclient = target;
  218.                     }
  219.                 }
  220.             }
  221.         }
  222.         #if DEBUG
  223.         Debug_PrintText("Jockey (%i, %N) has changed targets to Survivor %N! (id:%i)", jockey, jockey, weakestclient, weakestclient);
  224.         #endif
  225.         // he is now the Jockey's target
  226.         victim = GetEntData(weakestclient, L4D2_RefEntityHandle());
  227.         return Plugin_Changed;
  228.     }
  229.     else if (g_jockeyaitype == 2) //2 = Prioritize Survivor with higest hp (EXCLUDING INCAPS)
  230.     {
  231.         new healthiestclient, mosthp = 0, leastincaps = 5;
  232.         for (new target = 1; target <= MaxClients; target++)
  233.         {
  234.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  235.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(jockey, target, 400.0))
  236.             {
  237.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") <= leastincaps)
  238.                 {
  239.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) >= mosthp)
  240.                     {
  241.                         leastincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  242.                         mosthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  243.                         healthiestclient = target;
  244.                     }
  245.                 }
  246.             }
  247.         }
  248.         #if DEBUG
  249.         Debug_PrintText("Jockey (%i, %N) has changed targets to Survivor %N! (id:%i)", jockey, jockey, healthiestclient, healthiestclient);
  250.         #endif
  251.         // he is now the Jockey's target
  252.         victim = GetEntData(healthiestclient, L4D2_RefEntityHandle());
  253.         return Plugin_Changed;
  254.     }
  255.     return Plugin_Continue;
  256. }
  257.  
  258. public Action:L4D2_OnChargerAttackUpdate(charger, &victim)
  259. {
  260.     if (g_chargeraitype == 1) //1 = Prioritize Survivor with lowest hp (EXCLUDING INCAPS)
  261.     {
  262.         new weakestclient, leasthp = 100, mostincaps = 0;
  263.         for (new target = 1; target <= MaxClients; target++)
  264.         {
  265.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  266.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(charger, target, 600.0))
  267.             {
  268.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") >= mostincaps)
  269.                 {
  270.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) <= leasthp)
  271.                     {
  272.                         mostincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  273.                         leasthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  274.                         weakestclient = target;
  275.                     }
  276.                 }
  277.             }
  278.         }
  279.         #if DEBUG
  280.         Debug_PrintText("Charger (%i, %N) has changed targets to Survivor %N! (id:%i)", charger, charger, weakestclient, weakestclient);
  281.         #endif
  282.         // he is now the Charger's target
  283.         victim = GetEntData(weakestclient, L4D2_RefEntityHandle());
  284.         return Plugin_Changed;
  285.     }
  286.     else if (g_chargeraitype == 2) //2 = Prioritize Survivor with higest hp (EXCLUDING INCAPS)
  287.     {
  288.         new healthiestclient, mosthp = 0, leastincaps = 5;
  289.         for (new target = 1; target <= MaxClients; target++)
  290.         {
  291.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  292.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(charger, target, 600.0))
  293.             {
  294.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") <= leastincaps)
  295.                 {
  296.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) >= mosthp)
  297.                     {
  298.                         leastincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  299.                         mosthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  300.                         healthiestclient = target;
  301.                     }
  302.                 }
  303.             }
  304.         }
  305.         #if DEBUG
  306.         Debug_PrintText("Charger (%i, %N) has changed targets to Survivor %N! (id:%i)", charger, charger, healthiestclient, healthiestclient);
  307.         #endif
  308.         // he is now the Charger's target
  309.         victim = GetEntData(healthiestclient, L4D2_RefEntityHandle());
  310.         return Plugin_Changed;
  311.     }
  312.     return Plugin_Continue;
  313. }
  314.  
  315. public Action:L4D2_OnSpitterAttackUpdate(spitter, &victim)
  316. {
  317.     if (g_spitteraitype == 1) //1 = Prioritize Survivor with lowest hp (EXCLUDING INCAPS)
  318.     {
  319.         new weakestclient, leasthp = 100, mostincaps = 0;
  320.         for (new target = 1; target <= MaxClients; target++)
  321.         {
  322.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  323.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(spitter, target, 400.0))
  324.             {
  325.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") >= mostincaps)
  326.                 {
  327.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) <= leasthp)
  328.                     {
  329.                         mostincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  330.                         leasthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  331.                         weakestclient = target;
  332.                     }
  333.                 }
  334.             }
  335.         }
  336.         #if DEBUG
  337.         Debug_PrintText("spitter (%i, %N) has changed targets to Survivor %N! (id:%i)", spitter, spitter, weakestclient, weakestclient);
  338.         #endif
  339.         // he is now the spitter's target
  340.         victim = GetEntData(weakestclient, L4D2_RefEntityHandle());
  341.         return Plugin_Changed;
  342.     }
  343.     else if (g_spitteraitype == 2) //2 = Prioritize Survivor with higest hp (EXCLUDING INCAPS)
  344.     {
  345.         new healthiestclient, mosthp = 0, leastincaps = 5;
  346.         for (new target = 1; target <= MaxClients; target++)
  347.         {
  348.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  349.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(spitter, target, 400.0))
  350.             {
  351.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") <= leastincaps)
  352.                 {
  353.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) >= mosthp)
  354.                     {
  355.                         leastincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  356.                         mosthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  357.                         healthiestclient = target;
  358.                     }
  359.                 }
  360.             }
  361.         }
  362.         #if DEBUG
  363.         Debug_PrintText("spitter (%i, %N) has changed targets to Survivor %N! (id:%i)", spitter, spitter, healthiestclient, healthiestclient);
  364.         #endif
  365.         // he is now the spitter's target
  366.         victim = GetEntData(healthiestclient, L4D2_RefEntityHandle());
  367.         return Plugin_Changed;
  368.     }
  369.     return Plugin_Continue;
  370. }
  371.  
  372. public Action:L4D2_OnSmokerAttackUpdate(smoker, &victim)
  373. {
  374.     if (g_smokeraitype == 1) //1 = Prioritize Survivor with lowest hp (EXCLUDING INCAPS)
  375.     {
  376.         new weakestclient, leasthp = 100, mostincaps = 0;
  377.         for (new target = 1; target <= MaxClients; target++)
  378.         {
  379.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  380.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(smoker, target, 400.0))
  381.             {
  382.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") >= mostincaps)
  383.                 {
  384.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) <= leasthp)
  385.                     {
  386.                         mostincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  387.                         leasthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  388.                         weakestclient = target;
  389.                     }
  390.                 }
  391.             }
  392.         }
  393.         #if DEBUG
  394.         Debug_PrintText("smoker (%i, %N) has changed targets to Survivor %N! (id:%i)", smoker, smoker, weakestclient, weakestclient);
  395.         #endif
  396.         // he is now the smoker's target
  397.         victim = GetEntData(weakestclient, L4D2_RefEntityHandle());
  398.         return Plugin_Changed;
  399.     }
  400.     else if (g_smokeraitype == 2) //2 = Prioritize Survivor with higest hp (EXCLUDING INCAPS)
  401.     {
  402.         new healthiestclient, mosthp = 0, leastincaps = 5;
  403.         for (new target = 1; target <= MaxClients; target++)
  404.         {
  405.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  406.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(smoker, target, 400.0))
  407.             {
  408.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") <= leastincaps)
  409.                 {
  410.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) >= mosthp)
  411.                     {
  412.                         leastincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  413.                         mosthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  414.                         healthiestclient = target;
  415.                     }
  416.                 }
  417.             }
  418.         }
  419.         #if DEBUG
  420.         Debug_PrintText("smoker (%i, %N) has changed targets to Survivor %N! (id:%i)", smoker, smoker, healthiestclient, healthiestclient);
  421.         #endif
  422.         // he is now the smoker's target
  423.         victim = GetEntData(healthiestclient, L4D2_RefEntityHandle());
  424.         return Plugin_Changed;
  425.     }
  426.     return Plugin_Continue;
  427. }
  428.  
  429. public Action:L4D2_OnBoomerAttackUpdate(boomer, &victim)
  430. {
  431.     if (g_boomeraitype == 1) //1 = Prioritize Survivor with lowest hp (EXCLUDING INCAPS)
  432.     {
  433.         new weakestclient, leasthp = 100, mostincaps = 0;
  434.         for (new target = 1; target <= MaxClients; target++)
  435.         {
  436.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  437.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(boomer, target, 400.0))
  438.             {
  439.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") >= mostincaps)
  440.                 {
  441.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) <= leasthp)
  442.                     {
  443.                         mostincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  444.                         leasthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  445.                         weakestclient = target;
  446.                     }
  447.                 }
  448.             }
  449.         }
  450.         #if DEBUG
  451.         Debug_PrintText("boomer (%i, %N) has changed targets to Survivor %N! (id:%i)", boomer, boomer, weakestclient, weakestclient);
  452.         #endif
  453.         // he is now the boomer's target
  454.         victim = GetEntData(weakestclient, L4D2_RefEntityHandle());
  455.         return Plugin_Changed;
  456.     }
  457.     else if (g_boomeraitype == 2) //2 = Prioritize Survivor with higest hp (EXCLUDING INCAPS)
  458.     {
  459.         new healthiestclient, mosthp = 0, leastincaps = 5;
  460.         for (new target = 1; target <= MaxClients; target++)
  461.         {
  462.             // Is our new target alive? not incapped? not pinned by another si? not too far away?
  463.             if (IsSurvivor(target) && IsPlayerAlive(target) && !IsIncaped(target) && !IsPlayerHeld(target) && IsNotFarFromTarget(boomer, target, 400.0))
  464.             {
  465.                 if (GetEntProp(target, Prop_Send, "m_currentReviveCount") <= leastincaps)
  466.                 {
  467.                     if (GetClientHealth(target) + GetPlayerTempHealth(target) >= mosthp)
  468.                     {
  469.                         leastincaps = GetEntProp(target, Prop_Send, "m_currentReviveCount");
  470.                         mosthp = GetClientHealth(target) + GetPlayerTempHealth(target);
  471.                         healthiestclient = target;
  472.                     }
  473.                 }
  474.             }
  475.         }
  476.         #if DEBUG
  477.         Debug_PrintText("boomer (%i, %N) has changed targets to Survivor %N! (id:%i)", boomer, boomer, healthiestclient, healthiestclient);
  478.         #endif
  479.         // he is now the boomer's target
  480.         victim = GetEntData(healthiestclient, L4D2_RefEntityHandle());
  481.         return Plugin_Changed;
  482.     }
  483.     return Plugin_Continue;
  484. }
  485.  
  486. stock bool:IsTank(client)
  487. {
  488.     return GetEntProp(client, Prop_Send, "m_zombieClass") == 8;
  489. }
  490.  
  491. stock bool:IsSurvivor(client)
  492. {
  493.     return client > 0 && client <= MaxClients && IsClientInGame(client) && (GetClientTeam(client) == 2 || GetClientTeam(client) == 4);
  494. }
  495.  
  496. stock bool:IsInfected(client)
  497. {
  498.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3;
  499. }
  500.  
  501. stock bool:IsIncaped(client)
  502. {
  503.     return bool:GetEntProp(client, Prop_Send, "m_isIncapacitated", 1);
  504. }
  505.  
  506. stock bool:IsPlayerHeld(client)
  507. {
  508.     new jockey = GetEntPropEnt(client, Prop_Send, "m_jockeyAttacker");
  509.     new charger = GetEntPropEnt(client, Prop_Send, "m_pummelAttacker");
  510.     new hunter = GetEntPropEnt(client, Prop_Send, "m_pounceAttacker");
  511.     new smoker = GetEntPropEnt(client, Prop_Send, "m_tongueOwner");
  512.     if (jockey > 0 || charger > 0 || hunter > 0 || smoker > 0)
  513.     {
  514.         return true;
  515.     }
  516.     return false;
  517. }
  518.  
  519. stock bool:IsNotFarFromTarget(client, target, Float:targetdistance)
  520. {
  521.     new Float:Origin[3], Float:TOrigin[3];
  522.    
  523.     GetEntPropVector(client, Prop_Send, "m_vecOrigin", Origin);
  524.     GetEntPropVector(target, Prop_Send, "m_vecOrigin", TOrigin);
  525.    
  526.     new Float:distance = GetVectorDistance(TOrigin, Origin);
  527.    
  528.     if (distance <= targetdistance)
  529.     {
  530.         return true;
  531.     }
  532.     return false;
  533. }
  534.  
  535. // temp health stock bool shamelessly taken from l4d_stocks
  536. stock GetPlayerTempHealth(client)
  537. {
  538.     static Handle:painPillsDecayCvar = INVALID_HANDLE;
  539.     if (painPillsDecayCvar == INVALID_HANDLE)
  540.     {
  541.         painPillsDecayCvar = FindConVar("pain_pills_decay_rate");
  542.         if (painPillsDecayCvar == INVALID_HANDLE)
  543.         {
  544.             return -1;
  545.         }
  546.     }
  547.    
  548.     new tempHealth = RoundToCeil(GetEntPropFloat(client, Prop_Send, "m_healthBuffer") - ((GetGameTime() - GetEntPropFloat(client, Prop_Send, "m_healthBufferTime")) * GetConVarFloat(painPillsDecayCvar))) - 1;
  549.     return tempHealth < 0 ? 0 : tempHealth;
  550. }
  551.  
  552. public ConVarHunterAIType(Handle:convar, const String:oldValue[], const String:newValue[])
  553. {
  554.     g_hunteraitype = GetConVarInt(convar);
  555. }
  556. public ConVarJockeyAIType(Handle:convar, const String:oldValue[], const String:newValue[])
  557. {
  558.     g_jockeyaitype = GetConVarInt(convar);
  559. }
  560. public ConVarChargerAIType(Handle:convar, const String:oldValue[], const String:newValue[])
  561. {
  562.     g_chargeraitype = GetConVarInt(convar);
  563. }
  564. public ConVarSmokerAIType(Handle:convar, const String:oldValue[], const String:newValue[])
  565. {
  566.     g_smokeraitype = GetConVarInt(convar);
  567. }
  568. public ConVarSpitterAIType(Handle:convar, const String:oldValue[], const String:newValue[])
  569. {
  570.     g_spitteraitype = GetConVarInt(convar);
  571. }
  572. public ConVarBoomerAIType(Handle:convar, const String:oldValue[], const String:newValue[])
  573. {
  574.     g_boomeraitype = GetConVarInt(convar);
  575. }
  576.  
  577. #if DEBUG
  578. stock Debug_PrintText(const String:format[], any:...)
  579. {
  580.     decl String:buffer[256];
  581.     VFormat(buffer, sizeof(buffer), format, 2);
  582.     LogMessage(buffer);
  583.    
  584.     new AdminId:adminId;
  585.     for (new client = 1; client <= MaxClients; client++)
  586.     {
  587.         if (!IsClientInGame(client) || IsFakeClient(client))
  588.         {
  589.             continue;
  590.         }
  591.         adminId = GetUserAdmin(client);
  592.         if (adminId == INVALID_ADMIN_ID || !GetAdminFlag(adminId, Admin_Root))
  593.         {
  594.             continue;
  595.         }
  596.         PrintToChat(client, DEBUG_PRINT_FORMAT, DEBUG_TAG, buffer);
  597.     }
  598. }
  599. #endif
Advertisement
Add Comment
Please, Sign In to add comment