📄 triggers.htm
字号:
<html><head><title>triggers.qc</title></head><body bgcolor="#C0F0D0">
<base target=examine>
<pre>
<a href="qc-types.htm#entity">entity</a> stemp, otemp, s, old;
<a href="qc-types.htm#void">void</a>() <b>trigger_reactivate</b><a name="trigger_reactivate">=</a>
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_solid">solid</a> = <a href="qc-defs.htm#SOLID_TRIGGER">SOLID_TRIGGER</a>;
};
<i>//=============================================================================</i>
<a href="qc-types.htm#float">float</a> <b><a name="SPAWNFLAG_NOMESSAGE">SPAWNFLAG_NOMESSAGE</a></b> = 1;
<a href="qc-types.htm#float">float</a> <b><a name="SPAWNFLAG_NOTOUCH">SPAWNFLAG_NOTOUCH</a></b> = 1;
<i>// the wait time has passed, so set back up for another activation</i>
<a href="qc-types.htm#void">void</a>() <b>multi_wait</b><a name="multi_wait">=</a>
{
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_max_health">max_health</a>)
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_health">health</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_max_health">max_health</a>;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_takedamage">takedamage</a> = <a href="qc-defs.htm#DAMAGE_YES">DAMAGE_YES</a>;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_solid">solid</a> = <a href="qc-defs.htm#SOLID_BBOX">SOLID_BBOX</a>;
}
};
<i>// the trigger was just touched/killed/used</i>
<i>// self.enemy should be set to the activator so it can be held through a delay</i>
<i>// so wait for the delay time before firing</i>
<a href="qc-types.htm#void">void</a>() <b>multi_trigger</b><a name="multi_trigger">=</a>
{
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> > <a href="qc-glob.htm#time">time</a>)
{
<b>return</b>; <i>// allready been triggered</i>
}
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_classname">classname</a> == <b>"trigger_secret"</b>)
{
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_enemy">enemy</a>.<a href="qc-enty.htm#dot_classname">classname</a> != <b>"player"</b>)
<b>return</b>;
<a href="qc-glob.htm#found_secrets">found_secrets</a> = <a href="qc-glob.htm#found_secrets">found_secrets</a> + 1;
<a href="qc-netf.htm#WriteByte">WriteByte</a> (<a href="qc-net.htm#MSG_ALL">MSG_ALL</a>, <a href="qc-net.htm#SVC_FOUNDSECRET">SVC_FOUNDSECRET</a>);
}
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_noise">noise</a>)
<a href="qc-built.htm#sound">sound</a> (<a href="qc-glob.htm#self">self</a>, <a href="qc-defs.htm#CHAN_VOICE">CHAN_VOICE</a>, <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_noise">noise</a>, 1, <a href="qc-defs.htm#ATTN_NORM">ATTN_NORM</a>);
<i>// don't trigger again until reset</i>
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_takedamage">takedamage</a> = <a href="qc-defs.htm#DAMAGE_NO">DAMAGE_NO</a>;
<a href="defs.htm#activator">activator</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_enemy">enemy</a>;
<a href="subs.htm#SUB_UseTargets">SUB_UseTargets</a>();
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_wait">wait</a> > 0)
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_think">think</a> = <a href="triggers.htm#multi_wait">multi_wait</a>;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> = <a href="qc-glob.htm#time">time</a> + <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_wait">wait</a>;
}
<b>else</b>
{ <i>// we can't just remove (self) here, because this is a touch function</i>
<i>// called wheil C code is looping through area links...</i>
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_touch">touch</a> = <a href="subs.htm#SUB_Null">SUB_Null</a>;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> = <a href="qc-glob.htm#time">time</a> + 0.1;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_think">think</a> = <a href="subs.htm#SUB_Remove">SUB_Remove</a>;
}
};
<a href="qc-types.htm#void">void</a>() <b>multi_killed</b><a name="multi_killed">=</a>
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_enemy">enemy</a> = <a href="defs.htm#damage_attacker">damage_attacker</a>;
<a href="triggers.htm#multi_trigger">multi_trigger</a>();
};
<a href="qc-types.htm#void">void</a>() <b>multi_use</b><a name="multi_use">=</a>
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_enemy">enemy</a> = <a href="defs.htm#activator">activator</a>;
<a href="triggers.htm#multi_trigger">multi_trigger</a>();
};
<a href="qc-types.htm#void">void</a>() <b>multi_touch</b><a name="multi_touch">=</a>
{
<b>if</b> (<a href="qc-glob.htm#other">other</a>.<a href="qc-enty.htm#dot_classname">classname</a> != <b>"player"</b>)
<b>return</b>;
<i>// if the trigger has an angles field, check player's facing direction</i>
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movedir">movedir</a> != '0 0 0')
{
<a href="qc-built.htm#makevectors">makevectors</a> (<a href="qc-glob.htm#other">other</a>.<a href="qc-enty.htm#dot_angles">angles</a>);
<b>if</b> (<a href="qc-built.htm#v_forward">v_forward</a> * <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movedir">movedir</a> < 0)
<b>return</b>; <i>// not facing the right way</i>
}
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_enemy">enemy</a> = <a href="qc-glob.htm#other">other</a>;
<a href="triggers.htm#multi_trigger">multi_trigger</a> ();
};
<i>/*QUAKED trigger_multiple (.5 .5 .5) ? notouch
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 "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
4)
set "message" to text string
*/</i>
<a href="qc-types.htm#void">void</a>() <b>trigger_multiple</b><a name="trigger_multiple">=</a>
{
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_sounds">sounds</a> == 1)
{
<a href="qc-built.htm#precache_sound">precache_sound</a> (<b>"misc/secret.wav"</b>);
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_noise">noise</a> = <b>"misc/secret.wav"</b>;
}
<b>else</b> <b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_sounds">sounds</a> == 2)
{
<a href="qc-built.htm#precache_sound">precache_sound</a> (<b>"misc/talk.wav"</b>);
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_noise">noise</a> = <b>"misc/talk.wav"</b>;
}
<b>else</b> <b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_sounds">sounds</a> == 3)
{
<a href="qc-built.htm#precache_sound">precache_sound</a> (<b>"misc/trigger1.wav"</b>);
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_noise">noise</a> = <b>"misc/trigger1.wav"</b>;
}
<b>if</b> (!<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_wait">wait</a>)
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_wait">wait</a> = 0.2;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_use">use</a> = <a href="triggers.htm#multi_use">multi_use</a>;
<a href="subs.htm#InitTrigger">InitTrigger</a> ();
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_health">health</a>)
{
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_spawnflags">spawnflags</a> & <a href="triggers.htm#SPAWNFLAG_NOTOUCH">SPAWNFLAG_NOTOUCH</a>)
<a href="qc-built.htm#objerror">objerror</a> (<b>"health and notouch don't make sense\n"</b>);
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_max_health">max_health</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_health">health</a>;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_th_die">th_die</a> = <a href="triggers.htm#multi_killed">multi_killed</a>;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_takedamage">takedamage</a> = <a href="qc-defs.htm#DAMAGE_YES">DAMAGE_YES</a>;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_solid">solid</a> = <a href="qc-defs.htm#SOLID_BBOX">SOLID_BBOX</a>;
<a href="qc-built.htm#setorigin">setorigin</a> (<a href="qc-glob.htm#self">self</a>, <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_origin">origin</a>); <i>// make sure it links into the world</i>
}
<b>else</b>
{
<b>if</b> ( !(<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_spawnflags">spawnflags</a> & <a href="triggers.htm#SPAWNFLAG_NOTOUCH">SPAWNFLAG_NOTOUCH</a>) )
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_touch">touch</a> = <a href="triggers.htm#multi_touch">multi_touch</a>;
}
}
};
<i>/*QUAKED trigger_once (.5 .5 .5) ? notouch
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
4)
set "message" to text string
*/</i>
<a href="qc-types.htm#void">void</a>() <b>trigger_once</b><a name="trigger_once">=</a>
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_wait">wait</a> = -1;
<a href="triggers.htm#trigger_multiple">trigger_multiple</a>();
};
<i>//=============================================================================</i>
<i>/*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
This fixed size trigger cannot be touched, it can only be fired by other events. It can contain killtargets, targets, delays, and messages.
*/</i>
<a href="qc-types.htm#void">void</a>() <b>trigger_relay</b><a name="trigger_relay">=</a>
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_use">use</a> = <a href="subs.htm#SUB_UseTargets">SUB_UseTargets</a>;
};
<i>//=============================================================================</i>
<i>/*QUAKED trigger_secret (.5 .5 .5) ?
secret counter trigger
sounds
1) secret
2) beep beep
3)
4)
set "message" to text string
*/</i>
<a href="qc-types.htm#void">void</a>() <b>trigger_secret</b><a name="trigger_secret">=</a>
{
<a href="qc-glob.htm#total_secrets">total_secrets</a> = <a href="qc-glob.htm#total_secrets">total_secrets</a> + 1;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_wait">wait</a> = -1;
<b>if</b> (!<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_message">message</a>)
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_message">message</a> = <b>"You found a secret area!"</b>;
<b>if</b> (!<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_sounds">sounds</a>)
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_sounds">sounds</a> = 1;
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_sounds">sounds</a> == 1)
{
<a href="qc-built.htm#precache_sound">precache_sound</a> (<b>"misc/secret.wav"</b>);
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_noise">noise</a> = <b>"misc/secret.wav"</b>;
}
<b>else</b> <b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_sounds">sounds</a> == 2)
{
<a href="qc-built.htm#precache_sound">precache_sound</a> (<b>"misc/talk.wav"</b>);
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_noise">noise</a> = <b>"misc/talk.wav"</b>;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -