Play audio in car - 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: Play audio in car (
/showthread.php?tid=642051)
Play audio in car -
SonicFreeStyle - 24.09.2017
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?
Re: Play audio in car -
Kane - 24.09.2017
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(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid))
return SendClientMessgae(playerid, -1, "You aren't in a vehicle...");
new
vehicleid = GetPlayerVehicleID(playerid);
if(VehicleRadioOn[vehicleid][VehicleRadioOn])
{
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerInVehicle(i, vehicleid))
{
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 i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerInVehicle(i, vehicleid))
{
PlayAudioStreamForPlayer(i, params);
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.)
Re: Play audio in car -
SonicFreeStyle - 24.09.2017
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(playerid, params[])
{
if(!IsPlayerInAnyVehicle(playerid))
return SendClientMessgae(playerid, -1, "You aren't in a vehicle...");
new
vehicleid = GetPlayerVehicleID(playerid);
if(VehicleRadioOn[vehicleid][VehicleRadioOn])
{
for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerInVehicle(i, vehicleid))
{
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 i = 0, j = GetPlayerPoolSize(); i <= j; i++)
{
if(IsPlayerInVehicle(i, vehicleid))
{
PlayAudioStreamForPlayer(i, params);
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
Re: Play audio in car -
Kane - 24.09.2017
I don't see a plausible way of doing it.