2 void SUB_DontUseTargets(entity this, entity actor, entity trigger) { }
4 void SUB_UseTargets(entity this, entity actor, entity trigger);
6 void DelayThink(entity this)
8 SUB_UseTargets (this, this.enemy, NULL);
12 void FixSize(entity e)
14 e.mins_x = rint(e.mins_x);
15 e.mins_y = rint(e.mins_y);
16 e.mins_z = rint(e.mins_z);
18 e.maxs_x = rint(e.maxs_x);
19 e.maxs_y = rint(e.maxs_y);
20 e.maxs_z = rint(e.maxs_z);
25 bool autocvar_g_triggers_debug = true;
27 void trigger_init(entity this)
29 string m = this.model;
31 if(autocvar_g_triggers_debug)
36 _setmodel(this, m); // no precision needed
38 setorigin(this, this.origin);
40 setsize(this, this.mins * this.scale, this.maxs * this.scale);
42 setsize(this, this.mins, this.maxs);
45 if(autocvar_g_triggers_debug)
46 BITSET_ASSIGN(this.effects, EF_NODEPTHTEST);
49 void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendfunc)
51 setSendEntity(this, sendfunc);
52 this.SendFlags = 0xFFFFFF;
55 void trigger_common_write(entity this, bool withtarget)
58 if(this.warpzone_isboxy)
60 if(this.origin != '0 0 0')
62 WriteByte(MSG_ENTITY, f);
66 WriteString(MSG_ENTITY, this.target);
67 WriteString(MSG_ENTITY, this.target2);
68 WriteString(MSG_ENTITY, this.target3);
69 WriteString(MSG_ENTITY, this.target4);
70 WriteString(MSG_ENTITY, this.targetname);
71 WriteString(MSG_ENTITY, this.killtarget);
76 WriteCoord(MSG_ENTITY, this.origin.x);
77 WriteCoord(MSG_ENTITY, this.origin.y);
78 WriteCoord(MSG_ENTITY, this.origin.z);
81 WriteShort(MSG_ENTITY, this.modelindex);
82 WriteCoord(MSG_ENTITY, this.mins.x);
83 WriteCoord(MSG_ENTITY, this.mins.y);
84 WriteCoord(MSG_ENTITY, this.mins.z);
85 WriteCoord(MSG_ENTITY, this.maxs.x);
86 WriteCoord(MSG_ENTITY, this.maxs.y);
87 WriteCoord(MSG_ENTITY, this.maxs.z);
88 WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255));
90 WriteCoord(MSG_ENTITY, this.movedir_x);
91 WriteCoord(MSG_ENTITY, this.movedir_y);
92 WriteCoord(MSG_ENTITY, this.movedir_z);
94 WriteCoord(MSG_ENTITY, this.angles_x);
95 WriteCoord(MSG_ENTITY, this.angles_y);
96 WriteCoord(MSG_ENTITY, this.angles_z);
101 void trigger_common_read(entity this, bool withtarget)
104 this.warpzone_isboxy = (f & 1);
108 if(this.target) { strunzone(this.target); }
109 this.target = strzone(ReadString());
110 if(this.target2) { strunzone(this.target2); }
111 this.target2 = strzone(ReadString());
112 if(this.target3) { strunzone(this.target3); }
113 this.target3 = strzone(ReadString());
114 if(this.target4) { strunzone(this.target4); }
115 this.target4 = strzone(ReadString());
116 if(this.targetname) { strunzone(this.targetname); }
117 this.targetname = strzone(ReadString());
118 if(this.killtarget) { strunzone(this.killtarget); }
119 this.killtarget = strzone(ReadString());
124 this.origin_x = ReadCoord();
125 this.origin_y = ReadCoord();
126 this.origin_z = ReadCoord();
129 this.origin = '0 0 0';
130 setorigin(this, this.origin);
132 this.modelindex = ReadShort();
133 this.mins_x = ReadCoord();
134 this.mins_y = ReadCoord();
135 this.mins_z = ReadCoord();
136 this.maxs_x = ReadCoord();
137 this.maxs_y = ReadCoord();
138 this.maxs_z = ReadCoord();
139 this.scale = ReadByte() / 16;
140 setsize(this, this.mins, this.maxs);
142 this.movedir_x = ReadCoord();
143 this.movedir_y = ReadCoord();
144 this.movedir_z = ReadCoord();
146 this.angles_x = ReadCoord();
147 this.angles_y = ReadCoord();
148 this.angles_z = ReadCoord();
151 void trigger_remove_generic(entity this)
153 if(this.target) { strunzone(this.target); }
154 this.target = string_null;
156 if(this.target2) { strunzone(this.target2); }
157 this.target2 = string_null;
159 if(this.target3) { strunzone(this.target3); }
160 this.target3 = string_null;
162 if(this.target4) { strunzone(this.target4); }
163 this.target4 = string_null;
165 if(this.targetname) { strunzone(this.targetname); }
166 this.target = string_null;
168 if(this.killtarget) { strunzone(this.killtarget); }
169 this.killtarget = string_null;
175 ==============================
178 the global "activator" should be set to the entity that initiated the firing.
180 If this.delay is set, a DelayedUse entity will be created that will actually
181 do the SUB_UseTargets after that many seconds have passed.
183 Centerprints any this.message to the activator.
185 Removes all entities with a targetname that match this.killtarget,
186 and removes them, so some events can remove other triggers.
188 Search for (string)targetname in all entities that
189 match (string)this.target and call their .use function
191 ==============================
194 void SUB_UseTargets_Ex(entity this, entity actor, entity trigger, bool preventReuse)
201 // create a temp object to fire at a later time
202 entity t = new(DelayedUse);
203 t.nextthink = time + this.delay;
204 setthink(t, DelayThink);
206 t.message = this.message;
207 t.killtarget = this.killtarget;
208 t.target = this.target;
209 t.target2 = this.target2;
210 t.target3 = this.target3;
211 t.target4 = this.target4;
212 t.antiwall_flag = this.antiwall_flag;
223 if(IS_PLAYER(actor) && this.message != "")
224 if(IS_REAL_CLIENT(actor))
226 centerprint(actor, this.message);
227 if (this.noise == "")
228 play2(actor, SND(TALK));
232 // kill the killtagets
237 for(entity t = NULL; (t = find(t, targetname, s)); )
246 if(this.target_random)
247 RandomSelection_Init();
249 for(int i = 0; i < 4; ++i)
254 case 0: s = this.target; break;
255 case 1: s = this.target2; break;
256 case 2: s = this.target3; break;
257 case 3: s = this.target4; break;
261 // Flag to set func_clientwall state
262 // 1 == deactivate, 2 == activate, 0 == do nothing
263 int aw_flag = this.antiwall_flag;
264 for(entity t = NULL; (t = find(t, targetname, s)); )
266 if(t.use && (t.sub_target_used != time || !preventReuse))
268 if(this.target_random)
270 RandomSelection_AddEnt(t, 1, 0);
274 if (t.classname == "func_clientwall" || t.classname == "func_clientillusionary")
275 t.antiwall_flag = aw_flag;
277 t.use(t, actor, this);
279 t.sub_target_used = time;
286 if(this.target_random && RandomSelection_chosen_ent)
288 RandomSelection_chosen_ent.use(RandomSelection_chosen_ent, actor, this);
290 RandomSelection_chosen_ent.sub_target_used = time;
294 void SUB_UseTargets(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, false); }
295 void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger) { SUB_UseTargets_Ex(this, actor, trigger, true); }
297 void SUB_UseTargets_self(entity this)
299 SUB_UseTargets(this, NULL, NULL);