Writing after commas (Arguments/parameters)
#1

pawn Код:
stock SetAdminCommand(command[], level)
{
    if(level)
    {
        Group_SetGlobalCommand(Command_GetID(command), false);

        new cl = 0;
        while(cl != MAX_ADMIN_LEVELS)
        {
            cl += 1;
            if(cl == level)
            {
                Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][cl], Command_GetID(command), true);
            }

            else
            {
                Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][cl], Command_GetID(command), false);
            }
        }
    }

    else
    {
        Group_SetGlobalCommand(Command_GetID(command), true);
    }
}
Any ideas how to write levels after commas?

pawn Код:
SetAdminCommand("ban", 1, 2, 3, 4, 5, 6[...]);
Reply
#2

This will help you: https://sampforum.blast.hk/showthread.php?tid=77000
Reply
#3

Tried:

pawn Код:
stock SetAdminCommand(command[], ...)
{
    for(new level = 1; level < numargs(); level++)
    {
        if(getarg(level))
        {
            Group_SetGlobalCommand(Command_GetID(command), false);

            new cl = 0;
            while(cl != MAX_ADMIN_LEVELS)
            {
                cl += 1;
                if(cl == level)
                {
                    Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][cl], Command_GetID(command), true);
                }

                else
                {
                    Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][cl], Command_GetID(command), false);
                }
            }
        }
       
        else
        {
            Group_SetGlobalCommand(Command_GetID(command), true);
        }
    }
}
Not working at all..
Reply
#4

Bump.
Reply
#5

You should look up y_va.inc https://sampforum.blast.hk/showthread.php?tid=399069
Reply
#6

Quote:
Originally Posted by LarzI
Посмотреть сообщение
Tried, no idea how to start with it.. any advice?
Reply
#7

Edited your code a bit, changed it into two functions so it should be a little easier to debug if you have problems.

UNTESTED:
pawn Код:
stock SetAdminCommand(command[], ...)
{
    new idx = 0;
   
    for(new level = 1; level < numargs(); level++)
    {
        if( ( idx = getarg(level) ) )//if level is more than zero
        {
            Group_SetGlobalCommand(Command_GetID(command), false);

            //you appeared to use the admin level as an index in your code.
            //You should add bounds checks to make sure you don't access elements OOB
            Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][ idx ], Command_GetID(command), true);
        }
        else
        {
            Group_SetGlobalCommand(Command_GetID(command), true);
        }
    }
}

stock UnSetAdminCommand(command[], ...)
{
    new idx = 0;
   
    for(new level = 1; level < numargs(); level++)
    {
        if( ( idx = getarg(level) ) )
        {
            Group_SetGlobalCommand(Command_GetID(command), true);
           
            //You should add bounds checks to make sure you don't access elements OOB
            Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][ idx ], Command_GetID(command), false);
        }
        else
        {
            Group_SetGlobalCommand(Command_GetID(command), false);
        }
    }
}
Reply
#8

Quote:
Originally Posted by Riddick94
Посмотреть сообщение
Tried, no idea how to start with it.. any advice?
I apologise! I was certain y_va was easy to use with integers too, but I couldn't quite understand how you would do it - if it's even possible.

Read iggy's response - it should work!
Reply
#9

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Edited your code a bit, changed it into two functions so it should be a little easier to debug if you have problems.

UNTESTED:
pawn Код:
stock SetAdminCommand(command[], ...)
{
    new idx = 0;
   
    for(new level = 1; level < numargs(); level++)
    {
        if( ( idx = getarg(level) ) )//if level is more than zero
        {
            Group_SetGlobalCommand(Command_GetID(command), false);

            //you appeared to use the admin level as an index in your code.
            //You should add bounds checks to make sure you don't access elements OOB
            Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][ idx ], Command_GetID(command), true);
        }
        else
        {
            Group_SetGlobalCommand(Command_GetID(command), true);
        }
    }
}

stock UnSetAdminCommand(command[], ...)
{
    new idx = 0;
   
    for(new level = 1; level < numargs(); level++)
    {
        if( ( idx = getarg(level) ) )
        {
            Group_SetGlobalCommand(Command_GetID(command), true);
           
            //You should add bounds checks to make sure you don't access elements OOB
            Group_SetCommand(SerwerData[E_SERWER_GROUP_ADMINS][ idx ], Command_GetID(command), false);
        }
        else
        {
            Group_SetGlobalCommand(Command_GetID(command), false);
        }
    }
}
Works like a charm, thanks.

Quote:
Originally Posted by LarzI
Посмотреть сообщение
I apologise! I was certain y_va was easy to use with integers too, but I couldn't quite understand how you would do it - if it's even possible.

Read iggy's response - it should work!
No worries, both repped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)