16.03.2014, 04:04
(
Последний раз редактировалось RoboN1X; 16.03.2014 в 04:05.
Причина: too late
)
The code is obviously wrong, because it just take one character from the string
So even you do this:
The formatted output will be like this:
You must use strtok function to pick the strings after a space symbol from the command.
Alternatively, using sscanf but it's usually used on zcmd for multiple parameters, zcmd can handle the params without strtok (it will work like strrest).
So if you liked to use strcmp and strtok try this:
EDIT: late post lol...
pawn Код:
if(!strcmp(cmdtext, "/music", true, 6))
{
if(!cmdtext[6])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /music [url]"); // Check if there is no character on "cmdtext" at position '6'
new audio[128];
format(audio, sizeof(audio), "%s", cmdtext[7]); // Only take one character from "cmdtext" at position '7'
PlayAudioStreamForPlayer(-1, audio, 0.0, 0.0, 0.0, 50.0, 0);
return 1;
}
Quote:
Код:
/music http://www.tonycuffe.com/mp3/tailtoddle_lo.mp3 |
Код:
/music h
Alternatively, using sscanf but it's usually used on zcmd for multiple parameters, zcmd can handle the params without strtok (it will work like strrest).
So if you liked to use strcmp and strtok try this:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[128], idx;
cmd = strtok(cmdtext, idx);
if(!strcmp(cmd, "/music", true, 6))
{
new tmp[128];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /music [url]");
PlayAudioStreamForPlayer(-1, tmp, 0.0, 0.0, 0.0, 50.0, 0); // We don't need to format "audio" as it's equal to "tmp"
return 1;
}
return 0;
}