View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-15-2020 , 14:03   Re: Reserve slot for disconnected player
Reply With Quote #19

Ok.. try this version. It will not work properly with bots since they all share the same authid.
PHP Code:

#include <amxmodx>

#define MAX_PLAYERS 32

const SLOT_COUNT 5;
const 
SLOT_NOT_FOUND = -1;

new const 
g_szKickReason[] = "There are no unreserved slots, please try again later.";

enum SlotInfo
{
    
AuthID34 ],
    
DisconnectTime
}

new 
g_siSlotsSLOT_COUNT ][ SlotInfo ];

new 
g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
bool:g_bKickedMAX_PLAYERS ];

new 
g_iUsedSlots;
new 
g_pReserveTime;

public 
plugin_init()
{
    
register_plugin"Disconnect Reserve Slot" "0.2" "bugsy" );
    
    
g_pReserveTime register_cvar"drs_reserveminutes" "5" );
}

#if AMXX_VERSION_NUM < 190
public client_disconnectid )
#else
public client_disconnectedid )
#endif
{
    
RefreshSlots();
    
    if ( !
g_bKickedid ] )
    {
        
AddSlotid );
    }
}

public 
client_authorizedid )
{
    new 
iSlotID;
    
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
g_bKickedid ] = false;
    
    
RefreshSlots();

    if ( 
g_iUsedSlots )
    {
        
iSlotID GetPlayerSlotIDid );
        
        if ( 
iSlotID == SLOT_NOT_FOUND )
        {
            
g_bKickedid ] = true;
            
server_cmd"kick #%d ^"%s^"" get_user_useridid ) , g_szKickReason );
        }
        else
        {
            
g_siSlotsiSlotID ][ AuthID ][ ] = EOS;
            
g_siSlotsiSlotID ][ DisconnectTime ] = 0;
            
g_iUsedSlots--;
        }
    }
}

AddSlotid )
{
    if ( 
g_iUsedSlots SLOT_COUNT )
    {
        for ( new 
sizeofg_siSlots ) ; i++ )    
        {
            if ( 
g_siSlots][ AuthID ][ ] == EOS )
            {
                
copyg_siSlots][ AuthID ] , charsmaxg_siSlots[][ AuthID ] ) , g_szAuthIDid ] );
                
g_siSlots][ DisconnectTime ] = get_systime();
                
g_iUsedSlots++;
                break;
            }
        }
    }
}

GetPlayerSlotIDid )
{
    new 
iSlotID SLOT_NOT_FOUND;
    
    for ( new 
sizeofg_siSlots ) ; i++ )    
    {
        if ( 
equalg_siSlots][ AuthID ] , g_szAuthIDid ] ) )
        {
            
iSlotID i;
            break;
        }
    }
    
    return 
iSlotID;
}

RefreshSlots()
{
    new 
iSlotTime = ( get_pcvar_numg_pReserveTime ) * 60 );
    new 
iSysTime get_systime();
    
    for ( new 
sizeofg_siSlots ) ; i++ )
    {
        if ( 
g_siSlots][ DisconnectTime ] && ( ( g_siSlots][ DisconnectTime ] + iSlotTime ) < iSysTime ) )
        {
            
g_siSlots][ AuthID ][ ] = EOS;
            
g_siSlots][ DisconnectTime ] = 0;
            
g_iUsedSlots--;
        }
    }        

__________________

Last edited by Bugsy; 02-20-2020 at 19:06.
Bugsy is offline