djcev.com

//

Git Repos / fte_dogmode / qc / triggers / multiple.qc

Last update to this file was on 2024-04-12 at 18:56.

Show multiple.qc

//==============================================================================
// trigger_multiple, trigger_once
//==============================================================================

//======================================================================
// constants
//======================================================================

const float TRIGGER_MULTIPLE_NOTOUCH = 1;
// used for Wait for retrigger spawnflag
const float TRIGGER_MULTIPLE_TURNS_OFF = 2;

//======================================================================
// forward declarations
//======================================================================

// base_multiple
void() base_multiple_think_wait;
void() base_multiple_fire;
void(vector dir) base_multiple_destroy;
void() base_multiple_touch;
void() base_multiple_use;
void(entity e) base_multiple_init;
strip void() base_multiple;

// trigger_multiple
void(entity e) trigger_multiple_init;
void() trigger_multiple;

// trigger_once
void(entity e) trigger_once_init;
void() trigger_once;

//------------------------------------------------------------------------------

//----------------------------------------------------------------------
// generic multiple class
//----------------------------------------------------------------------
// class base_multiple: base_trigger
// {
//--------------------------------------------------------------
// the wait time has passed, so set back up for another activation
//--------------------------------------------------------------
void() base_multiple_think_wait =
{
if (self.max_health)
{
self.health = self.max_health;
self.takedamage = DAMAGE_YES;
self.solid = SOLID_BBOX;
}
};

//--------------------------------------------------------------
// the trigger was just touched/killed/used
// this.enemy should be set to the activator so it can be held
// through a delay so wait for the delay time before firing
//--------------------------------------------------------------
void() base_multiple_fire =
{
if (self.nextthink > time)
{
// already been triggered
return;
}

if (self.classtype == CT_TRIGGER_SECRET)
{
if (self.enemy.classtype != CT_PLAYER)
return;
if (cutscene)
// Don't activate in cutscene mode
return;
found_secrets = found_secrets + 1;
WriteByte (MSG_ALL, SVC_FOUNDSECRET);
}

if (self.noise != "")
sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);

// don't trigger again until reset
self.takedamage = DAMAGE_NO;

activator = self.enemy;
sub_usetargets ();

if (self.wait > 0)
{
self.think = base_multiple_think_wait;
self.nextthink = time + self.wait;
if (self.spawnflags & TRIGGER_MULTIPLE_TURNS_OFF)
{
self.is_waiting = 1;
sub_checkwaiting (self);
}
}
else
{
// we can't just remove (self) here, because self
// is a touch function called while C code is looping
// through area links...
self.touch = sub_null;
self.think = sub_remove;
self.nextthink = time + 0.1;
}
};

//--------------------------------------------------------------
// multi_killed; dumptruck_ds
//--------------------------------------------------------------
void(vector dir) base_multiple_destroy =
{
// Supa, restore health and do nothing if we're still
// waiting to be activated
if (self.estate != STATE_ACTIVE)
{
self.health = self.max_health; // nyah nyah~!
self.takedamage = DAMAGE_YES;
self.solid = SOLID_BBOX;

return;
}

self.enemy = damage_attacker;
base_multiple_fire ();
};

//--------------------------------------------------------------
// dumptruck_ds
//--------------------------------------------------------------
void() base_multiple_touch =
{
if (self.spawnflags & TRIGGER_MULTIPLE_NOTOUCH)
return;

if (other.classtype != CT_PLAYER)
return;

// from Copper -- dumptruck_ds
if (other.movetype == MOVETYPE_NOCLIP)
return;

if (self.estate != STATE_ACTIVE)
return;

// if the trigger has an angles field, check player's
// facing direction
if (self.movedir != '0 0 0')
{
makevectors (other.angles);
if (v_forward * self.movedir < 0)
// not facing the right way
return;
}

self.enemy = other;
base_multiple_fire ();
};

//--------------------------------------------------------------
// dumptruck_ds
//--------------------------------------------------------------
void() base_multiple_use =
{
self.enemy = activator;
base_multiple_fire ();
};

//--------------------------------------------------------------
void(entity e) base_multiple_init =
{
if (e.sounds == 1)
{
precache_sound ("misc/secret.wav");
e.noise = "misc/secret.wav";
}
else if (e.sounds == 2)
{
precache_sound ("misc/talk.wav");
e.noise = "misc/talk.wav";
}
else if (e.sounds == 3)
{
precache_sound ("misc/trigger1.wav");
e.noise = "misc/trigger1.wav";
}

if (!e.wait)
{
e.wait = 0.2;
}
else if (e.wait < 0 &&
(e.spawnflags & TRIGGER_MULTIPLE_TURNS_OFF))
{
objerror ("base_multiple_init: wait for retrigger "
"and negative wait don't make sense\n");
}

e.use = base_multiple_use;

base_trigger_init (e);

if (e.health)
{
if (e.spawnflags & TRIGGER_MULTIPLE_NOTOUCH)
objerror ("base_multiple_init: health "
"and notouch don't make sense\n");
e.max_health = e.health;
e.destroy = base_multiple_destroy;
e.takedamage = DAMAGE_YES;
e.solid = SOLID_BBOX;
// make sure it links into the world
setorigin (e, e.origin);
}
else
{
if (!(e.spawnflags & TRIGGER_MULTIPLE_NOTOUCH))
e.touch = base_multiple_touch;
}

sub_checkwaiting (e);
};

//--------------------------------------------------------------
strip void() base_multiple =
{
base_multiple_init (self);
};
// };

/*QUAKED trigger_multiple (.5 .5 .5) ? notouch WAIT_FOR_RETRIGGER X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY

Variable sized repeatable trigger. Must be targeted at one or more entities. If "health" is set, the trigger must be killed to activate each time.
If "WAIT_FOR_RETRIGGER" is set, it must be triggered by another entity before it can trigger again.
If "delay" is set, the trigger waits some time after activating before firing.
"wait" : Seconds between triggerings. (.2 default)
If notouch is set, the trigger is only fired by other entities, not by touching.
NOTOUCH has been obsoleted by trigger_relay!
sounds
1) secret
2) beep beep
3) large switch
set "message" to text string
"is_waiting" : If set to 1, this trigger will do nothing until another trigger activates it
*/
//----------------------------------------------------------------------
// class trigger_multiple: base_multiple
// {
//--------------------------------------------------------------
void(entity e) trigger_multiple_init =
{
e.classname = "trigger_multiple";
e.classtype = CT_TRIGGER_MULTIPLE;
base_multiple_init (e);
};

//--------------------------------------------------------------
void() trigger_multiple =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

trigger_multiple_init (self);
};
// };

/*QUAKED trigger_once (.5 .5 .5) ? notouch X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY

Variable sized trigger. Triggers once, then removes itself. You must set the key "target" to the name of another object in the level that has a matching
"targetname". If "health" is set, the trigger must be killed to activate.
If notouch is set, the trigger is only fired by other entities, not by touching.
if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
if "angle" is set, the trigger will only fire when someone is facing the direction of the angle. Use "360" for an angle of 0.
sounds
1) secret
2) beep beep
3) large switch
set "message" to text string
*/
//----------------------------------------------------------------------
// class trigger_once: base_multiple
// {
//--------------------------------------------------------------
void(entity e) trigger_once_init =
{
e.classname = "trigger_once";
e.classtype = CT_TRIGGER_ONCE;
e.wait = -1;
base_multiple_init (e);
};

//--------------------------------------------------------------
void() trigger_once =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

trigger_once_init (self);
};
// };

Return to the top of this page or return to the overview of this repo.

Log multiple.qc

Return to the top of this page or return to the overview of this repo.