djcev.com

//

Git Repos / fte_dogmode / qc / func / elvtr_button.qc

Last update to this file was on 2025-03-30 at 19:29.

Show elvtr_button.qc

//==============================================================================
// func_elvtr_button - Rogue Dissolution Of Eternity
//==============================================================================

// elevator button
// pmack
// sept 96

//======================================================================
// constants
//======================================================================

#ifdef SSQC
//----------------------------------------------------------------------
// func_elvtr_button spawnflags -- CEV
//----------------------------------------------------------------------
typedef enumflags
{
SPAWNFLAG_FUNC_ELVTR_BUTTON_DOWN = 1
// SPAWNFLAG_NOT_ON_EASY = 256, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_NORMAL = 512,
// SPAWNFLAG_NOT_ON_HARD_OR_NIGHTMARE = 1024,
// SPAWNFLAG_NOT_IN_DEATHMATCH = 2048,
// SPAWNFLAG_NOT_IN_COOP = 4096,
// SPAWNFLAG_NOT_IN_SP = 8192,
// SPAWNFLAG_NOT_ON_SKILL2 = 32768, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_SKILL3 = 65536, // see base_entities.qc -- CEV
// SPAWNFLAG_CENTERPRINTALL = 131072 // see base_entities.qc -- CEV
} func_elvtr_button_spawnflags;
#endif

//======================================================================
// globals
//======================================================================

#ifdef SSQC
float elv_butn_dir;
#endif

//======================================================================
// forward declarations
//======================================================================

// func_elvtr_button
#ifdef CSQC
void(float isnew) func_elvtr_button_netreceive;
#endif
#ifdef SSQC
void() func_elvtr_button_wait;
void() func_elvtr_button_done;
void() func_elvtr_button_return;
void() func_elvtr_button_fire;
void() func_elvtr_button_blocked;
void(vector dir) func_elvtr_button_destroy;
void() func_elvtr_button_touch;
void() func_elvtr_button_use;
#endif
#if defined(CSQC) || defined(SSQC)
void(entity e) func_elvtr_button_init;
#endif
#ifdef SSQC
void() func_elvtr_button;
#endif

//------------------------------------------------------------------------------

/*QUAKED func_elvtr_button (0 .5 .8) ? ELVTR_DOWN X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY

ELEVATOR BUTTON ONLY!

ELVTR_DOWN causes this to be a DOWN button.
Default is UP.

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
*/
//----------------------------------------------------------------------
// class func_elvtr_button: base_func
// {
#ifdef CSQC
//--------------------------------------------------------------
void(float isnew) func_elvtr_button_netreceive =
{
// creates the netflag variable -- CEV
BASE_FUNC_NETRECEIVE (func_elvtr_button_init)

if (isnew)
base_entity_que_add (self, QUE_TYPE_ACTOR);
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
void() func_elvtr_button_wait =
{
if (self.spawnflags & SPAWNFLAG_FUNC_ELVTR_BUTTON_DOWN)
elv_butn_dir = -1;
else
elv_butn_dir = 1;

self.state = FUNC_STATE_TOP;
activator = self.enemy;
sub_usetargets ();

// use alternate textures
self.frame = 1;
self.SendFlags |= NETFLAG_BASE_ENTITY_FRAME;

// schedule next action
self.think = func_elvtr_button_return;
self.nextthink = self.ltime + self.wait;
};

//--------------------------------------------------------------
void() func_elvtr_button_done =
{
self.state = FUNC_STATE_BOTTOM;
};

//--------------------------------------------------------------
void() func_elvtr_button_return =
{
self.state = FUNC_STATE_DOWN;
base_func_calcmove (self, self.pos1, self.speed,
func_elvtr_button_done);

// use normal textures
self.frame = 0;
self.SendFlags |= NETFLAG_BASE_ENTITY_FRAME;

if (self.health)
// can be shot again
self.takedamage = DAMAGE_YES;
};

//--------------------------------------------------------------
void() func_elvtr_button_fire =
{
if (self.state == FUNC_STATE_UP || self.state == FUNC_STATE_TOP)
return;

sound (self, CHAN_VOICE, self.noise, VOL_MID, ATTN_NORM);

self.state = FUNC_STATE_UP;
base_func_calcmove (self, self.pos2, self.speed,
func_elvtr_button_wait);
};

//--------------------------------------------------------------
void() func_elvtr_button_blocked =
{
// do nothing, just don't come all the way back out
};

//--------------------------------------------------------------
void(vector dir) func_elvtr_button_destroy =
{
self.enemy = damage_attacker;
self.health = self.max_health;
// wil be reset upon return
self.takedamage = DAMAGE_NO;
func_elvtr_button_fire ();
};

//--------------------------------------------------------------
void() func_elvtr_button_touch =
{
// if (self.health > 0)
// return;

if (other.classtype != CT_PLAYER)
return;

self.enemy = other;
func_elvtr_button_fire ();
};

//--------------------------------------------------------------
void() func_elvtr_button_use =
{
self.enemy = activator;
func_elvtr_button_fire ();
};
#endif

#if defined(CSQC) || defined(SSQC)
//--------------------------------------------------------------
void(entity e) func_elvtr_button_init =
{
e.classname = "func_elvtr_button";
e.classtype = CT_FUNC_ELVTR_BUTTON;
base_func_init (e);

#ifdef CSQC
setmodelindex (e, e.modelindex);
setsize (e, e.mins, e.maxs);
setorigin (e, e.origin);
e.drawmask = DRAWMASK_NORMAL;
e.predraw = base_func_predraw;
#endif

#ifdef SSQC
if (e.sounds == 0)
{
precache_sound ("buttons/airbut1.wav");
e.noise = "buttons/airbut1.wav";
}

if (e.sounds == 1)
{
precache_sound ("buttons/switch21.wav");
e.noise = "buttons/switch21.wav";
}

if (e.sounds == 2)
{
precache_sound ("buttons/switch02.wav");
e.noise = "buttons/switch02.wav";
}

if (e.sounds == 3)
{
precache_sound ("buttons/switch04.wav");
e.noise = "buttons/switch04.wav";
}

sub_setmovedir (e);

e.movetype = MOVETYPE_PUSH;
e.solid = SOLID_BSP;
setmodel (e, e.model);

e.blocked = func_elvtr_button_blocked;
e.use = func_elvtr_button_use;

if (e.health)
{
e.max_health = e.health;
e.takedamage = DAMAGE_YES;
e.destroy = func_elvtr_button_destroy;
}
else
{
e.touch = func_elvtr_button_touch;
}

if (!e.speed)
e.speed = 40;
if (!e.wait)
e.wait = 1;
if (!e.lip)
e.lip = 4;

e.state = FUNC_STATE_BOTTOM;

e.pos1 = e.origin;
e.pos2 = e.pos1 + e.movedir *
(fabs(e.movedir * e.size) - e.lip);

// network to the CSQC client -- CEV
e.tick = base_func_neteval;
e.SendEntity = base_entity_netsend;
e.SendFlags = NETFLAG_BASE_ENTITY_FULLSEND;
#endif
};
#endif

#ifdef SSQC
//--------------------------------------------------------------
void() func_elvtr_button =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

func_elvtr_button_init (self);
};
#endif
// };

Return to the top of this page or return to the overview of this repo.

Log elvtr_button.qc

Date Commit Message Author + -
2025-03-30 Big commit. Entity networking, etc. cev +60 -5
2024-06-15 Major update, committing as-is, will have bugs cev +9 -1
2024-04-12 Moveable gibs, heads, some bugfixes cev +2 -2
2024-03-24 2nd pass refactor, rework QC class structure cev +120 -94
2024-02-18 Client/player, projectiles, entrypoints refactor cev +11 -12
2024-01-31 Class based monster refactor & start projectiles cev +20 -1
2024-01-09 Continue OO / Class-based refactor cev +137 -136
2023-11-27 Code reorg, minor movement changes, misc cev +182  

Return to the top of this page or return to the overview of this repo.