Music for players near car
#1

Hello. I wanted to make script that will play music for players near ceratin car and stop if they move out from that car.

Here is my code:

Код:
new BusMuza;

public OnFilterScriptInit()
{
	BusMuza = CreateVehicle(437,914.2512,-1692.9191,13.5017,179.9307,5,5, 5000);
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public OnPlayerConnect(playerid)
{
   	SetPVarInt(playerid, "Muzyka", 0);
   	SetPVarString(playerid, "BoomboxURL", "http://djmixes.radioparty.pl:8888/listen.pls");
        return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    new BusMuza;
    if((vehicleid == BusMuza) &&  (GetPVarInt(forplayerid, "Muzyka") == 0)) {
    SetPVarInt(forplayerid, "Muzyka", 1);
    new streamurl[256];
    GetPVarString(forplayerid, "BoomboxURL", streamurl, 256);
    PlayAudioStreamForPlayer(forplayerid, streamurl);
    return 1;
    }
    return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
    new BusMuza;
    if((vehicleid == BusMuza) &&  (GetPVarInt(forplayerid, "Muzyka") == 1)) {
    SetPVarInt(forplayerid, "Muzyka", 0);
    StopAudioStreamForPlayer(forplayerid);
    return 1;
    }
    return 1;
}
But it isn't working at all Any ideas?
Reply
#2

Should be good. That's all you need. PlayAudioStreamForPlayer has build-in params for location, use them.

PHP код:
new BusMuza;
public 
OnFilterScriptInit()
{
    
BusMuza CreateVehicle(437,914.2512,-1692.9191,13.5017,179.9307,5,55000);
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
     
SetPVarInt(playerid"Muzyka"0);
    
SetPVarString(playerid"BoomboxURL""http://djmixes.radioparty.pl:8888/listen.pls");
    new 
streamurl[256],Float:Pos[3];
     
GetPVarString(forplayerid"BoomboxURL"streamurl256);
      
GetVehiclePos(BusMuza,Pos[0],Pos[1],Pos[2]);
    
PlayAudioStreamForPlayer(playeridstreamurl,Pos[0],Pos[1],Pos[2],20.0,1);
    return 
1;

Reply
#3

Yes, but i wanted to attach music to car, so if player is near moving car will hear this audio stream And when he is gone away from that car the audio stream will stop
Reply
#4

You can't attach audio to a vehicle without timers, which wouldn't be a good way of doing it.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)