sfcnr/gamemodes/irresistible/cnr/features/boom_box.pwn

201 lines
6.5 KiB
Plaintext
Raw Normal View History

2019-06-05 08:51:23 +00:00
/*
* Irresistible Gaming 2018
* Developed by Night
* Module: cnr\features\boom_box.pwn
* Purpose: boombox related feature
*/
/* ** Includes ** */
#include < YSI\y_hooks >
/* ** Definitions ** */
#define DEFAULT_BOOMBOX_RANGE ( 50.0 )
2019-06-11 10:05:34 +00:00
#define BOOMBOX_URL_LEN ( 128 )
2019-06-05 08:51:23 +00:00
/* ** Variables ** */
enum E_BOOMBOX_DATA
{
E_OBJECT, Text3D: E_LABEL, E_MUSIC_AREA,
2019-06-11 10:05:34 +00:00
Float: E_X, Float: E_Y, Float: E_Z,
E_URL[ BOOMBOX_URL_LEN ]
2019-06-05 08:51:23 +00:00
};
static stock
2019-06-11 09:43:44 +00:00
g_boomboxData [ MAX_PLAYERS ] [ E_BOOMBOX_DATA ],
bool: p_Boombox [ MAX_PLAYERS char ],
bool: p_UsingBoombox [ MAX_PLAYERS char ]
2019-06-05 08:51:23 +00:00
;
/* ** Hooks ** */
hook OnPlayerDisconnect( playerid, reason )
{
2019-06-11 10:05:34 +00:00
SetPlayerBoombox( playerid, false );
2019-06-05 08:51:23 +00:00
return 1;
}
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
hook OnPlayerDeath( playerid, killerid, reason )
#endif
{
Boombox_Destroy( playerid );
return 1;
}
hook OnPlayerJailed( playerid )
{
Boombox_Destroy( playerid );
return 1;
}
2019-06-05 08:51:23 +00:00
hook OnPlayerEnterDynArea( playerid, areaid )
{
foreach ( new i : Player )
{
2019-06-05 13:51:14 +00:00
if ( IsValidDynamicArea( g_boomboxData[ i ] [ E_MUSIC_AREA ] ) )
2019-06-05 08:51:23 +00:00
{
2019-06-05 13:51:14 +00:00
if ( areaid == g_boomboxData[ i ] [ E_MUSIC_AREA ] )
2019-06-05 08:51:23 +00:00
{
// start the music
2019-06-05 13:51:14 +00:00
PlayAudioStreamForPlayer( playerid, g_boomboxData[ i ] [ E_URL ], g_boomboxData[ i ] [ E_X ], g_boomboxData[ i ] [ E_Y ], g_boomboxData[ i ] [ E_Z ], DEFAULT_BOOMBOX_RANGE, 1 );
SendServerMessage( playerid, "You are now listening to a nearby boombox!" );
2019-06-05 08:51:23 +00:00
return 1;
}
}
}
return 1;
}
hook OnPlayerLeaveDynArea( playerid, areaid )
{
foreach ( new i : Player )
{
2019-06-05 13:51:14 +00:00
if ( IsValidDynamicArea( g_boomboxData[ i ] [ E_MUSIC_AREA ] ) )
2019-06-05 08:51:23 +00:00
{
2019-06-05 13:51:14 +00:00
if ( areaid == g_boomboxData[ i ] [ E_MUSIC_AREA ] )
2019-06-05 08:51:23 +00:00
{
// stop the music
2019-06-05 13:51:14 +00:00
StopAudioStreamForPlayer( playerid );
SendServerMessage( playerid, "You stopped listening to a nearby boombox!" );
2019-06-05 08:51:23 +00:00
return 1;
}
}
}
return 1;
}
/* ** Commands ** */
CMD:boombox( playerid, params[ ] )
{
if ( ! GetPlayerBoombox( playerid ) )
return SendError( playerid, "You can buy Boombox at Supa Save or a 24/7 store." );
2019-06-07 22:31:50 +00:00
2019-06-05 10:18:56 +00:00
if ( IsPlayerInAnyVehicle(playerid) )
return SendError( playerid, "You cannot use Boombox inside of a vehicle.");
2019-06-05 08:51:23 +00:00
2019-06-07 22:31:50 +00:00
if ( ! strcmp( params, "play", false, 3 ) )
2019-06-05 08:51:23 +00:00
{
2019-06-07 22:31:50 +00:00
static
2019-06-11 10:05:34 +00:00
Float: X,
Float: Y,
Float: Z,
Float: Angle,
szURL[ BOOMBOX_URL_LEN ];
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." );
2019-06-07 22:31:50 +00:00
else
{
if ( GetPlayerPos( playerid, X, Y, Z ) && GetPlayerFacingAngle( playerid, Angle ) )
{
2019-06-11 10:05:34 +00:00
new
current_boombox = GetCurrentBoombox( playerid );
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;
}
2019-06-07 22:31:50 +00:00
}
}
2019-06-05 08:51:23 +00:00
}
2019-06-07 22:31:50 +00:00
else if ( ! strcmp( params, "stop", false, 3 ) )
2019-06-05 08:51:23 +00:00
{
if ( ! IsPlayerUsingBoombox( playerid ) ) return SendError( playerid, "You are not using Boombox." );
StopAudioStreamForPlayer( playerid );
Boombox_Destroy( playerid );
SendServerMessage( playerid, "You have removed your Boombox.");
p_UsingBoombox{ playerid } = false;
}
else SendUsage( playerid, "/boombox [PLAY/STOP]" );
return 1;
}
/* ** Functions ** */
stock IsPlayerUsingBoombox( playerid ) return p_UsingBoombox{ playerid };
stock GetPlayerBoombox( playerid ) return p_Boombox{ playerid };
2019-06-11 09:43:44 +00:00
stock SetPlayerBoombox( playerid, bool: toggle )
{
if ( ( p_Boombox{ playerid } = toggle ) == false ) {
Boombox_Destroy( playerid );
}
}
2019-06-05 08:51:23 +00:00
stock Boombox_Destroy( playerid )
{
2019-06-11 09:43:44 +00:00
p_UsingBoombox{ playerid } = false;
2019-06-05 08:51:23 +00:00
g_boomboxData[ playerid ] [ E_X ] = 0.0;
g_boomboxData[ playerid ] [ E_Y ] = 0.0;
g_boomboxData[ playerid ] [ E_Z ] = 0.0;
2019-06-05 13:51:14 +00:00
g_boomboxData[ playerid ] [ E_URL ] [ 0 ] = '\0';
2019-06-05 08:51:23 +00:00
DestroyDynamicObject( g_boomboxData[ playerid ] [ E_OBJECT ] );
DestroyDynamic3DTextLabel( g_boomboxData[ playerid ] [ E_LABEL ] );
DestroyDynamicArea( g_boomboxData[ playerid ] [ E_MUSIC_AREA ] );
return 1;
}
2019-06-11 10:05:34 +00:00
stock Boombox_Create( playerid, szURL[ BOOMBOX_URL_LEN ], Float: X, Float: Y, Float: Z, Float: Angle, Float: fDistance = DEFAULT_BOOMBOX_RANGE )
2019-06-05 08:51:23 +00:00
{
2019-06-11 10:05:34 +00:00
format( g_boomboxData[ playerid ] [ E_URL ], BOOMBOX_URL_LEN, "%s", szURL );
2019-06-05 13:51:14 +00:00
g_boomboxData[ playerid ] [ E_X ] = X;
g_boomboxData[ playerid ] [ E_Y ] = Y;
g_boomboxData[ playerid ] [ E_Z ] = Z;
2019-06-05 08:51:23 +00:00
2019-06-05 17:32:54 +00:00
g_boomboxData[ playerid ] [ E_OBJECT ] = CreateDynamicObject( 2103, X, Y, Z - 0.92, 0, 0, 0, GetPlayerVirtualWorld( playerid ), GetPlayerInterior( playerid ), -1, Angle );
g_boomboxData[ playerid ] [ E_LABEL ] = CreateDynamic3DTextLabel( sprintf( "%s(%d)'s Boombox", ReturnPlayerName( playerid ), playerid ), COLOR_GOLD, X, Y, Z, 20, .worldid = GetPlayerVirtualWorld( playerid ), .interiorid = GetPlayerInterior( playerid ) );
2019-06-05 08:51:23 +00:00
g_boomboxData[ playerid ] [ E_MUSIC_AREA ] = CreateDynamicSphere( X, Y, Z, fDistance, .worldid = GetPlayerVirtualWorld( playerid ), .interiorid = GetPlayerInterior( playerid ) );
return 1;
2019-06-05 13:51:37 +00:00
}
2019-06-05 13:51:14 +00:00
2019-06-11 10:05:34 +00:00
stock GetCurrentBoombox( playerid )
2019-06-05 13:51:14 +00:00
{
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 ) {
2019-06-11 10:05:34 +00:00
return i;
2019-06-05 13:51:14 +00:00
}
}
2019-06-11 10:05:34 +00:00
return -1;
2019-06-05 08:51:23 +00:00
}