View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-16-2016 , 16:25   Re: Temporary Admin - Add admin for x days
Reply With Quote #12

I put this together for you so you can get an idea for what I recommended above:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>

new const Version[] = "0.1";

#define MAX_PLAYERS 32

const DaySeconds 86400;

new 
g_Vault g_szAuthIDMAX_PLAYERS ][ 34 ];

public 
plugin_init() 
{
    
register_plugin"Temp Admin" Version "bugsy" );
    
    
register_concmd"add_admin" "AddAdmin" );
    
register_concmd"remove_admin" "RemoveAdmin" );
    
    
g_Vault nvault_open"tempAdmin" );
}

public 
plugin_end() 
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    new 
szFlags25 ] , iTS szMsg64 ];
    
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
    
    
//Check if user has a record in the vault
    
if ( nvault_lookupg_Vault g_szAuthIDid ] , szFlags charsmaxszFlags ) , iTS ) )
    {
        
//A record exists, check if the timestamp for the record is greater than now.
        //If it is, then this player should be given flags because his time has not expired yet.
        
if ( iTS get_systime() )
        {
            
formatexszMsg charsmaxszMsg ) , "* You have admin for %0.1f more days" floatiTS get_systime() ) / floatDaySeconds ) );
            
set_user_flagsid read_flagsszFlags ) );
        }
        else
        {
            
copyszMsg charsmaxszMsg ) , "* You no longer have admin powers" );
            
nvault_removeg_Vault g_szAuthIDid ] );
        }
        
        
set_task7.0 "PrintMsg" id szMsg sizeofszMsg ) );
    }
}

public 
client_disconnectid )
{
    
remove_taskid );
}

public 
PrintMsg( const szMsg[] , id )
{
    
client_printid print_chat szMsg );
}

public 
AddAdminid )
{
    new 
iPlayer szPlayer33 ] , iDays szDays] , szFlags25 ];
    
    
read_argvszPlayer charsmaxszPlayer ) );
    
    if ( ( 
iPlayer cmd_targetid szPlayer ) ) )
    {
        
read_argvszDays charsmaxszDays ) );
        
read_argvszFlags charsmaxszFlags ) );
        
        
iDays str_to_numszDays );
        
        
//Set a record in the vault and then set the timestamp for when the temp admin period ends.
        //This is done using a unix timestamp: now + X days..
        
nvault_setg_Vault g_szAuthIDiPlayer ] , szFlags );
        
nvault_touchg_Vault g_szAuthIDiPlayer ] , get_systime() + ( iDays DaySeconds ) );
    
        
client_printiPlayer print_chat "* You have been given admin for %d days" iDays );
    }
}

public 
RemoveAdminid )
{
    
nvault_removeg_Vault g_szAuthIDid ] );

__________________

Last edited by Bugsy; 10-16-2016 at 16:33.
Bugsy is offline