2019-06-15 23:25:37 +02:00
# pragma semicolon 1
# include <sourcemod>
# include <cstrike>
# include <AFKManager>
# include <mapchooser_extended>
2019-06-15 23:39:54 +02:00
# pragma newdecls required
2019-06-15 23:25:37 +02:00
int g_iAdminAFKTime ;
int g_iSelfMaxExtendsAmount ;
int g_iSelfExtendsTime ;
float g_fSelfExtendsRatio ;
float g_fSelfExtendsDelay ;
bool g_bSelfExtends [ MAXPLAYERS + 1 ] = { false , . . . } ;
bool g_bSelfExtendsAllowed ;
2019-07-08 15:33:53 +02:00
bool g_bActiveAdmin [ MAXPLAYERS + 1 ] = { false , . . . } ;
2019-06-15 23:25:37 +02:00
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 " ,
2019-07-08 15:33:53 +02:00
version = " 1.1.0 " ,
2019-06-15 23:25:37 +02:00
url = " "
} ;
public void OnPluginStart ( )
{
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 ;
2019-07-07 22:44:43 +02:00
delete cvar ;
2019-06-15 23:25:37 +02:00
g_cvarTimeLimit = FindConVar ( " mp_timelimit " ) ;
2019-06-15 23:39:54 +02:00
AutoExecConfig ( ) ;
2019-06-15 23:25:37 +02:00
}
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 ;
}
2019-07-08 15:33:53 +02:00
public bool ActiveAdmin ( int client )
2019-06-15 23:25:37 +02:00
{
2019-07-08 15:33:53 +02:00
if ( GetClientIdleTime ( client ) < g_iAdminAFKTime )
return true ;
return false ;
2019-06-15 23:25:37 +02:00
}
public void OnClientDisconnect ( int client )
{
2019-06-15 23:39:54 +02:00
g_bSelfExtends [ client ] = false ;
2019-07-08 15:33:53 +02:00
g_bActiveAdmin [ client ] = false ;
2019-06-15 23:25:37 +02:00
CheckRatio ( ) ;
}
2019-07-08 15:33:53 +02:00
public void OnClientPostAdminCheck ( int client )
2019-06-15 23:25:37 +02:00
{
2019-07-08 15:33:53 +02:00
if ( CheckCommandAccess ( client , " " , ADMFLAG_GENERIC ) & & IsValidClient ( client ) )
{
g_bActiveAdmin [ client ] = true ;
}
2019-06-15 23:25:37 +02:00
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 + + )
2019-06-15 23:39:54 +02:00
g_bSelfExtends [ i ] = false ;
2019-06-15 23:25:37 +02:00
}
public void OnMapEnd ( )
{
g_bSelfExtendsAllowed = false ;
}
public Action Timer_DelaySelfExtend ( Handle timer )
{
g_bSelfExtendsAllowed = true ;
}
public Action Command_DisplayActiveAdmins ( int client , int args )
{
2019-07-08 15:33:53 +02:00
for ( int i = 1 ; i < = MaxClients ; i + + )
if ( CheckCommandAccess ( i , " " , ADMFLAG_GENERIC ) & & IsValidClient ( i ) & & ActiveAdmin ( i ) )
g_bActiveAdmin [ i ] = true ;
char aBuf [ 1024 ] ;
char aBuf2 [ MAX_NAME_LENGTH ] ;
char bBuf [ 1024 ] ;
char bBuf2 [ MAX_NAME_LENGTH ] ;
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( IsClientInGame ( i ) & & ! IsFakeClient ( i ) )
{
if ( g_bActiveAdmin [ i ] )
{
GetClientName ( i , aBuf2 , sizeof ( aBuf2 ) ) ;
StrCat ( aBuf , sizeof ( aBuf ) , aBuf2 ) ;
StrCat ( aBuf , sizeof ( aBuf ) , " , " ) ;
}
if ( ! g_bActiveAdmin [ i ] & & CheckCommandAccess ( i , " " , ADMFLAG_GENERIC ) & & IsValidClient ( i ) )
{
GetClientName ( i , bBuf2 , sizeof ( bBuf2 ) ) ;
StrCat ( bBuf , sizeof ( bBuf ) , bBuf2 ) ;
StrCat ( bBuf , sizeof ( bBuf ) , " , " ) ;
}
}
}
if ( strlen ( aBuf ) )
{
aBuf [ strlen ( aBuf ) - 2 ] = 0 ;
ReplyToCommand ( client , " [SM] Active Admins online: %s " , aBuf ) ;
}
else
ReplyToCommand ( client , " [SM] Active Admins online: none " ) ;
if ( strlen ( bBuf ) )
{
bBuf [ strlen ( bBuf ) - 2 ] = 0 ;
ReplyToCommand ( client , " [SM] Inactive Admins online: %s " , bBuf ) ;
}
2019-06-15 23:25:37 +02:00
else
2019-07-08 15:33:53 +02:00
ReplyToCommand ( client , " [SM] Inactive Admins online: none " ) ;
2019-06-15 23:25:37 +02:00
return Plugin_Handled ;
}
public Action Command_SelfExtend ( int client , int args )
{
2019-07-08 15:33:53 +02:00
int iAdminActivity = 0 ;
for ( int i = 1 ; i < = MaxClients ; i + + )
if ( g_bActiveAdmin [ i ] )
iAdminActivity + + ;
2019-06-15 23:39:54 +02:00
if ( GetExtendsLeft ( ) > 0 )
2019-06-15 23:25:37 +02:00
{
ReplyToCommand ( client , " [SM] Not available because not all regular extends have been depleted. " ) ;
return Plugin_Handled ;
}
2019-07-08 15:33:53 +02:00
if ( iAdminActivity > 0 )
2019-06-15 23:25:37 +02:00
{
ReplyToCommand ( client , " [SM] Not available because there is atleast one active Admin who can extend. Please ask the Admins. " ) ;
return Plugin_Handled ;
}
2019-06-15 23:39:54 +02:00
if ( ! g_bSelfExtendsAllowed )
2019-06-15 23:25:37 +02:00
{
ReplyToCommand ( client , " [SM] Not available because it's still too early in the map. " ) ;
return Plugin_Handled ;
}
2019-06-15 23:39:54 +02:00
if ( g_iSelfMaxExtendsAmount < = g_iSelfExtends )
2019-06-15 23:25:37 +02:00
{
2019-06-15 23:39:54 +02:00
ReplyToCommand ( client , " [SM] Not available because this map was already self-extended %d times. " , g_iSelfMaxExtendsAmount ) ;
return Plugin_Handled ;
}
2019-06-15 23:25:37 +02:00
2019-06-15 23:39:54 +02:00
if ( ! g_bSelfExtends [ client ] )
{
g_bSelfExtends [ client ] = true ;
PrintToChatAll ( " [SM] %N wants to self-extend the map. " , client ) ;
2019-06-15 23:25:37 +02:00
CheckRatio ( ) ;
}
2019-06-15 23:39:54 +02:00
else
ReplyToCommand ( client , " [SM] You have already voted to self-extend the map. " ) ;
2019-06-15 23:25:37 +02:00
return Plugin_Handled ;
}
2019-06-15 23:39:54 +02:00
public void CheckRatio ( )
2019-06-15 23:25:37 +02:00
{
if ( ! g_bSelfExtendsAllowed )
2019-06-15 23:39:54 +02:00
return ;
2019-06-15 23:25:37 +02:00
2019-06-15 23:39:54 +02:00
int iPlayers ;
int iSelfExtendsPlayers ;
int iPlayersNeeded ;
2019-06-15 23:25:37 +02:00
for ( int i = 1 ; i < = MaxClients ; i + + )
{
if ( IsValidClient ( i ) )
2019-06-15 23:39:54 +02:00
iPlayers + + ;
2019-06-15 23:25:37 +02:00
if ( g_bSelfExtends [ i ] )
2019-06-15 23:39:54 +02:00
iSelfExtendsPlayers + + ;
2019-06-15 23:25:37 +02:00
}
2019-06-16 00:13:49 +02:00
iPlayersNeeded = RoundToFloor ( float ( iPlayers ) * g_fSelfExtendsRatio ) ;
2019-06-15 23:25:37 +02:00
2019-06-15 23:39:54 +02:00
if ( iSelfExtendsPlayers > = iPlayersNeeded )
2019-06-15 23:25:37 +02:00
{
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 + + )
2019-06-15 23:39:54 +02:00
g_bSelfExtends [ j ] = false ;
2019-06-15 23:25:37 +02:00
}
2019-06-15 23:39:54 +02:00
return ;
2019-06-15 23:25:37 +02:00
}
static stock bool IsValidClient ( int client )
{
if ( client > 0 & & client < = MaxClients & & IsClientInGame ( client ) )
{
return true ;
}
else
{
return false ;
}
}