Sound is supposed to be played at a certain position
#1

Title sums it up.
I want a player sound to be played at a certain position(and there should be also a range to it) and don't know how to do it or where to put the whole thing. Seriously, this is driving me crazy.

SAMP wiki says I should only use the cordinates, but I simply don't get the meaning behind it, since "PlayerPlaySound(1130, 0.0, 0.0, 10.0);"(playerid was removed) does not seem to work.

Thanks in advance.
Reply
#2

IsPlayerInRangeOfPoint
Reply
#3

If you mean you want to PlayerPlaySound in a range of coordinates, then:
pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerInRangeOfPoint(i, 10, 0.0, 0.0, 0.0))//edit
   {
        PlayerPlaySound(i)//....
   }
}
Reply
#4

Now, where am I supposed to put this to?

So it's like that, right?
Quote:

for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 10, 1319.1042,1253.9703,14.2731))//edit
{
PlayerPlaySound(i, 1185, 1319.1042,1253.9703,14.2731);//....
}
}
return 1;
}

Reply
#5

Put it where you want to make it function. OnPlayerCommand, OnPlayerText or wherever.
Reply
#6

https://sampwiki.blast.hk/wiki/SoundID
Try this, and this link is for Sounds ID.
pawn Код:
new SoundTimer[MAX_PLAYERS];
pawn Код:
public OnPlayerConnect(playerid) {
    SoundTimer[playerid] = SetTimer("SoundTimer", 1000, true);
    return 1;
}
pawn Код:
public OnPlayerDisconnect(playerid) {
    KillTimer(SoundTimer[playerid]);
    return 1;
}
pawn Код:
forward SoundTimerFunc();
public SoundTimerFunc() {
    for(new i; i < MAX_PLAYERS; i++) {
        if(IsPlayerInRangeOfPoint(i, DISTANCE, X, Y, Z)) { // Change your X, Y, Z and distance.
            PlayerPlaySound(i, SoundID, 0.0, 0.0, 0.0); // Change your SoundID to a specific ID, posted a link.
        }
    }
    return 1;
}
Reply
#7

You may put it OnPlayerUpdate but you need to make a variable.

pawn Код:
new bool:calledSound[MAX_PLAYERS char];

//OnPlayerUpdate
if(IsPlayerInRangeOfPoint(...))
{
    if(calledSound{playerid} == false) {
        //play sound
        calledSound{playerid} = true;
    }
}


else
{
    if(calledSound{playerid} == true)  calledSound{playerid} =false;

}
Reply
#8

Thanks a lot, you two.
Lorenc_'s version works, EliranPesahov's... umm... not so much.

But there's still a problem left: Once the player is out of range, the sound is supposed to stop playing.
Reply
#9

Bump. I still need help.
Reply
#10

Playing soundid 1186 should stop it

pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 10, 1319.1042,1253.9703,14.2731))
{
    if(calledSound{playerid} == false)
    {
        PlayerPlaySound(playerid, 1185, 0, 0, 0);
        calledSound{playerid} = true;
    }
}
else
{
    if(calledSound{playerid} == true)
    {
        PlayerPlaySound(playerid, 1186, 0, 0, 0);
        calledSound{playerid} = false;
    }
}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)