[Tutorial] PlayAudioStreamForPlayer
#1

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 ");
now a simple code of will play the stream for the player with id ' playerid '


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);
will work the same as

pawn Код:
PlayAudioStreamForPlayer(playerid," URL ");
now if you want the co-ords to take effect you have to change the last value to a 1

pawn Код:
PlayAudioStreamForPlayer(playerid," URL ",X,Y,Z,range,1);
These were the basics of PlayAudioStreamForPlayer

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;
}
this is what my stock looks like :-

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 stops

im 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;
}
Notice i am not using the co-ordinates and range and usepos.. because we want the radio to play everywhere u go

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 this


Really simple , put it under OnPlayerConnect

pawn Код:
public OnPlayerConnect(playerid)
{
    PlayAudioStreamForPlayer(playerid,"URL");
    return 1;
}
radio will be on for every player who enters your server

DONT forget to shut it for that id when he/she dissconnects


pawn Код:
public OnPlayerDisconnect(playerid)
{
    StopAudioStreamForPlayer(playerid,"URL");
    return 1;
}
Hope this helped you, good day


Helpfull :

https://sampwiki.blast.hk/wiki/PlayAudioStreamForPlayer

https://sampwiki.blast.hk/wiki/StopAudioStreamForPlayer
Reply
#2

waaa thanks buddy
Reply
#3

how can i remove the string saing "now playing url..."
Reply
#4

Quote:
Originally Posted by Steezy_
Посмотреть сообщение
how can i remove the string saing "now playing url..."
You Cant Its The Function Included in SAMP
Reply
#5

Quote:
Originally Posted by GTA_DAM_RUNNER
Посмотреть сообщение
You Cant Its The Function Included in SAMP
In Mini-Missions they fixed it...

btw why dont edit the include? it may be work...
Reply
#6

Quote:
Originally Posted by Steezy_
Посмотреть сообщение
how can i remove the string saing "now playing url..."
No , this cant be removed yet ( until samp does something about it).. this is the audio stream server side..

if you dont want it .. you should host your own audio stream
Reply
#7

there is some command ingame to disable it, it only disables for the player who types the command.
Reply
#8

/audiomsg ? no i dont think its for that , im not sure

Код:
audiomsgoff - If this option is set to 1, no Audio Stream: messages will be displayed in the chat window when the server requests the client to connect to an audio stream. This option is enabled/disable with the client-side /audiomsg command.
Reply
#9

Quote:
Originally Posted by spd_sahil
Посмотреть сообщение
No , this cant be removed yet ( until samp does something about it).. this is the audio stream server side..

if you dont want it .. you should host your own audio stream
It can.

http://blackace.square7.ch/SAMP/Rele.../AudioHide.inc

Credits to BlackAce
Reply
#10

Quote:
Originally Posted by Dripac
Посмотреть сообщение
Can you post new link?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)