B2SX

[CSGO] Advanced Auto Respawn

Jan 18th, 2018
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.80 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <sdktools>
  3.  
  4. #define PREFIX "\x01[\x03SM\x01]"
  5.  
  6. float gf_UsedVAR[32];
  7. Handle ARVEnabled = INVALID_HANDLE, gHud;
  8. bool gb_AutoRespawn = false, gb_ARVoted[32] =  { false, ... };
  9. int gi_ARVoters = 0, gi_ARVotes = 0, gi_ARVotesNeeded = 0, gVAR, TimeAR, SpawnProtection, ARTime;
  10.  
  11. public Plugin myinfo =
  12. {
  13.     name = "[CSGO] Advanced Auto Respawn",
  14.     author = "BaroNN",
  15.     description = "",
  16.     version = "1.5",
  17.     url = "http://steamcommunity.com/id/BaRoNN-Main"
  18. }
  19.  
  20. public OnPluginStart()
  21. {
  22.     RegConsoleCmd("sm_votear", PlayerVoting);
  23.     RegAdminCmd("sm_ar", AR, ADMFLAG_GENERIC);
  24.     ARVEnabled = CreateConVar("sm_autorespawn_playervote", "0", "Player vote Enabled?");
  25.     HookConVarChange(ARVEnabled, OnCvarChanged);
  26.     HookEvent("player_spawn", Hook);
  27.     gHud = CreateHudSynchronizer();
  28. }
  29.  
  30. public void OnMapStart()
  31. {
  32.     ServerCommand("sm_cvar mp_autokick 0")
  33. }
  34.  
  35. public Action AR(int client, int args)
  36. {
  37.     if (!IsValidClient(client))
  38.         return Plugin_Handled;
  39.    
  40.     char String1[128];
  41.     Handle menu = CreateMenu(MenuHandelr);
  42.     SetMenuTitle(menu, "[AutoRespawn] Main Menu");
  43.    
  44.     if (!gVAR)AddMenuItem(menu, "", "Enable AutoRespawn");
  45.     else AddMenuItem(menu, "", "Disable AutoRespawn");
  46.    
  47.     Format(String1, 128, "Time: %d minutes", ARTime);
  48.     if (ARTime != 0)AddMenuItem(menu, "", String1);
  49.     else AddMenuItem(menu, "", "Time: Unlimted");
  50.    
  51.     Format(String1, 128, "Spawn Protection - %s", SpawnProtection ? ("Yes"):("No"));
  52.     AddMenuItem(menu, "", String1);
  53.    
  54.     if (!gVAR)AddMenuItem(menu, "", "Vote For AutoRespawn");
  55.     else AddMenuItem(menu, "", "Vote For AutoRespawn", ITEMDRAW_DISABLED);
  56.    
  57.     DisplayMenu(menu, client, 15);
  58.     return Plugin_Continue;
  59. }
  60.  
  61. public int MenuHandelr(Menu menu, MenuAction action, int client, int itemNum)
  62. {
  63.     if (action != MenuAction_Select || !IsClientConnected(client))
  64.         return 1;
  65.    
  66.     switch (itemNum)
  67.     {
  68.         case 0:
  69.         {
  70.             if (gVAR)
  71.             {
  72.                 gVAR = 0;
  73.                 TimeAR = false;
  74.                 AR(client, 0);
  75.                 ServerCommand("mp_respawn_on_death_t 0"), ServerCommand("mp_respawn_on_death_ct 0");
  76.                 PrintToChatAll("%s \x01%N \x02Disabled \x04Auto Respawn!", PREFIX, client);
  77.                 SetHudTextParams(0.3, 0.150, 5.0, 255, 0, 0, 255, 1, 0.1, 0.1, 0.1);
  78.                 for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "%N Disabled Auto Respawn!", client);
  79.             }
  80.             else
  81.             {
  82.                 gVAR = 1;
  83.                 AR(client, 0);
  84.                 ServerCommand("mp_respawn_on_death_t 1"), ServerCommand("mp_respawn_on_death_ct 1");
  85.                
  86.                 if (ARTime != 0)
  87.                 {
  88.                     TimeAR = true;
  89.                     int sec = ARTime * 60;
  90.                     CreateTimer(float(sec), DisableAutoRespawn, client);
  91.                     PrintToChatAll("%s \x01%N \x04Enabled\x03 Auto Respawn for %d minutes!", PREFIX, client, ARTime);
  92.                     SetHudTextParams(0.3, 0.150, 5.0, 0, 250, 0, 255, 1, 0.1, 0.1, 0.1);
  93.                     for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "%N Enabled Auto Respawn for %d minutes!", client, ARTime);
  94.                 }
  95.                 else
  96.                 {
  97.                     PrintToChatAll("%s \x01%N \x04Enabled\x03 Auto Respawn!", PREFIX, client);
  98.                     SetHudTextParams(0.3, 0.150, 5.0, 0, 255, 0, 255, 1, 0.1, 0.1, 0.1);
  99.                     for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "%N Enabled Auto Respawn!", client);
  100.                 }
  101.             }
  102.         }
  103.         case 1:
  104.         {
  105.             ARTime += 5;
  106.             if (ARTime > 60)ARTime = 0;
  107.             AR(client, 0);
  108.         }
  109.         case 2:
  110.         {
  111.             SpawnProtection = !SpawnProtection;
  112.             SetHudTextParams(0.3, 0.150, 5.0, 255, 215, 0, 255, 1, 0.1, 0.1, 0.1);
  113.             for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "%N %s Spawn Protection!", client, SpawnProtection ? ("Enabled"):("Disabled"));
  114.             AR(client, 0);
  115.         }
  116.         case 3:
  117.         {
  118.             gVAR = 1;
  119.             ShowMenu();
  120.             PrintToChatAll("%s \x01%N \x04Started a\x03 Vote for Auto Respawn", PREFIX, client);
  121.             SetHudTextParams(0.3, 0.150, 5.0, 0, 0, 255, 255, 1, 0.1, 0.1, 0.1);
  122.             for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "%N Started a Vote for Auto Respawn", client);
  123.         }
  124.     }
  125.     return 0;
  126. }
  127.  
  128. public Action PlayerVoting(int client, int args)
  129. {
  130.     if (GetConVarBool(ARVEnabled))
  131.     {
  132.         if (GetEngineTime() - gf_UsedVAR[client] < 5)
  133.         {
  134.             PrintToChat(client, "%s \x02Vote AutoRespawn\x04 Is allowed once in 5 seconds", PREFIX);
  135.             return Plugin_Handled;
  136.         }
  137.         gf_UsedVAR[client] = GetEngineTime();
  138.        
  139.         char name[64];
  140.         GetClientName(client, name, sizeof(name));
  141.         if (!gb_ARVoted[client])
  142.         {
  143.             gi_ARVotes++;
  144.             PrintToChatAll("%s \x02%s\x04 Wants To \x02%s%\x04 AutoRespawn (%d votes, %d required)", PREFIX, name, gb_AutoRespawn ? "Disable":"Enable", gi_ARVotes, gi_ARVotesNeeded);
  145.         }
  146.         else
  147.         {
  148.             gi_ARVotes--;
  149.             PrintToChatAll("%s \x02%s\x04 devoted (%d votes, %d required)", PREFIX, name, gi_ARVotes, gi_ARVotesNeeded);
  150.         }
  151.        
  152.         SetConVarInt(ARVEnabled, 1);
  153.         gb_ARVoted[client] = !gb_ARVoted[client];
  154.        
  155.         if (gi_ARVotes >= gi_ARVotesNeeded)
  156.         {
  157.             EnableAutoRespawn();
  158.         }
  159.         return Plugin_Handled;
  160.     }
  161.     else
  162.     {
  163.         SetConVarInt(ARVEnabled, 0);
  164.         PrintToChat(client, "%s \x02Player Voting is Currently Disabled!", PREFIX)
  165.     }
  166.     return Plugin_Handled;
  167. }
  168.  
  169. public void ShowMenu()
  170. {
  171.     if (IsVoteInProgress())
  172.     {
  173.         return;
  174.     }
  175.    
  176.     Handle vote = CreateMenu(VoteCT_Handler);
  177.     SetMenuTitle(vote, "[SM] Enable AutoRespawn?");
  178.     AddMenuItem(vote, "Yes", "Yes");
  179.     AddMenuItem(vote, "No", "No");
  180.     SetMenuExitButton(vote, false);
  181.    
  182.     VoteMenuToAll(vote, 20);
  183. }
  184.  
  185. public VoteCT_Handler(Handle menu, MenuAction:action, param1, param2)
  186. {
  187.     if (action == MenuAction_VoteEnd)
  188.     {
  189.         char info[32];
  190.         GetMenuItem(menu, param1, info, 32);
  191.        
  192.         if (StrEqual(info, "Yes"))
  193.         {
  194.             gVAR = 1;
  195.             ServerCommand("mp_respawn_on_death_ct 1");
  196.             ServerCommand("mp_respawn_on_death_t 1");
  197.             PrintToChatAll("%s \x04Vote has been Success\x10 AutoRespawn Has been \x04Enabled", PREFIX);
  198.             SetHudTextParams(0.3, 0.150, 5.0, 0, 240, 0, 255, 1, 0.1, 0.1, 0.1);
  199.             for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "Vote has been Success, AutoRespawn Has been Enabled!");
  200.         }
  201.         else if (StrEqual(info, "No"))
  202.         {
  203.             gVAR = 0;
  204.             ServerCommand("mp_respawn_on_death_ct 0");
  205.             ServerCommand("mp_respawn_on_death_t 0");
  206.             PrintToChatAll("%s \x02Vote Failed\x10 AutoRespawn Will Be \x02Disabled", PREFIX);
  207.             SetHudTextParams(0.3, 0.150, 5.0, 240, 0, 0, 255, 1, 0.1, 0.1, 0.1);
  208.             for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "Vote Failed, AutoRespawn Will Be Disabled!");
  209.         }
  210.     }
  211.     return 0;
  212. }
  213.  
  214. public Action DisableAutoRespawn(Handle timer, any client)
  215. {
  216.     if (TimeAR)
  217.     {
  218.         gVAR = 0;
  219.         SetHudTextParams(0.3, 0.150, 5.0, 0, 230, 0, 255, 1, 0.1, 0.1, 0.1);
  220.         for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "AutoRespawn Has Been Disabled Automatically!");
  221.         PrintToChatAll("%s \x02Auto Respawn has been \x02Disabled \x10Automatically!", PREFIX);
  222.         ServerCommand("mp_respawn_on_death_ct 0");
  223.         ServerCommand("mp_respawn_on_death_t 0");
  224.     }
  225. }
  226.  
  227. EnableAutoRespawn()
  228. {
  229.     for (int i = 0; i < MAXPLAYERS; i++)
  230.     {
  231.         gb_ARVoted[i] = false;
  232.     }
  233.     gi_ARVotes = 0;
  234.     gi_ARVotesNeeded = RoundToFloor(float(gi_ARVoters) * 0.5);
  235.     gb_AutoRespawn = !gb_AutoRespawn;
  236.    
  237.     if (gb_AutoRespawn)
  238.     {
  239.         gVAR = 1;
  240.         gb_AutoRespawn = true;
  241.         ServerCommand("mp_respawn_on_death_ct 1");
  242.         ServerCommand("mp_respawn_on_death_t 1");
  243.     }
  244.     else
  245.     {
  246.         gVAR = 0;
  247.         gb_AutoRespawn = false;
  248.         ServerCommand("mp_respawn_on_death_ct 0");
  249.         ServerCommand("mp_respawn_on_death_t 0");
  250.     }
  251.     PrintToChatAll("%s \x03AutoRespawn Has been \x02%s", PREFIX, gb_AutoRespawn ? "Enabled":"Disabled");
  252.     SetHudTextParams(0.3, 0.150, 5.0, 255, 215, 0, 255, 1, 0.1, 0.1, 0.1);
  253.     for (int i = 1; i <= MaxClients; i++)if (IsClientInGame(i))ShowSyncHudText(i, gHud, "AutoRespawn Has been %s", gb_AutoRespawn ? "Enabled":"Disabled");
  254. }
  255.  
  256. public OnCvarChanged(Handle cvar, const char[] oldVal, const char[] newVal)
  257. {
  258.     if (cvar == ARVEnabled)
  259.     {
  260.         if (GetConVarBool(ARVEnabled))
  261.         {
  262.             PrintToChatAll("[SM] \x04Player Auto Respawn Voting is now \x03%sabled", StringToInt(newVal) ? "En":"Dis");
  263.         }
  264.     }
  265. }
  266.  
  267. public Action Hook(Handle event, const char[] name, bool dontBroadcast)
  268. {
  269.     if (SpawnProtection)
  270.     {
  271.         SpawnProtection = 1;
  272.         int client = GetClientOfUserId(GetEventInt(event, "userid"));
  273.         CreateTimer(5.0, Timer_GodMode, GetClientSerial(client));
  274.         SetEntProp(client, Prop_Data, "m_takedamage", 0, 1)
  275.     }
  276. }
  277.  
  278. public Action Timer_GodMode(Handle timer, any serial)
  279. {
  280.     int client = GetClientFromSerial(serial);
  281.     if (client == 0) { return Plugin_Stop; }
  282.     SetEntProp(client, Prop_Data, "m_takedamage", 2, 1)
  283.     return Plugin_Handled;
  284. }
  285.  
  286. stock bool IsValidClient(int client, bool bAlive = false)
  287. {
  288.     if (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && (bAlive == false || IsPlayerAlive(client)))
  289.     {
  290.         return true;
  291.     }
  292.     return false;
  293. }
Advertisement
Add Comment
Please, Sign In to add comment