3 // button and multiple button
5 void button_wait(entity this);
6 void button_return(entity this);
8 void button_wait(entity this)
10 this.state = STATE_TOP;
11 this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
12 SUB_THINK(this, button_return);
13 SUB_UseTargets(this, this.enemy, NULL);
14 this.frame = 1; // use alternate textures
17 void button_done(entity this)
19 this.state = STATE_BOTTOM;
22 void button_return(entity this)
24 this.state = STATE_DOWN;
25 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, button_done);
26 this.frame = 0; // use normal textures
28 this.takedamage = DAMAGE_YES; // can be shot again
32 void button_blocked(entity this, entity blocker)
34 // do nothing, just don't come all the way back out
38 void button_fire(entity this)
40 this.health = this.max_health;
41 this.takedamage = DAMAGE_NO; // will be reset upon return
43 if (this.state == STATE_UP || this.state == STATE_TOP)
47 _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
49 this.state = STATE_UP;
50 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, button_wait);
53 void button_reset(entity this)
55 this.health = this.max_health;
56 setorigin(this, this.pos1);
57 this.frame = 0; // use normal textures
58 this.state = STATE_BOTTOM;
60 this.takedamage = DAMAGE_YES; // can be shot again
63 void button_use(entity this, entity actor, entity trigger)
65 if(this.active != ACTIVE_ACTIVE)
72 void button_touch(entity this, entity toucher)
76 if (!toucher.iscreature)
78 if(toucher.velocity * this.movedir < 0)
82 this.enemy = toucher.owner;
86 void button_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
88 if(this.spawnflags & DOOR_NOSPLASH)
89 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
91 this.health = this.health - damage;
94 this.enemy = damage_attacker;
100 /*QUAKED spawnfunc_func_button (0 .5 .8) ?
101 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.
103 "angle" determines the opening direction
104 "target" all entities with a matching targetname will be used
105 "speed" override the default 40 speed
106 "wait" override the default 1 second wait (-1 = never return)
107 "lip" override the default 4 pixel lip remaining at end of move
108 "health" if set, the button must be killed instead of touched. If set to -1, the button will fire on ANY attack, even damageless ones like the InstaGib laser
115 spawnfunc(func_button)
119 if (!InitMovingBrushTrigger(this))
121 this.effects |= EF_LOWPRECISION;
123 setblocked(this, button_blocked);
124 this.use = button_use;
126 // if (this.health == 0) // all buttons are now shootable
130 this.max_health = this.health;
131 this.event_damage = button_damage;
132 this.takedamage = DAMAGE_YES;
135 settouch(this, button_touch);
145 precache_sound(this.noise);
147 this.active = ACTIVE_ACTIVE;
149 this.pos1 = this.origin;
150 this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
151 this.flags |= FL_NOTARGET;