Quote:
Originally Posted by SilverKiller
pawn Code:
CMD:setadmin(playerid, params[]) { new id, adminlevel; if(PlayerInfo[playerid][pAdmin] <= 4) return SendClientMessage(playerid, COLOR_SILVER, "You must be atleast a Community Owner to use this command!"); else if(sscanf(params, "ud", id, adminlevel)) return SendClientMessage(playerid, COLOR_SILVER, "Syntax: /setadmin [PlayerID][Admin Level]"); else if(adminlevel > 0 || adminlevel < 5) return SendClientMessage(playerid, COLOR_SILVER, "Error: Must be level 1-5!"); else { if(PlayerInfo[id][pAdmin] == adminlevel) return SendClientMessage(playerid, COLOR_SILVER, "Error: This player is already that level!"); else { PlayerInfo[id][pAdmin] = adminlevel; } } return 1; }
Should work fine..
|
That almost worked fine.
When using that code, whenever I typed it, it came up with: Error: "Must be Level 1-5"
So I changed it to this
pawn Code:
CMD:setadmin(playerid, params[])
{
new id, adminlevel;
if(PlayerInfo[playerid][pAdmin] <= 4) return SendClientMessage(playerid, COLOR_SILVER, "You must be atleast a Community Owner to use this command!");
else if(sscanf(params, "ud", id, adminlevel)) return SendClientMessage(playerid, COLOR_SILVER, "Syntax: /setadmin [PlayerID][Admin Level]");
else if(adminlevel < 0 || adminlevel > 5) return SendClientMessage(playerid, COLOR_SILVER, "Error: Must be level 1-5!");
else
{
if(PlayerInfo[id][pAdmin] == adminlevel) return SendClientMessage(playerid, COLOR_SILVER, "Error: This player is already that level!");
else
{
PlayerInfo[id][pAdmin] = adminlevel;
}
}
return 1;
}
and it works absolutely fine.
Quote:
Also whats nice to save a lot of coding is make some defines like this........
pawn Code:
#define CMDLEVEL(%0) if(PlayerInfo[playerid][pAdmin] < %0 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000FF, "You do not have the privilege to use that command.")
or....
pawn Code:
#define COMMUNITYLEVEL(%0) if(PlayerInfo[playerid][pAdmin] <= %0) return SendClientMessage(playerid, COLOR_SILVER, "You must be atleast a Community Owner to use this command!");
Then simply put....
CMDLEVEL(5);
COMMUNITYLEVEL(4);
Best way to do these things neatly
|
Thank you for your response, but it is working now.
Quote:
Originally Posted by [uL]Pottus
This is a really basic solution you'll surely want to add more messages and more checks etc but just to give you a idea.
Code:
CMD:setlevel(playerid, params[])
{
new pid;
new level;
sscanf(params, "ui", pid, level);
if(IsPlayerConnected(pid))
{
// Level between 1 and 5
if(level >= 1 && level <= 5)
{
PlayerInfo[playerid][pAdmin] = newlevel;
SendClientMessage(playerid, 0xFF00FFFF, "Set This Users Level!");
}
}
}
Edit - I see a lot of people posting code with multiple returns don't get into that habit it's bad practice and makes ugly looking hard to read code.
|
I agree, and am going to add more messages, like it is going to post it to everybody, but I just wanted to get the basic command, as you can see, my original question was just asking for one line of code.
thanks.
I have +REP'd everybody who has posted here, thank you for your help!