26.10.2013, 22:22
Hey I have problem with Shout command, I can't make it work, so problem is when I write /shout "a" it says "USAGE: /shout [text]" when I do /shout AAAAAaaaaaaaAAAAA it says me same thing "USAGE:...." if I write /shout (a lot of mixed letters) it will show only last letters for example: iagnslfhwrshnaskdbngh it will show: "(name) shouts: bngh"
What is wrong?
this is also what I have current OnPlayerCommandText:
And I'm using strtok also..
I think I showed you everything I need :P thanks for help in advance
What is wrong?
pawn Код:
if(strcmp(cmd, "/shout", true) == 0)
{
//if(IsDown[playerid] == 1 || IsDown[playerid] == 2) { return SendClientMessage(playerid,0xFF0000AA,"You can't shout while incapacitated."); }
if(IsPlayerConnected(playerid))
{
GetPlayerName(playerid, Name, sizeof(Name));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[256];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
if(!strlen(result))
{
SendClientMessage(playerid, 0xffffffff, "USAGE: /shout [text]");
return 1;
}
format(Str, sizeof(Str), "%s shouts: %s", Name, result);
SendClientMessage(playerid, 0xffffffff, Str);
//ProxDetector(30.0, playerid, string,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF);
printf("- /shout: %s", Str);
}
return 1;
}
return 0;
}
pawn Код:
new cmd[256];
new tmp[256];
new idx;
cmd = strtok(cmdtext, idx);
tmp = strtok(cmdtext, idx);
new id = strval(tmp);
new Float:x;
new Float:y;
new Float:z;
new Str[256];
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;
}