-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBUTTONS.QC
219 lines (172 loc) · 4.28 KB
/
BUTTONS.QC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// button and multiple button
#define BUTTON_START_OUT 32
void() button_wait;
void() button_return;
void() button_wait =
{
self.state = #STATE_TOP;
self.nextthink = self.ltime + self.wait;
self.think = button_return;
activator = self.enemy;
SUB_UseTargets();
self.frame = 1; // use alternate textures
};
void() button_done =
{
self.state = #STATE_BOTTOM;
};
void() button_return =
{
self.goal_state = #TFGS_INACTIVE;
self.state = #STATE_DOWN;
SUB_CalcMove (self.pos1, self.speed, button_done);
self.frame = 0; // use normal textures
if (self.health)
self.takedamage = #DAMAGE_YES; // can be shot again
};
void() button_blocked =
{ // do nothing, just don't come all the way back out
};
void() button_fire =
{
if (self.state == #STATE_UP || self.state == #STATE_TOP)
return;
sound (self, #CHAN_VOICE, self.noise, 1, #ATTN_NORM);
self.state = #STATE_UP;
SUB_CalcMove (self.pos2, self.speed, button_wait);
};
void() button_use =
{
self.enemy = activator;
button_fire ();
};
/*void() button_touch =
{
local entity te;
if (other.classname != "player")
return;
if (self.goal_activation & #TFGA_SPANNER)
return;
if (!Activated(self,other))
{
// If an else goal should be activated, activate it
if (self.else_goal != 0)
{
te = Findgoal(self.else_goal);
if (te)
DoResults(te, other, (self.goal_result & #TFGR_ADD_BONUSES));
}
return;
}
self.enemy = other;
button_fire ();
};*/
void() button_touch =
{
local entity te;
if (other.classname != "player")
return;
// OfN --------------------------------------//
//- BUGFIX Avoid observers touching buttons //
if (other.playerclass == #PC_UNDEFINED)
return;
if (other.done_custom & #CUSTOM_BUILDING) // skip ppl customizing
return;
//------------------------------------------//
if (self.goal_activation & #TFGA_SPANNER)
return;
if (!Activated(self,other))
{
// If an else goal should be activated, activate it
if (self.else_goal != 0)
{
te = Findgoal(self.else_goal);
if (te)
DoResults(te, other, (self.goal_result & #TFGR_ADD_BONUSES));
}
return;
}
self.enemy = other;
button_fire ();
};
void() button_killed =
{
if (self.goal_activation & #TFGA_SPANNER)
return;
self.enemy = damage_attacker;
self.health = self.max_health;
self.takedamage = #DAMAGE_NO; // wil be reset upon return
button_fire ();
};
/*QUAKED func_button (0 .5 .8) ?
When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.
"angle" determines the opening direction
"target" all entities with a matching targetname will be used
"speed" override the default 40 speed
"wait" override the default 1 second wait (-1 = never return)
"lip" override the default 4 pixel lip remaining at end of move
"health" if set, the button must be killed instead of touched
"sounds"
0) steam metal
1) wooden clunk
2) metallic click
3) in-out
TF Note:
If the spawnflags has the #BUTTON_START_OUT (32), then the button
will automatically fire at the start of the level, allowing you
to light in the out position.
*/
void() func_button =
{
//local float gtemp, ftemp;
if (CheckExistence() == #FALSE)
{
dremove(self);
return;
}
if (self.sounds == 0)
{
precache_sound ("buttons/airbut1.wav");
self.noise = "buttons/airbut1.wav";
}
if (self.sounds == 1)
{
precache_sound ("buttons/switch21.wav");
self.noise = "buttons/switch21.wav";
}
if (self.sounds == 2)
{
precache_sound ("buttons/switch02.wav");
self.noise = "buttons/switch02.wav";
}
if (self.sounds == 3)
{
precache_sound ("buttons/switch04.wav");
self.noise = "buttons/switch04.wav";
}
SetMovedir ();
self.movetype = #MOVETYPE_PUSH;
self.solid = #SOLID_BSP;
setmodel (self, self.model);
self.blocked = button_blocked;
self.use = button_use;
if (self.health)
{
self.max_health = self.health;
self.th_die = button_killed;
self.takedamage = #DAMAGE_YES;
}
else
self.touch = button_touch;
if (!self.speed)
self.speed = 40;
if (!self.wait)
self.wait = 1;
if (!self.lip)
self.lip = 4;
self.state = #STATE_BOTTOM;
self.pos1 = self.origin;
self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
if (self.spawnflags & #BUTTON_START_OUT)
button_fire ();
};