Alarm System with PlayAudioStreamForPlayer.
#1

pawn Код:
forward HouseAlarm();
public HouseAlarm()
{
    foreach(i, Player)
    {
        if(NearAlarm[playerid] > 0 && HouseAlarm[NearAlarm[playerid]] == 1)
        {
            PlayAudioStreamForPlayer(i, "http://yourlisten.com/GrantAlexander/burglar-intruder-alarm-sound-effect", HouseEntX[NearAlarm[playerid]], HouseEntY[NearAlarm[playerid]], HouseEntZ[NearAlarm[playerid]], 50, 1);
        }
        if(NearAlarm[playerid] > 0 && HouseAlarm[NearAlarm[playerid]] == 2)
        {
            PlayAudioStreamForPlayer(i, "http://yourlisten.com/GrantAlexander/burglar-intruder-alarm-sound-effect", HouseEntX[NearAlarm[playerid]], HouseEntY[NearAlarm[playerid]], HouseEntZ[NearAlarm[playerid]], 100, 1);
        }
        if(NearAlarm[playerid] > 0 && HouseAlarm[NearAlarm[playerid]] == 3)
        {
            PlayAudioStreamForPlayer(i, "http://yourlisten.com/GrantAlexander/burglar-intruder-alarm-sound-effect", HouseEntX[NearAlarm[playerid]], HouseEntY[NearAlarm[playerid]], HouseEntZ[NearAlarm[playerid]], 150, 1);
        }
    }
 }
Doing this will cause lag and I want the system for anyone who is near the house to hear, running a loop for each player every 2 or 3 seconds would cause lag.

How can I do it so I can make the sound play for any player when they are near the co-ordinates of the house without looping through all the players?
Reply
#2

I suggest making a checkpoint or pickup?
Reply
#3

The idea is that if you're driving around you might hear it
Reply
#4

Could you provide the code that changes the NearAlarm state?
Reply
#5

I was going to use onplayerupdate but I'd have to run a loop and that would cause lag
Reply
#6

I'd suggest using Tasks, and running everything in there related to the player, every 1,2,3,4,5 seconds. I've used a one-second timer in the past with players upto 25 for testing.
Reply
#7

What do you mean?
Reply
#8

You can do it simply by using OnPlayerEnterDynamicArea callback..Hope i helped you
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)