[Ajuda] converter comando.
#1

eu tenho este comando em strcmp, e gostaria te-lo convertido para ZCMD.
Poderiam-me ajudar ?

pawn Код:
if(strcmp(cmd, "/attempt", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_GRAD2, "[USAGE:] /attempt [action]");
                return 1;
            }
            new succeed = 1 + random(2);
            if(succeed == 1)
            {
                format(string, sizeof(string), "[Tentar:] %s tenta %s e consegue.", GetPlayerNameEx(playerid), result);
                ProxDetector(10.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
            }
            else if(succeed == 2)
            {
                format(string, sizeof(string), "[Tentar:] %s tenta %s e falha.", GetPlayerNameEx(playerid), result);
                ProxDetector(10.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
            }
        }
        return 1;
    }
Reply
#2

Aconselho fortemente o uso de sscanf, por ser relativamente muito mais rбpido!
pawn Код:
CMD:attempt(playerid, params[])
{
    new gMensage[128];
    if(sscanf(params, "s", gMensage)) return SendClientMessage(playerid, COLOR_GRAD2, "[USAGE:] /attempt [action]");
    //if(sscanf(params, "s[128]", gMensage)) return SendClientMessage(playerid, COLOR_GRAD2, "[USAGE:] /attempt [action]");//sscanf 2.0
    new string[164];
    new succeed = 1 + random(2);
    if(succeed == 1)
    {
        format(string, sizeof(string), "[Tentar:] %s tenta %s e consegue.", GetPlayerNameEx(playerid), gMensage);
        ProxDetector(10.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
    }
    else if(succeed == 2)
    {
        format(string, sizeof(string), "[Tentar:] %s tenta %s e falha.", GetPlayerNameEx(playerid), gMensage);
        ProxDetector(10.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
    }
    return 1;
}
Forma sem sscanf:
pawn Код:
CMD:attempt(playerid, params[])
{
    new idx;
    new length = strlen(params);
    while ((idx < length) && (params[idx] <= ' ')){idx++;}
    new offset = idx;
    new result[64];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1))){result[idx - offset] = params[idx]; idx++;}
    result[idx - offset] = EOS;
    if(!strlen(result))return SendClientMessage(playerid, COLOR_GRAD2, "[USAGE:] /attempt [action]");
    new succeed = 1 + random(2);
    if(succeed == 1)
    {
        format(string, sizeof(string), "[Tentar:] %s tenta %s e consegue.", GetPlayerNameEx(playerid), result);
        ProxDetector(10.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
    }
    else if(succeed == 2)
    {
        format(string, sizeof(string), "[Tentar:] %s tenta %s e falha.", GetPlayerNameEx(playerid), result);
        ProxDetector(10.0, playerid, string, COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE,COLOR_LIGHTBLUE);
    }
    return 1;
}
Vocк pode encontrar sscanf aqui: https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#3

editado:
jб consegui. Obrigado Larceny.
Reply
#4

Woops! Eu havia esquecido de alterar o result para gMensage.
pawn Код:
format(string, sizeof(string), "[Tentar:] %s tenta %s e consegue.", GetPlayerNameEx(playerid), result);
para:
pawn Код:
format(string, sizeof(string), "[Tentar:] %s tenta %s e consegue.", GetPlayerNameEx(playerid), gMensage);
Dб uma olhada no post acima...

--


Quote:
Originally Posted by noobre
Посмотреть сообщение
editado:
jб consegui. Obrigado Larceny.
Beleza! Internet tб um caos aqui, 5minutos para o post chegar no fуrum.
Reply
#5

Quote:
Originally Posted by Larceny
Посмотреть сообщение
Woops! Eu havia esquecido de alterar o result para gMensage.
pawn Код:
format(string, sizeof(string), "[Tentar:] %s tenta %s e consegue.", GetPlayerNameEx(playerid), result);
para:
pawn Код:
format(string, sizeof(string), "[Tentar:] %s tenta %s e consegue.", GetPlayerNameEx(playerid), gMensage);
Dб uma olhada no post acima...
Fico-lhe grato, obrigado mais uma vez.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)