Play Sound for Nearby Players
#1

Sorry, if i might not get some things or terms. I am fairly new to scripting and have only used scripting for mapping.

So I am trying to play a sound when people enter a command to open a garage. I am trying to make it so that all near by players will have the sounds played, but I have not figured out how to do it. If someone could please help me, it would really appreciated.


Command for Opening/Closing garage:
Код:
CMD:garage(playerid, params[])
{
new Float: x, Float: y, Float: z;
GetDynamicObjectPos(H148Gate, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 30, x, y, z))
{
switch(H148GarageOpen)
{
case 0:
{
H148GarageOpen = 1;
new string[128];
format(string, sizeof(string), "* %s uses their remote to open the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2575.88188, 12.24580, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
}
case 1:
{
H148GarageOpen = 0;
new string[128];
format(string, sizeof(string), "* %s uses their remote to close the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2576.24587, 11.12580, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
}
}
}
return 1;
}
Code for the sound that needs to be played and then another sound that needs to be played 3 seconds after the first sound has been played.
First Sound:
Код:
PlayerPlaySound(playerid, 1153, 1656.4711, 2576.2517, 10.8535);
Second Sound 2 secs later:
Код:
PlayerPlaySound(playerid, 1154, 1656.4711, 2576.2517, 10.8535);
Thanks and sorry, if I'm just asking you to do all the work. I've tried to the best of my knowledge of scripting but have not been able to do it.
Reply
#2

Loop through all the players. Then check if the player is in range of at least 5.5 from the gate object, then play the sound. It should be something like:

pawn Код:
for(new i = 0 < MAX_PLAYERS; i++)
{
    if(IsPlayerInRangeOfPoiint(i, 5.5, Gate_X, Gate_Y, Gate_Z))
    {
        PlayerPlaySound(i, 1153, 1656.4711, 2576.2517, 10.8535);
    }
}
Reply
#3

Quote:
Originally Posted by iOxide
Посмотреть сообщение
Loop through all the players. Then check if the player is in range of at least 5.5 from the gate object, then play the sound. It should be something like:

pawn Код:
for(new i = 0 < MAX_PLAYERS; i++)
{
    if(IsPlayerInRangeOfPoiint(i, 5.5, Gate_X, Gate_Y, Gate_Z))
    {
        PlayerPlaySound(i, 1153, 1656.4711, 2576.2517, 10.8535);
    }
}
When I added this, this comes up:
Код:
House.pwn(1167) : error 001: expected token: ";", but found ")"
Reply
#4

Make sure you have IsPlayerInRangeOfPoint and not IsPlayerInRangeOfPoiint.

It should be:
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Rather than:
Код:
for(new i = 0 < MAX_PLAYERS; i++)
Reply
#5

Quote:
Originally Posted by Robert515
Посмотреть сообщение
When I added this, this comes up:
Код:
House.pwn(1167) : error 001: expected token: ";", but found ")"
Can you show us line 1167?
Reply
#6

Line 1167:
for(new i = 0 < MAX_PLAYERS;i++)
Reply
#7

pawn Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Reply
#8

Quote:
Originally Posted by Robert515
Посмотреть сообщение
Line 1167:
for(new i = 0 < MAX_PLAYERS;i++)
Quote:
Originally Posted by Adamss
Посмотреть сообщение
It should be:
Код:
for(new i = 0; i < MAX_PLAYERS; i++)
Rather than:
Код:
for(new i = 0 < MAX_PLAYERS; i++)
You're missing the "; i" after new i.
Reply
#9

Thanks guys, it worked!
Reply
#10

Sorry, if I'm double-posting but can any of you help me on making it so that if garage is moving, you can't enter the cmd again. So it's basically a command timer. Thanks!

Here's the code:
Код:
CMD:garage(playerid, params[])
{
new Float: x, Float: y, Float: z;
GetDynamicObjectPos(H148Gate, x, y, z);
if(IsPlayerInRangeOfPoint(playerid, 30, x, y, z))
{
switch(H148GarageOpen)
{
case 0:
{
H148GarageOpen = 1;
new string[128];
format(string, sizeof(string), "* %s uses their remote to open the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2575.88188, 12.24580, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.01870, 12.25530, 0.5, 0.00000, -90.00000, 90.00000);
H148GarageSound1(playerid);
}
case 1:
{
H148GarageOpen = 0;
new string[128];
format(string, sizeof(string), "* %s uses their remote to close the garage.", GetName(playerid));
NearByMessage(playerid, 0x9A2EFEFF, string);
MoveDynamicObject(H148Garage, 1656.53455, 2576.24587, 11.12580, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol1, 1657.35132, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
MoveDynamicObject(H148GarageCol2, 1655.71033, 2576.29858, 11.61530, 0.5, 0.00000, 0.00000, 90.00000);
H148GarageSound1(playerid);
}
}
}
return 1;
}

forward H148GarageSound1(playerid);
public H148GarageSound1(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30, 1656.4711, 2576.2517, 10.8535))
{
PlayerPlaySound(i, 1153, 1656.4711, 2576.2517, 10.8535);
SetTimerEx("H148GarageSound2", 2000, false, "i", playerid);
        
}
}
}

forward H148GarageSound2(playerid);
public H148GarageSound2(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInRangeOfPoint(i, 30, 1656.4711, 2576.2517, 10.8535))
{
PlayerPlaySound(i, 1154, 1656.4711, 2576.2517, 10.8535);
}
}
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)