Streaming Audio Only in a Car
#1

I was wondering how i can make it to when i stream audio that it only plays when you are in a vehicle. Help please?

Код:
CMD:music(playerid, params[])
{
	new string[128];
   	if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
	if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /music [url]");
	if(!strcmp(params, "stop", true, 4))
	{
	    StopAudioStreamForPlayer(playerid);
	    SendClientMessage(playerid, COLOR_LIGHTRED, " You have stopped listening to music.");
	    return 1;
	}
	if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
	format(string, sizeof(string), "AdmCmd: %s has started playing a song globally. ('/music stop' to stop listening)", RPN(playerid));
	SendClientMessageToAll(COLOR_LIGHTRED, string);
	foreach(Player, i)
	{
		PlayAudioStreamForPlayer(i, params);
	}
	return 1;
}
Reply
#2

use this . .
https://sampwiki.blast.hk/wiki/IsPlayerInAnyVehicle
Reply
#3

pawn Код:
CMD:music(playerid, params[])
{
    new string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /music [url]");
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0x00FF00AA,"You're not in a vehicle!");
    if(!strcmp(params, "stop", true, 4))
    {
        StopAudioStreamForPlayer(playerid);
        SendClientMessage(playerid, COLOR_LIGHTRED, " You have stopped listening to music.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    format(string, sizeof(string), "AdmCmd: %s has started playing a song globally. ('/music stop' to stop listening)", RPN(playerid));
    SendClientMessageToAll(COLOR_LIGHTRED, string);
    foreach(Player, i)
    {
        PlayAudioStreamForPlayer(i, params);
    }
    return 1;
}
pawn Код:
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0x00FF00AA,"You're not in a vehicle!");
Reply
#4

I tried it but it keeps playing when I exit the vehicle. I have to be in the car to start it though..
Reply
#5

StopAudioStreamForPlayer under OnPlayerStateChange when oldstate is PLAYER_STATE_DRIVER or PLAYER_STATE_PASSENGER.
Reply
#6

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
StopAudioStreamForPlayer under OnPlayerStateChange when oldstate is PLAYER_STATE_DRIVER or PLAYER_STATE_PASSENGER.
And to start the audio up again when they enter the car?
Reply
#7

Save the audio URL in a variable and play it to the player when newstate is PLAYER_STATE_DRIVER or PLAYER_STATE_PASSENGER.
Reply
#8

well, you'll have to get a variable to save the radio station of each car and when they enter the car you'll just stream that for the player
something like:
Код:
new radiostation[MAX_VEHICLES][128];
and on the command you add
Код:
radiostation[vehicleid][128] = string;
and on player enter car you use
Код:
PlayAudioStreamForPlayer(i, radiostation[vehicleid]);
Atleast i think something like that'll work, hope you understand what I'm trying to tell you
Reply
#9

Quote:
Originally Posted by Ranama
Посмотреть сообщение
well, you'll have to get a variable to save the radio station of each car and when they enter the car you'll just stream that for the player
something like:
Код:
new radiostation[MAX_VEHICLES][128];
and on the command you add
Код:
radiostation[vehicleid][128] = string;
and on player enter car you use
Код:
PlayAudioStreamForPlayer(i, radiostation[vehicleid]);
Atleast i think something like that'll work, hope you understand what I'm trying to tell you
Yeah I understand what you're saying lol just not sure if I will be able to get it working like that. I just thought I could add IsPlayerInAnyVehicle and be done haha. I'll try your example.


EDIT: I tried and I couldnt seem to figure it out :/ I would hate to ask this but its my only hope. Can someone copy my code and put fix it for me and show me anything else I have to put in there? Sorry
Reply
#10

new MusicOn[MAX_PLAYERS];

pawn Код:
CMD:music(playerid, params[])
{
    new string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(sscanf(params, "s[256]", params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /music [url]");
    if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,0x00FF00AA,"You're not in a vehicle!");
    if(!strcmp(params, "stop", true, 4))
    {
        StopAudioStreamForPlayer(playerid);
        SendClientMessage(playerid, COLOR_LIGHTRED, " You have stopped listening to music.");
        MusicOn[playerid] = 0;
        return 1;
    }
    if(PlayerInfo[playerid][pAdmin] < 6) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    format(string, sizeof(string), "AdmCmd: %s has started playing a song globally. ('/music stop' to stop listening)", RPN(playerid));
    SendClientMessageToAll(COLOR_LIGHTRED, string);
    foreach(Player, i)
    {
        PlayAudioStreamForPlayer(i, params);
        MusicOn[playerid] = 1;
    }
    return 1;
}
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER )
    {
        if(MusicOn[playerid] == 1) return PlayAudioStream(blah blah)
    }
    else if(oldstate == PLAYER_STATE_DRIVER || PLAYER_STATE_PASSENGER && newstate == PPLAYER_STATE_ONFOOT )
    {
        StopAudioStream(blah blah)
    }
    return 1;
}
Then on player disconnect or whenever do MusicOn[playerid] = 0;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)