From dd84e1081b9c8a66729bbf0831faa1899b243862 Mon Sep 17 00:00:00 2001 From: wootguy Date: Mon, 18 Nov 2024 23:54:18 -0800 Subject: [PATCH] add env_sentence --- dlls/CMakeLists.txt | 1 + dlls/env/CEnvSentence.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 dlls/env/CEnvSentence.cpp diff --git a/dlls/CMakeLists.txt b/dlls/CMakeLists.txt index ab0dfb7..b55d7a2 100644 --- a/dlls/CMakeLists.txt +++ b/dlls/CMakeLists.txt @@ -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 diff --git a/dlls/env/CEnvSentence.cpp b/dlls/env/CEnvSentence.cpp new file mode 100644 index 0000000..0c6cb7f --- /dev/null +++ b/dlls/env/CEnvSentence.cpp @@ -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); +}