update boombox for players in area

This commit is contained in:
Lorenc Pekaj 2019-06-11 20:05:34 +10:00
parent 32402b938c
commit f7f7dbf14d

View File

@ -10,13 +10,14 @@
/* ** Definitions ** */
#define DEFAULT_BOOMBOX_RANGE ( 50.0 )
#define BOOMBOX_URL_LEN ( 128 )
/* ** Variables ** */
enum E_BOOMBOX_DATA
{
E_OBJECT, Text3D: E_LABEL, E_MUSIC_AREA,
E_URL[ 128 ],
Float: E_X, Float: E_Y, Float: E_Z
Float: E_X, Float: E_Y, Float: E_Z,
E_URL[ BOOMBOX_URL_LEN ]
};
static stock
@ -28,9 +29,7 @@ static stock
/* ** Hooks ** */
hook OnPlayerDisconnect( playerid, reason )
{
p_UsingBoombox{ playerid } = false;
p_Boombox{ playerid } = false;
Boombox_Destroy( playerid );
SetPlayerBoombox( playerid, false );
return 1;
}
@ -40,14 +39,12 @@ hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
hook OnPlayerDeath( playerid, killerid, reason )
#endif
{
p_UsingBoombox{ playerid } = false;
Boombox_Destroy( playerid );
return 1;
}
hook OnPlayerJailed( playerid )
{
p_UsingBoombox{ playerid } = false;
Boombox_Destroy( playerid );
return 1;
}
@ -100,21 +97,42 @@ CMD:boombox( playerid, params[ ] )
if ( ! strcmp( params, "play", false, 3 ) )
{
static
Float: X, Float: Y, Float: Z, Float: Angle;
Float: X,
Float: Y,
Float: Z,
Float: Angle,
szURL[ BOOMBOX_URL_LEN ];
new szURL[ 128 ];
if ( sscanf( params[ 5 ], "s[128]", szURL ) ) return SendUsage( playerid, "/boombox play [URL]" );
else if ( IsPlayerUsingBoombox( playerid ) ) return SendError( playerid, "You are already using Boombox." );
else if ( IsPlayerNearBoombox( playerid ) ) return SendError( playerid, "You cannot be near another Boombox if you wish to create your own." );
if ( sscanf( params[ 5 ], sprintf( "s[%d]", BOOMBOX_URL_LEN ), szURL ) ) return SendUsage( playerid, "/boombox play [URL]" );
// else if ( IsPlayerUsingBoombox( playerid ) ) return SendError( playerid, "You are already using Boombox." );
else
{
if ( GetPlayerPos( playerid, X, Y, Z ) && GetPlayerFacingAngle( playerid, Angle ) )
{
Boombox_Create( playerid, szURL, X, Y, Z, Angle );
p_UsingBoombox{ playerid } = true;
new
current_boombox = GetCurrentBoombox( playerid );
SendServerMessage( playerid, "If the stream doesn't respond then it must be offline. Use "COL_GREY"/boombox stop"COL_WHITE" to stop the stream." );
if ( current_boombox != -1 && current_boombox != playerid ) {
return SendError( playerid, "You cannot be near another Boombox if you wish to create your own." );
}
if ( IsPlayerUsingBoombox( playerid ) ) {
if ( GetPlayerDistanceFromPoint( playerid, g_boomboxData[ playerid ] [ E_X ], g_boomboxData[ playerid ] [ E_Y ], g_boomboxData[ playerid ] [ E_Z ] ) > DEFAULT_BOOMBOX_RANGE ) {
return SendError( playerid, "You are too far from your boombox. Use "COL_GREY"/boombox stop"COL_WHITE" to stop it." );
}
format( g_boomboxData[ playerid ] [ E_URL ], BOOMBOX_URL_LEN, "%s", szURL );
foreach ( new i : Player ) {
if ( GetPlayerDistanceFromPoint( i, g_boomboxData[ playerid ] [ E_X ], g_boomboxData[ playerid ] [ E_Y ], g_boomboxData[ playerid ] [ E_Z ] ) < DEFAULT_BOOMBOX_RANGE ) {
StopAudioStreamForPlayer( i );
PlayAudioStreamForPlayer( i, g_boomboxData[ playerid ] [ E_URL ], g_boomboxData[ playerid ] [ E_X ], g_boomboxData[ playerid ] [ E_Y ], g_boomboxData[ playerid ] [ E_Z ], DEFAULT_BOOMBOX_RANGE, 1 );
}
}
SendServerMessage( playerid, "You have updated your boombox stream to: "COL_GREY"%s", szURL );
} else {
SendServerMessage( playerid, "If the stream doesn't respond then it must be offline. Use "COL_GREY"/boombox stop"COL_WHITE" to stop the stream." );
Boombox_Create( playerid, szURL, X, Y, Z, Angle );
p_UsingBoombox{ playerid } = true;
}
}
}
}
@ -158,9 +176,9 @@ stock Boombox_Destroy( playerid )
return 1;
}
stock Boombox_Create( playerid, szURL[ ], Float: X, Float: Y, Float: Z, Float: Angle, Float: fDistance = DEFAULT_BOOMBOX_RANGE )
stock Boombox_Create( playerid, szURL[ BOOMBOX_URL_LEN ], Float: X, Float: Y, Float: Z, Float: Angle, Float: fDistance = DEFAULT_BOOMBOX_RANGE )
{
format( g_boomboxData[ playerid ] [ E_URL ], 128, "%s", szURL );
format( g_boomboxData[ playerid ] [ E_URL ], BOOMBOX_URL_LEN, "%s", szURL );
g_boomboxData[ playerid ] [ E_X ] = X;
g_boomboxData[ playerid ] [ E_Y ] = Y;
@ -172,12 +190,12 @@ stock Boombox_Create( playerid, szURL[ ], Float: X, Float: Y, Float: Z, Float: A
return 1;
}
stock IsPlayerNearBoombox( playerid )
stock GetCurrentBoombox( playerid )
{
foreach ( new i : Player ) {
if ( GetPlayerDistanceFromPoint( playerid, g_boomboxData[ i ] [ E_X ], g_boomboxData[ i ] [ E_Y ], g_boomboxData[ i ] [ E_Z ] ) < DEFAULT_BOOMBOX_RANGE ) {
return true;
return i;
}
}
return false;
return -1;
}