03.07.2013, 16:00
When the driver is clicking play, it will get HIS vehicle ID and then under this will LOOP through everyone in his car:
When the driver has clicked on a radio and this loop will cycle through the players in his car and play the selected radio:
This is how I've done it and it's worked for me every time.
Note: If you're not using foreach I can convert it to a standard loop. Foreach is much better for speed.
pawn Код:
new vehicleradio = GetPlayerVehicleID(playerid); // The vehicle ID is stored inside the integer and called when he clicks play.
pawn Код:
foreach(Player, i) // The loop
{
if(GetPlayerVehicleID(i) == vehicleradio && IsPlayerInAnyVehicle(i) && GetPlayerState(i) == PLAYER_STATE_PASSENGER && i != playerid) // Checks if the vehicle is the same as the one who typed the command and does other checks to see if there are people in the car
{
// Now that there are people in the car, the audio will play.
PlayAudioStreamForPlayer(i, AUDIO URL);
}
}
Note: If you're not using foreach I can convert it to a standard loop. Foreach is much better for speed.