22.11.2013, 23:30
(
Последний раз редактировалось VenomXNL; 23.11.2013 в 00:14.
Причина: Put snippet in the subject
)
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
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:
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
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 ;)
}
}
}
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