📄 g_trigger.pas
字号:
if (not self^.item) then
begin
gi.dprintf('item %s not found for trigger_key at %s\n', st.item, vtos(self^.s.origin));
exit;
end;
if (not self^.target) then
begin
gi.dprintf('%s at %s has no target\n', self^.classname, vtos(self^.s.origin));
exit;
end;
gi.soundindex ('misc/keytry.wav');
gi.soundindex ('misc/keyuse.wav');
self^.use := trigger_key_use;
end;
(*
===============================================================================
trigger_counter
==============================================================================
*)
(*QUAKED trigger_counter (.5 .5 .5) ? nomessage
Acts as an intermediary for an action that takes multiple inputs.
If nomessage is not set, t will print '1 more.. ' etc when triggered and 'sequence complete' when finished.
After the counter has been triggered 'count' times (default 2), it will fire all of it's targets and remove itself.
*)
procedure trigger_counter_use(self:pedict_t; other:pedict_t; activator:pedict_t);
begin
if (self^.count = 0) then
exit;
self^.count := self^.count - 1;
if (self^.count = 1) then
begin
if (not (self^.spawnflags and 1)) then
begin
gi.centerprintf(activator, '%i more to go...', self^.count);
gi.sound (activator, CHAN_AUTO, gi.soundindex ('misc/talk1.wav'), 1, ATTN_NORM, 0);
end;
exit;
end;
if (not (self^.spawnflags and 1)) then
begin
gi.centerprintf(activator, 'Sequence completed!');
gi.sound (activator, CHAN_AUTO, gi.soundindex ('misc/talk1.wav'), 1, ATTN_NORM, 0);
end;
self^.activator := activator;
multi_trigger (self);
end;
procedure SP_trigger_counter (self:pedict_t);
begin
self^.wait := -1;
if (not self^.count) then
self^.count := 2;
self^.use := trigger_counter_use;
end;
(*
==============================================================================
trigger_always
==============================================================================
*)
(*QUAKED trigger_always (.5 .5 .5) (-8 -8 -8) (8 8 8)
This trigger will always fire. It is activated by the world.
*)
procedure SP_trigger_always (ent:pedict_t);
begin
// we must have some delay to make sure our use targets are present
if (ent^.delay < 0.2) then
ent^.delay := 0.2;
G_UseTargets(ent, ent);
end;
(*
==============================================================================
trigger_push
==============================================================================
*)
const PUSH_ONCE = 1 ;
var windsound:smallint;
procedure trigger_push_touch (self:pedict_t; other:pedict_t; plane:pcplane_t, surf:pcsurface_t);
begin
if (strcomp(other^.classname, 'grenade') = 0) then
begin
VectorScale (self^.movedir, self^.speed * 10, other^.velocity);
end
else if (other^.health > 0) then
begin
VectorScale (self^.movedir, self^.speed * 10, other^.velocity);
if (other^.client) then
begin
// don't take falling damage immediately from this
VectorCopy (other^.velocity, other^.client^.oldvelocity);
if (other^.fly_sound_debounce_time < level.time) then
begin
other^.fly_sound_debounce_time := level.time + 1.5;
gi.sound (other, CHAN_AUTO, windsound, 1, ATTN_NORM, 0);
end;
end;
end;
if (self^.spawnflags and PUSH_ONCE) then
G_FreeEdict (self);
end;
(*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
Pushes the player
'speed' defaults to 1000
*)
procedure SP_trigger_push (self:pedict_t);
begin
InitTrigger (self);
windsound := gi.soundindex ('misc/windfly.wav');
self^.touch := trigger_push_touch;
if (not self^.speed) then
self^.speed := 1000;
gi.linkentity (self);
end;
(*
==============================================================================
trigger_hurt
==============================================================================
*)
(*QUAKED trigger_hurt (.5 .5 .5) ? START_OFF TOGGLE SILENT NO_PROTECTION SLOW
Any entity that touches this will be hurt.
It does dmg points of damage each server frame
SILENT supresses playing the sound
SLOW changes the damage rate to once per second
NO_PROTECTION *nothing* stops the damage
'dmg' default 5 (whole numbers only)
*)
procedure hurt_use (edict_t *self, edict_t *other, edict_t *activator);
begin
if (self^.solid = SOLID_NOT) then
self^.solid := SOLID_TRIGGER
else
self^.solid := SOLID_NOT;
gi.linkentity (self);
if (not (self^.spawnflags and 2)) then
self^.use := NiL;
end;
procedure hurt_touch (self:pedict_t; other:pedict_t; plane:pcplane_t; surf:pcsurface_t);
var dflags:smallint;
begin
if (not other^.takedamage) then
exit;
if (self^.timestamp > level.time) then
exit;
if (self^.spawnflags and 16) then
self^.timestamp := level.time + 1
else
self^.timestamp := level.time + FRAMETIME;
if (not (self^.spawnflags and 4)) then
begin
if ((level.framenum mod 10) = 0) then
gi.sound (other, CHAN_AUTO, self^.noise_index, 1, ATTN_NORM, 0);
end;
if (self^.spawnflags and 8) then
dflags := DAMAGE_NO_PROTECTION
else
dflags := 0;
T_Damage (other, self, self, vec3_origin, other^.s.origin, vec3_origin, self^.dmg, self^.dmg, dflags, MOD_TRIGGER_HURT);
end;
procedure SP_trigger_hurt (self:pedict_t);
begin
InitTrigger (self);
self^.noise_index := gi.soundindex ('world/electro.wav');
self^.touch := hurt_touch;
if (not self^.dmg) then
self^.dmg := 5;
if (self^.spawnflags and 1) then
self^.solid := SOLID_NOT
else
self^.solid := SOLID_TRIGGER;
if (self^.spawnflags and 2) then
self^.use := hurt_use;
gi.linkentity (self);
end;
(*
==============================================================================
trigger_gravity
==============================================================================
*)
(*QUAKED trigger_gravity (.5 .5 .5) ?
Changes the touching entites gravity to
the value of 'gravity'. 1.0 is standard
gravity for the level.
*)
procedure trigger_gravity_touch ( self:pedict_t; other:pedict_t; plane:pcplane_t; surf:pcsurface_t);
begin
other^.gravity := self^.gravity;
end;
procedure SP_trigger_gravity (self:pedict_t);
begin
if (st.gravity = 0) then
begin
gi.dprintf('trigger_gravity without gravity set at %s\n', vtos(self^.s.origin));
G_FreeEdict (self);
exit;
end;
InitTrigger (self);
self^.gravity := atoi(st.gravity);
self^.touch := trigger_gravity_touch;
end;
(*
==============================================================================
trigger_monsterjump
==============================================================================
*)
(*QUAKED trigger_monsterjump (.5 .5 .5) ?
Walking monsters that touch this will jump in the direction of the trigger's angle
'speed' default to 200, the speed thrown forward
'height' default to 200, the speed thrown upwards
*)
procedure trigger_monsterjump_touch ( self:pedict_t; other:pedict_t; plane:pcplane_t; surf:pcsurface_t);
begin
if (other^.flags and (FL_FLY or FL_SWIM) ) then
exit;
if (other^.svflags and SVF_DEADMONSTER) then
exit;
if ( not(other^.svflags and SVF_MONSTER)) then
exit;
// set XY even if not on ground, so the jump will clear lips
other^.velocity[0] := self^.movedir[0] * self^.speed;
other^.velocity[1] := self^.movedir[1] * self^.speed;
if (not other^.groundentity) then
exit;
other^.groundentity := Nil;
other^.velocity[2] := self^.movedir[2];
end;
procedure SP_trigger_monsterjump ( self:pedict_t);
begin
if (not self^.speed) then
self^.speed := 200;
if (not st.height) then
st.height := 200;
if (self^.s.angles[YAW] = 0) then
self^.s.angles[YAW] := 360;
InitTrigger (self);
self^.touch := trigger_monsterjump_touch;
self^.movedir[2] := st.height;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -