SA-MP Forums Archive
Audio stream question - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Audio stream question (/showthread.php?tid=501013)



Audio stream question - Rabbayazza - 16.03.2014

Код:
        if(!strcmp(cmdtext, "/music", true, 6))
{
        if(!cmdtext[6])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /music [url]");
        new audio[128];
        format(audio, sizeof(audio), "%s", cmdtext[7]);
        PlayAudioStreamForPlayer(-1, audio, 0.0, 0.0, 0.0, 50.0, 0);
        return 1;
}
Don't smite me for using strcmp, but is there any way I can get this to work? The idea is that the player types in a URL and then it plays for everyone on the server.

Whenever I do the command it just doesn't work and nothing plays.


Re: Audio stream question - Gus_Stone - 16.03.2014

Put this on top of your gamemode

Код:
#include <foreach>
And replace your /music cmd with this

Код:
if(!strcmp(cmdtext, "/music", true, 6))
	{
        if(!cmdtext[6])return SendClientMessage(playerid, 0xFF0000FF, "USAGE: /music [url]");
        new audio[128];
        format(audio, sizeof(audio), "%s", cmdtext[7]);
        foreach(Player, i)
		{
		PlayAudioStreamForPlayer(i, audio);
		}
        return 1;
	}
Tried it ingame and it worked


Re: Audio stream question - Rabbayazza - 16.03.2014

Quote:
Originally Posted by Gus_Stone
Посмотреть сообщение
Put this on top of your gamemode



And replace your /music cmd with this



Tried it ingame and it worked, +rep if it helped you
Didn't work. Nothing played when I did the command.


Re: Audio stream question - Gus_Stone - 16.03.2014

You sure you're using a valid .mp3 URL?

Try to do this in-game

Код:
/music http://www.tonycuffe.com/mp3/tailtoddle_lo.mp3
And then tell me if you heard the soundtrack


Re: Audio stream question - Rabbayazza - 16.03.2014

Quote:
Originally Posted by Gus_Stone
Посмотреть сообщение
You sure you're using a valid .mp3 URL?

Try to do this in-game



And then tell me if you heard the soundtrack
Yeah. It's not playing anything.


Re: Audio stream question - Rabbayazza - 16.03.2014

Never mind. Should have said I was using a filterscript. I added to game mode and it worked fine.

Thank you.


Re: Audio stream question - Gus_Stone - 16.03.2014

Oh okay, glad I could help.


Re: Audio stream question - RoboN1X - 16.03.2014

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:
Код:
/music h
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...


Re: Audio stream question - Gus_Stone - 16.03.2014

EDIT: Nevermind


Re: Audio stream question - Ceathor - 16.03.2014

Quote:
Originally Posted by Gus_Stone
Посмотреть сообщение
feel free to +rep if it helped you
I'm sorry for being all off-topic here, and I'm sorry, but when I see this I just facepalm too much.
You don't ask for rep, you get it because someone thinks you deserved it.
Meaning, I'll never rep anyone who has something like that in their post or signature.


Anyway on-topic: I highly recommend using zcmd (https://sampforum.blast.hk/showthread.php?tid=91354) and sscanf (https://sampforum.blast.hk/showthread.php?tid=120356). They will enable you to process commands quicker, better and easier.