home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / programs / qplus11 / triggers.qc < prev    next >
Encoding:
Text File  |  1996-08-18  |  14.0 KB  |  645 lines

  1.  
  2. entity stemp, otemp, s, old;
  3.  
  4.  
  5. void() trigger_reactivate =
  6. {
  7.     self.solid = SOLID_TRIGGER;
  8. };
  9.  
  10. //=============================================================================
  11.  
  12. float    SPAWNFLAG_NOMESSAGE = 1;
  13. float    SPAWNFLAG_NOTOUCH = 1;
  14.  
  15. // the wait time has passed, so set back up for another activation
  16. void() multi_wait =
  17. {
  18.     if (self.max_health)
  19.     {
  20.         self.health = self.max_health;
  21.         self.takedamage = DAMAGE_YES;
  22.         self.solid = SOLID_BBOX;
  23.         self.flags = FL_OBJECT;            //ws        
  24.     }
  25. };
  26.  
  27.  
  28. // the trigger was just touched/killed/used
  29. // self.enemy should be set to the activator so it can be held through a delay
  30. // so wait for the delay time before firing
  31. void() multi_trigger =
  32. {
  33.     if (self.nextthink > time)
  34.     {
  35.         return;        // allready been triggered
  36.     }
  37.  
  38.     if (self.classname == "trigger_secret")
  39.     {
  40.         if (self.enemy.classname != "player")
  41.             return;
  42.         found_secrets = found_secrets + 1;
  43.         WriteByte (MSG_ALL, SVC_FOUNDSECRET);
  44.     }
  45.  
  46.     if (self.noise)
  47.         sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
  48.  
  49. // don't trigger again until reset
  50.     self.takedamage = DAMAGE_NO;
  51.  
  52.     activator = self.enemy;
  53.     
  54.     SUB_UseTargets();
  55.  
  56.     if (self.wait > 0)    
  57.     {
  58.         self.think = multi_wait;
  59.         self.nextthink = time + self.wait;
  60.     }
  61.     else
  62.     {    // we can't just remove (self) here, because this is a touch function
  63.         // called wheil C code is looping through area links...
  64.         self.touch = SUB_Null;
  65.         self.nextthink = time + 0.1;
  66.         self.think = SUB_Remove;
  67.     }
  68. };
  69.  
  70. void() multi_killed =
  71. {
  72.     self.enemy = damage_attacker;
  73.     multi_trigger();
  74. };
  75.  
  76. void() multi_use =
  77. {
  78.     self.enemy = activator;
  79.     multi_trigger();
  80. };
  81.  
  82. void() multi_touch =
  83. {
  84.     if (other.classname != "player")
  85.         return;
  86.     
  87. // if the trigger has an angles field, check player's facing direction
  88.     if (self.movedir != '0 0 0')
  89.     {
  90.         makevectors (other.angles);
  91.         if (v_forward * self.movedir < 0)
  92.             return;        // not facing the right way
  93.     }
  94.     
  95.     self.enemy = other;
  96.     multi_trigger ();
  97. };
  98.  
  99. /*QUAKED trigger_multiple (.5 .5 .5) ? notouch
  100. 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.
  101. If "delay" is set, the trigger waits some time after activating before firing.
  102. "wait" : Seconds between triggerings. (.2 default)
  103. If notouch is set, the trigger is only fired by other entities, not by touching.
  104. NOTOUCH has been obsoleted by trigger_relay!
  105. sounds
  106. 1)    secret
  107. 2)    beep beep
  108. 3)    large switch
  109. 4)
  110. set "message" to text string
  111. */
  112. void() trigger_multiple =
  113. {
  114.     if (self.sounds == 1)
  115.     {
  116.         precache_sound ("misc/secret.wav");
  117.         self.noise = "misc/secret.wav";
  118.     }
  119.     else if (self.sounds == 2)
  120.     {
  121.         precache_sound ("misc/talk.wav");
  122.         self.noise = "misc/talk.wav";
  123.     }
  124.     else if (self.sounds == 3)
  125.     {
  126.         precache_sound ("misc/trigger1.wav");
  127.         self.noise = "misc/trigger1.wav";
  128.     }
  129.     
  130.     if (!self.wait)
  131.         self.wait = 0.2;
  132.     self.use = multi_use;
  133.  
  134.     InitTrigger ();
  135.  
  136.     if (self.health)
  137.     {
  138.         if (self.spawnflags & SPAWNFLAG_NOTOUCH)
  139.             objerror ("health and notouch don't make sense\n");
  140.         self.max_health = self.health;
  141.         self.th_die = multi_killed;
  142.         self.takedamage = DAMAGE_YES;
  143.         self.solid = SOLID_BBOX;
  144.         self.flags = FL_OBJECT;            //ws
  145.         setorigin (self, self.origin);    // make sure it links into the world
  146.     }
  147.     else
  148.     {
  149.         if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) )
  150.         {
  151.             self.touch = multi_touch;
  152.         }
  153.     }
  154. };
  155.  
  156.  
  157. /*QUAKED trigger_once (.5 .5 .5) ? notouch
  158. 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
  159. "targetname".  If "health" is set, the trigger must be killed to activate.
  160. If notouch is set, the trigger is only fired by other entities, not by touching.
  161. if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
  162. 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.
  163. sounds
  164. 1)    secret
  165. 2)    beep beep
  166. 3)    large switch
  167. 4)
  168. set "message" to text string
  169. */
  170. void() trigger_once =
  171. {
  172.     self.wait = -1;
  173.     trigger_multiple();
  174. };
  175.  
  176. //=============================================================================
  177.  
  178. /*QUAKED trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
  179. This fixed size trigger cannot be touched, it can only be fired by other events.  It can contain killtargets, targets, delays, and messages.
  180. */
  181. void() trigger_relay =
  182. {
  183.     self.use = SUB_UseTargets;
  184. };
  185.  
  186.  
  187. //=============================================================================
  188.  
  189. /*QUAKED trigger_secret (.5 .5 .5) ?
  190. secret counter trigger
  191. sounds
  192. 1)    secret
  193. 2)    beep beep
  194. 3)
  195. 4)
  196. set "message" to text string
  197. */
  198. void() trigger_secret =
  199. {
  200.     total_secrets = total_secrets + 1;
  201.     self.wait = -1;
  202.     if (!self.message)
  203.         self.message = "You found a secret area!";
  204.     if (!self.sounds)
  205.         self.sounds = 1;
  206.     
  207.     if (self.sounds == 1)
  208.     {
  209.         precache_sound ("misc/secret.wav");
  210.         self.noise = "misc/secret.wav";
  211.     }
  212.     else if (self.sounds == 2)
  213.     {
  214.         precache_sound ("misc/talk.wav");
  215.         self.noise = "misc/talk.wav";
  216.     }
  217.  
  218.     trigger_multiple ();
  219. };
  220.  
  221. //=============================================================================
  222.  
  223.  
  224. void() counter_use =
  225. {
  226.     local string junk;
  227.  
  228.     self.count = self.count - 1;
  229.     if (self.count < 0)
  230.         return;
  231.     
  232.     if (self.count != 0)
  233.     {
  234.         if (activator.classname == "player"
  235.         && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  236.         {
  237.             if (self.count >= 4)
  238.                 centerprint (activator, "There are more to go...");
  239.             else if (self.count == 3)
  240.                 centerprint (activator, "Only 3 more to go...");
  241.             else if (self.count == 2)
  242.                 centerprint (activator, "Only 2 more to go...");
  243.             else
  244.                 centerprint (activator, "Only 1 more to go...");
  245.         }
  246.         return;
  247.     }
  248.     
  249.     if (activator.classname == "player"
  250.     && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
  251.         centerprint(activator, "Sequence completed!");
  252.     self.enemy = activator;
  253.     multi_trigger ();
  254. };
  255.  
  256. /*QUAKED trigger_counter (.5 .5 .5) ? nomessage
  257. Acts as an intermediary for an action that takes multiple inputs.
  258.  
  259. If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
  260.  
  261. After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
  262. */
  263. void() trigger_counter =
  264. {
  265.     self.wait = -1;
  266.     if (!self.count)
  267.         self.count = 2;
  268.  
  269.     self.use = counter_use;
  270. };
  271.  
  272.  
  273. /*
  274. ==============================================================================
  275.  
  276. TELEPORT TRIGGERS
  277.  
  278. ==============================================================================
  279. */
  280.  
  281. float    PLAYER_ONLY    = 1;
  282. float    SILENT = 2;
  283.  
  284. void() play_teleport =
  285. {
  286.     local    float v;
  287.     local    string tmpstr;
  288.  
  289.     v = random() * 5;
  290.     if (v < 1)
  291.         tmpstr = "misc/r_tele1.wav";
  292.     else if (v < 2)
  293.         tmpstr = "misc/r_tele2.wav";
  294.     else if (v < 3)
  295.         tmpstr = "misc/r_tele3.wav";
  296.     else if (v < 4)
  297.         tmpstr = "misc/r_tele4.wav";
  298.     else
  299.         tmpstr = "misc/r_tele5.wav";
  300.  
  301.     sound (self, CHAN_VOICE, tmpstr, 1, ATTN_NORM);
  302.     remove (self);
  303. };
  304.  
  305. void(vector org) spawn_tfog =
  306. {
  307.     s = spawn ();
  308.     s.origin = org;
  309.     s.nextthink = time + 0.2;
  310.     s.think = play_teleport;
  311.  
  312.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  313.     WriteByte (MSG_BROADCAST, TE_TELEPORT);
  314.     WriteCoord (MSG_BROADCAST, org_x);
  315.     WriteCoord (MSG_BROADCAST, org_y);
  316.     WriteCoord (MSG_BROADCAST, org_z);
  317. };
  318.  
  319.  
  320. void() tdeath_touch =
  321. {
  322.     if (other == self.owner)
  323.         return;
  324.  
  325. // frag anyone who teleports in on top of an invincible player
  326.     if (other.classname == "player")
  327.     {
  328.         if (other.invincible_finished > time)
  329.             self.classname = "teledeath2";
  330.         if (self.owner.classname != "player")
  331.         {    // other monsters explode themselves
  332.             T_Damage (self.owner, self, self, 50000);
  333.             return;
  334.         }
  335.         
  336.     }
  337.  
  338.     if (other.health)
  339.     {
  340.         T_Damage (other, self, self, 50000);
  341.     }
  342. };
  343.  
  344.  
  345. void(vector org, entity death_owner) spawn_tdeath =
  346. {
  347. local entity    death;
  348.  
  349.     death = spawn();
  350.     death.classname = "teledeath";
  351.     death.movetype = MOVETYPE_NONE;
  352.     death.solid = SOLID_TRIGGER;
  353.     death.angles = '0 0 0';
  354.     setsize (death, death_owner.mins - '1 1 1', death_owner.maxs + '1 1 1');
  355.     setorigin (death, org);
  356.     death.touch = tdeath_touch;
  357.     death.nextthink = time + 0.2;
  358.     death.think = SUB_Remove;
  359.     death.owner = death_owner;
  360.     
  361.     force_retouch = 2;        // make sure even still objects get hit
  362. };
  363.  
  364. void() teleport_touch =
  365. {
  366. local entity    t;
  367. local vector    org;
  368.  
  369.     if (self.targetname)
  370.     {
  371.         if (self.nextthink < time)
  372.         {
  373.             return;        // not fired yet
  374.         }
  375.     }
  376.  
  377.     if (self.spawnflags & PLAYER_ONLY)
  378.     {
  379.         if (other.classname != "player")
  380.             return;
  381.     }
  382.  
  383. // only teleport living creatures
  384.     if (other.health <= 0 || other.solid != SOLID_SLIDEBOX)
  385.         return;
  386.  
  387.     SUB_UseTargets ();
  388.  
  389. // put a tfog where the player was
  390.     spawn_tfog (other.origin);
  391.  
  392.     t = find (world, targetname, self.target);
  393.     if (!t)
  394.         objerror ("couldn't find target");
  395.         
  396. // spawn a tfog flash in front of the destination
  397.     makevectors (t.mangle);
  398.     org = t.origin + 32 * v_forward;
  399.  
  400.     spawn_tfog (org);
  401.     spawn_tdeath(t.origin, other);
  402.  
  403. // move the player and lock him down for a little while
  404.     if (!other.health)
  405.     {
  406.         other.origin = t.origin;
  407.         other.velocity = (v_forward * other.velocity_x) + (v_forward * other.velocity_y);
  408.         return;
  409.     }
  410.  
  411.     setorigin (other, t.origin);
  412.     other.angles = t.mangle;
  413.     if (other.classname == "player")
  414.     {
  415.         other.fixangle = 1;        // turn this way immediately
  416.         other.teleport_time = time + 0.7;
  417.         if (other.flags & FL_ONGROUND)
  418.             other.flags = other.flags - FL_ONGROUND;
  419.         other.velocity = v_forward * 300;
  420.     }
  421.     other.flags = other.flags - other.flags & FL_ONGROUND;
  422. };
  423.  
  424. /*QUAKED info_teleport_destination (.5 .5 .5) (-8 -8 -8) (8 8 32)
  425. This is the destination marker for a teleporter.  It should have a "targetname" field with the same value as a teleporter's "target" field.
  426. */
  427. void() info_teleport_destination =
  428. {
  429. // this does nothing, just serves as a target spot
  430.     self.mangle = self.angles;
  431.     self.angles = '0 0 0';
  432.     self.model = "";
  433.     self.origin = self.origin + '0 0 27';
  434.     if (!self.targetname)
  435.         objerror ("no targetname");
  436. };
  437.  
  438. void() teleport_use =
  439. {
  440.     self.nextthink = time + 0.2;
  441.     force_retouch = 2;        // make sure even still objects get hit
  442.     self.think = SUB_Null;
  443. };
  444.  
  445. /*QUAKED trigger_teleport (.5 .5 .5) ? PLAYER_ONLY SILENT
  446. 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.
  447.  
  448. If the trigger_teleport has a targetname, it will only teleport entities when it has been fired.
  449. */
  450. void() trigger_teleport =
  451. {
  452.     local vector o;
  453.  
  454.     InitTrigger ();
  455.     self.touch = teleport_touch;
  456.     // find the destination 
  457.     if (!self.target)
  458.         objerror ("no target");
  459.     self.use = teleport_use;
  460.  
  461.     if (!(self.spawnflags & SILENT))
  462.     {
  463.         precache_sound ("ambience/hum1.wav");
  464.         o = (self.mins + self.maxs)*0.5;
  465.         ambientsound (o, "ambience/hum1.wav",0.5 , ATTN_STATIC);
  466.     }
  467. };
  468.  
  469. /*
  470. ==============================================================================
  471.  
  472. trigger_setskill
  473.  
  474. ==============================================================================
  475. */
  476.  
  477. void() trigger_skill_touch =
  478. {
  479.     if (other.classname != "player")
  480.         return;
  481.         
  482.     cvar_set ("skill", self.message);
  483. };
  484.  
  485. /*QUAKED trigger_setskill (.5 .5 .5) ?
  486. sets skill level to the value of "message".
  487. Only used on start map.
  488. */
  489. void() trigger_setskill =
  490. {
  491.     InitTrigger ();
  492.     self.touch = trigger_skill_touch;
  493. };
  494.  
  495.  
  496. /*
  497. ==============================================================================
  498.  
  499. ONLY REGISTERED TRIGGERS
  500.  
  501. ==============================================================================
  502. */
  503.  
  504. void() trigger_onlyregistered_touch =
  505. {
  506.     if (other.classname != "player")
  507.         return;
  508.     if (self.attack_finished > time)
  509.         return;
  510.  
  511.     self.attack_finished = time + 2;
  512.     if (cvar("registered"))
  513.     {
  514.         self.message = "";
  515.         SUB_UseTargets ();
  516.         remove (self);
  517.     }
  518.     else
  519.     {
  520.         if (self.message != "")
  521.         {
  522.             centerprint (other, self.message);
  523.             sound (other, CHAN_BODY, "misc/talk.wav", 1, ATTN_NORM);
  524.         }
  525.     }
  526. };
  527.  
  528. /*QUAKED trigger_onlyregistered (.5 .5 .5) ?
  529. Only fires if playing the registered version, otherwise prints the message
  530. */
  531. void() trigger_onlyregistered =
  532. {
  533.     precache_sound ("misc/talk.wav");
  534.     InitTrigger ();
  535.     self.touch = trigger_onlyregistered_touch;
  536. };
  537.  
  538. //============================================================================
  539.  
  540. void() hurt_on =
  541. {
  542.     self.solid = SOLID_TRIGGER;
  543.     self.nextthink = -1;
  544. };
  545.  
  546. void() hurt_touch =
  547. {
  548.     if (other.takedamage)
  549.     {
  550.         self.solid = SOLID_NOT;
  551.         T_Damage (other, self, self, self.dmg);
  552.         self.think = hurt_on;
  553.         self.nextthink = time + 1;
  554.     }
  555.  
  556.     return;
  557. };
  558.  
  559. /*QUAKED trigger_hurt (.5 .5 .5) ?
  560. Any object touching this will be hurt
  561. set dmg to damage amount
  562. defalt dmg = 5
  563. */
  564. void() trigger_hurt =
  565. {
  566.     InitTrigger ();
  567.     self.touch = hurt_touch;
  568.     if (!self.dmg)
  569.         self.dmg = 5;
  570. };
  571.  
  572. //============================================================================
  573.  
  574. float PUSH_ONCE = 1;
  575.  
  576. void() trigger_push_touch =
  577. {
  578.     if (other.classname == "grenade")
  579.         other.velocity = self.speed * self.movedir * 10;
  580.     else if (other.health > 0)
  581.     {
  582.         other.velocity = self.speed * self.movedir * 10;
  583.         if (other.classname == "player")
  584.         {
  585.             if (other.fly_sound < time)
  586.             {
  587.                 other.fly_sound = time + 1.5;
  588.                 sound (other, CHAN_AUTO, "ambience/windfly.wav", 1, ATTN_NORM);
  589.             }
  590.         }
  591.     }
  592.     if (self.spawnflags & PUSH_ONCE)
  593.         remove(self);
  594. };
  595.  
  596.  
  597. /*QUAKED trigger_push (.5 .5 .5) ? PUSH_ONCE
  598. Pushes the player
  599. */
  600. void() trigger_push =
  601. {
  602.     InitTrigger ();
  603.     precache_sound ("ambience/windfly.wav");
  604.     self.touch = trigger_push_touch;
  605.     if (!self.speed)
  606.         self.speed = 1000;
  607. };
  608.  
  609. //============================================================================
  610.  
  611. void() trigger_monsterjump_touch =
  612. {
  613.     if ( other.flags & (FL_MONSTER | FL_FLY | FL_SWIM) != FL_MONSTER )
  614.         return;
  615.  
  616. // set XY even if not on ground, so the jump will clear lips
  617.     other.velocity_x = self.movedir_x * self.speed;
  618.     other.velocity_y = self.movedir_y * self.speed;
  619.     
  620.     if ( !(other.flags & FL_ONGROUND) )
  621.         return;
  622.     
  623.     other.flags = other.flags - FL_ONGROUND;
  624.  
  625.     other.velocity_z = self.height;
  626. };
  627.  
  628. /*QUAKED trigger_monsterjump (.5 .5 .5) ?
  629. Walking monsters that touch this will jump in the direction of the trigger's angle
  630. "speed" default to 200, the speed thrown forward
  631. "height" default to 200, the speed thrown upwards
  632. */
  633. void() trigger_monsterjump =
  634. {
  635.     if (!self.speed)
  636.         self.speed = 200;
  637.     if (!self.height)
  638.         self.height = 200;
  639.     if (self.angles == '0 0 0')
  640.         self.angles = '0 360 0';
  641.     InitTrigger ();
  642.     self.touch = trigger_monsterjump_touch;
  643. };
  644.  
  645.