Raised This Month: $12 Target: $400
 3% 

Temporary Admin - Add admin for x days


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-16-2016 , 13:31   Re: Temporary Admin - Add admin for x days
Reply With Quote #11

Quote:
Originally Posted by eyal282 View Post
Update v1.3:

You can type instead of the flags the words "Manager", "SuperAdmin", "Admin", "VIP" and change via defines ( because it will be too easily abused as a cvar ).
In a released plugin, you should not have to edit the source code to modify something that is a core part of the plugin. I'm not sure why you would think that a cvar can be abused (it can't).

Also, you should listen to Bugsy.
__________________

Last edited by fysiks; 10-16-2016 at 13:34.
fysiks is offline
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
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-16-2016 , 18:01   Re: Temporary Admin - Add admin for x days
Reply With Quote #13

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
eyal282
Veteran Member
Join Date: Aug 2011
Old 10-21-2016 , 20:22   Re: Temporary Admin - Add admin for x days
Reply With Quote #14

As for now, I think all bugs are fixed.
eyal282 is offline
Skyliner
Member
Join Date: Sep 2011
Location: Fagaras
Old 11-29-2016 , 16:56   Re: Temporary Admin - Add admin for x days
Reply With Quote #15

Hey, one question.
I wanna put this plugin on my server for the VIPS.
But, I am ussing a plugin that anyone can register there nicknames from a site.
And the admins are on a database, on a SQL data base with tables and so on.
If I will put this plugin then the admin will be put in the DB or in users.ini ? Thanks!
__________________

Skyliner is offline
Send a message via Yahoo to Skyliner Send a message via Skype™ to Skyliner
B3none
AlliedModders Donor
Join Date: Oct 2016
Location: United Kingdom
Old 12-01-2016 , 05:20   Re: Temporary Admin - Add admin for x days
Reply With Quote #16

Is there a way to link this to a MySQL server thus allowing it to work across multiple servers?
__________________
B3none is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-02-2016 , 20:35   Re: Temporary Admin - Add admin for x days
Reply With Quote #17

Quote:
Originally Posted by b3none View Post
Is there a way to link this to a MySQL server thus allowing it to work across multiple servers?
Should be pretty simple as this plugin is not very complicated.
__________________
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-09-2017 , 10:22   Re: Temporary Admin - Add admin for x days
Reply With Quote #18

Quote:
Originally Posted by Black Rose View Post
I have to agree with eyal282 that the original one is not that good.
However, even if this one has more functions it's not very well written. Sorry.

Rant:
Why can't people seem to find these amazing functions in core.inc:
native time(&hour=0,&minute=0,&second=0);
native date(&year=0,&month=0,&day=0);

I know people generally assume people are male when talking about them in second person on this forum or in games but seriously... FindHim is a horrible name for a function. FindPlayer or FindPerson would do just fine.

You should look into how to use the new file functions, pcvars and dynamic arrays.
Name the variables descriptively. Combat and Combat2 is used for different times, makes no sense at all.
Why is it named /astatus? Where does the "a" come from? Why not /tempadmin or /admintime, /temptime, /adminstatus, /tempstatus, timestatus or all of them?
What is the point of the prefix if you leave it to default "PREFIX"?

I didn't look through it all, but you can start with that.
This.
__________________
HamletEagle is offline
Reply


Thread Tools
Display Modes

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 16:11.


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