Play audio in car
#1

idk if its possible but...i wanna make a sound car so i want to put a stream audio playing fixed in the car position. can i play an audio from a car in movement? how?
Reply
#2

It's nothing special. You could do, for example:

PHP код:
enum E_VEHICLE_DATA
{
   
bool:VehicleRadioOn,
   
VehicleRadioURL[128]
}
new 
VehicleInfo[MAX_VEHICLES][E_VEHICLE_DATA]; 
Create an enumerator or just use variables for it.

You want to make a command to be able to set the station and turn it on and off.

PHP код:
CMD:radio(playeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid))
        return 
SendClientMessgae(playerid, -1"You aren't in a vehicle...");
    
    new
        
vehicleid GetPlayerVehicleID(playerid);
        
    if(
VehicleRadioOn[vehicleid][VehicleRadioOn])
    {
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
IsPlayerInVehicle(ivehicleid))
            {
                
StopAudioStreamForPlayer(i); 
                
SendClientMessage(i, -1"The radio was stopped.");
            }
        }
    }
    else
    {
        if(
isnull(params) || strlen(params) < 3)
            return 
SendClientMessgae(playerid, -1"/radio [url] to turn it on.");
            
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
IsPlayerInVehicle(ivehicleid))
            {
                
PlayAudioStreamForPlayer(iparams);
                
SendClientMessage(i, -1"The radio started...");
            }
        }
    }    
    return 
1;

When a player exits / enters a vehicle, use OnPlayerStateChange.

If they leave and the radios on, stop the audio stream. If they enter and it's on, start the audio stream.

https://sampwiki.blast.hk/wiki/PlayAudioStreamForPlayer
https://sampwiki.blast.hk/wiki/StopAudioStreamForPlayer
https://sampwiki.blast.hk/wiki/IsPlayerInVehicle
https://sampwiki.blast.hk/wiki/OnPlayerStateChange

(There's a full working system for this here: https://sampforum.blast.hk/showthread.php?tid=641235 if you want to check it out.)
Reply
#3

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
It's nothing special. You could do, for example:

PHP код:
enum E_VEHICLE_DATA
{
   
bool:VehicleRadioOn,
   
VehicleRadioURL[128]
}
new 
VehicleInfo[MAX_VEHICLES][E_VEHICLE_DATA]; 
Create an enumerator or just use variables for it.

You want to make a command to be able to set the station and turn it on and off.

PHP код:
CMD:radio(playeridparams[])
{
    if(!
IsPlayerInAnyVehicle(playerid))
        return 
SendClientMessgae(playerid, -1"You aren't in a vehicle...");
    
    new
        
vehicleid GetPlayerVehicleID(playerid);
        
    if(
VehicleRadioOn[vehicleid][VehicleRadioOn])
    {
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
IsPlayerInVehicle(ivehicleid))
            {
                
StopAudioStreamForPlayer(i); 
                
SendClientMessage(i, -1"The radio was stopped.");
            }
        }
    }
    else
    {
        if(
isnull(params) || strlen(params) < 3)
            return 
SendClientMessgae(playerid, -1"/radio [url] to turn it on.");
            
        for(new 
0GetPlayerPoolSize(); <= ji++)
        {
            if(
IsPlayerInVehicle(ivehicleid))
            {
                
PlayAudioStreamForPlayer(iparams);
                
SendClientMessage(i, -1"The radio started...");
            }
        }
    }    
    return 
1;

When a player exits / enters a vehicle, use OnPlayerStateChange.

If they leave and the radios on, stop the audio stream. If they enter and it's on, start the audio stream.

https://sampwiki.blast.hk/wiki/PlayAudioStreamForPlayer
https://sampwiki.blast.hk/wiki/StopAudioStreamForPlayer
https://sampwiki.blast.hk/wiki/IsPlayerInVehicle
https://sampwiki.blast.hk/wiki/OnPlayerStateChange

(There's a full working system for this here: https://sampforum.blast.hk/showthread.php?tid=641235 if you want to check it out.)
Nice but, i was thinking about put a music for everyone around hear it. idk if its possible cause the music have to change the position everytime when the car is running
Reply
#4

I don't see a plausible way of doing it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)