-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: added trigger_teleport_point entity from Diffusion mod
Thanks to @Aynekko for sharing
- Loading branch information
1 parent
c25e1cd
commit 08bb151
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "trigger_teleport_point.h" | ||
#include "player.h" | ||
#include "monsters.h" | ||
|
||
LINK_ENTITY_TO_CLASS( trigger_teleport_point, CTriggerTeleportPoint ); | ||
|
||
BEGIN_DATADESC( CTriggerTeleportPoint ) | ||
DEFINE_KEYFIELD( m_entity, FIELD_STRING, "entityname" ), | ||
END_DATADESC(); | ||
|
||
void CTriggerTeleportPoint::KeyValue(KeyValueData* pkvd) | ||
{ | ||
if (FStrEq(pkvd->szKeyName, "entityname")) | ||
{ | ||
m_entity = ALLOC_STRING(pkvd->szValue); | ||
pkvd->fHandled = TRUE; | ||
} | ||
else | ||
CBaseDelay::KeyValue(pkvd); | ||
} | ||
|
||
void CTriggerTeleportPoint::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) | ||
{ | ||
if (IsLockedByMaster(pActivator)) | ||
return; | ||
|
||
if (!pActivator || !pActivator->IsPlayer()) | ||
pActivator = CBaseEntity::Instance(INDEXENT(1)); | ||
|
||
CBasePlayer* pPlayer = (CBasePlayer*)pActivator; | ||
CBaseEntity* pEntity = NULL; | ||
|
||
if (FStrEq(STRING(m_entity), "player") || !m_entity) | ||
pEntity = pPlayer; | ||
else | ||
pEntity = UTIL_FindEntityByTargetname(pEntity, STRING(m_entity)); | ||
|
||
if (!pEntity) | ||
{ | ||
ALERT(at_error, "trigger_teleport_point \"%s\" can't find specified entity!\n", STRING(pev->targetname)); | ||
return; | ||
} | ||
|
||
// this entity acts as a teleport target | ||
Vector targetOrg = GetAbsOrigin(); | ||
Vector targetAng = GetAbsAngles(); | ||
|
||
Vector entityVelocity = g_vecZero; | ||
if (FBitSet(pev->spawnflags, PT_KEEP_VELOCITY)) { | ||
entityVelocity = pEntity->GetAbsVelocity(); | ||
} | ||
|
||
Vector EntityAngles = targetAng; | ||
if (FBitSet(pev->spawnflags, PT_KEEP_ANGLES)) { | ||
EntityAngles = pEntity->GetAbsAngles(); | ||
} | ||
|
||
// offset to correctly teleport the player... | ||
if (pEntity->IsPlayer()) { | ||
targetOrg.z += 36; | ||
} | ||
|
||
pEntity->Teleport(&targetOrg, &EntityAngles, &entityVelocity); | ||
|
||
UTIL_FireTargets(pev->target, pActivator, pCaller, USE_TOGGLE, 0); | ||
|
||
if (FBitSet(pev->spawnflags, PT_REMOVEONFIRE)) { | ||
UTIL_Remove(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "extdll.h" | ||
#include "util.h" | ||
#include "cbase.h" | ||
|
||
//======================================================================================================================= | ||
// diffusion - teleports entity regardless of its position (no teleport brush needed) - this entity also acts as a target | ||
//======================================================================================================================= | ||
|
||
#define PT_KEEP_VELOCITY BIT(0) // keep the velocity of the entity | ||
#define PT_KEEP_ANGLES BIT(1) // don't snap to new angles | ||
#define PT_REMOVEONFIRE BIT(2) | ||
|
||
// UNDONE: redirect player's velocity to entity's view origin? | ||
|
||
class CTriggerTeleportPoint : public CBaseDelay | ||
{ | ||
DECLARE_CLASS(CTriggerTeleportPoint, CBaseDelay); | ||
public: | ||
void Use(CBaseEntity* pActivator, CBaseEntity* pCaller, USE_TYPE useType, float value); | ||
void KeyValue(KeyValueData* pkvd); | ||
int ObjectCaps(void) { return BaseClass::ObjectCaps() & ~FCAP_ACROSS_TRANSITION; } | ||
|
||
DECLARE_DATADESC(); | ||
|
||
string_t m_entity; | ||
}; |