05.04.2012, 04:43
Introduction
I've seen many requests in the suggestions board this suggestion, I mean like alot of people suggested / requested it. it wasn't too hard to script, and I made it as an experiment, a simple experiment, however I thought someone would find it useful for their servers as long they edit it so it works better.
For example, if you are using scripted sirens for vehicles, you would know that they have no sound, but using the audio streams introduced in 0.3d, you can make that feature, you can make a jukebox object that has a radio stream attached, and other things you can come upon with.
Usage
Thanks to the (required) y_hooks include by ****** this is really easy to use. There are three functions:
Known bugs
They are listed in the include:
Download
You got it.
I've seen many requests in the suggestions board this suggestion, I mean like alot of people suggested / requested it. it wasn't too hard to script, and I made it as an experiment, a simple experiment, however I thought someone would find it useful for their servers as long they edit it so it works better.
For example, if you are using scripted sirens for vehicles, you would know that they have no sound, but using the audio streams introduced in 0.3d, you can make that feature, you can make a jukebox object that has a radio stream attached, and other things you can come upon with.
Usage
Thanks to the (required) y_hooks include by ****** this is really easy to use. There are three functions:
pawn Code:
AttachStreamToObject( objectid, Float:range, url[] ); // create an attached audio stream for an object
StopObjectStream( objectid ); // destroys the attached audio stream
IsStreamAttachedToObject( objectid ); // returns 1 if an audio stream is attached to the objectid
They are listed in the include:
pawn Code:
/* * Known bugs
--------------------------------------
- There can be problems (or not) if you destroy the object before
stopping the audio stream, use StopObjectStream prior destroying
an object with attached stream.
- The data is not reset if the stream is over. I recommend using this
for streams that are very long, or not ending, like radio stations, or a timer to destroy the attached stream with the stream duration.
- There is no support for the PlayAudioStreamForPlayer extra parameters
like how the sound fades smoothly when you approach it.
--------------------------------------*/
pawn Code:
/*
ATTACH SOUND TO OBJECT WRITTEN BY ADMANTIS
CREDITS TO ****** FOR HIS FANTASTIC YSI LIBRARY AND FOREACH LIBRARY
* Functions
--------------------------------------
AttachStreamToObject( objectid, range, url )
INFO: Attach a stream to a object, so when a player approaches the object,
it can be heard. For example, using the function in scripted sirens using
0.3e objects, you can get sounds for the siren using the 0.3d
PlayAudioStreamForPlayer function.
* objectid: the object ID the stream will be attached.
* range: meters you need to approach to the object to hear the stream.
* url: valid .mp3, .ogg, icecast, shoutcast link for the audio stream.
--------------------------------------
StopObjectStream( objectid )
INFO: Destroy the attached sound stream for that object.
* objectid: the object ID the stream will be destroyed.
--------------------------------------
* Known bugs
--------------------------------------
- There can be problems (or not) if you destroy the object before
stopping the audio stream, use StopObjectStream prior destroying
an object with attached stream.
- The data is not reset if the stream is over. I recommend using this
for streams that are very long, or not ending, like radio stations, or a timer to destroy the attached stream with the stream duration.
- There is no support for the PlayAudioStreamForPlayer extra parameters
like how the sound fades smoothly when you approach it.
--------------------------------------
Do whatever you want with this, seriously, I did it because it was
requested by many people in the suggestions board and it would be
interesting for me to write it.
*/
#include <a_samp>
#include <foreach>
#include <YSI\y_hooks>
enum g_stream
{
gStreamEnabled,
gStreamURL[128],
Float:gStreamRange
}
new gObjectStream[MAX_OBJECTS][g_stream];
new gActiveStreamObjectID[MAX_PLAYERS];
forward StreamCheckTimer( );
stock StopObjectStream( objectid )
{
gObjectStream[objectid][gStreamURL] = "";
gObjectStream[objectid][gStreamEnabled] = 0;
gObjectStream[objectid][gStreamRange] = 0;
}
stock AttachStreamToObject( objectid, Float:range, url[] )
{
if( !IsValidObject( objectid ) )
return 0;
format( gObjectStream[objectid][gStreamURL], 128, url );
gObjectStream[objectid][gStreamEnabled] = 1;
gObjectStream[objectid][gStreamRange] = range;
return 1;
}
stock IsStreamAttachedToObject( objectid ) {
return ( gObjectStream[objectid][gStreamEnabled] == 1 ) ? 1 : 0;
}
hook OnGameModeInit()
{
SetTimer( "StreamCheckTimer", 1000, true );
return 1;
}
public StreamCheckTimer( )
{
new Float:objpos[3];
foreach(Player, x)
{
for( new y = 0; y != MAX_OBJECTS; ++y )
{
if( 1 != gObjectStream[y][gStreamEnabled] )
continue;
else
{
GetObjectPos( y, objpos[0], objpos[1], objpos[2] );
if( IsPlayerInRangeOfPoint( x, gObjectStream[y][gStreamRange], objpos[0], objpos[1], objpos[2] ) )
{
if( gActiveStreamObjectID[x] != y )
{
gActiveStreamObjectID[x] = y;
PlayAudioStreamForPlayer( x, gObjectStream[y][gStreamURL] );
}
if( gActiveStreamObjectID[x] == y && gStreamObject[y][gStreamEnabled] == 0 )
{
gActiveStreamObjectID[x] = 0;
StopAudioStreamForPlayer( x );
}
}
else
{
if( gActiveStreamObjectID[x] == y ) // if is listening to a stream
{
gActiveStreamObjectID[x] = 0;
StopAudioStreamForPlayer( x );
}
}
}
}
}
return 1;
}