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;
13 this.nextthink = this.ltime + this.wait;
14 setthink(this, button_return);
16 SUB_UseTargets(this, this.enemy, NULL);
17 this.frame = 1; // use alternate textures
20 void button_done(entity this)
22 this.state = STATE_BOTTOM;
25 void button_return(entity this)
27 this.state = STATE_DOWN;
28 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, button_done);
29 this.frame = 0; // use normal textures
30 if (GetResourceAmount(this, RESOURCE_HEALTH))
31 this.takedamage = DAMAGE_YES; // can be shot again
35 void button_blocked(entity this, entity blocker)
37 // do nothing, just don't come all the way back out
41 void button_fire(entity this)
43 SetResourceAmountExplicit(this, RESOURCE_HEALTH, this.max_health);
44 this.takedamage = DAMAGE_NO; // will be reset upon return
46 if (this.state == STATE_UP || this.state == STATE_TOP)
50 _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
52 this.state = STATE_UP;
53 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, button_wait);
56 void button_reset(entity this)
58 SetResourceAmountExplicit(this, RESOURCE_HEALTH, this.max_health);
59 setorigin(this, this.pos1);
60 this.frame = 0; // use normal textures
61 this.state = STATE_BOTTOM;
62 this.velocity = '0 0 0';
63 setthink(this, func_null);
65 if (GetResourceAmount(this, RESOURCE_HEALTH))
66 this.takedamage = DAMAGE_YES; // can be shot again
69 void button_use(entity this, entity actor, entity trigger)
71 if(this.active != ACTIVE_ACTIVE)
78 void button_touch(entity this, entity toucher)
82 if (!toucher.iscreature)
84 if(toucher.velocity * this.movedir < 0)
88 this.enemy = toucher.owner;
92 void button_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
94 if(this.spawnflags & NOSPLASH)
95 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
97 if (this.spawnflags & BUTTON_DONTACCUMULATEDMG)
99 if (GetResourceAmount(this, RESOURCE_HEALTH) <= damage)
101 this.enemy = attacker;
107 TakeResource(this, RESOURCE_HEALTH, damage);
108 if (GetResourceAmount(this, RESOURCE_HEALTH) <= 0)
110 this.enemy = attacker;
117 /*QUAKED spawnfunc_func_button (0 .5 .8) ?
118 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.
120 "angle" determines the opening direction
121 "target" all entities with a matching targetname will be used
122 "speed" override the default 40 speed
123 "wait" override the default 1 second wait (-1 = never return)
124 "lip" override the default 4 pixel lip remaining at end of move
125 "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
126 "noise" sound that is played when the button is activated
128 spawnfunc(func_button)
132 if (!InitMovingBrushTrigger(this))
134 this.effects |= EF_LOWPRECISION;
136 setblocked(this, button_blocked);
137 this.use = button_use;
139 // if (this.health == 0) // all buttons are now shootable
141 if (GetResourceAmount(this, RESOURCE_HEALTH))
143 this.max_health = GetResourceAmount(this, RESOURCE_HEALTH);
144 this.event_damage = button_damage;
145 this.takedamage = DAMAGE_YES;
148 settouch(this, button_touch);
158 precache_sound(this.noise);
160 this.active = ACTIVE_ACTIVE;
162 this.pos1 = this.origin;
163 this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
164 this.flags |= FL_NOTARGET;
166 this.reset = button_reset;