09.04.2012, 06:57
(
Последний раз редактировалось spd_sahil; 09.04.2012 в 16:46.
)
PlayAudioStreamForPlayer
This function , released in samp server 0.3d , ive noticed around. a lot of people new scripters are having troubles in making this work efficiently , they experience lag , etc . so i have made a small tutorial in which i have completely explained the function.Function
pawn Код:
PlayAudioStreamForPlayer(playerid, url[], Float:posX, Float:posY, Float:posZ , Float:distance, usepos)
Basically this function plays an online audio stream.. mostly in ' .pls ' format ingame.
we have 7 parameters out of which only 2 are compulsory
playerid - the id of the player who will listen to the stream
url - the url of the stream closed in inverted commas i.e " " eg :- "http://somafm.com/tags.pls"
pawn Код:
PlayAudioStreamForPlayer(playerid," URL ");
But , you want the radio to play for the player at a specific place. and you notice on other servers the volume of the radio goes low as you go far from the specific point, we use the following parameters for that
Float Pos X , Y , Z - basically the co-ordinated of the radio . where the sound will come from
range - the radio will be heard till this much range.. it will keep getting volume down till this much radius of the point
and lastly usepos - a value of 0 will disable the use of co-ordinates , that means if you have a value zero for it . the reducing volume effect will be removed.. that means a code of :-
pawn Код:
PlayAudioStreamForPlayer(playerid," URL ",X,Y,Z,range,0);
pawn Код:
PlayAudioStreamForPlayer(playerid," URL ");
pawn Код:
PlayAudioStreamForPlayer(playerid," URL ",X,Y,Z,range,1);
we move on to advanced radio making
Advanced Radio
To create a radio which will activate only when the player goes in a specific range of it
there is two ways to go about.
1. IsPlayerInRangeOfPoint
2. Create a Stock for the above
both will work same.. but somehow i prefer creating a stock
we will use OnPlayerUpdate in this case
and our code will look something like this :-
pawn Код:
public OnPlayerUpdate(playerid)
{
if(IsPlayerInRadioArea(playerid)) // or you can use If(IsPlayerInRangeOfPoint(playerid,range,X,Y,Z)
{
if(!GetPVarInt(playerid,"spawn")) // we are looking if there as variable with the name 'spawn' present , which we havent created yet
{
SetPVarInt(playerid,"spawn",1); // since there wasnt , we now create it so that the loop doesnt enter this again n again and create 'lag'
PlayAudioStreamForPlayer(playerid,"URL GOES HERE",X,Y,Z,range,1);
}
}
else // player is not in point range
{
if(GetPVarInt(playerid,"spawn")) // since we create it before and played the stream , it will be there
{
DeletePVar(playerid,"spawn");// delete the variable so that next time player goes in range the radio can be started again
StopAudioStreamForPlayer(playerid); and stop stream
}
}
return 1;
}
pawn Код:
stock IsPlayerInRadioArea(playerid)
{
new Float:X,Float:Y,Float:Z;
GetPlayerPos(playerid,X,Y,Z);
if(X > MINX && X < MAXX && Y > MINY && Y < MAXY)
{
return 1; // if player is in that area , the stock will return 1 or true
}
return 0; // if not then 0 or false
}
Car Radio
A rather simple one to make, our logic behind this is that when player enters the car , radio starts , and when exits , its stopsim goona use OnPlayerStateChange cause it works better than OnPlayerEnterVehicle
the code will look something like this
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
{
PlayAudioStreamForPlayer(playerid,"URL");
}
if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
{
StopAudioStreamForPlayer(playerid);
}
return 1;
}
All the Time Radio
WARNING : this one will create a little lag , other functions might or might not be affected. i strongly dissaprove the use of thisReally simple , put it under OnPlayerConnect
pawn Код:
public OnPlayerConnect(playerid)
{
PlayAudioStreamForPlayer(playerid,"URL");
return 1;
}
DONT forget to shut it for that id when he/she dissconnects
pawn Код:
public OnPlayerDisconnect(playerid)
{
StopAudioStreamForPlayer(playerid,"URL");
return 1;
}
Helpfull :
https://sampwiki.blast.hk/wiki/PlayAudioStreamForPlayer
https://sampwiki.blast.hk/wiki/StopAudioStreamForPlayer