Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Pragma
- #pragma semicolon 1
- #pragma newdecls required
- //Sourcemod Includes
- #include <sourcemod>
- //ConVars
- ConVar convar_Status;
- ConVar convar_SlotsOnStart;
- ConVar convar_SlotsOnEmpty;
- Handle convar_MaxPlayers;
- //Globals
- public Plugin myinfo =
- {
- name = "Empty Servers Reset Slots",
- author = "Keith Warren (Drixevel)",
- description = "Resets the slots value of a server with no players playing.",
- version = "1.0.0",
- url = "http://www.drixevel.com/"
- };
- public void OnPluginStart()
- {
- LoadTranslations("common.phrases");
- convar_Status = CreateConVar("sm_emptyserversresetslots_status", "1", "Status of the plugin.\n1 = on, 0 = off", FCVAR_NOTIFY, true, 0.0, true, 1.0);
- convar_SlotsOnStart = CreateConVar("sm_emptyserversresetslots_slotsonstart", "32", "Slots to start off with on server start.", FCVAR_NOTIFY, true, 1.0);
- convar_SlotsOnEmpty = CreateConVar("sm_emptyserversresetslots_slotsonempty", "32", "Slots to set to once server is empty.", FCVAR_NOTIFY, true, 1.0);
- AutoExecConfig();
- convar_MaxPlayers = FindConVar("sv_maxplayers");
- }
- public void OnConfigsExecuted()
- {
- if (GetConVarBool(convar_Status))
- {
- SetConVarInt(convar_MaxPlayers, GetConVarInt(convar_SlotsOnStart));
- }
- }
- public void OnClientDisconnect_Post(int client)
- {
- if (GetConVarBool(convar_Status) && GetClientCountNoBots() == 0)
- {
- SetConVarInt(convar_MaxPlayers, GetConVarInt(convar_SlotsOnEmpty));
- }
- }
- int GetClientCountNoBots()
- {
- int count;
- for (int i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i) && !IsFakeClient(i))
- {
- count++;
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement