djcev.com

//

Git Repos / fte_dogmode / qc / triggers / look.qc

Last update to this file was on 2024-06-15 at 19:50.

Show look.qc

////////////////////////////////////////////////////////////////////////////////
// trigger_look (a.k.a. trigger_onlookat from NullPointPaladin!)
////////////////////////////////////////////////////////////////////////////////

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

#ifdef SSQC
// trigger_look
void() trigger_look_use;
void() trigger_look_touch;
void(entity e) trigger_look_init;
void() trigger_look;
#endif

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

#ifdef SSQC
/*QUAKED trigger_look (.5 .5 .5) ? X 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
This will trigger when a player is within the brush trigger and looks directly at a target entity.
Use the first target key for the "looked at entity" and use the subsequent targets (2-4) to trigger other events.

speed = Distance from player to search for trigger, adjust if the target is too far from the trigger (default 500 units)
wait = Time between re-triggering (default 0)
sounds = 0-3 are standard Quake trigger choices, 4 allows a custom sound, requires a path set in noise1 key
noise1 = Path to custom sound. Use with sounds key set to 4 (e.g. fish/bite.wav)

See manual for complete details. See pd_cutscenes sample map for example
*/
//----------------------------------------------------------------------
// class trigger_look: base_multiple
// {
//--------------------------------------------------------------
void() trigger_look_use =
{
base_multiple_fire ();
};

//--------------------------------------------------------------
void() trigger_look_touch =
{
// from Copper -- dumptruck_ds
if (sub_checkvalidtouch(other) == FALSE)
return;

if (self.nextthink > time)
// already been triggered
return;

// added player view offset to make self more accurate
// to the player crosshairs
local vector player_offset = other.origin + other.view_ofs;

makevectors (other.v_angle);

// using speed to determine the reach of the trace
if (!self.speed)
self.speed = 500;

traceline (player_offset,
(player_offset + (v_forward * self.speed)),
FALSE, other);

if (trace_ent.targetname == self.target)
{
// Play message if available
if (self.message != "")
centerprint (other, self.message);

self.use = trigger_look_use;
sub_usetargets ();

if (self.noise != "")
sound (self, CHAN_VOICE, self.noise,
VOL_HIGH, ATTN_NORM);
else
sound (self, CHAN_VOICE, self.noise1,
VOL_HIGH, ATTN_NORM);

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

//--------------------------------------------------------------
void(entity e) trigger_look_init =
{
e.classname = "trigger_look";
e.classtype = CT_TRIGGER_LOOK;

// play all the sounds available for a normal trigger
if (e.sounds == 0)
{
precache_sound ("misc/null.wav");
e.noise = "misc/null.wav";
}
else 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";
}
else if (e.sounds == 4)
{
if (!e.noise1)
{
// dumptruck_ds
objerror ("trigger_look_init: no soundfile "
"set in noise1!\n");
remove (e);
return;
}
else
{
precache_sound (e.noise1);
}
e.noise = e.noise1;
}

base_trigger_init (e);
e.touch = trigger_look_touch;
sub_checkwaiting (e);
};

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

trigger_look_init (self);
};
// };
#endif

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

Log look.qc

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