djcev.com

//

Git Repos / fte_dogmode / qc / func / laser.qc

Last update to this file was on 2024-03-24 at 02:40.

Show laser.qc

//==============================================================================
// func_laser -- selections from Rubicon 2 qc by john fitzgibbons
//==============================================================================

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

const float LASER_START_OFF = 1;
const float LASER_SOLID = 2;

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

// temp_laser_helper
void() temp_laser_helper_think;
entity(entity own, float newalpha) spawn_temp_laser_helper;
void(entity e) temp_laser_helper_init;
strip void() temp_laser_helper;

// func_laser
void() func_laser_touch;
void() func_laser_use;
void(entity e) func_laser_init;
void() func_laser;

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

//----------------------------------------------------------------------
// class temp_laser_helper: base_tempentity
// {
//--------------------------------------------------------------
void() temp_laser_helper_think =
{
if (!self.owner || self.owner.classtype != CT_FUNC_LASER)
{
remove (self);
return;
}

if (!(self.owner.spawnflags & LASER_START_OFF))
self.owner.alpha = self.alpha * 0.8 +
self.alpha * random() * 0.4;

self.nextthink = time + 0.05;
};

//--------------------------------------------------------------
entity(entity own, float newalpha) spawn_temp_laser_helper =
{
local entity e = spawn ();
e.owner = own;
e.alpha = newalpha;
temp_laser_helper_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) temp_laser_helper_init =
{
e.classname = "temp_laser_helper";
e.classtype = CT_TEMP_LASER_HELPER;
base_tempentity_init (e);

e.think = temp_laser_helper_think;
e.nextthink = 0.05;
};

//--------------------------------------------------------------
strip void() temp_laser_helper =
{
temp_laser_helper_init (self);
};
// };

/*QUAKED func_laser (0 .5 .8) ? LASER_START_OFF LASER_SOLID 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

A toggleable laser, hurts to touch, can be used to block players

LASER_START_OFF: Laser starts off.

LASER_SOLID: Laser blocks movement while turned on.

Keys:

"dmg" damage to do on touch. default 1

"alpha" approximate alpha you want the laser drawn at. default 0.5. alpha will vary by 20% of this value.

"message" message to display when activated

"message2" message to display when deactivated

*/
//----------------------------------------------------------------------
// class func_laser: base_func
// {
//--------------------------------------------------------------
void() func_laser_touch =
{
// from Copper -- dumptruck_ds
if (other.movetype == MOVETYPE_NOCLIP)
return;

if (other.takedamage && self.attack_finished < time)
{
t_damage2 (other, self, self, self.dmg);
self.attack_finished = time + 0.1;
}

};

//--------------------------------------------------------------
void() func_laser_use =
{
if (self.spawnflags & LASER_START_OFF)
{
setorigin (self, '0 0 0');
self.spawnflags = self.spawnflags - LASER_START_OFF;

// changed for progs_dump: the laser sound is now
// emitted from the func_laser itself instead of
// from the activator -- iw
sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);

if (activator.classtype == CT_PLAYER &&
self.message != "")
{
centerprint (activator, self.message);
}
}
else
{
// changed for progs_dump: the laser sound is now
// emitted from the func_laser itself instead of
// from the activator -- iw
sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);

setorigin (self, '0 0 9000');
self.spawnflags = self.spawnflags + LASER_START_OFF;

if (activator.classtype == CT_PLAYER &&
self.message2 != "")
{
centerprint (activator, self.message2);
}
}
};

//--------------------------------------------------------------
void(entity e) func_laser_init =
{
e.classname = "func_laser";
e.classtype = CT_FUNC_LASER;
base_func_init (e);

setmodel (e, e.model);

precache_sound ("buttons/switch02.wav");
precache_sound ("buttons/switch04.wav");

if (e.spawnflags & LASER_SOLID)
{
// so you can shoot between lasers in a single bmodel
e.solid = SOLID_BSP;
// required becuase of SOLID_BSP
e.movetype = MOVETYPE_PUSH;
}
else
{
e.solid = SOLID_TRIGGER;
e.movetype = MOVETYPE_NONE;
}

if (!e.alpha)
e.alpha = 0.5;

if (!e.dmg)
e.dmg = 1;

e.touch = func_laser_touch;
e.use = func_laser_use;

if (e.spawnflags & LASER_START_OFF)
setorigin (e, '0 0 9000');

if (e.noise != "")
precache_sound (e.noise);
else
e.noise = "buttons/switch02.wav";

if (e.noise1 != "")
precache_sound (e.noise1);
else
e.noise1 = "buttons/switch04.wav";

// spawn a second entity to handle alpha changes, since
// MOVETYPE_PUSH doesn't support think functions
spawn_temp_laser_helper (e, e.alpha);
};

//--------------------------------------------------------------
void() func_laser =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

func_laser_init (self);
};
// };

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

Log laser.qc

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