New Plugin: NoAdminTools

+ new native to mapchooser_extended
This commit is contained in:
Dogan 2019-06-15 23:25:37 +02:00
parent 4f65d02cb9
commit 19c75cdd0c
4 changed files with 276 additions and 0 deletions

View File

@ -0,0 +1,24 @@
#if defined _AFKManager_Included
#endinput
#endif
#define _AFKManager_Included
native int GetClientIdleTime(int client);
public SharedPlugin __pl_AFKManager =
{
name = "AFKManager",
file = "AFKManager.smx",
#if defined REQUIRE_PLUGIN
required = 1,
#else
required = 0,
#endif
};
#if !defined REQUIRE_PLUGIN
public __pl_AFKManager_SetNTVOptional()
{
MarkNativeAsOptional("GetClientIdleTime");
}
#endif

View File

@ -0,0 +1,239 @@
#pragma semicolon 1
#include <sourcemod>
#include <cstrike>
#include <AFKManager>
#include <mapchooser_extended>
int g_iAdminAFKTime;
int g_iSelfMaxExtendsAmount;
int g_iSelfExtendsTime;
float g_fSelfExtendsRatio;
float g_fSelfExtendsDelay;
bool g_bSelfExtends[MAXPLAYERS + 1] = { false, ...};
bool g_bSelfExtendsAllowed;
int g_iSelfExtends;
ConVar g_cvarTimeLimit;
public Plugin myinfo =
{
name = "No Admin Tools",
author = "Dogan",
description = "Make it possible for the server to do several things when there is no active admin online",
version = "1.0.0",
url = ""
};
public void OnPluginStart()
{
g_iSelfExtends = 0;
g_bSelfExtendsAllowed = false;
RegAdminCmd("sm_checkadmins", Command_DisplayActiveAdmins, ADMFLAG_GENERIC, "Check if there are any active Admins online or not.");
RegConsoleCmd("sm_selfextend", Command_SelfExtend, "Is available when all regular extends are depleted and there is no active admin online. Makes it possible for players to extend the map themselves");
ConVar cvar;
HookConVarChange((cvar = CreateConVar("sm_admin_afk_time", "30", "Time in seconds until an admin is considered as AFK.")), Cvar_AdminAFKTime);
g_iAdminAFKTime = cvar.IntValue;
HookConVarChange((cvar = CreateConVar("sm_selfextend_amount", "2", "Amount of sm_selfextend's allowed.")), Cvar_SelfExtendsAmount);
g_iSelfMaxExtendsAmount = cvar.IntValue;
HookConVarChange((cvar = CreateConVar("sm_selfextend_time", "10", "How long to extend in minutes when sm_selfextend passes through.")), Cvar_SelfExtendsTime);
g_iSelfExtendsTime = cvar.IntValue;
HookConVarChange((cvar = CreateConVar("sm_selfextend_ratio", "0.6", "Ratio needed for sm_selfextend to pass through.")), Cvar_SelfExtendsRatio);
g_fSelfExtendsRatio = cvar.FloatValue;
HookConVarChange((cvar = CreateConVar("sm_selfextend_delay", "60.0", "Time to pass until sm_selfextend can be used")), Cvar_SelfExtendsDelay);
g_fSelfExtendsDelay = cvar.FloatValue;
CloseHandle(cvar);
g_cvarTimeLimit = FindConVar("mp_timelimit");
AutoExecConfig(true, "plugin.NoAdminTools");
}
public void Cvar_AdminAFKTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iAdminAFKTime = convar.IntValue;
}
public void Cvar_SelfExtendsAmount(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iSelfMaxExtendsAmount = convar.IntValue;
}
public void Cvar_SelfExtendsTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_iSelfExtendsTime = convar.IntValue;
}
public void Cvar_SelfExtendsRatio(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_fSelfExtendsRatio = convar.FloatValue;
}
public void Cvar_SelfExtendsDelay(ConVar convar, const char[] oldValue, const char[] newValue)
{
g_fSelfExtendsDelay = convar.FloatValue;
}
public bool ActiveAdminPresent()
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && CheckCommandAccess(i, "", ADMFLAG_GENERIC) && (GetClientIdleTime(i) < g_iAdminAFKTime))
{
return true;
}
}
return false;
}
public void OnClientDisconnect(int client)
{
if(g_bSelfExtends[client])
g_bSelfExtends[client] = false;
CheckRatio();
}
public void OnClientConnected(int client)
{
CheckRatio();
}
public void OnMapStart()
{
g_iSelfExtends = 0;
g_bSelfExtendsAllowed = false;
CreateTimer(g_fSelfExtendsDelay, Timer_DelaySelfExtend, _, TIMER_FLAG_NO_MAPCHANGE);
for(int i; i <= MaxClients; i++)
{
if(g_bSelfExtends[i])
g_bSelfExtends[i] = false;
}
}
public void OnMapEnd()
{
g_bSelfExtendsAllowed = false;
}
public Action Timer_DelaySelfExtend(Handle timer)
{
g_bSelfExtendsAllowed = true;
}
public Action Command_DisplayActiveAdmins(int client, int args)
{
if(ActiveAdminPresent())
{
ReplyToCommand(client, "[SM] There are active Admins online.");
}
else
{
ReplyToCommand(client, "[SM] There are no active Admins online.");
}
return Plugin_Handled;
}
public Action Command_SelfExtend(int client, int args)
{
PrintToChatAll("%d", g_iSelfExtends);
if(g_iSelfMaxExtendsAmount <= g_iSelfExtends)
{
ReplyToCommand(client, "[SM] Not available because this map was already self-extended %d times.", g_iSelfMaxExtendsAmount);
return Plugin_Handled;
}
else if(GetExtendsLeft() > 0)
{
ReplyToCommand(client, "[SM] Not available because not all regular extends have been depleted.");
return Plugin_Handled;
}
else if(ActiveAdminPresent())
{
ReplyToCommand(client, "[SM] Not available because there is atleast one active Admin who can extend. Please ask the Admins.");
return Plugin_Handled;
}
else if(!g_bSelfExtendsAllowed)
{
ReplyToCommand(client, "[SM] Not available because it's still too early in the map.");
return Plugin_Handled;
}
else
{
char sName[32];
GetClientName(client, sName, sizeof(sName));
if(!g_bSelfExtends[client])
{
g_bSelfExtends[client] = true;
PrintToChatAll("[SM] %s wants to self-extend the map.", sName);
}
else
{
ReplyToCommand(client, "[SM] You have already voted to self-extend the map.");
}
CheckRatio();
}
return Plugin_Handled;
}
public Action CheckRatio()
{
if(!g_bSelfExtendsAllowed)
return Plugin_Handled;
float Players;
float SelfExtendsPlayers;
float PlayersNeeded;
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
Players++;
}
if(g_bSelfExtends[i])
{
SelfExtendsPlayers++;
}
}
PlayersNeeded = Players * g_fSelfExtendsRatio;
if(SelfExtendsPlayers >= PlayersNeeded)
{
PrintToChatAll("[SM] Enough Players voted to self-extend the map. Adding %d minutes to the timelimit.", g_iSelfExtendsTime);
g_iSelfExtends++;
g_cvarTimeLimit.IntValue += g_iSelfExtendsTime;
for(int j; j <= MaxClients; j++)
{
if(g_bSelfExtends[j])
g_bSelfExtends[j] = false;
}
}
return Plugin_Handled;
}
static stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientInGame(client))
{
return true;
}
else
{
return false;
}
}

View File

@ -132,6 +132,13 @@ native int GetMapGroupRestriction(const char[] map, int client = 0);
native bool GetMapVIPRestriction(const char[] map, int client = 0);
/**
* gives back the amount of extends left on a map
*
* #return amounts of extends left
*/
native int GetExtendsLeft();
public SharedPlugin __pl_mapchooser_extended =
{
name = "mapchooser",

View File

@ -415,6 +415,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
CreateNative("GetMapGroups", Native_GetMapGroups);
CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction);
CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction);
CreateNative("GetExtendsLeft", Native_GetExtendsLeft);
return APLRes_Success;
}
@ -2340,6 +2341,11 @@ public int Native_GetMapVIPRestriction(Handle plugin, int numParams)
return InternalGetMapVIPRestriction(map);
}
public int Native_GetExtendsLeft(Handle plugin, int numParams)
{
return GetConVarInt(g_Cvar_Extend) - g_Extends;
}
stock void AddMapItem(const char[] map)
{
if(g_NativeVotes)