Admin Title Command
#1

This command is meant to set an admin's title and save it to the database, but it doesn't work. I can set the title via the database manually and it loads it fine, but when I use the /admintitle command it resets the title of the person executing the command and doesn't update the title.

pawn Код:
CMD:admintitle(playerid, params[])
{
    static
        atitle[32],
        userid;
       
    if(PlayerData[playerid][pAdmin] < 6)
        return SendErrorMessage(playerid, "You don't have permission to use this command.");
       
    if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if(PlayerData[userid][pAdmin] < 1)
        return SendErrorMessage(playerid, "This player is not an administrator.");

    format(PlayerData[userid][pAdminTitle], 32, atitle);
    return 1;
}
Reply
#2

You forgot to process the parameters. I recommend using sscanf for this.
pawn Код:
if(sscanf(params, "us[32]", userid, atitle))
{
//error
}
else
{
//atitle and userid are both set
}
Reply
#3

Like this?

pawn Код:
CMD:admintitle(playerid, params[])
{
    static
        atitle[32],
        userid;

    if(PlayerData[playerid][pAdmin] < 6)
        return SendErrorMessage(playerid, "You don't have permission to use this command.");

    if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if(PlayerData[userid][pAdmin] < 1)
        return SendErrorMessage(playerid, "This player is not an administrator.");

    if(sscanf(params, "uss[32]", userid, atitle)) {
        return SendSyntaxMessage(playerid, "/admintitle [ID/Name] [Title]");
    }
    else format(PlayerData[userid][pAdminTitle], 32, atitle);
    return 1;
}
Reply
#4

sscanf is processing your parameters. Before using them, you need to process them. The first use of the parameters is in the first if-statement, so sscanf must be placed before it.
Here you can find more info about sscanf: https://github.com/Y-Less/sscanf/wiki
Reply
#5

There's some mistakes with that:

1.
You need to use it above
pawn Код:
if (userid == INVALID_PLAYER_ID)
As "userid" needs to be defined by sscanf too.

2.
"uss[32]" will be "ID", "string" and "string"[size of 32], yet you only added "userid" and "atitle", so you're not using the one in the middle, delete it.
Also, you need to use a string size if you wanted to use the string in the middle.

3. (Not really anything wrong with it, but just saying)
There's no need to use an "else" or the brackets with your sscanf.
Reply
#6

pawn Код:
CMD:admintitle(playerid, params[])
{
    static
        atitle[32],
        userid;

    if(PlayerData[playerid][pAdmin] < 6)
        return SendErrorMessage(playerid, "You don't have permission to use this command.");

    if(sscanf(params, "uss[32]", userid, atitle)) {
        return SendSyntaxMessage(playerid, "/admintitle [ID/Name] [Title]");
        }
    else format(PlayerData[userid][pAdminTitle], 32, atitle);

    if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if(PlayerData[userid][pAdmin] < 1)
        return SendErrorMessage(playerid, "This player is not an administrator.");
    return 1;
}
So how about this/
Reply
#7

That wont work, these will be invalid:
pawn Код:
if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if(PlayerData[userid][pAdmin] < 1)
        return SendErrorMessage(playerid, "This player is not an administrator.");
And again:
Quote:

"uss[32]" will be "ID", "string" and "string"[size of 32], yet you only added "userid" and "atitle", so you're not using the one in the middle, delete it.
Also, you need to use a string size if you wanted to use the string in the middle.

It should be like this:
pawn Код:
CMD:admintitle(playerid, params[])
{
    static
        atitle[32],
        userid;

    if(PlayerData[playerid][pAdmin] < 6)
        return SendErrorMessage(playerid, "You don't have permission to use this command.");

    if(sscanf(params, "us[32]", userid, atitle))
        return SendSyntaxMessage(playerid, "/admintitle [ID/Name] [Title]");

    if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if(PlayerData[userid][pAdmin] < 1)
        return SendErrorMessage(playerid, "This player is not an administrator.");

    format(PlayerData[userid][pAdminTitle], 32, atitle);

    return 1;
}
Reply
#8

Quote:
Originally Posted by CalvinC
Посмотреть сообщение
That wont work, these will be invalid:
pawn Код:
if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if(PlayerData[userid][pAdmin] < 1)
        return SendErrorMessage(playerid, "This player is not an administrator.");
And again:


It should be like this:
pawn Код:
CMD:admintitle(playerid, params[])
{
    static
        atitle[32],
        userid;

    if(PlayerData[playerid][pAdmin] < 6)
        return SendErrorMessage(playerid, "You don't have permission to use this command.");

    if(sscanf(params, "us[32]", userid, atitle))
        return SendSyntaxMessage(playerid, "/admintitle [ID/Name] [Title]");

    if (userid == INVALID_PLAYER_ID)
        return SendErrorMessage(playerid, "You have specified an invalid player.");

    if(PlayerData[userid][pAdmin] < 1)
        return SendErrorMessage(playerid, "This player is not an administrator.");

    format(PlayerData[userid][pAdminTitle], 32, atitle);

    return 1;
}
I see what you mean now, I will give it a try
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)