Guest User

Untitled

a guest
Apr 30th, 2010
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.64 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5.  
  6. #define PLUGIN_VERSION "1.1"
  7.  
  8. #define L4D_MAXPLAYERS 14
  9. #define L4D_TEAM_UNASSIGNED 0
  10. #define L4D_TEAM_SPECTATOR 1
  11. #define L4D_TEAM_SURVIVOR 2
  12. #define L4D_TEAM_INFECTED 3
  13.  
  14. public Plugin:info = {
  15.     name = "[MV] L4D TakeOverBot",
  16.     version = PLUGIN_VERSION,
  17.     description = "Let's you take over bots when you're dead.",
  18.     author = "Matthias Vance",
  19.     url = "http://www.matthiasvance.com/" // Nothing there at the moment
  20. }
  21.  
  22. new Handle:hSetHumanSpec, Handle:hTakeOverBot;
  23. new bool:bRoundEnd = false;
  24. //new nDeadPlayers[L4D_MAXPLAYERS];
  25.  
  26. public OnPluginStart() {
  27.     CreateConVar("mv_l4d_takeoverbot_version", PLUGIN_VERSION, "[MV] L4D TakeOverBot Version", FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_NOTIFY);
  28.  
  29.     new Handle:hConfig = LoadGameConfigFile("mv_l4d_takeoverbot");
  30.     if(hConfig == INVALID_HANDLE) {
  31.         SetFailState("[MV] Could not load mv_l4d_takeoverbot gamedata.");
  32.     } else {
  33.         // SetHumanSpec
  34.         StartPrepSDKCall(SDKCall_Player);
  35.         if(PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "SetHumanSpec")) {
  36.             PrepSDKCall_AddParameter(SDKType_CBasePlayer, SDKPass_Pointer);
  37.             hSetHumanSpec = EndPrepSDKCall();
  38.         }
  39.  
  40.         // TakeOverBot
  41.         StartPrepSDKCall(SDKCall_Player);
  42.         if(PrepSDKCall_SetFromConf(hConfig, SDKConf_Signature, "TakeOverBot")) {
  43.             PrepSDKCall_AddParameter(SDKType_Bool, SDKPass_Plain);
  44.             hTakeOverBot = EndPrepSDKCall();
  45.         }
  46.  
  47.         if(hSetHumanSpec == INVALID_HANDLE || hTakeOverBot == INVALID_HANDLE) {
  48.             SetFailState("[MV] Could not find the correct signatures.");
  49.         } else {
  50.             HookEvent("player_death", event_PlayerDeath);
  51.             HookEvent("mission_lost", event_MissionLost);
  52.             HookEvent("round_start", event_RoundStart);
  53.             /*HookEvent("player_bot_replace", event_PlayerBotReplace);
  54.             HookEvent("player_spawn", event_PlayerSpawn);*/
  55.  
  56.             CreateConVar("tob_enable", "1");
  57.             CreateConVar("tob_respawn_time", "5.0", "", 0, true, 5.0);
  58.         }
  59.     }
  60. }
  61.  
  62. /*
  63. stock array_filter(array[], nLength) {
  64.     new nValue;
  65.     for(new i = 0; i < nLength - 1; i++) {
  66.         nValue = array[i];
  67.         if(!nValue) {
  68.             array[i] = array[i + 1];
  69.             array[i + 1] = 0;
  70.         }
  71.     }
  72. }
  73.  
  74. stock array_remove(array[], nLength, value) {
  75.     new index = array_find_int(array, nLength, value);
  76.     if(index != -1) {
  77.         array[index] = 0;
  78.     }
  79. }
  80.  
  81. stock array_clear(array[], nLength) {
  82.     for(new i = 0; i < nLength; i++) {
  83.         array[i] = 0;
  84.     }
  85. }
  86.  
  87. public RemoveDeadPlayer(nClient) {
  88.     array_remove(nDeadPlayers, sizeof(nDeadPlayers), nClient);
  89.     array_filter(nDeadPlayers, sizeof(nDeadPlayers));
  90. }
  91.  
  92. public AddDeadPlayer(nClient) {
  93.     for(new i = 0; i < sizeof(nDeadPlayers); i++) {
  94.         if(!nDeadPlayers[i]) {
  95.             nDeadPlayers[i] = nClient;
  96.             break;
  97.         }
  98.     }
  99. }
  100.  
  101. public Action:event_PlayerSpawn(Handle:hEvent, String:sEventName[], bool:bDontBroadcast) {
  102.     new nClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
  103.     RemoveDeadPlayer(nClient);
  104. }
  105.  
  106. public Action:event_PlayerBotReplace(Handle:hEvent, String:sEventName[], bool:bDontBroadcast) {
  107.     new nBot = GetClientOfUserId(GetEventInt(hEvent, "bot"));
  108.     if(GetClientTeam(nBot) == L4D_TEAM_SURVIVOR) {
  109.         // Check for available clients
  110.         new nClient = nDeadPlayers[0];
  111.         if(nClient) {
  112.             TakeOverBot(nClient);
  113.         }
  114.     }
  115. }*/
  116.  
  117. public Action:event_MissionLost(Handle:hEvent, String:sEventName[], bool:bDontBroadcast) {
  118.     bRoundEnd = true;
  119. }
  120.  
  121. public OnClientDisconnect(nClient) {
  122.     //RemoveDeadPlayer(nClient);
  123. }
  124.  
  125. public Action:event_RoundStart(Handle:hEvent, String:sEventName[], bool:bDontBroadcast) {
  126.     bRoundEnd = false;
  127.     //array_clear(nDeadPlayers);
  128. }
  129.  
  130. public Action:event_PlayerDeath(Handle:hEvent, String:sEventName[], bool:bDontBroadcast) {
  131.     new nClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
  132.     new Attacker = GetClientOfUserId(GetEventInt(hEvent, "attacker"));
  133.  
  134.     /*
  135.     LogMessage("%i", Attacker);
  136.     if ( nClient == Attacker && nClient ) {
  137.         LogMessage("%i SUICIDE", Attacker);
  138.     }  
  139.     */
  140.  
  141.     if(!bRoundEnd && nClient && IsClientConnected(nClient) && !IsFakeClient(nClient) && GetClientTeam(nClient) == L4D_TEAM_SURVIVOR && nClient != Attacker) {
  142.         /*if(GetFirstDeadPlayer()) {
  143.             AddDeadPlayer(nClient);
  144.         } else {*/
  145.             LogMessage("%i TAKING OVER BOT", Attacker);
  146.             TakeOverBot(nClient);
  147.         /*}*/
  148.     }
  149. }
  150.  
  151. public TakeOverBot(nClient) {
  152.     new nBot = FindBot(L4D_TEAM_SURVIVOR, true);
  153.     if(nBot) {
  154.         new Handle:hConVar = FindConVar("tob_respawn_time");
  155.         new Handle:hPanel = CreatePanel();
  156.  
  157.         new String:sMessage[64];
  158.         Format(sMessage, sizeof(sMessage), "You will take over a survivor bot in %d seconds.", GetConVarInt(hConVar));
  159.         DrawPanelText(hPanel, sMessage);
  160.         SendPanelToClient(hPanel, nClient, panel_TakeOverBot, 3);
  161.         CloseHandle(hPanel);
  162.  
  163.         SDKCall(hSetHumanSpec, nBot, nClient);
  164.  
  165.         ChangeClientTeam(nClient, L4D_TEAM_SPECTATOR);
  166.         CreateTimer(GetConVarFloat(hConVar), timer_ChangeTeam, nClient);
  167.     }
  168. }
  169.  
  170. public panel_TakeOverBot(Handle:hPanel, MenuAction:action, param1, param2) {
  171.     // Do nothing
  172. }
  173.  
  174. public Action:timer_ChangeTeam(Handle:hTimer, any:nClient) {
  175.     if(!bRoundEnd && IsClientConnected(nClient) && GetClientTeam(nClient) == L4D_TEAM_SPECTATOR) {
  176.         new nBot = FindBot(L4D_TEAM_SURVIVOR, true);
  177.         if(nBot) {
  178.             SDKCall(hSetHumanSpec, nBot, nClient);
  179.             SDKCall(hTakeOverBot, nClient, true);
  180.         } else {
  181.             nBot = FindBot(L4D_TEAM_SURVIVOR, false);
  182.             if(nBot) {
  183.                 SDKCall(hSetHumanSpec, nBot, nClient);
  184.                 SDKCall(hTakeOverBot, nClient, true);
  185.             }
  186.         }
  187.     }
  188. }
  189.  
  190. stock FindBot(nTeam, bool:bAlive) {
  191.     for(new i = 1; i < L4D_MAXPLAYERS; i++) {
  192.         if(IsClientConnected(i) && IsFakeClient(i) && GetClientTeam(i) == nTeam) {
  193.             if(bAlive) {
  194.                 if(IsPlayerAlive(i)) {
  195.                     return i;
  196.                 }
  197.             } else {
  198.                 return i;
  199.             }
  200.         }
  201.     }
  202.     return 0;
  203. }
Advertisement
Add Comment
Please, Sign In to add comment