syntax fixes and cleanup

This commit is contained in:
neon 2019-06-15 23:39:54 +02:00
parent 2520e5d6ec
commit 534d1a55ca
2 changed files with 37 additions and 89 deletions

View File

@ -1,24 +0,0 @@
#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

@ -5,6 +5,8 @@
#include <AFKManager>
#include <mapchooser_extended>
#pragma newdecls required
int g_iAdminAFKTime;
int g_iSelfMaxExtendsAmount;
int g_iSelfExtendsTime;
@ -28,9 +30,6 @@ public Plugin myinfo =
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");
@ -49,7 +48,7 @@ public void OnPluginStart()
g_cvarTimeLimit = FindConVar("mp_timelimit");
AutoExecConfig(true, "plugin.NoAdminTools");
AutoExecConfig();
}
public void Cvar_AdminAFKTime(ConVar convar, const char[] oldValue, const char[] newValue)
@ -82,19 +81,14 @@ 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;
g_bSelfExtends[client] = false;
CheckRatio();
}
@ -111,10 +105,7 @@ public void OnMapStart()
CreateTimer(g_fSelfExtendsDelay, Timer_DelaySelfExtend, _, TIMER_FLAG_NO_MAPCHANGE);
for(int i; i <= MaxClients; i++)
{
if(g_bSelfExtends[i])
g_bSelfExtends[i] = false;
}
g_bSelfExtends[i] = false;
}
public void OnMapEnd()
@ -130,98 +121,79 @@ public Action Timer_DelaySelfExtend(Handle timer)
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)
{
if(GetExtendsLeft() > 0)
{
ReplyToCommand(client, "[SM] Not available because not all regular extends have been depleted.");
return Plugin_Handled;
}
if(ActiveAdminPresent())
{
ReplyToCommand(client, "[SM] Not available because there is atleast one active Admin who can extend. Please ask the Admins.");
return Plugin_Handled;
}
if(!g_bSelfExtendsAllowed)
{
ReplyToCommand(client, "[SM] Not available because it's still too early in the map.");
return Plugin_Handled;
}
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.");
}
if(!g_bSelfExtends[client])
{
g_bSelfExtends[client] = true;
PrintToChatAll("[SM] %N wants to self-extend the map.", client);
CheckRatio();
}
else
ReplyToCommand(client, "[SM] You have already voted to self-extend the map.");
return Plugin_Handled;
}
public Action CheckRatio()
public void CheckRatio()
{
if(!g_bSelfExtendsAllowed)
return Plugin_Handled;
return;
float Players;
float SelfExtendsPlayers;
float PlayersNeeded;
int iPlayers;
int iSelfExtendsPlayers;
int iPlayersNeeded;
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
Players++;
}
iPlayers++;
if(g_bSelfExtends[i])
{
SelfExtendsPlayers++;
}
iSelfExtendsPlayers++;
}
PlayersNeeded = Players * g_fSelfExtendsRatio;
int iPlayersNeeded = RoundToFloor(float(iSelfExtendsPlayers) * g_fSelfExtendsRatio);
if(SelfExtendsPlayers >= PlayersNeeded)
if(iSelfExtendsPlayers >= iPlayersNeeded)
{
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;
}
g_bSelfExtends[j] = false;
}
return Plugin_Handled;
return;
}
static stock bool IsValidClient(int client)