SA-MP Forums Archive
Admin Title Command - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Admin Title Command (/showthread.php?tid=563951)



Admin Title Command - Luke_James - 18.02.2015

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;
}



Re: Admin Title Command - HazardouS - 18.02.2015

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
}



Re: Admin Title Command - Luke_James - 18.02.2015

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;
}



Re: Admin Title Command - HazardouS - 18.02.2015

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


Re: Admin Title Command - CalvinC - 18.02.2015

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.


Re: Admin Title Command - Luke_James - 18.02.2015

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/


Re: Admin Title Command - CalvinC - 18.02.2015

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;
}



Re: Admin Title Command - Luke_James - 18.02.2015

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