improved the check and tells how many people still are needed for self extend

This commit is contained in:
jenz 2026-07-04 16:54:07 +02:00
parent 5986bedc42
commit 1139fd89d0

View File

@ -37,7 +37,7 @@ public void OnPluginStart()
ConVar cvar; ConVar cvar;
HookConVarChange((cvar = CreateConVar("sm_admin_afk_time", "30", "Time in seconds until an admin is considered as AFK.")), Cvar_AdminAFKTime); HookConVarChange((cvar = CreateConVar("sm_admin_afk_time", "30", "Time in seconds until an admin is considered as AFK.")), Cvar_AdminAFKTime);
g_iAdminAFKTime = cvar.IntValue; g_iAdminAFKTime = cvar.IntValue;
HookConVarChange((cvar = CreateConVar("sm_selfextend_amount", "2", "Amount of sm_selfextend's allowed.")), Cvar_SelfExtendsAmount); HookConVarChange((cvar = CreateConVar("sm_selfextend_amount", "2", "Amount of sm_selfextends allowed.")), Cvar_SelfExtendsAmount);
g_iSelfMaxExtendsAmount = cvar.IntValue; g_iSelfMaxExtendsAmount = cvar.IntValue;
HookConVarChange((cvar = CreateConVar("sm_selfextend_time", "10", "How long to extend in minutes when sm_selfextend passes through.")), Cvar_SelfExtendsTime); HookConVarChange((cvar = CreateConVar("sm_selfextend_time", "10", "How long to extend in minutes when sm_selfextend passes through.")), Cvar_SelfExtendsTime);
g_iSelfExtendsTime = cvar.IntValue; g_iSelfExtendsTime = cvar.IntValue;
@ -175,24 +175,14 @@ public Action Command_DisplayActiveAdmins(int client, int args)
public Action Command_SelfExtend(int client, int args) public Action Command_SelfExtend(int client, int args)
{ {
int iAdminActivity = 0;
for(int i = 1; i <= MaxClients; i++)
if(g_bActiveAdmin[i])
iAdminActivity++;
if(GetExtendsLeft() > 0) if(GetExtendsLeft() > 0)
{ {
ReplyToCommand(client, "[SM] Not available because not all regular extends have been depleted."); ReplyToCommand(client, "[SM] Not available because not all regular extends have been depleted.");
return Plugin_Handled; return Plugin_Handled;
} }
if(iAdminActivity > 0)
{
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) if(!g_bSelfExtendsAllowed)
{ {
ReplyToCommand(client, "[SM] Not available because it's still too early in the map."); ReplyToCommand(client, "[SM] Not available because its still too early in the map.");
return Plugin_Handled; return Plugin_Handled;
} }
if(g_iSelfMaxExtendsAmount <= g_iSelfExtends) if(g_iSelfMaxExtendsAmount <= g_iSelfExtends)
@ -201,14 +191,34 @@ public Action Command_SelfExtend(int client, int args)
return Plugin_Handled; return Plugin_Handled;
} }
int iPlayers;
int iSelfExtendsPlayers;
int iPlayersNeeded;
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
iPlayers++;
if(g_bSelfExtends[i])
iSelfExtendsPlayers++;
}
iPlayersNeeded = RoundToFloor(float(iPlayers) * g_fSelfExtendsRatio);
if (iPlayersNeeded == 0)
{
iPlayersNeeded = 1;
}
if(!g_bSelfExtends[client]) if(!g_bSelfExtends[client])
{ {
g_bSelfExtends[client] = true; g_bSelfExtends[client] = true;
PrintToChatAll("[SM] %N wants to self-extend the map.", client); PrintToChatAll("[SM] %N wants to self-extend the map. %i/%i", client, iSelfExtendsPlayers + 1, iPlayersNeeded);
CheckRatio(); CheckRatio();
} }
else else
ReplyToCommand(client, "[SM] You have already voted to self-extend the map."); {
ReplyToCommand(client, "[SM] You have already voted to self-extend the map. %i/%i", iSelfExtendsPlayers, iPlayersNeeded);
}
return Plugin_Handled; return Plugin_Handled;
} }
@ -233,7 +243,7 @@ public void CheckRatio()
iPlayersNeeded = RoundToFloor(float(iPlayers) * g_fSelfExtendsRatio); iPlayersNeeded = RoundToFloor(float(iPlayers) * g_fSelfExtendsRatio);
if(iSelfExtendsPlayers >= iPlayersNeeded && iPlayersNeeded != 0) if(iSelfExtendsPlayers >= iPlayersNeeded && iSelfExtendsPlayers > 0)
{ {
PrintToChatAll("[SM] Enough Players voted to self-extend the map. Adding %d minutes to the timelimit.", g_iSelfExtendsTime); PrintToChatAll("[SM] Enough Players voted to self-extend the map. Adding %d minutes to the timelimit.", g_iSelfExtendsTime);
LogMessage("Enough Players voted to self-extend the map. Adding %d minutes to the timelimit.", g_iSelfExtendsTime); LogMessage("Enough Players voted to self-extend the map. Adding %d minutes to the timelimit.", g_iSelfExtendsTime);
@ -243,7 +253,6 @@ public void CheckRatio()
for(int j; j <= MaxClients; j++) for(int j; j <= MaxClients; j++)
g_bSelfExtends[j] = false; g_bSelfExtends[j] = false;
} }
return; return;
} }