Raised This Month: $ Target: $400
 0% 

Temporary Admin - Add admin for x days


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-16-2016 , 18:01   Re: Temporary Admin - Add admin for x days
Reply With Quote #14

Quote:
Originally Posted by Bugsy View Post
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 ] );

I edited my version to make it more efficient, and I prefer that amx_addtempadmin will be an offline command like amx_addadmin is.
eyal282 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:37.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode