Browse Source

Fix trigger_mp3audio.

blackops
Night Owl 7 years ago
parent
commit
58ff94c2f3
  1. 17
      cl_dll/hud.cpp
  2. 7
      dlls/client.cpp
  3. 2
      dlls/player.cpp
  4. 42
      dlls/triggers.cpp

17
cl_dll/hud.cpp

@ -100,6 +100,20 @@ void __CmdFunc_ToggleServerBrowser( void )
{ {
} }
int __MsgFunc_PlayMP3( const char *pszName, int iSize, void *pbuf )
{
BEGIN_READ( pbuf, iSize );
gEngfuncs.pfnPrimeMusicStream( READ_STRING(), 0 );
return 1;
}
void __CmdFunc_StopMP3( void )
{
gEngfuncs.pfnPrimeMusicStream( 0, 0 );
}
// TFFree Command Menu Message Handlers // TFFree Command Menu Message Handlers
int __MsgFunc_ValClass( const char *pszName, int iSize, void *pbuf ) int __MsgFunc_ValClass( const char *pszName, int iSize, void *pbuf )
{ {
@ -183,6 +197,9 @@ void CHud::Init( void )
// VGUI Menus // VGUI Menus
HOOK_MESSAGE( VGUIMenu ); HOOK_MESSAGE( VGUIMenu );
HOOK_MESSAGE( PlayMP3 );
HOOK_COMMAND( "stopaudio", StopMP3 );
CVAR_CREATE( "hud_classautokill", "1", FCVAR_ARCHIVE | FCVAR_USERINFO ); // controls whether or not to suicide immediately on TF class switch CVAR_CREATE( "hud_classautokill", "1", FCVAR_ARCHIVE | FCVAR_USERINFO ); // controls whether or not to suicide immediately on TF class switch
CVAR_CREATE( "hud_takesshots", "0", FCVAR_ARCHIVE ); // controls whether or not to automatically take screenshots at the end of a round CVAR_CREATE( "hud_takesshots", "0", FCVAR_ARCHIVE ); // controls whether or not to automatically take screenshots at the end of a round
hud_textmode = CVAR_CREATE ( "hud_textmode", "0", FCVAR_ARCHIVE ); hud_textmode = CVAR_CREATE ( "hud_textmode", "0", FCVAR_ARCHIVE );

7
dlls/client.cpp

@ -49,6 +49,7 @@ extern void CopyToBodyQue( entvars_t* pev );
extern int giPrecacheGrunt; extern int giPrecacheGrunt;
extern int gmsgSayText; extern int gmsgSayText;
extern int gmsgBhopcap; extern int gmsgBhopcap;
extern int gmsgPlayMP3;
extern cvar_t allow_spectators; extern cvar_t allow_spectators;
@ -487,6 +488,12 @@ void ClientCommand( edict_t *pEntity )
{ {
GetClassPtr( (CBasePlayer *)pev )->ForceClientDllUpdate(); GetClassPtr( (CBasePlayer *)pev )->ForceClientDllUpdate();
} }
else if( FStrEq(pcmd, "playaudio" ) )
{
MESSAGE_BEGIN( MSG_ONE, gmsgPlayMP3, NULL, ENT( pev ) );
WRITE_STRING( (char *)CMD_ARGV( 1 ) );
MESSAGE_END();
}
else if( FStrEq(pcmd, "give" ) ) else if( FStrEq(pcmd, "give" ) )
{ {
if( g_flWeaponCheat != 0.0 ) if( g_flWeaponCheat != 0.0 )

2
dlls/player.cpp

@ -189,6 +189,7 @@ int gmsgStatusText = 0;
int gmsgStatusValue = 0; int gmsgStatusValue = 0;
int gmsgNightvision = 0; int gmsgNightvision = 0;
int gmsgPlayMP3 = 0;
void LinkUserMessages( void ) void LinkUserMessages( void )
{ {
@ -238,6 +239,7 @@ void LinkUserMessages( void )
gmsgStatusValue = REG_USER_MSG( "StatusValue", 3 ); gmsgStatusValue = REG_USER_MSG( "StatusValue", 3 );
gmsgNightvision = REG_USER_MSG( "Nightvision", 1 ); gmsgNightvision = REG_USER_MSG( "Nightvision", 1 );
gmsgPlayMP3 = REG_USER_MSG( "PlayMP3", -1 );
} }
LINK_ENTITY_TO_CLASS( player, CBasePlayer ) LINK_ENTITY_TO_CLASS( player, CBasePlayer )

42
dlls/triggers.cpp

@ -2385,11 +2385,12 @@ void CTriggerCamera::Move()
// //
// Adapted from TWHL - Using mp3s in Steam // Adapted from TWHL - Using mp3s in Steam
// //
#define SF_REMOVE_ON_FIRE 1
class CTargetMP3Audio : public CBaseTrigger class CTargetMP3Audio : public CBaseTrigger
{ {
public: public:
virtual int Save( CSave &save ); int Save( CSave &save );
virtual int Restore( CRestore &restore ); int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[]; static TYPEDESCRIPTION m_SaveData[];
void Spawn( void ); void Spawn( void );
@ -2397,15 +2398,16 @@ public:
void Touch( CBaseEntity *pOther ); void Touch( CBaseEntity *pOther );
int m_iszTrack; string_t m_iszTrack;
BOOL m_bTriggered; BOOL m_bPlaying;
}; };
LINK_ENTITY_TO_CLASS( trigger_mp3audio, CTargetMP3Audio ); LINK_ENTITY_TO_CLASS( trigger_mp3audio, CTargetMP3Audio );
TYPEDESCRIPTION CTargetMP3Audio::m_SaveData[] = TYPEDESCRIPTION CTargetMP3Audio::m_SaveData[] =
{ {
DEFINE_FIELD( CTargetMP3Audio, m_bTriggered, FIELD_BOOLEAN ), DEFINE_FIELD( CTargetMP3Audio, m_iszTrack, FIELD_STRING ),
DEFINE_FIELD( CTargetMP3Audio, m_bPlaying, FIELD_BOOLEAN ),
}; };
IMPLEMENT_SAVERESTORE( CTargetMP3Audio, CBaseTrigger ); IMPLEMENT_SAVERESTORE( CTargetMP3Audio, CBaseTrigger );
@ -2414,7 +2416,10 @@ void CTargetMP3Audio::KeyValue( KeyValueData *pkvd )
{ {
if( FStrEq( pkvd->szKeyName, "track" ) ) if( FStrEq( pkvd->szKeyName, "track" ) )
{ {
m_iszTrack = ALLOC_STRING( pkvd->szValue ); if( FStrEq( pkvd->szValue, "hl28.mp3" ) )
m_iszTrack = MAKE_STRING( "Suspense07.mp3" );
else
m_iszTrack = ALLOC_STRING( pkvd->szValue );
pkvd->fHandled = TRUE; pkvd->fHandled = TRUE;
} }
else else
@ -2424,22 +2429,31 @@ void CTargetMP3Audio::KeyValue( KeyValueData *pkvd )
void CTargetMP3Audio::Spawn( void ) void CTargetMP3Audio::Spawn( void )
{ {
InitTrigger(); InitTrigger();
m_bPlaying = FALSE; // start out not playing
m_bTriggered = FALSE;
} }
void CTargetMP3Audio::Touch( CBaseEntity *pOther ) void CTargetMP3Audio::Touch( CBaseEntity *pOther )
{ {
if( m_bTriggered ) char command[64];
return;
if( !pOther || !pOther->IsPlayer() ) if( !pOther || !pOther->IsPlayer() )
return; return;
m_bTriggered = TRUE; if( !m_bPlaying ) // if we're not playing, start playing!
if( FStrEq( STRING( gpGlobals->mapname ), "ops_17th" ) )
{ {
CLIENT_COMMAND( pOther->edict(), "play media/Suspense07.mp3\n" ); m_bPlaying = TRUE;
// issue the play/loop command
sprintf( command, "playaudio %s\n", STRING( m_iszTrack ) );
CLIENT_COMMAND( pOther->edict(), command );
} }
/*else
{
// if we're already playing, stop the mp3
m_bPlaying = FALSE;
CLIENT_COMMAND( pOther->edict(), "stopaudio\n" );
return;
}*/
if( pev->spawnflags & SF_REMOVE_ON_FIRE )
UTIL_Remove( this );
} }

Loading…
Cancel
Save