Multi-usage command
#1

Hello guys, I have made a command with more than one usage. Command is: /paintball.
Usage: /paintball[LIST/EDIT/LEADER].

"List" or "Edit" are working well, about the "leader" one, it's made to set the paintball leader.

so the usage should be like: /paintball leader [PLAYER_ID]. I scripted it, and went ingame, I did "/paintball leader", then it said: this player is not connected. I didn't even type a player name/id. And if I type a name/id, it says: USAGE: /paintball[LIST/EDIT/LEADER]..

PHP код:
CMD:paintball(playeridparams[])
{
    if(
sscanf(params"s[50]"params)) return UsageMSG(playerid"/paintball[LIST/EDIT/LEADER]");
     if(
strcmp(params"list"true) && strcmp(params"edit"true) && strcmp(params"leader"true)) return UsageMSG(playerid"/paintball[LIST/EDIT/LEADER]");
    if(!
strcmp(params"list"true))
    {
        
ShowPaintballLobbies(playerid);
     }
    if(!
strcmp(params"edit"true))
    {
        if(
pInfo[playerid][InPBLobby] == -1) return ErrorMSG(playerid"You are not in any paintball lobby.");
        if(
pbInfo[pInfo[playerid][InPBLobby]][pbLeader] != playerid) return ErrorMSG(playerid"You are not the paintball leader.");
        
ShowPaintballEdit(playeridpInfo[playerid][InPBLobby]);
    }
    if(!
strcmp(params"leader"true))
    {
        if(
pInfo[playerid][InPBLobby] == -1) return ErrorMSG(playerid"You are not in any paintball lobby.");
        if(
pbInfo[pInfo[playerid][InPBLobby]][pbLeader] != playerid) return ErrorMSG(playerid"You are not the paintball leader.");
        new 
pID;
        if(
sscanf(params"u"pID)) return UsageMSG(playerid"/paintball leader [PLAYER_ID]");
        if(!
IsPlayerConnected(pID)) return ErrorMSG(playerid"This player is not connected.");
        if(
pInfo[pID][InPBLobby] != pInfo[playerid][InPBLobby]) return ErrorMSG(playerid"This player isn't in your PB lobby.");
        new 
pbid pInfo[playerid][InPBLobby], string[128];
        
pbInfo[pbid][pbLeader] = pID;
        
format(stringsizeof(string), "%s(%d) is the new paintball leader."PlayerName(pID), pID);
        
SendMSGToPBMembers(pbidstring);
    }
    return 
1;

Reply
#2

First of all, you don't need sscanf at the first line, params already holds the text.

You would need to check if the first 6 characters are not "leader" to return the usage with the options but still can't be accurate enough if a player writes "leaderblabla" for example. The best way for me is to send the usage with the options in an else statement at the bottom.

Код:
if (!strcmp(params, "list", true)) ShowPaintballLobbies(playerid);

else if (!strcmp(params, "edit", true))
{
    if (pInfo[playerid][InPBLobby] == -1) return ErrorMSG(playerid, "You are not in any paintball lobby.");
    if (pbInfo[pInfo[playerid][InPBLobby]][pbLeader] != playerid) return ErrorMSG(playerid, "You are not the paintball leader.");

    ShowPaintballEdit(playerid, pInfo[playerid][InPBLobby]);
}

else if (!strcmp(params, "leader", true)) 
{
    if (pInfo[playerid][InPBLobby] == -1) return ErrorMSG(playerid, "You are not in any paintball lobby.");
    if (pbInfo[pInfo[playerid][InPBLobby]][pbLeader] != playerid) return ErrorMSG(playerid, "You are not the paintball leader.");
  
    UsageMSG(playerid, "/paintball leader [PLAYER_ID]");
}
else if (!strcmp(params, "leader ", true))
{
    new pID;
    if (sscanf(params[7], "u", pID)) return UsageMSG(playerid, "/paintball leader [PLAYER_ID]");
    if (!IsPlayerConnected(pID)) return ErrorMSG(playerid, "This player is not connected.");
    if (pInfo[pID][InPBLobby] != pInfo[playerid][InPBLobby]) return ErrorMSG(playerid, "This player isn't in your PB lobby.");

    new pbid = pInfo[playerid][InPBLobby], string[128];
    pbInfo[pbid][pbLeader] = pID;
    format(string, sizeof(string), "%s(%d) is the new paintball leader.", PlayerName(pID), pID);
    SendMSGToPBMembers(pbid, string);
}

else UsageMSG(playerid, "/paintball[LIST/EDIT/LEADER]");
As you can see, we ignore "paintball leader " and we use what is left as parameters (referring to params[7]).

Last, a note: be careful with what you reset pInfo[playerid][InPBLobby] - it may go out of bounds.
Reply
#3

Thank you so much! +REP'd
Reply
#4

Bro, I've tested it now, I did "/paintball leader", and it shows /paintball leader [PLAYER_ID], then I did /paintball leader 0 (my ID), then it showed the command usage (/paintball[LIST/EDIT/LEADER]).

Help please.
Reply
#5

Quote:
Originally Posted by Ahmed21
Посмотреть сообщение
Bro, I've tested it now, I did "/paintball leader", and it shows /paintball leader [PLAYER_ID], then I did /paintball leader 0 (my ID), then it showed the command usage (/paintball[LIST/EDIT/LEADER]).

Help please.
Change this:
Код:
else if (!strcmp(params, "leader ", true))
To this:
Код:
else if (!strcmp(params, "leader ", true, 7))
Reply
#6

Quote:
Originally Posted by Stinged
Посмотреть сообщение
Change this:
Код:
else if (!strcmp(params, "leader ", true))
To this:
Код:
else if (!strcmp(params, "leader ", true, 7))
Thank you!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)