Skip to content

Commit

Permalink
Add trigger_check_state
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Sep 15, 2023
1 parent 075a002 commit d59a557
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
71 changes: 71 additions & 0 deletions dlls/triggers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5814,6 +5814,77 @@ void CTriggerLook::Touch(CBaseEntity *pOther)
}
}

class CTriggerCheckState : public CPointEntity
{
public:
void KeyValue(KeyValueData *pkvd)
{
if(FStrEq(pkvd->szKeyName, "entity"))
{
m_entity = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if(FStrEq(pkvd->szKeyName, "fire_if_off"))
{
m_fireIfOff = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if(FStrEq(pkvd->szKeyName, "fire_if_on"))
{
m_fireIfOn = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else if(FStrEq(pkvd->szKeyName, "fire_if_absent"))
{
m_fireIfAbsent = ALLOC_STRING(pkvd->szValue);
pkvd->fHandled = TRUE;
}
else
CPointEntity::KeyValue(pkvd);
}
void Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value)
{
if (FStringNull(m_entity))
return;
CBaseEntity* pEntity = UTIL_FindEntityByTargetname(NULL, STRING(m_entity), this);
if (pEntity)
{
const bool state = pEntity->IsTriggered(pActivator);
if (pev->target)
FireTargets(STRING(pev->target), pActivator, this, state ? USE_ON : USE_OFF);
if (m_fireIfOff && !state)
FireTargets(STRING(m_fireIfOff), pActivator, this);
if (m_fireIfOn && state)
FireTargets(STRING(m_fireIfOn), pActivator, this);
}
else
{
if (m_fireIfAbsent)
FireTargets(STRING(m_fireIfAbsent), pActivator, this);
}
}

virtual int Save( CSave &save );
virtual int Restore( CRestore &restore );
static TYPEDESCRIPTION m_SaveData[];
protected:
string_t m_entity;
string_t m_fireIfOff;
string_t m_fireIfOn;
string_t m_fireIfAbsent;
};

TYPEDESCRIPTION CTriggerCheckState::m_SaveData[] =
{
DEFINE_FIELD( CTriggerCheckState, m_entity, FIELD_STRING ),
DEFINE_FIELD( CTriggerCheckState, m_fireIfOff, FIELD_STRING ),
DEFINE_FIELD( CTriggerCheckState, m_fireIfOn, FIELD_STRING ),
DEFINE_FIELD( CTriggerCheckState, m_fireIfAbsent, FIELD_STRING ),
};
IMPLEMENT_SAVERESTORE( CTriggerCheckState, CPointEntity )

LINK_ENTITY_TO_CLASS( trigger_check_state, CTriggerCheckState )

class CTriggerCompare : public CPointEntity
{
public:
Expand Down
9 changes: 9 additions & 0 deletions fgd/halflife.fgd
Original file line number Diff line number Diff line change
Expand Up @@ -7215,6 +7215,15 @@
message(target_destination) : "Trigger after operation" : : "Trigger entities after the value was set. This can call another trigger_changevalue without any delay so it's useful for chained operations."
]

@PointClass base(Targetname) = trigger_check_state : "Check entity's state"
[
entity(string) : "Entity to check"
target(target_destination) : "Target (on & off)"
fire_if_off(target_destination) : "Fire if off"
fire_if_on(target_destination) : "Fire if on"
fire_if_absent(target_destination) : "Fire if absent"
]

@PointClass base(Targetname) = trigger_command : "Console Command"
[
netname(string) : "Command String"
Expand Down

0 comments on commit d59a557

Please sign in to comment.