2018-12-31 01:00:38 +00:00
|
|
|
/***
|
|
|
|
*
|
2019-01-16 16:43:50 +00:00
|
|
|
* Copyright (c) 2016-2019 Marco 'eukara' Hladik. All rights reserved.
|
|
|
|
*
|
|
|
|
* See the file LICENSE attached with the sources for usage details.
|
2018-12-31 01:00:38 +00:00
|
|
|
*
|
|
|
|
****/
|
|
|
|
|
|
|
|
#define SF_HURT_ONCE 1 // Turn off once it fired the first time
|
|
|
|
#define SF_HURT_OFF 2 // Needs to be triggered in order to work again
|
|
|
|
#define SF_HURT_NOPLAYERS 8 // Don't hurt players
|
|
|
|
#define SF_HURT_FIREONPLAYER 16 // Only call UseTarget functions when it's a player
|
|
|
|
#define SF_HURT_TOUCHPLAYER 32 // Only hurt players
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
class trigger_hurt:CBaseTrigger
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
|
|
|
float m_flNextTrigger;
|
|
|
|
int m_iDamage;
|
|
|
|
float m_flDelay;
|
2019-01-03 01:26:39 +00:00
|
|
|
void() trigger_hurt;
|
2019-01-03 11:23:11 +00:00
|
|
|
|
|
|
|
virtual void() Trigger;
|
|
|
|
virtual void() Touch;
|
2019-02-28 07:17:14 +00:00
|
|
|
virtual void() Respawn;
|
2018-12-31 01:00:38 +00:00
|
|
|
};
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
void trigger_hurt::Trigger(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-03-02 13:03:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (solid != SOLID_NOT) {
|
|
|
|
#ifdef GS_DEVELOPER
|
|
|
|
print("trigger_hurt: de-activated.\n");
|
|
|
|
#endif
|
2018-12-31 01:00:38 +00:00
|
|
|
solid = SOLID_NOT;
|
2019-02-28 07:17:14 +00:00
|
|
|
touch = __NULL__;
|
|
|
|
} else {
|
2019-03-02 13:03:26 +00:00
|
|
|
#ifdef GS_DEVELOPER
|
|
|
|
print("trigger_hurt: activated.\n");
|
|
|
|
#endif
|
2019-02-28 07:17:14 +00:00
|
|
|
solid = SOLID_TRIGGER;
|
|
|
|
touch = Touch;
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
void trigger_hurt::Touch(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-03-02 13:03:26 +00:00
|
|
|
if (m_flNextTrigger > time) {
|
2018-12-31 01:00:38 +00:00
|
|
|
return;
|
2019-03-02 13:03:26 +00:00
|
|
|
} else if (other.takedamage == DAMAGE_NO) {
|
2018-12-31 01:00:38 +00:00
|
|
|
return;
|
2019-03-02 13:03:26 +00:00
|
|
|
} else if ((spawnflags & SF_HURT_TOUCHPLAYER) && !(other.flags & FL_CLIENT)) {
|
2018-12-31 01:00:38 +00:00
|
|
|
return;
|
2019-03-02 13:03:26 +00:00
|
|
|
} else if ((spawnflags & SF_HURT_NOPLAYERS) && (other.flags & FL_CLIENT)) {
|
2018-12-31 01:00:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
if (spawnflags & SF_HURT_FIREONPLAYER) {
|
|
|
|
if (other.flags & FL_CLIENT) {
|
|
|
|
if (m_flDelay > 0) {
|
|
|
|
CBaseTrigger::UseTargets_Delay(m_flDelay);
|
2018-12-31 01:00:38 +00:00
|
|
|
} else {
|
|
|
|
CBaseTrigger::UseTargets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-02 13:03:26 +00:00
|
|
|
if (m_flDelay > 0) {
|
|
|
|
CBaseTrigger::UseTargets_Delay(m_flDelay);
|
2018-12-31 01:00:38 +00:00
|
|
|
} else {
|
|
|
|
CBaseTrigger::UseTargets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
Damage_Apply(other, this, m_iDamage, other.origin, FALSE);
|
|
|
|
|
2018-12-31 01:00:38 +00:00
|
|
|
// Shut it down if used once
|
2019-03-02 13:03:26 +00:00
|
|
|
if (spawnflags & SF_HURT_ONCE) {
|
|
|
|
Trigger();
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 10:16:39 +00:00
|
|
|
m_flNextTrigger = time + 0.5;
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
void trigger_hurt::Respawn(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-02-25 17:19:54 +00:00
|
|
|
#ifdef GS_DEVELOPER
|
|
|
|
alpha = 0.5f;
|
|
|
|
#endif
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
m_flNextTrigger = 0;
|
|
|
|
|
|
|
|
if (spawnflags & SF_HURT_OFF) {
|
2018-12-31 01:00:38 +00:00
|
|
|
solid = SOLID_NOT;
|
2019-02-28 07:17:14 +00:00
|
|
|
touch = __NULL__;
|
|
|
|
} else {
|
|
|
|
solid = SOLID_TRIGGER;
|
|
|
|
touch = Touch;
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 13:03:26 +00:00
|
|
|
void trigger_hurt::trigger_hurt(void)
|
2018-12-31 01:00:38 +00:00
|
|
|
{
|
2019-03-02 13:03:26 +00:00
|
|
|
for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
|
|
|
|
switch (argv(i)) {
|
2018-12-31 01:00:38 +00:00
|
|
|
case "dmg":
|
2019-03-02 13:03:26 +00:00
|
|
|
m_iDamage = stoi(argv(i+1));
|
2018-12-31 01:00:38 +00:00
|
|
|
break;
|
|
|
|
case "wait":
|
|
|
|
case "delay":
|
2019-03-02 13:03:26 +00:00
|
|
|
m_flDelay = stof(argv(i+1));
|
2018-12-31 01:00:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-28 07:17:14 +00:00
|
|
|
|
2018-12-31 01:00:38 +00:00
|
|
|
CBaseEntity::CBaseEntity();
|
2019-02-28 07:17:14 +00:00
|
|
|
CBaseTrigger::InitBrushTrigger();
|
2019-03-02 13:03:26 +00:00
|
|
|
trigger_hurt::Respawn();
|
2018-12-31 01:00:38 +00:00
|
|
|
}
|