PlaySoundNearPlayerFA and PlaySoundForAllAt
#1

Hello there,

I have created a function for my own server but I thought that it might be useful for others,
so I've made two snippets of the function for the SA-MP forum, with two different approaches.
I only use the first one but I hope that I could help some starting scripters with these snippets
so i well commented them and adapted an second function that might also be useful for others.

In our RP server some event like popping tires occur due to tear and wear for example, and I
wanted to make sure that everyone in and around that tire would here the pop. (This is only
one of the uses) so i have created a function that will play a selected sound for ALL players
in range of the player that is causing the sound/event.

Both functions take care of checking the Virtual Worlds and the Interior ID's, there is also
a check to exclude NPC's (they are all deaf anyway :P), and they both take care of a
range check.

An usage example of the first one would be:
PlaySoundNearPlayerFA(3200, 0, 80);

The line above plays a Airhorn for all player within a range of 80 from player 0,
San Andreas/SA-MP takes care of the distance volume itself so no need to take
care of that part. Phiew
pawn Код:
stock PlaySoundNearPlayerFA(SoundID, NearPlayer, Range)
    {
        new Float:X,Float:Y,Float:Z, VWorld, IntID;         //Location Variables for the position where the sound comes from
        GetPlayerPos(NearPlayer, X, Y, Z);                  //Get the location where the sound needs to be played
        VWorld = GetPlayerVirtualWorld(NearPlayer);         //Get the Virtual World where the sound needs to be played
        IntID = GetPlayerInterior(NearPlayer);              //Get The Interior ID where the sound needs to be played

        for(new i=0;i<MAX_PLAYERS;i++)                      //Run a loop from ID 0 to the last id in the server
        {
            if(!IsPlayerConnected(i)) continue;             //Skip if the player id isn't taken/connected
            if(IsPlayerNPC(i)) continue;                    //Skip if the player id is taken by a NPC
            //if(PlayerSpawned[i] < 1) continue;            //Something I use in my server, because I use several spawning methods in my server
                                                            //You can leave this one out or replace it with a own 'spawning' variable if needed
            if(GetPlayerVirtualWorld(i) != VWorld) continue;//If the virtual worlds DO NOT match then skip playback for this player
            if(GetPlayerInterior(i) != IntID) continue;     //If the Interiors does match then skip playback for this player
                                                            //I Would RECOMMEND you to disable the interior checking (including the Variable on top
                                                            //if you use a system where each building has its own virtual world (saves server load/resources!)

            if(IsPlayerInRangeOfPoint(i, Range, X, Y, Z))   //This part will only execute if all above approve AND the player is in the given range
            {
                PlayerPlaySound(i, SoundID, X, Y, Z);       //And playing the sound ofcourse ;)
            }
        }
    }

I adapted my function above especially for the SA-MP forum, so that you could
play a sound happening on a location on the map at a chosen location and in a
virtual world of your choice:
pawn Код:
stock PlaySoundForAllAt(SoundID, Float:X, Float:Y, Float:Z, Range, VWorld)
    {
        for(new i=0;i<MAX_PLAYERS;i++)                      //Run a loop from ID 0 to the last id in the server
        {
            if(!IsPlayerConnected(i)) continue;             //Skip if the player id isn't taken/connected
            if(IsPlayerNPC(i)) continue;                    //Skip if the player id is taken by a NPC
            //if(PlayerSpawned[i] < 1) continue;            //Something I use in my server, because I use several spawning methods in my server
                                                            //You can leave this one out or replace it with a own 'spawning' variable if needed
            if(GetPlayerVirtualWorld(i) != VWorld) continue;//If the virtual worlds DO NOT match then skip playback for this player

            if(IsPlayerInRangeOfPoint(i, Range, X, Y, Z))   //This part will only execute if all above approve AND the player is in the given range
            {
                PlayerPlaySound(i, SoundID, X, Y, Z);       //And playing the sound ofcourse ;)
            }
        }
    }
If you need more explanation then please do not hesitate to ask.
I don't need/require any credits for this off-course (WAY to small code,
and to easy to create for experienced scripters).

BUT... I would like it if you leave a message if this snippet/code was useful to
you, then I at-least know that I'm not adapting and uploading my codes for nothing

Hope I could be of service and have fun scripting,
VenomXNL
Reply
#2

This is some kind of tutorial,not scripting help you should ask moderator to move it
Reply
#3

Quote:
Originally Posted by ***Niko***
Посмотреть сообщение
This is some kind of tutorial,not scripting help you should ask moderator to move it
Thanks for the idea, i just PM'ed ****** to ask for a (or the) snippet section, because this is not
a Tutorial either. It's just a snippet of code with could help people with their script.

A tutorial would be a step by step explanation if I'm correct, this is just a well commented piece of code,
in which I hope to help others complete their script

Don't get me wrong I don't mean any harm with my response and not trying to attack your comment ,
I just can't find the right spot to post my snippets to help out others.

And on my last snippet someone advised me to add it to a other thread with about
30 pages (yeah, like someone would find it then )

This seems the most logical topic if you ask me since the description of this topic is:
'Discussion and help related to creating scripts for SA-MP.'

Hope you understand my topic choice.

Kind Regards,
VenomXNL.
Reply
#4

Yeah so i guess this belongs into useful commands/functions
Reply
#5

Quote:
Originally Posted by ***Niko***
Посмотреть сообщение
Yeah so i guess this belongs into useful commands/functions
I see what you mean, that is the topic that the other guy mentioned indeed,
But then it is nearly unfindable. And it takes me to much time to adapt my
snippets for others if they can't find them

Take the 'GetPlayerPacketloss' function for example (just picked one out of that topic)
if you search for it it will only show the post names 'Useful snippets' not the page or item itself.

So never mind then, then I just don't upload/post the snippets.
Just trying to help others, not doing it for the Rep, likes or what ever anyway

Anyway thanks for the input.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)