Skip to content

Commit

Permalink
add env_sentence
Browse files Browse the repository at this point in the history
  • Loading branch information
wootguy committed Nov 19, 2024
1 parent b399ced commit dd84e10
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions dlls/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ set(ENV_SRC
env/CEnvFunnel.cpp
env/CEnvGlobal.cpp
env/CEnvLight.cpp
env/CEnvSentence.cpp
env/CEnvShooter.cpp
env/CEnvSound.cpp
env/CEnvSpark.cpp
Expand Down
55 changes: 55 additions & 0 deletions dlls/env/CEnvSentence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "customentity.h"
#include "effects.h"
#include "decals.h"
#include "CBreakable.h"
#include "shake.h"

#define SF_EMSG_ACTIVATOR_ONLY 1

class CEnvSentence : public CPointEntity
{
public:
void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value);
void KeyValue(KeyValueData* pkvd);

string_t message;
private:
};

LINK_ENTITY_TO_CLASS(env_sentence, CEnvSentence)

void CEnvSentence::KeyValue(KeyValueData* pkvd)
{
if (FStrEq(pkvd->szKeyName, "_text"))
{
message = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
CPointEntity::KeyValue(pkvd);
}


void CEnvSentence::Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value)
{
const char* spkString = UTIL_VarArgs(";spk \"%s\";", STRING(message));

if (pev->spawnflags & SF_EMSG_ACTIVATOR_ONLY) {
if (pActivator->IsPlayer()) {
MESSAGE_BEGIN(MSG_ONE, SVC_STUFFTEXT, NULL, pActivator->edict());
WRITE_STRING(spkString);
MESSAGE_END();
}
}
else
{
MESSAGE_BEGIN(MSG_ALL, SVC_STUFFTEXT);
WRITE_STRING(spkString);
MESSAGE_END();
}

SUB_UseTargets(this, USE_TOGGLE, 0);
}

0 comments on commit dd84e10

Please sign in to comment.