Advertisement
Guest User

emptyserverslots.sp

a guest
Apr 22nd, 2017
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.61 KB | None | 0 0
  1. //Pragma
  2. #pragma semicolon 1
  3. #pragma newdecls required
  4.  
  5. //Sourcemod Includes
  6. #include <sourcemod>
  7.  
  8. //ConVars
  9. ConVar convar_Status;
  10. ConVar convar_SlotsOnStart;
  11. ConVar convar_SlotsOnEmpty;
  12.  
  13. Handle convar_MaxPlayers;
  14.  
  15. //Globals
  16.  
  17. public Plugin myinfo =
  18. {
  19.     name = "Empty Servers Reset Slots",
  20.     author = "Keith Warren (Drixevel)",
  21.     description = "Resets the slots value of a server with no players playing.",
  22.     version = "1.0.0",
  23.     url = "http://www.drixevel.com/"
  24. };
  25.  
  26. public void OnPluginStart()
  27. {
  28.     LoadTranslations("common.phrases");
  29.    
  30.     convar_Status = CreateConVar("sm_emptyserversresetslots_status", "1", "Status of the plugin.\n1 = on, 0 = off", FCVAR_NOTIFY, true, 0.0, true, 1.0);
  31.     convar_SlotsOnStart = CreateConVar("sm_emptyserversresetslots_slotsonstart", "32", "Slots to start off with on server start.", FCVAR_NOTIFY, true, 1.0);
  32.     convar_SlotsOnEmpty = CreateConVar("sm_emptyserversresetslots_slotsonempty", "32", "Slots to set to once server is empty.", FCVAR_NOTIFY, true, 1.0);
  33.     AutoExecConfig();
  34.    
  35.     convar_MaxPlayers = FindConVar("sv_maxplayers");
  36. }
  37.  
  38. public void OnConfigsExecuted()
  39. {
  40.     if (GetConVarBool(convar_Status))
  41.     {
  42.         SetConVarInt(convar_MaxPlayers, GetConVarInt(convar_SlotsOnStart));
  43.     }
  44. }
  45.  
  46. public void OnClientDisconnect_Post(int client)
  47. {
  48.     if (GetConVarBool(convar_Status) && GetClientCountNoBots() == 0)
  49.     {
  50.         SetConVarInt(convar_MaxPlayers, GetConVarInt(convar_SlotsOnEmpty));
  51.     }
  52. }
  53.  
  54. int GetClientCountNoBots()
  55. {
  56.     int count;
  57.    
  58.     for (int i = 1; i <= MaxClients; i++)
  59.     {
  60.         if (IsClientInGame(i) && !IsFakeClient(i))
  61.         {
  62.             count++;
  63.         }
  64.     }
  65.    
  66.     return count;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement