DeathChaos25

[L4D2] Missing Survivor Fix

Aug 20th, 2015
727
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.83 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. static const String:MODEL_NICK[] = "models/survivors/survivor_gambler.mdl";
  4. static const String:MODEL_ROCHELLE[] = "models/survivors/survivor_producer.mdl";
  5. static const String:MODEL_COACH[] = "models/survivors/survivor_coach.mdl";
  6. static const String:MODEL_ELLIS[] = "models/survivors/survivor_mechanic.mdl";
  7.  
  8. #define MODEL_BILL "models/survivors/survivor_namvet.mdl"
  9. #define MODEL_ZOEY  "models/survivors/survivor_teenangst.mdl"
  10. #define MODEL_FRANCIS "models/survivors/survivor_biker.mdl"
  11. #define MODEL_LOUIS "models/survivors/survivor_manager.mdl"
  12.  
  13. #define MODEL_KIT "models/w_models/weapons/w_eq_medkit.mdl"
  14.  
  15. #include <sourcemod>
  16. #include <sdktools>
  17. #include <sdkhooks>
  18. #define PLUGIN_VERSION "1.0"
  19.  
  20. static bool:CoachExists = false;
  21. static bool:EllisExists = false;
  22. static bool:RochelleExists = false;
  23. static bool:NickExists = false;
  24.  
  25. static bool:BillExists = false;
  26. static bool:FrancisExists = false;
  27. static bool:LouisExists = false;
  28. static bool:ZoeyExists = false;
  29.  
  30. /* Plugin Information */
  31. public Plugin:myinfo =  {
  32.     name = "[L4D2] Missing Survivor Fix",
  33.     author = "DeathChaos25",
  34.     description = "",
  35.     url = ""
  36. }
  37.  
  38. public OnMapStart()
  39. {
  40.     ServerCommand("exec server");
  41. }
  42.  
  43. public void OnPluginStart()
  44. {
  45.     HookEvent("item_pickup", FIXBOTS);
  46.     HookEvent("round_start", Event_RoundStart, EventHookMode_Post);
  47. }
  48.  
  49. public FIXBOTS(Handle:event, const String:name[], bool:dontBroadcast)
  50. {
  51.     CreateTimer(0.2, FixBots);
  52.     CreateTimer(0.3, CheckMaxPlayers);
  53. }
  54.  
  55. public Action:Event_RoundStart(Handle:event, String:name[], bool:dontBroadcast)
  56. {
  57.     CreateTimer(10.0, GiveItems);
  58. }
  59. public Action:GiveItems(Handle:Timer)
  60. {
  61.     for (new i = 1; i <= MaxClients; i++)
  62.     {
  63.         if (IsSurvivor(i))
  64.         {
  65.             new item = GetPlayerWeaponSlot(i, 3);
  66.             new defib;
  67.             if (!IsValidEdict(item))
  68.             {
  69.                 new rng = GetRandomInt(1, 2);
  70.                 switch (rng)
  71.                 {
  72.                     case 1:defib = CreateEntityByName("weapon_defibrillator");
  73.                     case 2:defib = CreateEntityByName("weapon_first_aid_kit");
  74.                 }
  75.                 DispatchSpawn(defib);
  76.                 EquipPlayerWeapon(i, defib);
  77.             }
  78.             item = GetPlayerWeaponSlot(i, 4);
  79.             if (!IsValidEdict(item))
  80.             {
  81.                 new rng = GetRandomInt(1, 2);
  82.                 switch (rng)
  83.                 {
  84.                     case 1:defib = CreateEntityByName("weapon_pain_pills");
  85.                     case 2:defib = CreateEntityByName("weapon_adrenaline");
  86.                 }
  87.                 DispatchSpawn(defib);
  88.                 EquipPlayerWeapon(i, defib);
  89.             }
  90.         }
  91.     }
  92. }
  93.  
  94. public Action:CheckMaxPlayers(Handle:Timer)
  95. {
  96.     new Survivors = 0;
  97.     new LastBot = 0;
  98.    
  99.     for (new i = 1; i <= MaxClients; i++)
  100.     {
  101.         if (IsSurvivor(i))
  102.         {
  103.             Survivors++;
  104.         }
  105.         if (IsSurvivor(i) && IsFakeClient(i))
  106.         {
  107.             LastBot = i;
  108.         }
  109.     }
  110.     if (Survivors < 8)
  111.     {
  112.         CreateBot();
  113.     }
  114.     else if (Survivors > 8 && IsSurvivor(LastBot) && IsFakeClient(LastBot))
  115.     {
  116.         KickClient(LastBot);
  117.     }
  118. }
  119. public Action:FixBots(Handle:Timer)
  120. {
  121.     CoachExists = false;
  122.     EllisExists = false;
  123.     RochelleExists = false;
  124.     NickExists = false;
  125.    
  126.     BillExists = false;
  127.     FrancisExists = false;
  128.     LouisExists = false;
  129.     ZoeyExists = false;
  130.    
  131.     for (new i = 1; i <= MaxClients; i++)
  132.     {
  133.         if (IsSurvivor(i))
  134.         {
  135.             new String:model[128];
  136.             GetClientModel(i, model, sizeof(model));
  137.            
  138.             if (StrEqual(model, MODEL_COACH))
  139.             {
  140.                 CoachExists = true;
  141.             }
  142.             if (StrEqual(model, MODEL_ELLIS))
  143.             {
  144.                 EllisExists = true;
  145.             }
  146.             if (StrEqual(model, MODEL_ROCHELLE))
  147.             {
  148.                 RochelleExists = true;
  149.             }
  150.             if (StrEqual(model, MODEL_NICK))
  151.             {
  152.                 NickExists = true;
  153.             }
  154.             if (StrEqual(model, MODEL_BILL))
  155.             {
  156.                 BillExists = true;
  157.             }
  158.             if (StrEqual(model, MODEL_LOUIS))
  159.             {
  160.                 LouisExists = true;
  161.             }
  162.             if (StrEqual(model, MODEL_FRANCIS))
  163.             {
  164.                 FrancisExists = true;
  165.             }
  166.             if (StrEqual(model, MODEL_ZOEY))
  167.             {
  168.                 ZoeyExists = true;
  169.             }
  170.         }
  171.     }
  172.    
  173.     for (new i = 1; i <= MaxClients; i++)
  174.     {
  175.         if (IsSurvivor(i))
  176.         {
  177.             new String:model[128], String:model2[128];
  178.             GetClientModel(i, model, 128);
  179.             if (!CoachExists)
  180.             {
  181.                 for (new client = 1; client <= MaxClients; client++)
  182.                 {
  183.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  184.                     {
  185.                         GetClientModel(client, model2, 128);
  186.                         if (StrEqual(model, model2))
  187.                         {
  188.                             FakeClientCommand(client, "say /c");
  189.                             CoachExists = true;
  190.                         }
  191.                     }
  192.                 }
  193.             }
  194.             if (!EllisExists)
  195.             {
  196.                 for (new client = 1; client <= MaxClients; client++)
  197.                 {
  198.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  199.                     {
  200.                         GetClientModel(client, model2, 128);
  201.                         if (StrEqual(model, model2))
  202.                         {
  203.                             FakeClientCommand(client, "say /e");
  204.                             EllisExists = true;
  205.                         }
  206.                     }
  207.                 }
  208.             }
  209.             if (!RochelleExists)
  210.             {
  211.                 for (new client = 1; client <= MaxClients; client++)
  212.                 {
  213.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  214.                     {
  215.                         GetClientModel(client, model2, 128);
  216.                         if (StrEqual(model, model2))
  217.                         {
  218.                             FakeClientCommand(client, "say /r");
  219.                             RochelleExists = true;
  220.                         }
  221.                     }
  222.                 }
  223.             }
  224.             if (!NickExists)
  225.             {
  226.                 for (new client = 1; client <= MaxClients; client++)
  227.                 {
  228.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  229.                     {
  230.                         GetClientModel(client, model2, 128);
  231.                         if (StrEqual(model, model2))
  232.                         {
  233.                             FakeClientCommand(client, "say /n");
  234.                             NickExists = true;
  235.                         }
  236.                     }
  237.                 }
  238.             }
  239.             if (!BillExists)
  240.             {
  241.                 for (new client = 1; client <= MaxClients; client++)
  242.                 {
  243.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  244.                     {
  245.                         GetClientModel(client, model2, 128);
  246.                         if (StrEqual(model, model2))
  247.                         {
  248.                             FakeClientCommand(client, "say /b");
  249.                             BillExists = true;
  250.                         }
  251.                     }
  252.                 }
  253.             }
  254.             if (!LouisExists)
  255.             {
  256.                 for (new client = 1; client <= MaxClients; client++)
  257.                 {
  258.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  259.                     {
  260.                         GetClientModel(client, model2, 128);
  261.                         if (StrEqual(model, model2))
  262.                         {
  263.                             FakeClientCommand(client, "say /l");
  264.                             LouisExists = true;
  265.                         }
  266.                     }
  267.                 }
  268.             }
  269.             if (!FrancisExists)
  270.             {
  271.                 for (new client = 1; client <= MaxClients; client++)
  272.                 {
  273.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  274.                     {
  275.                         GetClientModel(client, model2, 128);
  276.                         if (StrEqual(model, model2))
  277.                         {
  278.                             FakeClientCommand(client, "say /f");
  279.                             FrancisExists = true;
  280.                         }
  281.                     }
  282.                 }
  283.             }
  284.             if (!ZoeyExists)
  285.             {
  286.                 for (new client = 1; client <= MaxClients; client++)
  287.                 {
  288.                     if (IsSurvivor(client) && client != i && IsFakeClient(client))
  289.                     {
  290.                         GetClientModel(client, model2, 128);
  291.                         if (StrEqual(model, model2))
  292.                         {
  293.                             FakeClientCommand(client, "say /z");
  294.                             ZoeyExists = true;
  295.                         }
  296.                     }
  297.                 }
  298.             }
  299.         }
  300.     }
  301. }
  302.  
  303. stock bool:IsSurvivor(client)
  304. {
  305.     return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2;
  306. }
  307.  
  308. stock CreateBot()
  309. {
  310.     // Spawn bot survivor.
  311.     new Bot = CreateFakeClient("SurvivorBot");
  312.     if (Bot == 0)
  313.         return;
  314.    
  315.     ChangeClientTeam(Bot, 2);
  316.     if (DispatchKeyValue(Bot, "classname", "SurvivorBot") == false)
  317.     {
  318.         return;
  319.     }
  320.     DispatchSpawn(Bot);
  321.     if (DispatchSpawn(Bot) == false)
  322.     {
  323.         return;
  324.     }
  325.     if (!IsPlayerAlive(Bot))
  326.     {
  327.         Respawn(Bot);
  328.     }
  329.    
  330.     if (IsSurvivor(Bot) && IsFakeClient(Bot))
  331.         KickClient(Bot, "Kicking Fake Client.");
  332. }
  333.  
  334. stock Respawn(client)
  335. {
  336.     static Handle:hRoundRespawn = INVALID_HANDLE;
  337.     if (hRoundRespawn == INVALID_HANDLE)
  338.     {
  339.         new Handle:hGameConf = LoadGameConfigFile("l4d_superversus");
  340.         StartPrepSDKCall(SDKCall_Player);
  341.         PrepSDKCall_SetFromConf(hGameConf, SDKConf_Signature, "RoundRespawn");
  342.         hRoundRespawn = EndPrepSDKCall();
  343.         if (hRoundRespawn == INVALID_HANDLE)
  344.         {
  345.             PrintToChatAll("L4D_SM_Respawn: RoundRespawn Signature broken");
  346.         }
  347.     }
  348.     SDKCall(hRoundRespawn, client);
  349. }
Advertisement
Add Comment
Please, Sign In to add comment