Writing after commas (Arguments/parameters) -
Riddick94 - 28.01.2013
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[...]);
Re: Writing after commas (Arguments/parameters) -
Roach_ - 28.01.2013
This will help you:
https://sampforum.blast.hk/showthread.php?tid=77000
Re: Writing after commas (Arguments/parameters) -
Riddick94 - 28.01.2013
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..
Re: Writing after commas (Arguments/parameters) -
Riddick94 - 29.01.2013
Bump.
Re: Writing after commas (Arguments/parameters) -
LarzI - 29.01.2013
You should look up y_va.inc
https://sampforum.blast.hk/showthread.php?tid=399069
Re: Writing after commas (Arguments/parameters) -
Riddick94 - 29.01.2013
Quote:
Originally Posted by LarzI
|
Tried, no idea how to start with it.. any advice?
Re: Writing after commas (Arguments/parameters) -
iggy1 - 29.01.2013
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);
}
}
}
Re: Writing after commas (Arguments/parameters) -
LarzI - 29.01.2013
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!
Re: Writing after commas (Arguments/parameters) -
Riddick94 - 29.01.2013
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.