|
|
1.1 root 1: // button and multiple button
2:
3: void() button_wait;
4: void() button_return;
5:
6: void() button_wait =
7: {
8: self.state = STATE_TOP;
9: self.nextthink = self.ltime + self.wait;
10: self.think = button_return;
11: activator = self.enemy;
12: SUB_UseTargets();
13: self.frame = 1; // use alternate textures
14: };
15:
16: void() button_done =
17: {
18: self.state = STATE_BOTTOM;
19: };
20:
21: void() button_return =
22: {
23: self.state = STATE_DOWN;
24: SUB_CalcMove (self.pos1, self.speed, button_done);
25: self.frame = 0; // use normal textures
26: if (self.health)
27: self.takedamage = DAMAGE_YES; // can be shot again
28: };
29:
30:
31: void() button_blocked =
32: { // do nothing, just don't ome all the way back out
33: };
34:
35:
36: void() button_fire =
37: {
38: if (self.state == STATE_UP || self.state == STATE_TOP)
39: return;
40:
41: sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
42:
43: self.state = STATE_UP;
44: SUB_CalcMove (self.pos2, self.speed, button_wait);
45: };
46:
47:
48: void() button_use =
49: {
50: self.enemy = activator;
51: button_fire ();
52: };
53:
54: void() button_touch =
55: {
56: if (other.classname != "player")
57: return;
58: self.enemy = other;
59: button_fire ();
60: };
61:
62: void() button_killed =
63: {
64: self.enemy = damage_attacker;
65: self.health = self.max_health;
66: self.takedamage = DAMAGE_NO; // wil be reset upon return
67: button_fire ();
68: };
69:
70:
71: /*QUAKED func_button (0 .5 .8) ?
72: 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.
73:
74: "angle" determines the opening direction
75: "target" all entities with a matching targetname will be used
76: "speed" override the default 40 speed
77: "wait" override the default 1 second wait (-1 = never return)
78: "lip" override the default 4 pixel lip remaining at end of move
79: "health" if set, the button must be killed instead of touched
80: "sounds"
81: 0) steam metal
82: 1) wooden clunk
83: 2) metallic click
84: 3) in-out
85: */
86: void() func_button =
87: {
88: local float gtemp, ftemp;
89:
90: if (self.sounds == 0)
91: {
92: precache_sound ("buttons/airbut1.wav");
93: self.noise = "buttons/airbut1.wav";
94: }
95: if (self.sounds == 1)
96: {
97: precache_sound ("buttons/switch21.wav");
98: self.noise = "buttons/switch21.wav";
99: }
100: if (self.sounds == 2)
101: {
102: precache_sound ("buttons/switch02.wav");
103: self.noise = "buttons/switch02.wav";
104: }
105: if (self.sounds == 3)
106: {
107: precache_sound ("buttons/switch04.wav");
108: self.noise = "buttons/switch04.wav";
109: }
110:
111: SetMovedir ();
112:
113: self.movetype = MOVETYPE_PUSH;
114: self.solid = SOLID_BSP;
115: setmodel (self, self.model);
116:
117: self.blocked = button_blocked;
118: self.use = button_use;
119:
120: if (self.health)
121: {
122: self.max_health = self.health;
123: self.th_die = button_killed;
124: self.takedamage = DAMAGE_YES;
125: }
126: else
127: self.touch = button_touch;
128:
129: if (!self.speed)
130: self.speed = 40;
131: if (!self.wait)
132: self.wait = 1;
133: if (!self.lip)
134: self.lip = 4;
135:
136: self.state = STATE_BOTTOM;
137:
138: self.pos1 = self.origin;
139: self.pos2 = self.pos1 + self.movedir*(fabs(self.movedir*self.size) - self.lip);
140: };
141:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.