[HELP] Command
#1

Why this dont work? O.o

It gives me wrong ID

1. I'll type: "/test 1 Test"
2. Then i'll get this message "Larsey123(0) (You) have tested the code at Larsey123(0) because Test"
That means it dont give me the correct ID, because i typed ID "1" and in the text it give me the id "0"

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new ID[256], idx, tmp[256];
    ID = strtok(cmdtext, idx);

    new targetid = strval(tmp);
    tmp = strtok(cmdtext, idx);

    new reason[256];
    reason = bigstrtok(cmdtext, idx);

    new pName [MAX_PLAYER_NAME], tName [MAX_PLAYER_NAME], string [128];
    GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
    GetPlayerName(targetid, tName, MAX_PLAYER_NAME);
   
    if (strcmp("/test", ID, true, 10) == 0)
    {
        if(!IsPlayerConnected(targetid)) return SendClientMessage(playerid,COLOR_ERROR,"Player is not connected");
        if(!IsNumeric(tmp)) return SendClientMessage(playerid,COLOR_ERROR,"The ID must be a number");
        if(!strlen(reason)) return SendClientMessage(playerid,COLOR_ERROR,"You must enter the message");
        {
            format (string, sizeof(string), "%s(%d) (You) have tested the code at %s(%d) because %s", pName, playerid, tName, targetid, reason);
            SendClientMessage(playerid, 0xFF000000,string);
            return 1;
        }
    }
    return 0;
}
strtok and bigstrtok:
pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

stock bigstrtok(const string[], &idx)
{
    new length = strlen(string);
    while ((idx < length) && (string[idx] <= ' '))
    {
        idx++;
    }
    new offset = idx;
    new result[128];
    while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
    {
        result[idx - offset] = string[idx];
        idx++;
    }
    result[idx - offset] = EOS;
    return result;
}
Reply


Messages In This Thread
[HELP] Command - by Larsey123IsMe - 15.01.2011, 01:00
Re: [HELP] Command - by *IsBack - 15.01.2011, 09:35
Re: [HELP] Command - by Larsey123IsMe - 15.01.2011, 11:28
Re: [HELP] Command - by *IsBack - 15.01.2011, 14:52

Forum Jump:


Users browsing this thread: 3 Guest(s)