Help! Ive made an IG radio streaming, but if leaving car the radio keeps playing!
#1

Help! Ive made an IG radio streaming, but if leaving car the radio keeps playing!
Everything works, except, if you leave the vehicle, the radio keeps playing...

I am a newbie, please fix the code for me! I will give creds!
CODE:
Code:
public OnPlayerCommandText(playerid, cmdtext[])
{

    if (strcmp("/startradio", cmdtext, true, 10) == 0) 
        if(IsPlayerInAnyVehicle(playerid)) {
        ShowPlayerDialog(playerid,90,DIALOG_STYLE_LIST,"Radio stations list","1. Dubstep.FM\r\n2. Radio Gold - Israeli Music\r\n3. Radio Kol Akko","Select", "Cancel");
     
        }
        else
		{
            SendClientMessage(playerid,0x00FF00AA,"You're not in a vehicle.");
        }
    }

    if (strcmp("/stopradio", cmdtext, true, 10) == 0)
    {
        SendClientMessage(playerid,0x00FF00AA,"You have stopped the radio.");
        StopAudioStreamForPlayer(playerid);
        return 1;
    }
    return 0;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 90: 
        {
            if(!response)
                    SendClientMessage(playerid, 0x42F3F198, "You canceled the dialog.");//This one sends a message when you close the dialog using (Cancel).
                    return 1;
            }

            switch(listitem)
            {
                case 0://Case 0 is basically the first line we made in ShowPlayerDialog (1.)
                {
					PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=148196");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming."); //This line sends a message to the listener that he can stop it using /stopradio.
                }
                case 1://Case 1 is the second line we put in ShowPlayerDialog (\r\n2.)
                {
                    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1267208");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming.");//This line sends a message to the listener that he can stop it using /stopradio.
                }
                case 2://Case 2 is the third line we put in ShowPlayerDialog(\r\n3.)
                {
                    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=79683");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming.");//This line sends a message to the listener that he can stop it using /stopradio.
                }
               
            }
        }
    }
    return 1;
}
Reply
#2

Give this a try:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp(cmdtext, "/startradio", true) == 0)
    {
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFF0000FF,"You're not in a vehicle.");
        ShowPlayerDialog(playerid,90,DIALOG_STYLE_LIST,"Radio stations list","1. Dubstep.FM\r\n2. Radio Gold - Israeli Music\r\n3. Radio Kol Akko","Select", "Cancel");
        return 1;
    }

    if (strcmp(cmdtext, "/stopradio", true) == 0)
    {
        SendClientMessage(playerid,0xFFFF00FF,"You have stopped the radio.");
        StopAudioStreamForPlayer(playerid);
        return 1;
    }
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 90:
        {
            if(!response) return SendClientMessage(playerid, 0x42F3F198, "You canceled the dialog.");//This one sends a message when you close the dialog using (Cancel).
            switch(listitem)
            {
                case 0://Case 0 is basically the first line we made in ShowPlayerDialog (1.)
                {
            PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=148196");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming."); //This line sends a message to the listener that he can stop it using /stopradio.
                }
                case 1://Case 1 is the second line we put in ShowPlayerDialog (\r\n2.)
                {
                    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1267208");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming.");//This line sends a message to the listener that he can stop it using /stopradio.
                }
                case 2://Case 2 is the third line we put in ShowPlayerDialog(\r\n3.)
                {
                    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=79683");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming.");//This line sends a message to the listener that he can stop it using /stopradio.
                }  
            }
            return 1;
        }
    }
    return 0;
}
https://sampwiki.blast.hk/wiki/OnPlayerStateChange
https://sampwiki.blast.hk/wiki/Playerstates
https://sampwiki.blast.hk/wiki/StopAudioStreamForPlayer
Reply
#3

Quote:
Originally Posted by BenzoAMG
View Post
Give this a try:
pawn Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp(cmdtext, "/startradio", true) == 0)
    {
        if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0xFF0000FF,"You're not in a vehicle.");
        ShowPlayerDialog(playerid,90,DIALOG_STYLE_LIST,"Radio stations list","1. Dubstep.FM\r\n2. Radio Gold - Israeli Music\r\n3. Radio Kol Akko","Select", "Cancel");
        return 1;
    }

    if (strcmp(cmdtext, "/stopradio", true) == 0)
    {
        SendClientMessage(playerid,0xFFFF00FF,"You have stopped the radio.");
        StopAudioStreamForPlayer(playerid);
        return 1;
    }
    return 0;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case 90:
        {
            if(!response) return SendClientMessage(playerid, 0x42F3F198, "You canceled the dialog.");//This one sends a message when you close the dialog using (Cancel).
            switch(listitem)
            {
                case 0://Case 0 is basically the first line we made in ShowPlayerDialog (1.)
                {
            PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=148196");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming."); //This line sends a message to the listener that he can stop it using /stopradio.
                }
                case 1://Case 1 is the second line we put in ShowPlayerDialog (\r\n2.)
                {
                    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=1267208");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming.");//This line sends a message to the listener that he can stop it using /stopradio.
                }
                case 2://Case 2 is the third line we put in ShowPlayerDialog(\r\n3.)
                {
                    PlayAudioStreamForPlayer(playerid, "http://yp.shoutcast.com/sbin/tunein-station.pls?id=79683");//This function will play our desired radio. So we have to put the url between its brackets.
                    SendClientMessage(playerid, 0x42F3F198, "Type /stopradio to stop audio streaming.");//This line sends a message to the listener that he can stop it using /stopradio.
                }  
            }
            return 1;
        }
    }
    return 0;
}
https://sampwiki.blast.hk/wiki/OnPlayerStateChange
https://sampwiki.blast.hk/wiki/Playerstates
https://sampwiki.blast.hk/wiki/StopAudioStreamForPlayer
Its says I am not inside a veh even if I am..
Reply
#4

pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}
Just add this to you're script.
Reply
#5

Quote:
Originally Posted by venomlivno8
View Post
pawn Code:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_ONFOOT)
    {
        if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
        {
            StopAudioStreamForPlayer(playerid);
        }
    }
    return 1;
}
Just add this to you're script.
Thanks! It worked!
P.S:
How do I do that it will pause when its on foot but it will resume when the player will go back to his car?
And I will be more than glad to help you with your'e server!
Reply
#6

Wait i'll make that script and then i'll send you a PM, no need to worry and if i helped you please REP+
Reply
#7

Quote:
Originally Posted by PazG
View Post
Thanks! It worked!
P.S:
How do I do that it will pause when its on foot but it will resume when the player will go back to his car?
And I will be more than glad to help you with your'e server!
Lol wtf... that is exactly what I posted...
Reply
#8

no, you didn't you fucked up the code on the /startradio command.
Reply
#9

Quote:
Originally Posted by PazG
View Post
How do I do that it will pause when its on foot but it will resume when the player will go back to his car?
You might need the audio plugin for this. https://sampforum.blast.hk/showthread.php?tid=82162.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)