15.01.2011, 01:00
(
Последний раз редактировалось Larsey123IsMe; 15.01.2011 в 02:42.
)
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"
strtok and bigstrtok:
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;
}
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;
}