AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Admin Counting [HELP FAST PLEASE] (https://forums.alliedmods.net/showthread.php?t=143283)

Trafikkz 11-17-2010 12:25

Admin Counting [HELP FAST PLEASE]
 
Code:

/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "WATF Check"
#define VERSION "1.0"
#define AUTHOR "Trafikk"

new maxplayers;
new admincvar;


public plugin_init() {
   
    register_plugin(PLUGIN, VERSION, AUTHOR);
    maxplayers = get_maxplayers();
    admincvar = register_cvar("amx_showadmins","1");
   
}

public onclientconnect(id) {
   
    new id, count
   
    for(id = 1 ; id <= maxplayers ; id++)
        if(is_user_connected(id))
        if(get_user_flags(id) & ADMIN_KICK)
        count++
   
    if(get_pcvar_num(admincvar) == 1)
    {
        if (count==1) {
            new flags = read_flags("bz");
            set_user_flags(id,flags);
        }
    }
   
}

This is the code of a plugin. There are no errors or other when I compile it but it doesn't work.

This plugin should be a plugin who counts the admins online when a player connects. Well, I used the code from /admin command for this one.

When a player connects, the code it's counting the admins online, if there is an admin online the plugin will automatically set him to bz, otherwise he will keep the admin access (if he is admin).

What I'm wanting to do is, a plugin when an admin is connecting, if there is an admin online his admin won't be available, his access will be set to "bz", otherwise, if isn't any admin online he will keep his access. I really need help, I don't know what's wrong!?

Exolent[jNr] 11-17-2010 13:01

Re: Admin Counting [HELP FAST PLEASE]
 
Quote:

Originally Posted by Trafikkz (Post 1351333)
Code:

public onclientconnect(id) {

Code:

public client_authorized(id) {

Trafikkz 11-17-2010 16:42

Re: Admin Counting [HELP FAST PLEASE]
 
Still not working....when 2 admins come online they both have access.

Well, what I want to make is.

How could I make a code that when an user connects on the server, the server will check if there are 1 or more admins, if there are, the user connected will have acces bz. I know how to make to set the acces, but I don't know how to make the count. Help me please. Something like:

Code:

public onclientconnect(id) {
   
    new id, count, x
   
    for(id = 1 ; id <= maxplayers ; id++)
        if(is_user_connected(id))
            if(get_user_flags(id) & ADMIN_BAN)
                get_user_name(id, aname[count++], 31)
               
    if(count >= 1)
        new flags = read_flags("z")
        set_user_flags(id, flags)
       
}


abdul-rehman 11-18-2010 02:03

Re: Admin Counting [HELP FAST PLEASE]
 
try this:
Code:
public client_putinserver( id ) {     if ( check_admins_online() )     {         static new_flags         new_flags = read_flags( "bz" )         // Set his new flags         set_user_flags( id, new_flags )     } } check_admins_online() {     static id     new count = 0     for( id = 1; id <= maxplayers; id ++ )     {         if ( is_user_connected( id ) && (get_user_flags( id ) & ADMIN_BAN))             count++     }     // Return number of online admins     return count; }

Trafikkz 11-18-2010 07:29

Re: Admin Counting [HELP FAST PLEASE]
 
Quote:

Originally Posted by abdul-rehman (Post 1351711)
try this:
Code:
public client_putinserver( id ) { if ( check_admins_online() ) { static new_flags
new_flags = read_flags( "bz" ) // Set his new flags set_user_flags( id, new_flags ) } } check_admins_online() { static id
new count = 0 for( id = 1; id <= maxplayers; id ++ ) { if ( is_user_connected( id ) && (get_user_flags( id ) & ADMIN_BAN)) count++ } // Return number of online admins return count;
}


Yeah, something like you said but it doesn't work. The code is just.....full of errors.

Bugsy 11-18-2010 09:49

Re: Admin Counting [HELP FAST PLEASE]
 
Make sure you have a global var maxplayers and set its value to get_maxplayers() in plugin init. Also, no need for the new_flags variable, put read_flags directly in set_user_flags..or just use ( ADMIN_BAN | ADMIN_USER ) (assuming flag b is ADMIN_BAN and z is ADMIN_USER). Be sure to call remove_user_flags prior to setting flags since set_user_flags is actually add_user_flags.

remove_user_flags( id );
set_user_flags( id , ADMIN_BAN | ADMIN_USER );

Trafikkz 11-18-2010 11:46

Re: Admin Counting [HELP FAST PLEASE]
 
Quote:

Originally Posted by Bugsy (Post 1351827)
Make sure you have a global var maxplayers and set its value to get_maxplayers() in plugin init. Also, no need for the new_flags variable, put read_flags directly in set_user_flags..or just use ( ADMIN_BAN | ADMIN_USER ) (assuming flag b is ADMIN_BAN and z is ADMIN_USER). Be sure to call remove_user_flags prior to setting flags since set_user_flags is actually add_user_flags.

remove_user_flags( id );
set_user_flags( id , ADMIN_BAN | ADMIN_USER );

An example?

Bugsy 11-18-2010 17:50

Re: Admin Counting [HELP FAST PLEASE]
 
Take a look at my Admin Hierarchy plugin, it does similar to what you are requesting.

Try this:
PHP Code:

//See users.ini for flags
//b = ADMIN_RESERVATION
//z = ADMIN_USER

//These flags are needed to be considered an admin. If you need to add flags, 
//use the | operator.  ADMIN_BAN | ADMIN_KICK |ADMIN_CVAR etc
const ADMIN_FLAGS ADMIN_BAN;

//These flags are given to players when their flags are removed and given new flags.
const FLAGS_TO_GIVE ADMIN_RESERVATION ADMIN_USER;

//A regular bool var would work for this but I used a bitsum to allow
//for further customization if wanted.
new g_OnlineAdmins;

public 
plugin_init()
{
    
//register_plugin( ... );
}

public 
client_putinserverid )
{
    
//If connecting player has admin flags defined above.
    
if ( get_user_flagsid ) & ADMIN_FLAGS )
    {
        
//If another admin currently online, give player FLAGS_TO_GIVE flags
        
if ( g_OnlineAdmins )
        {
            
remove_user_flagsid );
            
set_user_flagsid FLAGS_TO_GIVE );    
        }
        else
        {
            
//Player is admin and no other admins online.
            
g_OnlineAdmins |= ( << ( id 31 ) );
        }
    }
}

public 
client_disconnectid )
{
    
g_OnlineAdmins &= ~( << ( id 31 ) );



Trafikkz 11-21-2010 17:43

Re: Admin Counting [HELP FAST PLEASE]
 
UP! Doesn't work. Any other solutions? I can't find the missing key to work. Please? :mrgreen:


All times are GMT -4. The time now is 11:19.

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