Y_INI question
#1

Hello, I've another question.
So, a few days ago I started a new script, replacing RCON admin with an adminlevel using Y_INI.

To make check if somebody is admin I use

pawn Code:
If(PlayerInfo[playerid][pAdmin] <= 0)
So, I've been working on a /setadmin command. I've got quite far, also I would post it, but it's one of the first commands I've made without making references to the Wiki or a tutorial, so it is probably completely wrong.
Now, on to the point:

How do I actually change their admin level in pawn? Again, to check it it's

pawn Code:
If(PlayerInfo[playerid][pAdmin] <= 0)
so, how would I change it.

Thanks in advance,
anjh.
Reply
#2

Show me the command please.
Reply
#3

This is a cmd I did on my script here it is.
pawn Code:
CMD:makeadmin(playerid,params[])
{
    new id;
    new level;
    if(PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid,RED,"You are not allowed to use this command");
    else if(AdminAllowed[playerid] == 0) return SendClientMessage(playerid,RED,"You need to enter admin pass to use this command!");
    else if(sscanf(params, "ui", id, level))SendClientMessage(playerid, RED, "Usage: /makeadmin [id/name] [level]");
    PlayerInfo[id][pAdmin] = level;
    return 1;
}
Reply
#4

Quote:
Originally Posted by SilverKiller
View Post
Show me the command please.
I could PM it to you if it's required for you to help, but that I would prefer not to do.

Quote:

This is a cmd I did on my script here it is.
pawn Code:
CMD:makeadmin(playerid,params[])
{
    new id;
    new level;
    if(PlayerInfo[playerid][pAdmin] < 5) return SendClientMessage(playerid,RED,"You are now allowed to use this command");
    else if(AdminAllowed[playerid] == 0) return SendClientMessage(playerid,RED,"You need to enter admin pass to use this command!");
    else if(sscanf(params, "ui", id, level))SendClientMessage(playerid, RED, "Usage: /makeadmin [id/name] [level]");

    PlayerInfo[id][pAdmin] = level;
    return 1;
}
Yeah, in my attempts of making it I used:
pawn Code:
PlayerInfo[playerid][pAdmin] = adminlevel)
but I got a compiling error.


Just saying, if anybody is in doubt of what my question is, I want the link of code to change somebody's admin level ingame. Sorry if I've worded the question incorrectly.




Thanks,
anjh.
Reply
#5

Quote:
Originally Posted by Anjh
View Post
I could PM it to you if it's required for you to help, but that I would prefer not to do.



Yeah, in my attempts of making it I used:
pawn Code:
PlayerInfo[playerid][pAdmin] = adminlevel)
but I got a compiling error.

Thanks,
anjh.
pawn Code:
PlayerInfo[playerid][pAdmin] = adminlevel;
Also note that [playerid] is your ID in game not the target ID, that's why i said show your command so i can see what you did in there..
Reply
#6

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.
Reply
#7

Ok, my command is:

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, "d", 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[playerid][pAdmin] == adminlevel) return SendClientMessage(playerid, COLOR_SILVER, "Error: This player is already that level!");
        {
            PlayerInfo[id][pAdmin] = adminlevel;
        }
    }
    return 1;
}
It's probably horribly wrong.

I managed to edit out the compiling errors.

I've tested the command, and it does not work ingame. When you type it correctly, it does not do anything.

Thanks,
anjh.
Reply
#8

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..
Reply
#9

Also whats nice to save a lot of coding is make some defines like this........

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....

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
Reply
#10

Quote:
Originally Posted by SilverKiller
View Post
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
View Post
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!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)