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

183 lines
5.4 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 )
/* ** 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
};
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 )
{
p_UsingBoombox{ playerid } = false;
p_Boombox{ playerid } = false;
Boombox_Destroy( playerid );
return 1;
}
#if defined AC_INCLUDED
hook OnPlayerDeathEx( playerid, killerid, reason, Float: damage, bodypart )
#else
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;
}
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
Float: X, Float: Y, Float: Z, Float: Angle;
new szURL[ 128 ];
2019-06-05 08:51:23 +00:00
2019-06-07 22:31:50 +00:00
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." );
else
{
if ( GetPlayerPos( playerid, X, Y, Z ) && GetPlayerFacingAngle( playerid, Angle ) )
{
Boombox_Create( playerid, szURL, X, Y, Z, Angle );
p_UsingBoombox{ playerid } = true;
SendServerMessage( playerid, "If the stream doesn't respond then it must be offline. Use "COL_GREY"/boombox stop"COL_WHITE" to stop the stream." );
}
}
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;
}
stock Boombox_Create( playerid, szURL[ ], Float: X, Float: Y, Float: Z, Float: Angle, Float: fDistance = DEFAULT_BOOMBOX_RANGE )
{
2019-06-05 13:51:14 +00:00
format( g_boomboxData[ playerid ] [ E_URL ], 128, "%s", szURL );
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
stock IsPlayerNearBoombox( 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 false;
2019-06-05 08:51:23 +00:00
}