2 // button and multiple button
4 void button_wait(entity this);
5 void button_return(entity this);
7 void button_wait(entity this)
9 this.state = STATE_TOP;
10 this.SUB_NEXTTHINK = this.SUB_LTIME + this.wait;
11 SUB_THINK(this, button_return);
12 SUB_UseTargets(this, this.enemy, NULL);
13 this.frame = 1; // use alternate textures
16 void button_done(entity this)
18 this.state = STATE_BOTTOM;
21 void button_return(entity this)
23 this.state = STATE_DOWN;
24 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, button_done);
25 this.frame = 0; // use normal textures
27 this.takedamage = DAMAGE_YES; // can be shot again
31 void button_blocked(entity this, entity blocker)
33 // do nothing, just don't come all the way back out
37 void button_fire(entity this)
39 this.health = this.max_health;
40 this.takedamage = DAMAGE_NO; // will be reset upon return
42 if (this.state == STATE_UP || this.state == STATE_TOP)
46 _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
48 this.state = STATE_UP;
49 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, button_wait);
52 void button_reset(entity this)
54 this.health = this.max_health;
55 setorigin(this, this.pos1);
56 this.frame = 0; // use normal textures
57 this.state = STATE_BOTTOM;
59 this.takedamage = DAMAGE_YES; // can be shot again
62 void button_use(entity this, entity actor, entity trigger)
64 if(this.active != ACTIVE_ACTIVE)
71 void button_touch(entity this, entity toucher)
75 if (!toucher.iscreature)
77 if(toucher.velocity * this.movedir < 0)
81 this.enemy = toucher.owner;
85 void button_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
87 if(this.spawnflags & DOOR_NOSPLASH)
88 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
90 this.health = this.health - damage;
93 this.enemy = damage_attacker;
99 /*QUAKED spawnfunc_func_button (0 .5 .8) ?
100 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.
102 "angle" determines the opening direction
103 "target" all entities with a matching targetname will be used
104 "speed" override the default 40 speed
105 "wait" override the default 1 second wait (-1 = never return)
106 "lip" override the default 4 pixel lip remaining at end of move
107 "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
114 spawnfunc(func_button)
118 if (!InitMovingBrushTrigger(this))
120 this.effects |= EF_LOWPRECISION;
122 setblocked(this, button_blocked);
123 this.use = button_use;
125 // if (this.health == 0) // all buttons are now shootable
129 this.max_health = this.health;
130 this.event_damage = button_damage;
131 this.takedamage = DAMAGE_YES;
134 settouch(this, button_touch);
144 precache_sound(this.noise);
146 this.active = ACTIVE_ACTIVE;
148 this.pos1 = this.origin;
149 this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
150 this.flags |= FL_NOTARGET;