The code is obviously wrong, because it just take one character from the string
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;
}
So even you do this:
Quote:
Originally Posted by Gus_Stone
|
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:
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;
}
EDIT: late post lol...