AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Preventing the names from repeating (https://forums.alliedmods.net/showthread.php?t=282964)

EpicKiller 05-21-2016 18:17

Preventing the names from repeating
 
I have an admin_who plugin. I changed the check to include the flags, instead of equaling them. Why? Because the VIP flag is ADMIN_LEVEL_H, so if I add the t flag to an admin, he won't be shown in the admin list anymore. This way he would. The problem is that a founder will appear in all admin cathegories, as he fits them all, having full access. How could I add a check to prevent him from repeating? I mean placing him in the highest rank his flags allow him, but no lower.

Here's my code:
PHP Code:

#include < amxmodx >
#include < amxmisc >

#pragma semicolon 1

#define MAX_GROUPS 9

new g_groupNames[MAX_GROUPS][] = 
{
    
"Founder",
    
"Owner",
    
"Co-Owner",
    
"God",
    
"Super-Moderator",
    
"Moderator",
    
"Administrator",
    
"Helper",
    
"Slot"
};

new 
g_groupFlags[MAX_GROUPS][] = 
{
    
"abcdefghijklmnopqrsuv",    // Founder
    
"abcdefghijkmnopqrsu",        // Owner
    
"abcdefijmnopqrsu",            // Co-Owner
    
"abcdefijmnopqrs",            // God
    
"abcdefijmnopqr",            // Super-Moderator
    
"abcdefijmnopq",            // Moderator
    
"abcdefijmno",                // Administrator
    
"abceijmno",                // Helper
    
"ab"                        // Slot
};

new 
g_groupFlagsValue[MAX_GROUPS];

public 
plugin_init()
{
    
register_plugin("admin_who""1.0""rock!");
    
    
register_concmd("admin_who""cmdWho"0);
    
    
register_clcmd("say who""cmdSayWho");
    
register_clcmd("say /who""cmdSayWho");
    
register_clcmd("say admin""cmdSayWho");
    
register_clcmd("say /admin""cmdSayWho");
    
    for(new 
0MAX_GROUPSi++)
        
g_groupFlagsValue[i] = read_flags(g_groupFlags[i]);
}

public 
cmdWho(id)
{
    new 
players[32], inumplayername[32];
    
    
get_players(playersinum);
    
    
console_print(id"~~~~~ www..ro ~~~~~");
    
    for(new 
0MAX_GROUPSi++)
    {
        
console_print(id"-----[%d]%s-----"i+1g_groupNames[i]);
        
        for(new 
0inum; ++a)
        {
            
player players[a];
            
            
get_user_name(playername31);
            
            if((
get_user_flags(player) & g_groupFlagsValue[i]) == g_groupFlagsValue[i])
                
console_print(id"%s"name);
        }
    }
    
    
console_print(id"~~~~~ www..ro ~~~~~");
    
    return 
PLUGIN_HANDLED;
}

public 
cmdSayWho(id)
{
    
chat_color(id"!t[!g!t] !nCheck your console!");
    
    
cmdWho(id);
}

stock chat_color(const id, const input[], any:...)
{
    new 
iCount 1;
    new 
iPlayers[32];
    
    static 
sMsg[191];
    
    
vformat(sMsg190input3);
    
    
replace_all(sMsg190"!g""^4");
    
replace_all(sMsg190"!n""^1");
    
replace_all(sMsg190"!t""^3");
    
    if(
id)
        
iPlayers[0] = id;
    
    else
        
get_players(iPlayersiCount"ch");
    
    for(new 
0iCounti++)
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _iPlayers[i]);
            
write_byte(iPlayers[i]);
            
write_string(sMsg);
            
message_end();
        }



OciXCrom 05-21-2016 18:49

Re: Preventing the names from repeating
 
Switch the two for-loops. Put the groups loop inside the player loop, then check if the player has the flags, and if he does, simply add "break" in the groups loop, so the other groups below it don't get checked. Also, don't get the player's name before making sure that he has the flags.

EFFx 05-21-2016 19:38

Re: Preventing the names from repeating
 
The flags that you added at this plugin, you need to add the same flags in users.ini, if not it does not appear.
Example:

"VIP"

Flags:

"Abcdefh"

You will add at users.ini

"EFFx" "fuckingpassword" "abcdefh" "a"

Do you already tryed it?

OciXCrom 05-21-2016 20:11

Re: Preventing the names from repeating
 
Did you even read the question?

EpicKiller 05-21-2016 20:40

Re: Preventing the names from repeating
 
Quote:

Originally Posted by EFFx (Post 2420894)
The flags that you added at this plugin, you need to add the same flags in users.ini, if not it does not appear.
Example:

"VIP"

Flags:

"Abcdefh"

You will add at users.ini

"EFFx" "fuckingpassword" "abcdefh" "a"

Do you already tryed it?

You're watching a different movie, my friend.


Quote:

Originally Posted by OciXCrom (Post 2420883)
Switch the two for-loops. Put the groups loop inside the player loop, then check if the player has the flags, and if he does, simply add "break" in the groups loop, so the other groups below it don't get checked. Also, don't get the player's name before making sure that he has the flags.

I'll do it right away. Thank you, Ocixcrom!



Apparently, I messed it up again. It didn't double anything, that's a relief. I guess I scrambled the loops doe, as I tested it and it showed a founder as a helper and an owner as a slot. Then it kept showing different combinations. Please end my pain...

siriusmd99 05-22-2016 07:00

Re: Preventing the names from repeating
 
Check flag t remove it and then do equal , it's so hard?

PHP Code:

for(new 0inum; ++a)
        {
            
player players[a];
            new 
flags get_user_flags(player)
            if(
flags ADMIN_LEVEL_H)
                 
flags &= ~(ADMIN_LEVEL_H)
            if(
flags == g_groupFlagsValue[i]){
                  
get_user_name(player,name,31)
                
console_print(id"%s"name);
            }
        } 

And don't use get user name before checking flags, you are wasting memory ....

Bugsy 05-22-2016 09:08

Re: Preventing the names from repeating
 
I changed the way the plugin works by assigning the player group when the player connects. The who command will then match the players group with the list of groups as you loop through the groups. I also added a 'Player' group that will display players who do not match any of the defined groups. You can disable this group using the cvar aw_displayplayers. Let me know if this does what you want.

PHP Code:

#include < amxmodx >
#include < amxmisc >

#pragma semicolon 1

#define MAX_PLAYERS 32

enum Groups
{
    
Founder,
    
Owner,
    
CoOwner,
    
God,
    
SuperModerator,
    
Moderator,
    
Administrator,
    
Helper,
    
Slot,
    
Player
}

new 
g_groupNamesGroups ][] = 
{
    
"Founder",
    
"Owner",
    
"Co-Owner",
    
"God",
    
"Super-Moderator",
    
"Moderator",
    
"Administrator",
    
"Helper",
    
"Slot",
    
"Player"
};

new 
g_groupFlagsGroups ][] = 
{
    
"abcdefghijklmnopqrsuv",    // Founder
    
"abcdefghijkmnopqrsu",        // Owner
    
"abcdefijmnopqrsu",            // Co-Owner
    
"abcdefijmnopqrs",            // God
    
"abcdefijmnopqr",            // Super-Moderator
    
"abcdefijmnopq",            // Moderator
    
"abcdefijmno",                // Administrator
    
"abceijmno",                // Helper
    
"ab",                    // Slot
    
"z"                    //Player
};

new 
g_groupFlagsValue[Groups];

new 
Groups:g_PlayerGroupMAX_PLAYERS ] , g_pDisplayPlayers;

public 
plugin_init()
{
    
register_plugin("admin_who""1.0""rock!");
    
    
register_concmd("admin_who""cmdWho"0);
    
    
register_clcmd("say who""cmdSayWho");
    
register_clcmd("say /who""cmdSayWho");
    
register_clcmd("say admin""cmdSayWho");
    
register_clcmd("say /admin""cmdSayWho");
    
    
g_pDisplayPlayers register_cvar"aw_displayplayers""0" );
    
    for( new 
Groups:Founder Groupsi++ )
        
g_groupFlagsValue[i] = read_flags(g_groupFlags[i]);
}

public 
client_authorizedid )
{
    new 
iFlags get_user_flagsid );
    
    for ( new 
Groups:gGroup Founder gGroup Groups gGroup++ )
    {
        if( ( 
iFlags g_groupFlagsValuegGroup ] ) == g_groupFlagsValuegGroup ] )
        {
            
g_PlayerGroupid ] = gGroup;
            break;
        }
    }    
}

public 
cmdWho(id)
{
    new 
players[32], inumplayername[32];

    
get_players(playersinum);
    
    
console_print(id"~~~~~ www..ro ~~~~~");
    
    for(new 
Groups:gGroup FoundergGroup < ( Groups Groups:!get_pcvar_numg_pDisplayPlayers ) ) ; gGroup++ )
    {
        
console_printid "-----[%d]%s-----" _:gGroup+g_groupNamesgGroup ] );
        
        for(new 
0inum; ++a)
        {
            
player players[a];
            
            if( 
gGroup == g_PlayerGroupplayer ] )
            {
                
get_user_nameplayer name charsmaxname ) );
                
console_printid "%s" name );
            }
        }
    }
    
    
console_print(id"~~~~~ www..ro ~~~~~");
    
    return 
PLUGIN_HANDLED;
}

public 
cmdSayWho(id)
{
    
chat_color(id"!t[!g!t] !nCheck your console!");
    
    
cmdWho(id);
}

stock chat_color(const id, const input[], any:...)
{
    new 
iCount 1;
    new 
iPlayers[32];
    
    static 
sMsg[191];
    
    
vformat(sMsg190input3);
    
    
replace_all(sMsg190"!g""^4");
    
replace_all(sMsg190"!n""^1");
    
replace_all(sMsg190"!t""^3");
    
    if(
id)
        
iPlayers[0] = id;
    
    else
        
get_players(iPlayersiCount"ch");
    
    for(new 
0iCounti++)
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _iPlayers[i]);
            
write_byte(iPlayers[i]);
            
write_string(sMsg);
            
message_end();
        }



EpicKiller 05-23-2016 04:35

Re: Preventing the names from repeating
 
Quote:

Originally Posted by siriusmd99 (Post 2421023)
Check flag t remove it and then do equal , it's so hard?

PHP Code:

for(new 0inum; ++a)
        {
            
player players[a];
            new 
flags get_user_flags(player)
            if(
flags ADMIN_LEVEL_H)
                 
flags &= ~(ADMIN_LEVEL_H)
            if(
flags == g_groupFlagsValue[i]){
                  
get_user_name(player,name,31)
                
console_print(id"%s"name);
            }
        } 

And don't use get user name before checking flags, you are wasting memory ....

Well yeah, it is so hard, 'cause I'm a begginer and I don't get loops so well. Thank you!


Quote:

Originally Posted by Bugsy (Post 2421062)
I changed the way the plugin works by assigning the player group when the player connects. The who command will then match the players group with the list of groups as you loop through the groups. I also added a 'Player' group that will display players who do not match any of the defined groups. You can disable this group using the cvar aw_displayplayers. Let me know if this does what you want.

PHP Code:

#include < amxmodx >
#include < amxmisc >

#pragma semicolon 1

#define MAX_PLAYERS 32

enum Groups
{
    
Founder,
    
Owner,
    
CoOwner,
    
God,
    
SuperModerator,
    
Moderator,
    
Administrator,
    
Helper,
    
Slot,
    
Player
}

new 
g_groupNamesGroups ][] = 
{
    
"Founder",
    
"Owner",
    
"Co-Owner",
    
"God",
    
"Super-Moderator",
    
"Moderator",
    
"Administrator",
    
"Helper",
    
"Slot",
    
"Player"
};

new 
g_groupFlagsGroups ][] = 
{
    
"abcdefghijklmnopqrsuv",    // Founder
    
"abcdefghijkmnopqrsu",        // Owner
    
"abcdefijmnopqrsu",            // Co-Owner
    
"abcdefijmnopqrs",            // God
    
"abcdefijmnopqr",            // Super-Moderator
    
"abcdefijmnopq",            // Moderator
    
"abcdefijmno",                // Administrator
    
"abceijmno",                // Helper
    
"ab",                    // Slot
    
"z"                    //Player
};

new 
g_groupFlagsValue[Groups];

new 
Groups:g_PlayerGroupMAX_PLAYERS ] , g_pDisplayPlayers;

public 
plugin_init()
{
    
register_plugin("admin_who""1.0""rock!");
    
    
register_concmd("admin_who""cmdWho"0);
    
    
register_clcmd("say who""cmdSayWho");
    
register_clcmd("say /who""cmdSayWho");
    
register_clcmd("say admin""cmdSayWho");
    
register_clcmd("say /admin""cmdSayWho");
    
    
g_pDisplayPlayers register_cvar"aw_displayplayers""0" );
    
    for( new 
Groups:Founder Groupsi++ )
        
g_groupFlagsValue[i] = read_flags(g_groupFlags[i]);
}

public 
client_authorizedid )
{
    new 
iFlags get_user_flagsid );
    
    for ( new 
Groups:gGroup Founder gGroup Groups gGroup++ )
    {
        if( ( 
iFlags g_groupFlagsValuegGroup ] ) == g_groupFlagsValuegGroup ] )
        {
            
g_PlayerGroupid ] = gGroup;
            break;
        }
    }    
}

public 
cmdWho(id)
{
    new 
players[32], inumplayername[32];

    
get_players(playersinum);
    
    
console_print(id"~~~~~ www..ro ~~~~~");
    
    for(new 
Groups:gGroup FoundergGroup < ( Groups Groups:!get_pcvar_numg_pDisplayPlayers ) ) ; gGroup++ )
    {
        
console_printid "-----[%d]%s-----" _:gGroup+g_groupNamesgGroup ] );
        
        for(new 
0inum; ++a)
        {
            
player players[a];
            
            if( 
gGroup == g_PlayerGroupplayer ] )
            {
                
get_user_nameplayer name charsmaxname ) );
                
console_printid "%s" name );
            }
        }
    }
    
    
console_print(id"~~~~~ www..ro ~~~~~");
    
    return 
PLUGIN_HANDLED;
}

public 
cmdSayWho(id)
{
    
chat_color(id"!t[!g!t] !nCheck your console!");
    
    
cmdWho(id);
}

stock chat_color(const id, const input[], any:...)
{
    new 
iCount 1;
    new 
iPlayers[32];
    
    static 
sMsg[191];
    
    
vformat(sMsg190input3);
    
    
replace_all(sMsg190"!g""^4");
    
replace_all(sMsg190"!n""^1");
    
replace_all(sMsg190"!t""^3");
    
    if(
id)
        
iPlayers[0] = id;
    
    else
        
get_players(iPlayersiCount"ch");
    
    for(new 
0iCounti++)
        if(
is_user_connected(iPlayers[i]))
        {
            
message_begin(MSG_ONE_UNRELIABLEget_user_msgid("SayText"), _iPlayers[i]);
            
write_byte(iPlayers[i]);
            
write_string(sMsg);
            
message_end();
        }



It does exactly what I want and it does it even better. Thank you so much, Bugsy!


All times are GMT -4. The time now is 18:33.

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