6 activator = self.enemy;
12 ==============================
15 the global "activator" should be set to the entity that initiated the firing.
17 If self.delay is set, a DelayedUse entity will be created that will actually
18 do the SUB_UseTargets after that many seconds have passed.
20 Centerprints any self.message to the activator.
22 Removes all entities with a targetname that match self.killtarget,
23 and removes them, so some events can remove other triggers.
25 Search for (string)targetname in all entities that
26 match (string)self.target and call their .use function
28 ==============================
32 local entity t, stemp, otemp, act;
41 // create a temp object to fire at a later time
43 t.classname = "DelayedUse";
44 t.nextthink = time + self.delay;
47 t.message = self.message;
48 t.killtarget = self.killtarget;
49 t.target = self.target;
57 if (activator.classname == "player" && self.message != "")
59 if(clienttype(activator) == CLIENTTYPE_REAL)
61 centerprint (activator, self.message);
63 play2(activator, "misc/talk.wav");
68 // kill the killtagets
73 for(t = world; (t = find(t, targetname, s)); )
84 for(i = 0; i < 4; ++i)
89 case 0: s = stemp.target; break;
90 case 1: s = stemp.target2; break;
91 case 2: s = stemp.target3; break;
92 case 3: s = stemp.target4; break;
96 for(t = world; (t = find(t, targetname, s)); )
99 //print(stemp.classname, " ", stemp.targetname, " -> ", t.classname, " ", t.targetname, "\n");
114 //=============================================================================
116 float SPAWNFLAG_NOMESSAGE = 1;
117 float SPAWNFLAG_NOTOUCH = 1;
119 // the wait time has passed, so set back up for another activation
124 self.health = self.max_health;
125 self.takedamage = DAMAGE_YES;
126 self.solid = SOLID_BBOX;
131 // the trigger was just touched/killed/used
132 // self.enemy should be set to the activator so it can be held through a delay
133 // so wait for the delay time before firing
136 if (self.nextthink > time)
138 return; // allready been triggered
141 if (self.classname == "trigger_secret")
143 if (self.enemy.classname != "player")
145 found_secrets = found_secrets + 1;
146 WriteByte (MSG_ALL, SVC_FOUNDSECRET);
150 sound (self.enemy, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NORM);
152 // don't trigger again until reset
153 self.takedamage = DAMAGE_NO;
155 activator = self.enemy;
161 self.think = multi_wait;
162 self.nextthink = time + self.wait;
165 { // we can't just remove (self) here, because this is a touch function
166 // called wheil C code is looping through area links...
167 self.touch = SUB_Null;
169 self.nextthink = time + 0.1;
170 self.think = SUB_Remove;
176 self.enemy = activator;
182 if not(self.spawnflags & 2)
184 if not(other.iscreature)
188 if(self.team == other.team)
192 // if the trigger has an angles field, check player's facing direction
193 if (self.movedir != '0 0 0')
195 makevectors (other.angles);
196 if (v_forward * self.movedir < 0)
197 return; // not facing the right way
206 void multi_eventdamage (vector hitloc, float damage, entity inflictor, entity attacker, float deathtype)
208 if (!self.takedamage)
210 self.health = self.health - damage;
211 if (self.health <= 0)
213 self.enemy = attacker;
218 /*QUAKED spawnfunc_trigger_multiple (.5 .5 .5) ? notouch
219 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.
220 If "delay" is set, the trigger waits some time after activating before firing.
221 "wait" : Seconds between triggerings. (.2 default)
222 If notouch is set, the trigger is only fired by other entities, not by touching.
223 NOTOUCH has been obsoleted by spawnfunc_trigger_relay!
229 set "message" to text string
231 void spawnfunc_trigger_multiple()
233 if (self.sounds == 1)
235 precache_sound ("misc/secret.wav");
236 self.noise = "misc/secret.wav";
238 else if (self.sounds == 2)
240 precache_sound ("misc/talk.wav");
241 self.noise = "misc/talk.wav";
243 else if (self.sounds == 3)
245 precache_sound ("misc/trigger1.wav");
246 self.noise = "misc/trigger1.wav";
251 self.use = multi_use;
257 if (self.spawnflags & SPAWNFLAG_NOTOUCH)
258 objerror ("health and notouch don't make sense\n");
259 self.max_health = self.health;
260 self.event_damage = multi_eventdamage;
261 self.takedamage = DAMAGE_YES;
262 self.solid = SOLID_BBOX;
263 setorigin (self, self.origin); // make sure it links into the world
267 if ( !(self.spawnflags & SPAWNFLAG_NOTOUCH) )
269 self.touch = multi_touch;
270 setorigin (self, self.origin); // make sure it links into the world
276 /*QUAKED spawnfunc_trigger_once (.5 .5 .5) ? notouch
277 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
278 "targetname". If "health" is set, the trigger must be killed to activate.
279 If notouch is set, the trigger is only fired by other entities, not by touching.
280 if "killtarget" is set, any objects that have a matching "target" will be removed when the trigger is fired.
281 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.
287 set "message" to text string
289 void spawnfunc_trigger_once()
292 spawnfunc_trigger_multiple();
295 //=============================================================================
297 /*QUAKED spawnfunc_trigger_relay (.5 .5 .5) (-8 -8 -8) (8 8 8)
298 This fixed size trigger cannot be touched, it can only be fired by other events. It can contain killtargets, targets, delays, and messages.
300 void spawnfunc_trigger_relay()
302 self.use = SUB_UseTargets;
307 self.think = SUB_UseTargets;
308 self.nextthink = self.wait;
311 void spawnfunc_trigger_delay()
316 self.use = delay_use;
319 //=============================================================================
324 self.count = self.count - 1;
330 if (activator.classname == "player"
331 && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
334 centerprint (activator, "There are more to go...");
335 else if (self.count == 3)
336 centerprint (activator, "Only 3 more to go...");
337 else if (self.count == 2)
338 centerprint (activator, "Only 2 more to go...");
340 centerprint (activator, "Only 1 more to go...");
345 if (activator.classname == "player"
346 && (self.spawnflags & SPAWNFLAG_NOMESSAGE) == 0)
347 centerprint(activator, "Sequence completed!");
348 self.enemy = activator;
352 /*QUAKED spawnfunc_trigger_counter (.5 .5 .5) ? nomessage
353 Acts as an intermediary for an action that takes multiple inputs.
355 If nomessage is not set, t will print "1 more.. " etc when triggered and "sequence complete" when finished.
357 After the counter has been triggered "count" times (default 2), it will fire all of it's targets and remove itself.
359 void spawnfunc_trigger_counter()
365 self.use = counter_use;
368 .float triggerhurttime;
369 void trigger_hurt_touch()
371 // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu)
372 if (other.iscreature)
374 if (other.takedamage)
375 if (other.triggerhurttime < time)
378 other.triggerhurttime = time + 1;
379 Damage (other, self, self, self.dmg, DEATH_HURTTRIGGER, other.origin, '0 0 0');
386 if (other.items & IT_KEY1 || other.items & IT_KEY2) // reset flag
389 other.pain_finished = min(other.pain_finished, time + 2);
391 else if (other.classname == "rune") // reset runes
394 other.nextthink = min(other.nextthink, time + 1);
402 /*QUAKED spawnfunc_trigger_hurt (.5 .5 .5) ?
403 Any object touching this will be hurt
404 set dmg to damage amount
407 .entity trigger_hurt_next;
408 entity trigger_hurt_last;
409 entity trigger_hurt_first;
410 void spawnfunc_trigger_hurt()
413 self.touch = trigger_hurt_touch;
417 self.message = "was in the wrong place";
419 self.message2 = "was thrown into a world of hurt by";
421 if(!trigger_hurt_first)
422 trigger_hurt_first = self;
423 if(trigger_hurt_last)
424 trigger_hurt_last.trigger_hurt_next = self;
425 trigger_hurt_last = self;
428 float tracebox_hits_trigger_hurt(vector start, vector mi, vector ma, vector end)
432 for(th = trigger_hurt_first; th; th = th.trigger_hurt_next)
433 if(tracebox_hits_box(start, mi, ma, end, th.absmin, th.absmax))
439 //////////////////////////////////////////////////////////////
443 //Trigger heal --a04191b92fbd93aa67214ef7e72d6d2e
445 //////////////////////////////////////////////////////////////
447 .float triggerhealtime;
448 void trigger_heal_touch()
450 // only do the EXACTTRIGGER_TOUCH checks when really needed (saves some cpu)
451 if (other.iscreature)
453 if (other.takedamage)
454 if (other.triggerhealtime < time)
457 other.triggerhealtime = time + 1;
459 if (other.health < self.max_health)
461 other.health = min(other.health + self.health, self.max_health);
462 other.pauserothealth_finished = max(other.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
463 sound (other, CHAN_AUTO, self.noise, VOL_BASE, ATTN_NORM);
469 void spawnfunc_trigger_heal()
472 self.touch = trigger_heal_touch;
475 if (!self.max_health)
476 self.max_health = 200; //Max health topoff for field
478 self.noise = "misc/mediumhealth.wav";
479 precache_sound(self.noise);
483 //////////////////////////////////////////////////////////////
489 //////////////////////////////////////////////////////////////
493 // TODO add a way to do looped sounds with sound(); then complete this entity
494 .float volume, atten;
495 void target_speaker_use() {sound(self, CHAN_TRIGGER, self.noise, VOL_BASE * self.volume, self.atten);}
497 void spawnfunc_target_speaker()
500 precache_sound (self.noise);
504 self.atten = ATTN_NORM;
505 else if(self.atten < 0)
509 self.use = target_speaker_use;
514 self.atten = ATTN_STATIC;
515 else if(self.atten < 0)
519 ambientsound (self.origin, self.noise, VOL_BASE * self.volume, self.atten);
524 void spawnfunc_func_stardust() {
525 self.effects = EF_STARDUST;
528 float pointparticles_SendEntity(entity to, float fl)
530 WriteByte(MSG_ENTITY, ENT_CLIENT_POINTPARTICLES);
531 WriteByte(MSG_ENTITY, fl);
535 WriteCoord(MSG_ENTITY, self.impulse);
537 WriteCoord(MSG_ENTITY, 0); // off
541 WriteCoord(MSG_ENTITY, self.origin_x);
542 WriteCoord(MSG_ENTITY, self.origin_y);
543 WriteCoord(MSG_ENTITY, self.origin_z);
547 if(self.model != "null")
549 WriteShort(MSG_ENTITY, self.modelindex);
550 WriteCoord(MSG_ENTITY, self.mins_x);
551 WriteCoord(MSG_ENTITY, self.mins_y);
552 WriteCoord(MSG_ENTITY, self.mins_z);
553 WriteCoord(MSG_ENTITY, self.maxs_x);
554 WriteCoord(MSG_ENTITY, self.maxs_y);
555 WriteCoord(MSG_ENTITY, self.maxs_z);
559 WriteShort(MSG_ENTITY, 0);
560 WriteCoord(MSG_ENTITY, self.maxs_x);
561 WriteCoord(MSG_ENTITY, self.maxs_y);
562 WriteCoord(MSG_ENTITY, self.maxs_z);
564 WriteShort(MSG_ENTITY, self.cnt);
565 WriteShort(MSG_ENTITY, compressShortVector(self.velocity));
566 WriteShort(MSG_ENTITY, compressShortVector(self.movedir));
567 WriteCoord(MSG_ENTITY, self.waterlevel);
568 WriteCoord(MSG_ENTITY, self.count);
569 WriteByte(MSG_ENTITY, self.glow_color);
570 WriteString(MSG_ENTITY, self.noise);
575 void pointparticles_use()
577 self.state = !self.state;
581 void pointparticles_think()
583 if(self.origin != self.oldorigin)
586 self.oldorigin = self.origin;
588 self.nextthink = time;
591 void spawnfunc_func_pointparticles()
594 setmodel(self, self.model);
596 precache_sound (self.noise);
598 self.effects = EF_NODEPTHTEST;
599 self.SendEntity = pointparticles_SendEntity;
603 vector misave, masave;
606 setmodel(self, "null");
607 setorigin(self, self.origin + misave);
608 setsize(self, '0 0 0', masave - misave);
611 self.cnt = particleeffectnum(self.mdl);
614 self.use = pointparticles_use;
615 if(self.spawnflags & 1)
622 self.think = pointparticles_think;
623 self.nextthink = time;
626 void spawnfunc_func_sparks()
628 // self.cnt is the amount of sparks that one burst will spawn
630 self.cnt = 25.0; // nice default value
633 // self.wait is the probability that a sparkthink will spawn a spark shower
634 // range: 0 - 1, but 0 makes little sense, so...
635 if(self.wait < 0.05) {
636 self.wait = 0.25; // nice default value
639 self.count = self.cnt;
642 self.velocity = '0 0 -1';
643 self.mdl = "TE_SPARK";
644 self.impulse = 10 * self.wait; // by default 2.5/sec
646 self.cnt = 0; // use mdl
648 spawnfunc_func_pointparticles();
651 float rainsnow_SendEntity(float to)
653 WriteByte(MSG_ENTITY, ENT_CLIENT_RAINSNOW);
654 WriteByte(MSG_ENTITY, self.state);
655 WriteCoord(MSG_ENTITY, self.origin_x + self.mins_x);
656 WriteCoord(MSG_ENTITY, self.origin_y + self.mins_y);
657 WriteCoord(MSG_ENTITY, self.origin_z + self.mins_z);
658 WriteCoord(MSG_ENTITY, self.maxs_x - self.mins_x);
659 WriteCoord(MSG_ENTITY, self.maxs_y - self.mins_y);
660 WriteCoord(MSG_ENTITY, self.maxs_z - self.mins_z);
661 WriteShort(MSG_ENTITY, compressShortVector(self.dest));
662 WriteShort(MSG_ENTITY, self.count);
663 WriteByte(MSG_ENTITY, self.cnt);
667 /*QUAKED spawnfunc_func_rain (0 .5 .8) ?
668 This is an invisible area like a trigger, which rain falls inside of.
672 falling direction (should be something like '0 0 -700', use the X and Y velocity for wind)
674 sets color of rain (default 12 - white)
676 adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
678 void spawnfunc_func_rain()
680 self.dest = self.velocity;
681 self.velocity = '0 0 0';
683 self.dest = '0 0 -700';
684 self.angles = '0 0 0';
685 self.movetype = MOVETYPE_NONE;
686 self.solid = SOLID_NOT;
687 SetBrushEntityModel();
692 self.count = 0.01 * self.count * (self.size_x / 1024) * (self.size_y / 1024);
695 if(self.count > 65535)
698 self.state = 1; // 1 is rain, 0 is snow
699 self.effects = EF_NODEPTHTEST;
700 self.SendEntity = rainsnow_SendEntity;
705 vector misave, masave;
708 setmodel(self, "null");
709 setsize(self, misave, masave);
714 /*QUAKED spawnfunc_func_snow (0 .5 .8) ?
715 This is an invisible area like a trigger, which snow falls inside of.
719 falling direction (should be something like '0 0 -300', use the X and Y velocity for wind)
721 sets color of rain (default 12 - white)
723 adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
725 void spawnfunc_func_snow()
727 self.dest = self.velocity;
728 self.velocity = '0 0 0';
730 self.dest = '0 0 -300';
731 self.angles = '0 0 0';
732 self.movetype = MOVETYPE_NONE;
733 self.solid = SOLID_NOT;
734 SetBrushEntityModel();
739 self.count = 0.01 * self.count * (self.size_x / 1024) * (self.size_y / 1024);
742 if(self.count > 65535)
745 self.state = 0; // 1 is rain, 0 is snow
746 self.effects = EF_NODEPTHTEST;
747 self.SendEntity = rainsnow_SendEntity;
752 vector misave, masave;
755 setmodel(self, "null");
756 setsize(self, misave, masave);
761 void FireRailgunBullet (vector start, vector end, float bdamage, float bforce, float deathtype);
763 void misc_laser_aim()
768 if(self.spawnflags & 2)
770 if(self.enemy.origin != self.mangle)
772 self.mangle = self.enemy.origin;
778 a = vectoangles(self.enemy.origin - self.origin);
789 if(self.angles != self.mangle)
791 self.mangle = self.angles;
795 if(self.origin != self.oldorigin)
798 self.oldorigin = self.origin;
802 void misc_laser_init()
804 if(self.target != "")
805 self.enemy = find(world, targetname, self.target);
809 void misc_laser_think()
814 self.nextthink = time;
823 o = self.enemy.origin;
824 if not(self.spawnflags & 2)
825 o = self.origin + normalize(o - self.origin) * 32768;
829 makevectors(self.mangle);
830 o = self.origin + v_forward * 32768;
836 FireRailgunBullet(self.origin, o, 100000, 0, DEATH_HURTTRIGGER);
838 FireRailgunBullet(self.origin, o, self.dmg * frametime, 0, DEATH_HURTTRIGGER);
841 if(self.enemy.target != "") // DETECTOR laser
843 traceline(self.origin, o, MOVE_NORMAL, self);
844 if(trace_ent.iscreature)
846 self.pusher = trace_ent;
853 activator = self.pusher;
866 activator = self.pusher;
874 float laser_SendEntity(entity to, float fl)
876 WriteByte(MSG_ENTITY, ENT_CLIENT_LASER);
877 fl = fl - (fl & 0xC0); // use that bit to indicate finite length laser
878 if(self.spawnflags & 2)
882 WriteByte(MSG_ENTITY, fl);
885 WriteCoord(MSG_ENTITY, self.origin_x);
886 WriteCoord(MSG_ENTITY, self.origin_y);
887 WriteCoord(MSG_ENTITY, self.origin_z);
891 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
892 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
893 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
895 WriteByte(MSG_ENTITY, self.alpha * 255.0);
896 WriteShort(MSG_ENTITY, self.cnt + 1);
902 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
903 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
904 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
908 WriteCoord(MSG_ENTITY, self.mangle_x);
909 WriteCoord(MSG_ENTITY, self.mangle_y);
913 WriteByte(MSG_ENTITY, self.state);
917 /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED
918 Any object touching the beam will be hurt
921 spawnfunc_target_position where the laser ends
923 name of beam end effect to use
925 color of the beam (default: red)
927 damage per second (-1 for a laser that kills immediately)
931 self.state = !self.state;
936 void spawnfunc_misc_laser()
940 if(self.mdl == "none")
944 self.cnt = particleeffectnum(self.mdl);
947 self.cnt = particleeffectnum("laser_deadly");
953 self.cnt = particleeffectnum("laser_deadly");
960 if(self.colormod == '0 0 0')
962 self.colormod = '1 0 0';
964 self.message = "saw the light";
966 self.message2 = "was pushed into a laser by";
967 self.think = misc_laser_think;
968 self.nextthink = time;
969 InitializeEntity(self, misc_laser_init, INITPRIO_FINDTARGET);
971 self.effects = EF_NODEPTHTEST;
972 self.SendEntity = laser_SendEntity;
974 setmodel(self, "null");
975 self.mangle = self.angles;
979 self.use = laser_use;
980 if(self.spawnflags & 1)
989 // tZorks trigger impulse / gravity
995 // targeted (directional) mode
996 void trigger_impulse_touch1()
1002 // FIXME: Better checking for what to push and not.
1003 if not(other.iscreature)
1004 if (other.classname != "corpse")
1005 if (other.classname != "body")
1006 if (other.classname != "gib")
1007 if (other.classname != "missile")
1008 if (other.classname != "rocket")
1009 if (other.classname != "casing")
1010 if (other.classname != "grenade")
1011 if (other.classname != "plasma")
1012 if (other.classname != "plasma_prim")
1013 if (other.classname != "plasma_chain")
1014 if (other.classname != "droppedweapon")
1017 if (other.deadflag && other.iscreature)
1022 targ = find(world, targetname, self.target);
1025 objerror("trigger_force without a (valid) .target!\n");
1030 if(self.falloff == 1)
1031 str = (str / self.radius) * self.strength;
1032 else if(self.falloff == 2)
1033 str = (1 - (str / self.radius)) * self.strength;
1035 str = self.strength;
1037 pushdeltatime = time - other.lastpushtime;
1038 if (pushdeltatime > 0.15) pushdeltatime = 0;
1039 other.lastpushtime = time;
1040 if(!pushdeltatime) return;
1042 other.velocity = other.velocity + normalize(targ.origin - self.origin) * self.strength * pushdeltatime;
1045 // Directionless (accelerator/decelerator) mode
1046 void trigger_impulse_touch2()
1048 float pushdeltatime;
1050 // FIXME: Better checking for what to push and not.
1051 if not(other.iscreature)
1052 if (other.classname != "corpse")
1053 if (other.classname != "body")
1054 if (other.classname != "gib")
1055 if (other.classname != "missile")
1056 if (other.classname != "rocket")
1057 if (other.classname != "casing")
1058 if (other.classname != "grenade")
1059 if (other.classname != "plasma")
1060 if (other.classname != "plasma_prim")
1061 if (other.classname != "plasma_chain")
1062 if (other.classname != "droppedweapon")
1065 if (other.deadflag && other.iscreature)
1070 pushdeltatime = time - other.lastpushtime;
1071 if (pushdeltatime > 0.15) pushdeltatime = 0;
1072 other.lastpushtime = time;
1073 if(!pushdeltatime) return;
1075 //if(self.strength > 1)
1076 other.velocity = other.velocity * (self.strength * pushdeltatime);
1078 // other.velocity = other.velocity - (other.velocity * self.strength * pushdeltatime);
1081 // Spherical (gravity/repulsor) mode
1082 void trigger_impulse_touch3()
1084 float pushdeltatime;
1087 // FIXME: Better checking for what to push and not.
1088 if not(other.iscreature)
1089 if (other.classname != "corpse")
1090 if (other.classname != "body")
1091 if (other.classname != "gib")
1092 if (other.classname != "missile")
1093 if (other.classname != "rocket")
1094 if (other.classname != "casing")
1095 if (other.classname != "grenade")
1096 if (other.classname != "plasma")
1097 if (other.classname != "plasma_prim")
1098 if (other.classname != "plasma_chain")
1099 if (other.classname != "droppedweapon")
1102 if (other.deadflag && other.iscreature)
1107 pushdeltatime = time - other.lastpushtime;
1108 if (pushdeltatime > 0.15) pushdeltatime = 0;
1109 other.lastpushtime = time;
1110 if(!pushdeltatime) return;
1112 setsize(self, '-1 -1 -1' * self.radius,'1 1 1' * self.radius);
1114 str = min(self.radius, vlen(self.origin - other.origin));
1116 if(self.falloff == 1)
1117 str = (1 - str / self.radius) * self.strength; // 1 in the inside
1118 else if(self.falloff == 2)
1119 str = (str / self.radius) * self.strength; // 0 in the inside
1121 str = self.strength;
1123 other.velocity = other.velocity + normalize(other.origin - self.origin) * str * pushdeltatime;
1126 /*QUAKED spawnfunc_trigger_impulse (.5 .5 .5) ?
1127 -------- KEYS --------
1128 target : If this is set, this points to the spawnfunc_target_position to which the player will get pushed.
1129 If not, this trigger acts like a damper/accelerator field.
1131 strength : This is how mutch force to add in the direction of .target each second
1132 when .target is set. If not, this is hoe mutch to slow down/accelerate
1133 someting cought inside this trigger. (1=no change, 0,5 half speed rougthly each tic, 2 = doubble)
1135 radius : If set, act as a spherical device rather then a liniar one.
1137 falloff : 0 = none, 1 = liniar, 2 = inverted liniar
1139 -------- NOTES --------
1140 Use a brush textured with common/origin in the trigger entity to determine the origin of the force
1141 in directional and sperical mode. For damper/accelerator mode this is not nessesary (and has no effect).
1144 void spawnfunc_trigger_impulse()
1149 if(!self.strength) self.strength = 2000;
1150 setorigin(self, self.origin);
1151 setsize(self, '-1 -1 -1' * self.radius,'1 1 1' * self.radius);
1152 self.touch = trigger_impulse_touch3;
1158 if(!self.strength) self.strength = 950;
1159 self.touch = trigger_impulse_touch1;
1163 if(!self.strength) self.strength = 0.9;
1164 self.touch = trigger_impulse_touch2;
1169 /*QUAKED spawnfunc_trigger_flipflop (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ENABLED
1170 "Flip-flop" trigger gate... lets only every second trigger event through
1174 self.state = !self.state;
1179 void spawnfunc_trigger_flipflop()
1181 if(self.spawnflags & 1)
1183 self.use = flipflop_use;
1186 /*QUAKED spawnfunc_trigger_monoflop (.5 .5 .5) (-8 -8 -8) (8 8 8)
1187 "Mono-flop" trigger gate... turns one trigger event into one "on" and one "off" event, separated by a delay of "wait"
1191 self.nextthink = time + self.wait;
1192 self.enemy = activator;
1198 void monoflop_fixed_use()
1202 self.nextthink = time + self.wait;
1204 self.enemy = activator;
1208 void monoflop_think()
1211 activator = self.enemy;
1215 void spawnfunc_trigger_monoflop()
1219 if(self.spawnflags & 1)
1220 self.use = monoflop_fixed_use;
1222 self.use = monoflop_use;
1223 self.think = monoflop_think;
1227 void multivibrator_send()
1232 cyclestart = floor((time + self.phase) / (self.wait + self.respawntime)) * (self.wait + self.respawntime) - self.phase;
1234 newstate = (time < cyclestart + self.wait);
1237 if(self.state != newstate)
1239 self.state = newstate;
1242 self.nextthink = cyclestart + self.wait + 0.01;
1244 self.nextthink = cyclestart + self.wait + self.respawntime + 0.01;
1247 void multivibrator_toggle()
1249 if(self.nextthink == 0)
1251 multivibrator_send();
1264 /*QUAKED trigger_multivibrator (.5 .5 .5) (-8 -8 -8) (8 8 8) START_ON
1265 "Multivibrator" trigger gate... repeatedly sends trigger events. When triggered, turns on or off.
1266 -------- KEYS --------
1267 target: trigger all entities with this targetname when it goes off
1268 targetname: name that identifies this entity so it can be triggered; when off, it always uses the OFF state
1269 phase: offset of the timing
1270 wait: "on" cycle time (default: 1)
1271 respawntime: "off" cycle time (default: same as wait)
1272 -------- SPAWNFLAGS --------
1273 START_ON: assume it is already turned on (when targeted)
1275 void spawnfunc_trigger_multivibrator()
1279 if(!self.respawntime)
1280 self.respawntime = self.wait;
1283 self.use = multivibrator_toggle;
1284 self.think = multivibrator_send;
1285 self.nextthink = time;
1289 if(!(self.spawnflags & 1))
1290 self.nextthink = 0; // wait for a trigger event
1293 self.nextthink = time;
1300 src = find(world, targetname, self.killtarget);
1301 dst = find(world, targetname, self.target);
1305 objerror("follow: could not find target/killtarget");
1309 dst.movetype = MOVETYPE_FOLLOW;
1311 dst.punchangle = src.angles;
1312 dst.view_ofs = dst.origin - src.origin;
1313 dst.v_angle = dst.angles - src.angles;
1318 void spawnfunc_misc_follow()
1320 InitializeEntity(self, follow_init, INITPRIO_FINDTARGET);
1325 void gamestart_use() {
1331 void spawnfunc_trigger_gamestart() {
1334 self.think = gamestart_use;
1335 self.nextthink = self.wait;
1338 InitializeEntity(self, gamestart_use, INITPRIO_FINDTARGET);
1344 .entity voicescript; // attached voice script
1345 .float voicescript_index; // index of next voice, or -1 to use the randomized ones
1346 .float voicescript_nextthink; // time to play next voice
1347 .float voicescript_voiceend; // time when this voice ends
1349 void target_voicescript_clear(entity pl)
1351 pl.voicescript = world;
1354 void target_voicescript_use()
1356 if(activator.voicescript != self)
1358 activator.voicescript = self;
1359 activator.voicescript_index = 0;
1360 activator.voicescript_nextthink = time + self.delay;
1364 void target_voicescript_next(entity pl)
1369 vs = pl.voicescript;
1372 if(vs.message == "")
1374 if(pl.classname != "player")
1379 if(time >= pl.voicescript_voiceend)
1381 if(time >= pl.voicescript_nextthink)
1383 // get the next voice...
1384 n = tokenize_sane(vs.message);
1386 if(pl.voicescript_index < vs.cnt)
1387 i = pl.voicescript_index * 2;
1388 else if(n > vs.cnt * 2)
1389 i = mod(pl.voicescript_index - vs.cnt, (n - vs.cnt * 2 - 1) / 2) * 2 + vs.cnt * 2 + 1;
1395 play2(pl, strcat(vs.netname, "/", argv(i), ".wav"));
1396 pl.voicescript_voiceend = time + stof(argv(i + 1));
1399 pl.voicescript = world;
1401 pl.voicescript_index += 1;
1402 pl.voicescript_nextthink = pl.voicescript_voiceend + vs.wait * (0.5 + random());
1407 void spawnfunc_target_voicescript()
1409 // netname: directory of the sound files
1410 // message: list of "sound file" duration "sound file" duration, a *, and again a list
1411 // foo1 4.1 foo2 4.0 foo3 3.1 * fool1 1.1 fool2 7.1 fool3 9.1 fool4 3.7
1412 // wait: average time between messages
1413 // delay: initial delay before the first message
1416 self.use = target_voicescript_use;
1418 n = tokenize_sane(self.message);
1420 for(i = 0; i+1 < n; i += 2)
1427 precache_sound(strcat(self.netname, "/", argv(i), ".wav"));