strtok problem
#1

Hi,
when i type /Chan it says
USAGE: /Chan [channel id] ( it suppose to do that )
but when i type /Chan 63 for example it says "Unknown Command", here is the code:
pawn Код:
#include <a_samp>

new Chan[MAX_PLAYERS] = 0;

public OnPlayerText(playerid, text[])
{
    if(Chan[playerid] >= 1)
    {
        new str[256];
        new pName[17];
        GetPlayerName(playerid, pName, 17);
        format(str, 256, "%s: %s (Channel :%d)",pName, text, Chan[playerid]);
        SendClientMessageToChan(Chan[playerid], 0xF6F6F6AA, str);
        return 0;
  }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
  new cmd[128], idx;
    cmd = strtok(cmdtext, idx);
    new tmp[128];
    if (strcmp("/Chan", cmdtext, true, 10) == 0)
    {
        tmp = strtok(cmdtext, idx);

        if(strlen(tmp) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /Chan [channel id]");

        Chan[playerid] = strval(tmp);

        return 1;
    }
    return 0;
}


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

SendClientMessageToChan(ChanID, color, const msg[])
{
  for (new i = 0; i >= GetMaxPlayers(); i++)
  {
        if(Chan[i] == ChanID)
        {
            SendClientMessage(i, color, msg);
        }
    }
}
Fix me, thanks
Reply
#2

pawn Код:
if (strcmp("/Chan", cmd, true, 10) == 0)
And use dcmd. It's faster and easier
Reply
#3

Quote:
Originally Posted by dice7
pawn Код:
if (strcmp("/Chan", cmd, true, 10) == 0)
And use dcmd. It's faster and easier
holy shit, i forgot to replace cmdtext to cmd, thanks, and i will try dcmd
Reply
#4

Quote:
Originally Posted by dice7
pawn Код:
if (strcmp("/Chan", cmd, true, 10) == 0)
And use dcmd. It's faster and easier
Yeah, I agree. It's much easier to work with, too. Glad I started out learning DCMD from the get-go.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)