704 lines
15 KiB
C++
704 lines
15 KiB
C++
|
|
entity stemp, otemp, s, old;
|
|
|
|
|
|
void() trigger_reactivate =
|
|
{
|
|
self.solid = solid_trigger;
|
|
};
|
|
|
|
//=============================================================================
|
|
|
|
float spawnflag_nomessage = 1;
|
|
float spawnflag_notouch = 1;
|
|
|
|
// the wait time has passed, so set back up for another activation
|
|
void() multi_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
|
|
// self.enemy should be set to the activator so it can be held through a delay
|
|
// so wait for the delay time before firing
|
|
void() multi_trigger =
|
|
{
|
|
if (self.nextthink > time)
|
|
{
|
|
return; // allready been triggered
|
|
}
|
|
|
|
if (self.classname == "trigger_secret")
|
|
{
|
|
if (self.enemy.classname != "player")
|
|
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 = multi_wait;
|
|
self.nextthink = time + self.wait;
|
|
}
|
|
else
|
|
{ // we can't just remove (self) here, because this is a touch function
|
|
// called wheil c code is looping through area links...
|
|
self.touch = sub_null;
|
|
self.nextthink = time + 0.1;
|
|
self.think = sub_remove;
|
|
}
|
|
//med 12/01/96 added cnt stuff
|
|
if (self.cnt > 0)
|
|
{
|
|
self.cnt = self.cnt - 1;
|
|
if (self.cnt == 0)
|
|
{
|
|
self.touch = sub_null;
|
|
self.nextthink = time + 0.1;
|
|
self.think = sub_remove;
|
|
}
|
|
}
|
|
};
|
|
|
|
void() multi_killed =
|
|
{
|
|
self.enemy = damage_attacker;
|
|
multi_trigger();
|
|
};
|
|
|
|
void() multi_use =
|
|
{
|
|
self.enemy = activator;
|
|
multi_trigger();
|
|
};
|
|
|
|
void() multi_touch =
|
|
{
|
|
if (other.classname != "player")
|
|
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)
|
|
return; // not facing the right way
|
|
}
|
|
|
|
self.enemy = other;
|
|
multi_trigger ();
|
|
};
|
|
|
|
//med 12/01/96 added count field
|
|
/*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)
|
|
"cnt" how many times it can be triggered (infinite 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
|
|
*/
|
|
void() trigger_multiple =
|
|
{
|
|
if (self.sounds == 1)
|
|
{
|
|
precache_sound ("misc/secret.wav");
|
|
self.noise = "misc/secret.wav";
|
|
}
|
|
else if (self.sounds == 2)
|
|
{
|
|
precache_sound ("misc/talk.wav");
|
|
self.noise = "misc/talk.wav";
|
|
}
|
|
else if (self.sounds == 3)
|
|
{
|
|
precache_sound ("misc/trigger1.wav");
|
|
self.noise = "misc/trigger1.wav";
|
|
}
|
|
|
|
if (!self.wait)
|
|
self.wait = 0.2;
|
|
self.use = multi_use;
|
|
|
|
inittrigger ();
|
|
|
|
if (self.health)
|
|
{
|
|
if (self.spawnflags & spawnflag_notouch)
|
|
objerror ("health and notouch don't make sense\n");
|
|
self.max_health = self.health;
|
|
self.th_die = multi_killed;
|
|
self.takedamage = damage_yes;
|
|
self.solid = solid_bbox;
|
|
setorigin (self, self.origin); // make sure it links into the world
|
|
}
|
|
else
|
|
{
|
|
if ( !(self.spawnflags & spawnflag_notouch) )
|
|
{
|
|
self.touch = multi_touch;
|
|
}
|
|
}
|
|
//med 12/01/96 added cnt stuff
|
|
if (self.cnt == 0)
|
|
self.cnt = -1;
|
|
};
|
|
|
|
|
|
/*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
|
|
*/
|
|
void() trigger_once =
|
|
{
|
|
self.wait = -1;
|
|
trigger_multiple();
|
|
};
|
|
|
|
//=============================================================================
|
|
|
|
/*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.
|
|
*/
|
|
void() trigger_relay =
|
|
{
|
|
self.use = sub_usetargets;
|
|
};
|
|
|
|
|
|
//=============================================================================
|
|
|
|
/*quaked trigger_secret (.5 .5 .5) ?
|
|
secret counter trigger
|
|
sounds
|
|
1) secret
|
|
2) beep beep
|
|
3)
|
|
4)
|
|
set "message" to text string
|
|
*/
|
|
void() trigger_secret =
|
|
{
|
|
total_secrets = total_secrets + 1;
|
|
self.wait = -1;
|
|
if (!self.message)
|
|
self.message = "you found a secret area!";
|
|
if (!self.sounds)
|
|
self.sounds = 1;
|
|
|
|
if (self.sounds == 1)
|
|
{
|
|
precache_sound ("misc/secret.wav");
|
|
self.noise = "misc/secret.wav";
|
|
}
|
|
else if (self.sounds == 2)
|
|
{
|
|
precache_sound ("misc/talk.wav");
|
|
self.noise = "misc/talk.wav";
|
|
}
|
|
|
|
trigger_multiple ();
|
|
};
|
|
|
|
//=============================================================================
|
|
|
|
|
|
void() counter_use =
|
|
{
|
|
local string junk;
|
|
|
|
self.count = self.count - 1;
|
|
if (self.count < 0)
|
|
return;
|
|
|
|
if (self.count != 0)
|
|
{
|
|
if (activator.classname == "player"
|
|
&& (self.spawnflags & spawnflag_nomessage) == 0)
|
|
{
|
|
if (self.count >= 4)
|
|
centerprint (activator, "there are more to go...");
|
|
else if (self.count == 3)
|
|
centerprint (activator, "only 3 more to go...");
|
|
else if (self.count == 2)
|
|
centerprint (activator, "only 2 more to go...");
|
|
else
|
|
centerprint (activator, "only 1 more to go...");
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (activator.classname == "player"
|
|
&& (self.spawnflags & spawnflag_nomessage) == 0)
|
|
centerprint(activator, "sequence completed!");
|
|
self.enemy = activator;
|
|
multi_trigger ();
|
|
};
|
|
|
|
/*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.
|
|
*/
|
|
void() trigger_counter =
|
|
{
|
|
self.wait = -1;
|
|
if (!self.count)
|
|
self.count = 2;
|
|
|
|
self.use = counter_use;
|
|
};
|
|
|
|
|
|
/*
|
|
==============================================================================
|
|
|
|
teleport triggers
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
float player_only = 1;
|
|
float silent = 2;
|
|
|
|
void() play_teleport =
|
|
{
|
|
local float v;
|
|
local string tmpstr;
|
|
|
|
v = random() * 5;
|
|
if (v < 1)
|
|
tmpstr = "misc/r_tele1.wav";
|
|
else if (v < 2)
|
|
tmpstr = "misc/r_tele2.wav";
|
|
else if (v < 3)
|
|
tmpstr = "misc/r_tele3.wav";
|
|
else if (v < 4)
|
|
tmpstr = "misc/r_tele4.wav";
|
|
else
|
|
tmpstr = "misc/r_tele5.wav";
|
|
|
|
sound (self, chan_voice, tmpstr, 1, attn_norm);
|
|
remove (self);
|
|
};
|
|
|
|
void(vector org) spawn_tfog =
|
|
{
|
|
s = spawn ();
|
|
s.origin = org;
|
|
s.nextthink = time + 0.2;
|
|
s.think = play_teleport;
|
|
|
|
writebyte (msg_broadcast, svc_tempentity);
|
|
writebyte (msg_broadcast, te_teleport);
|
|
writecoord (msg_broadcast, org_x);
|
|
writecoord (msg_broadcast, org_y);
|
|
writecoord (msg_broadcast, org_z);
|
|
};
|
|
|
|
|
|
void() tdeath_touch =
|
|
{
|
|
if (other == self.owner)
|
|
return;
|
|
|
|
// frag anyone who teleports in on top of an invincible player
|
|
if (other.classname == "player")
|
|
{
|
|
if (other.invincible_finished > time)
|
|
self.classname = "teledeath2";
|
|
if (self.owner.classname != "player")
|
|
{ // other monsters explode themselves
|
|
t_damage (self.owner, self, self, 50000);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
if (other.health)
|
|
{
|
|
t_damage (other, self, self, 50000);
|
|
}
|
|
};
|
|
|
|
|
|
void(vector org, entity death_owner) spawn_tdeath =
|
|
{
|
|
local entity death;
|
|
|
|
death = spawn();
|
|
death.classname = "teledeath";
|
|
death.movetype = movetype_none;
|
|
death.solid = solid_trigger;
|
|
death.angles = '0 0 0';
|
|
setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
|
|
setorigin (death, org);
|
|
death.touch = tdeath_touch;
|
|
death.nextthink = time + 0.2;
|
|
death.think = sub_remove;
|
|
death.owner = death_owner;
|
|
|
|
force_retouch = 2; // make sure even still objects get hit
|
|
};
|
|
|
|
void() teleport_touch =
|
|
{
|
|
local entity t;
|
|
local vector org;
|
|
|
|
if (self.targetname)
|
|
{
|
|
if (self.nextthink < time)
|
|
{
|
|
return; // not fired yet
|
|
}
|
|
}
|
|
|
|
if (self.spawnflags & player_only)
|
|
{
|
|
if (other.classname != "player")
|
|
return;
|
|
}
|
|
|
|
// only teleport living creatures
|
|
if (other.health <= 0 || other.solid != solid_slidebox)
|
|
return;
|
|
|
|
sub_usetargets ();
|
|
|
|
// put a tfog where the player was
|
|
spawn_tfog (other.origin);
|
|
|
|
t = find (world, targetname, self.target);
|
|
if (!t)
|
|
objerror ("couldn't find target");
|
|
|
|
// spawn a tfog flash in front of the destination
|
|
makevectors (t.mangle);
|
|
org = t.origin + 32 * v_forward;
|
|
|
|
spawn_tfog (org);
|
|
spawn_tdeath(t.origin, other);
|
|
|
|
// move the player and lock him down for a little while
|
|
if (!other.health)
|
|
{
|
|
other.origin = t.origin;
|
|
other.velocity = (v_forward * other.velocity_x) + (v_forward * other.velocity_y);
|
|
return;
|
|
}
|
|
|
|
setorigin (other, t.origin);
|
|
other.angles = t.mangle;
|
|
if (other.classname == "player")
|
|
{
|
|
other.fixangle = 1; // turn this way immediately
|
|
other.teleport_time = time + 0.7;
|
|
if (other.flags & fl_onground)
|
|
other.flags = other.flags - fl_onground;
|
|
other.velocity = v_forward * 300;
|
|
}
|
|
other.flags = other.flags - other.flags & fl_onground;
|
|
};
|
|
|
|
/*quaked info_teleport_destination (.5 .5 .5) (-8 -8 -8) (8 8 32)
|
|
this is the destination marker for a teleporter. it should have a "targetname" field with the same value as a teleporter's "target" field.
|
|
*/
|
|
void() info_teleport_destination =
|
|
{
|
|
// this does nothing, just serves as a target spot
|
|
self.mangle = self.angles;
|
|
self.angles = '0 0 0';
|
|
self.model = "";
|
|
self.origin = self.origin + '0 0 27';
|
|
if (!self.targetname)
|
|
objerror ("no targetname");
|
|
};
|
|
|
|
void() teleport_use =
|
|
{
|
|
self.nextthink = time + 0.2;
|
|
force_retouch = 2; // make sure even still objects get hit
|
|
self.think = sub_null;
|
|
};
|
|
|
|
/*quaked trigger_teleport (.5 .5 .5) ? player_only silent
|
|
any object touching this will be transported to the corresponding info_teleport_destination entity. you must set the "target" field, and create an object with a "targetname" field that matches.
|
|
|
|
if the trigger_teleport has a targetname, it will only teleport entities when it has been fired.
|
|
*/
|
|
void() trigger_teleport =
|
|
{
|
|
local vector o;
|
|
|
|
inittrigger ();
|
|
self.touch = teleport_touch;
|
|
// find the destination
|
|
if (!self.target)
|
|
objerror ("no target");
|
|
self.use = teleport_use;
|
|
|
|
if (!(self.spawnflags & silent))
|
|
{
|
|
precache_sound ("ambience/hum1.wav");
|
|
o = (self.mins + self.maxs)*0.5;
|
|
ambientsound (o, "ambience/hum1.wav",0.5 , attn_static);
|
|
}
|
|
};
|
|
|
|
/*
|
|
==============================================================================
|
|
|
|
trigger_setskill
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
void() trigger_skill_touch =
|
|
{
|
|
if (other.classname != "player")
|
|
return;
|
|
|
|
cvar_set ("skill", self.message);
|
|
};
|
|
|
|
/*quaked trigger_setskill (.5 .5 .5) ?
|
|
sets skill level to the value of "message".
|
|
only used on start map.
|
|
*/
|
|
void() trigger_setskill =
|
|
{
|
|
inittrigger ();
|
|
self.touch = trigger_skill_touch;
|
|
};
|
|
|
|
|
|
/*
|
|
==============================================================================
|
|
|
|
only registered triggers
|
|
|
|
==============================================================================
|
|
*/
|
|
|
|
void() trigger_onlyregistered_touch =
|
|
{
|
|
if (other.classname != "player")
|
|
return;
|
|
if (self.attack_finished > time)
|
|
return;
|
|
|
|
self.attack_finished = time + 2;
|
|
if (cvar("registered"))
|
|
{
|
|
self.message = "";
|
|
sub_usetargets ();
|
|
remove (self);
|
|
}
|
|
else
|
|
{
|
|
if (self.message != "")
|
|
{
|
|
centerprint (other, self.message);
|
|
sound (other, chan_body, "misc/talk.wav", 1, attn_norm);
|
|
}
|
|
}
|
|
};
|
|
|
|
/*quaked trigger_onlyregistered (.5 .5 .5) ?
|
|
only fires if playing the registered version, otherwise prints the message
|
|
*/
|
|
void() trigger_onlyregistered =
|
|
{
|
|
precache_sound ("misc/talk.wav");
|
|
inittrigger ();
|
|
self.touch = trigger_onlyregistered_touch;
|
|
};
|
|
|
|
//============================================================================
|
|
|
|
//jim
|
|
void( entity ent, float amount ) hurt_setdamage =
|
|
{
|
|
ent.dmg = amount;
|
|
if ( !amount )
|
|
{
|
|
ent.solid = solid_not;
|
|
}
|
|
else
|
|
{
|
|
ent.solid = solid_trigger;
|
|
}
|
|
ent.nextthink = -1;
|
|
};
|
|
|
|
void() hurt_on =
|
|
{
|
|
self.solid = solid_trigger;
|
|
self.nextthink = -1;
|
|
};
|
|
|
|
void() hurt_touch =
|
|
{
|
|
if (other.takedamage)
|
|
{
|
|
self.solid = solid_not;
|
|
t_damage (other, self, self, self.dmg);
|
|
self.think = hurt_on;
|
|
self.nextthink = time + 1;
|
|
//med 12/01/96 added count stuff
|
|
if (self.cnt > 0)
|
|
{
|
|
self.cnt = self.cnt - 1;
|
|
if (self.cnt == 0)
|
|
{
|
|
self.touch = sub_null;
|
|
self.nextthink = time + 0.1;
|
|
self.think = sub_remove;
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
};
|
|
|
|
//med 12/01/96 added count field
|
|
/*quaked trigger_hurt (.5 .5 .5) ?
|
|
any object touching this will be hurt
|
|
set dmg to damage amount
|
|
defalt dmg = 5
|
|
"cnt" default infinite, how many times to trigger
|
|
*/
|
|
void() trigger_hurt =
|
|
{
|
|
inittrigger ();
|
|
self.touch = hurt_touch;
|
|
if (!self.dmg)
|
|
self.dmg = 5;
|
|
//med 12/01/96 added count stuff
|
|
if (self.cnt == 0)
|
|
self.cnt = -1;
|
|
};
|
|
|
|
//============================================================================
|
|
|
|
float push_once = 1;
|
|
|
|
void() trigger_push_touch =
|
|
{
|
|
if (other.classname == "grenade")
|
|
other.velocity = self.speed * self.movedir * 10;
|
|
else if (other.health > 0)
|
|
{
|
|
other.velocity = self.speed * self.movedir * 10;
|
|
if (other.classname == "player")
|
|
{
|
|
if (other.fly_sound < time)
|
|
{
|
|
other.fly_sound = time + 1.5;
|
|
sound (other, chan_auto, "ambience/windfly.wav", 1, attn_norm);
|
|
}
|
|
}
|
|
}
|
|
if (self.spawnflags & push_once)
|
|
remove(self);
|
|
};
|
|
|
|
|
|
/*quaked trigger_push (.5 .5 .5) ? push_once
|
|
pushes the player
|
|
*/
|
|
void() trigger_push =
|
|
{
|
|
inittrigger ();
|
|
precache_sound ("ambience/windfly.wav");
|
|
self.touch = trigger_push_touch;
|
|
if (!self.speed)
|
|
self.speed = 1000;
|
|
};
|
|
|
|
//============================================================================
|
|
|
|
void() trigger_monsterjump_touch =
|
|
{
|
|
if ( other.flags & (fl_monster | fl_fly | fl_swim) != fl_monster )
|
|
return;
|
|
|
|
// set xy even if not on ground, so the jump will clear lips
|
|
other.velocity_x = self.movedir_x * self.speed;
|
|
other.velocity_y = self.movedir_y * self.speed;
|
|
|
|
if ( !(other.flags & fl_onground) )
|
|
return;
|
|
|
|
other.flags = other.flags - fl_onground;
|
|
|
|
other.velocity_z = self.height;
|
|
//med 12/01/96 added count stuff
|
|
if (self.cnt>0)
|
|
{
|
|
self.cnt = self.cnt - 1;
|
|
if (self.cnt == 0)
|
|
{
|
|
self.touch = sub_null;
|
|
self.nextthink = time + 0.1;
|
|
self.think = sub_remove;
|
|
}
|
|
}
|
|
};
|
|
|
|
//med 12/01/96 added count field
|
|
/*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
|
|
"cnt" default infinite, how many times to trigger
|
|
*/
|
|
void() trigger_monsterjump =
|
|
{
|
|
if (!self.speed)
|
|
self.speed = 200;
|
|
if (!self.height)
|
|
self.height = 200;
|
|
if (self.angles == '0 0 0')
|
|
self.angles = '0 360 0';
|
|
//med 12/01/96 added count stuff
|
|
if (self.cnt == 0)
|
|
self.cnt = -1;
|
|
inittrigger ();
|
|
self.touch = trigger_monsterjump_touch;
|
|
};
|