[Ajuda] Mudei uns comandos para strcmp
#6

Achei algumas coisas que lhe ajudara!

Quote:
Originally Posted by zSuYaNw
Посмотреть сообщение
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[]) {
    // Exemplo
    if(!strcmp(cmdtext,"/dinheiro", true)) {
   
        if(!IsPlayerAdmin(playerid))
            return SendClientMessage(playerid, 0x1E90FFFF, ">> Somente administradores rcon.");
           
        static id, quantia;
        if(sscanf(cmdtext, "ud", id, quantia))
            return SendClientMessage(playerid, 0x1E90FFFF, ">> Sintaxe: /dinheiro [ID] [Quantia]");
           
        GivePlayerMoney(id, quantia);
        return 1;
    }

    // Outros comandos
    return 0;
}
б й mesmo auehuaheuahueha
Quote:
Originally Posted by Kyosaur
Посмотреть сообщение
If your code isnt tested, you shouldnt post it. Those commands wont work correctly! Not only are specifying the wrong length to the strcmp function (10 for both, which neither equal 10!), but your passing the entire cmdtext string to sscanf, which includes the original command.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(!strcmp(cmdtext, "/Example", true, 8))
    {
        new
            number,
            string[16];

        if(!sscanf(cmdtext[9], "is[15]", number, string))
        {
            printf("number = %d, string = %s.", number, string);
            return 1;
        }
        SendClientMessage(playerid, 0xFF0000FF, "Syntax error: /Example <number> <string>");
        return 1;
    }

    return 0;
}
The above should work without any problems, but it's highly recommended to just use a command processor like zcmd/ycmd with sscanf. This not only is faster, but its much safer due to how easy it is to make mistakes using the above methodology.

Remember to always update the strcmp length parameter (should be the lenght of the command) and the index for cmdtext (should be the length of the command + 1) if you change the name of the command.

#Edit

Em vez de params e cmdtext

Reply


Messages In This Thread
Mudei uns comandos para strcmp - by clerISoN - 30.05.2013, 15:51
Re: Mudei uns comandos para strcmp - by -GooGle- - 30.05.2013, 15:59
Re: Mudei uns comandos para strcmp - by clerISoN - 30.05.2013, 16:18
Re: Mudei uns comandos para strcmp - by Cromado - 30.05.2013, 16:23
Re: Mudei uns comandos para strcmp - by clerISoN - 30.05.2013, 16:25
Re: Mudei uns comandos para strcmp - by Don_Speed - 30.05.2013, 16:27
Re: Mudei uns comandos para strcmp - by clerISoN - 30.05.2013, 16:53
Re: Mudei uns comandos para strcmp - by Cromado - 30.05.2013, 16:55
Re: Mudei uns comandos para strcmp - by Don_Speed - 30.05.2013, 17:01
Re: Mudei uns comandos para strcmp - by Cromado - 30.05.2013, 17:04

Forum Jump:


Users browsing this thread: 1 Guest(s)