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;
public OnPlayerCommandText(playerid, cmdtext[])
{
new
index,
cmd[20];
cmd = strtok(cmdtext, index);
if (strcmp(cmd, "/heal", true) == 0)
{
new
tmp[20],
id;
tmp = strtok(cmdtext, index);
if (strlen(tmp))
{
id = strval(tmp);
if (IsPlayerConnected(id))
{
SetPlayerHealth(id, 100.0);
SendClientMessage(id, 0x00FF00AA, "You have been healed");
SendClientMessage(playerid, 0x00FF00AA, "Player healed");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "Player not found");
}
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "Usage: \"/heal <playerid>\"");
}
return 1;
}
return 0;
http://forum.sa-mp.com/showthread.ph...utorial+strtok //Espaсol/Spanish
http://forum.sa-mp.com/showthread.ph...utorial+strtok //Inglкs http://forum.sa-mp.com/showthread.ph...tok#post798644 //Portuguкs |
while ((index < length) && (string[index] <= ' '))//Aqui ele vк se a string tem um espaзo. Enquanto ela tiver, o script continua. |
Vou explicar, o primeiro loop sу continua rodando enquanto o tamanho da string for menor que index ( mas o que й index ? index й o lugar onde se encontra o parвmetro. ), e tambйm vк se string[index] que й por exemplo em um comando do tipo /comando 9 6 para achar o 6 teria que ter um 11 no lugar de index entгo seria string[11], ele vai acessar a cйlula 11 que equivale a 32 (tambйm conhecido por ' ')
|