Audio stream question
#1

Код:
        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.
Reply
#2

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
Reply
#3

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.
Reply
#4

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

Try to do this in-game

And then tell me if you heard the soundtrack
Reply
#5

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.
Reply
#6

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

Thank you.
Reply
#7

Oh okay, glad I could help.
Reply
#8

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...
Reply
#9

EDIT: Nevermind
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)