|
|
|
@ -23,16 +23,13 @@
@@ -23,16 +23,13 @@
|
|
|
|
|
class CTriggerCommand : public CPointEntity |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
void Spawn(void); |
|
|
|
|
void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
void PlayMP3(CBaseEntity* pClient, const char* song); |
|
|
|
|
void Spawn(); |
|
|
|
|
void Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
LINK_ENTITY_TO_CLASS(trigger_command, CTriggerCommand); |
|
|
|
|
LINK_ENTITY_TO_CLASS( trigger_command, CTriggerCommand ) |
|
|
|
|
|
|
|
|
|
void CTriggerCommand::Spawn(void) |
|
|
|
|
void CTriggerCommand::Spawn() |
|
|
|
|
{ |
|
|
|
|
pev->solid = SOLID_NOT; |
|
|
|
|
pev->movetype = MOVETYPE_NONE; |
|
|
|
@ -40,61 +37,18 @@ void CTriggerCommand::Spawn(void)
@@ -40,61 +37,18 @@ void CTriggerCommand::Spawn(void)
|
|
|
|
|
pev->frame = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CTriggerCommand::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) |
|
|
|
|
void CTriggerCommand::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) |
|
|
|
|
{ |
|
|
|
|
if (!pActivator || !pActivator->IsNetClient()) |
|
|
|
|
return; |
|
|
|
|
char cmd[64]; |
|
|
|
|
|
|
|
|
|
const char* command = STRING(pev->netname); |
|
|
|
|
|
|
|
|
|
if (!command || !*command) |
|
|
|
|
if( !pActivator || !pActivator->IsPlayer() ) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
// ALERT(at_console, "%s with command \"%s\"\n", STRING(pev->classname), command);
|
|
|
|
|
|
|
|
|
|
char* str = NULL; |
|
|
|
|
|
|
|
|
|
if ((str = (char*)strstr(command, "playmp3")) != NULL) |
|
|
|
|
{ |
|
|
|
|
int pchlen = 0; |
|
|
|
|
int extlen = 3; // "mp3" excluding NULL terminator.
|
|
|
|
|
int ideallen = 0; |
|
|
|
|
|
|
|
|
|
char* pch = NULL, *lastpch = NULL; |
|
|
|
|
char* song = NULL; |
|
|
|
|
|
|
|
|
|
pch = strtok(str, " ."); |
|
|
|
|
|
|
|
|
|
while (pch) |
|
|
|
|
{ |
|
|
|
|
pchlen = strlen(pch); |
|
|
|
|
ideallen = (pchlen <= extlen) ? pchlen : extlen; |
|
|
|
|
|
|
|
|
|
if (strncmp(pch, "mp3", sizeof(char) * ideallen) == 0) |
|
|
|
|
{ |
|
|
|
|
pch = NULL; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
lastpch = pch; |
|
|
|
|
pch = strtok(NULL, " ."); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
song = lastpch; |
|
|
|
|
|
|
|
|
|
PlayMP3(pActivator, song); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
UTIL_Remove(this); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CTriggerCommand::PlayMP3(CBaseEntity* pClient, const char* song) |
|
|
|
|
{ |
|
|
|
|
ASSERT(pClient != NULL); |
|
|
|
|
if( !pev->netname ) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
char cmd[128]; |
|
|
|
|
sprintf(cmd, "play sound/mp3/%s.mp3\n", song); |
|
|
|
|
sprintf( cmd, "%s\n", STRING( pev->netname ) ); |
|
|
|
|
CLIENT_COMMAND( ENT( pActivator->pev ), cmd ); |
|
|
|
|
|
|
|
|
|
CLIENT_COMMAND(ENT(pClient->pev),cmd); |
|
|
|
|
UTIL_Remove( this ); |
|
|
|
|
} |
|
|
|
|