quake-hipnotic-sdk/progs/buttons.qc
1997-03-11 00:00:00 +00:00

141 lines
2.8 KiB
C++

// button and multiple button
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.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 ome 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 =
{
if (other.classname != "player")
return;
self.enemy = other;
button_fire ();
};
void() button_killed =
{
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
*/
void() func_button =
{
local float gtemp, ftemp;
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);
};