djcev.com

//

Git Repos / fte_dogmode / qc / items / health.qc

Last update to this file was on 2024-07-17 at 11:21.

Show health.qc

//==============================================================================
// HEALTH BOXES
//==============================================================================

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

#ifdef SSQC
// constants spawnflags
const float HEALTH_ROTTEN = 1; // rotten health box
const float HEALTH_MEGA = 2; // megahealth
const float HEALTH_VIAL = 4; // vial (AKA bubble)

// constants healtypes
const float HEALTH_TYPE_ROTTEN = 0; // rotten box
const float HEALTH_TYPE_NORMAL = 1; // normal box
const float HEALTH_TYPE_MEGA = 2; // megahealth

// constants amounts & respawn times
const float HEALTH_ROTTEN_AMOUNT = 15; // rotten heal amount; id1 15
const float HEALTH_NORMAL_AMOUNT = 25; // standard heal amount; id1 25
const float HEALTH_MEGA_AMOUNT = 100; // megahealth amount; id1 100
const float HEALTH_VIAL_AMOUNT = 5; // vial heal amount; Quake3 5
const float HEALTH_RESPAWN_DM = 20; // deathmatch respawn time; id1 20
const float HEALTH_RESPAWN_SP = 30; // singleplayer respawn time; id1 30
const float HEALTH_RESPAWN_MEGA = 125; // fixed mega respawn time; pd3 125
#endif

//======================================================================
// fields
//======================================================================

#ifdef SSQC
.float healamount;
.float healtype;
#endif

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

#ifdef SSQC
// TODO CEV rework the damage system
float (entity e, float healamount, float ignore) T_Heal;
#endif

#ifdef SSQC
// base_item_health
void() base_item_health_touch;
void(entity e) base_item_health_init;
strip void() base_item_health;
#endif

#ifdef SSQC
// item_health
entity(entity src, vector org, vector vel, float flags) spawn_item_health;
void(entity e) item_health_init;
void() item_health;
#endif

#ifdef SSQC
// item_health_vial
entity(entity src) item_health_vial_drop;
entity(entity src, vector org, vector vel) spawn_item_health_vial;
void(entity e) item_health_vial_init;
void() item_health_vial;
#endif

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

#ifdef SSQC
//----------------------------------------------------------------------
// T_Heal: add health to an entity, limiting health to max_health
// "ignore" will ignore max_health limit
//----------------------------------------------------------------------
float (entity e, float healamount, float ignore) T_Heal =
{
if (e.health <= 0)
return 0;
if ((!ignore) && (e.health >= other.max_health))
return 0;
healamount = ceil(healamount);

e.health = e.health + healamount;
if ((!ignore) && (e.health >= other.max_health))
e.health = other.max_health;

if (e.health > 250)
e.health = 250;
return 1;
};
#endif

#ifdef SSQC
//----------------------------------------------------------------------
// class base_item_health: base_item
// {
//--------------------------------------------------------------
// health_touch
//--------------------------------------------------------------
void() base_item_health_touch =
{
if (sub_checkvalidtouch(other) == FALSE)
return;

local float amount;
amount = self.healamount;

if (self.healtype == HEALTH_TYPE_MEGA)
{
// Megahealth? Ignore max_health...
if (other.health >= 250)
return;
if (!T_Heal(other, amount, 1))
return;
}
else
{
if (!T_Heal(other, amount, 0))
return;
}

sprint (other, sprintf("You receive %g health\n", amount));

// health touch sound
// sound (other, CHAN_ITEM, self.noise, VOL_HIGH, ATTN_NORM);
// custom sounds -- dumptruck_ds
sound_misc (other, CHAN_AUTO, self.noise, VOL_HIGH, ATTN_NORM);

stuffcmd (other, "bf\n");

self.model = __NULL__;
self.solid = SOLID_NOT;

// Megahealth = rot down the player's super health
if (self.healtype == HEALTH_TYPE_MEGA)
{
// thanks ydrol!!!
other.megahealth_rottime = time + 5;
other.items = other.items | IT_SUPERHEALTH;
self.owner = other;

// Regarding the deathmatch respawn time below:
// id's original code made the megahealth respawn
// 20 seconds after the health of the player who
// collected it finished rotting down. However,
// this mod has already got rid of the weird old
// megahealth behavior whereby it monitored the
// player who touched it, so the original respawn
// logic isn't applicable. As a solution, the code
// below uses a respawn time of 125 seconds for
// deathmatch, because that was the worst-case
// scenario of id's original code (5 seconds before
// the player's health started to rot, plus 100
// seconds to rot down 100 health points, plus the
// original 20 second delay before the item
// respawned). -- iw

base_item_check_respawn (self, HEALTH_RESPAWN_SP,
HEALTH_RESPAWN_MEGA);
}
else
{
base_item_check_respawn (self, HEALTH_RESPAWN_SP,
HEALTH_RESPAWN_DM);
}

// fire all targets / killtargets
activator = other;
sub_usetargets ();
};

//--------------------------------------------------------------
void(entity e) base_item_health_init =
{
e.classgroup |= CG_ITEM_HEALTH;
base_item_init (e);
};

//--------------------------------------------------------------
strip void() base_item_health =
{
base_item_health_init (self);
};
// };
#endif

#ifdef SSQC
/*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) ROTTEN MEGAHEALTH X X X SPAWN_SILENT TRIGGER_SPAWNED SUSPENDED_IN_AIR NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER RESPAWN_WITH_DM_EFFECTS NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
{
model ( {{ spawnflags & 1 -> { "path" : "maps/b_bh10.bsp" }, spawnflags & 2 -> { "path" : "maps/b_bh100.bsp" },
"maps/b_bh25.bsp" }} );
}
Health box. Normally gives 25 points.
Rotten box heals 15 points.
Megahealth will add 100 health, then start to
rot the player back down to 100 health after 5 seconds.
*/
//----------------------------------------------------------------------
// class item_health: base_item_health
// {
//--------------------------------------------------------------
entity(entity src, vector org, vector vel, float flags)
spawn_item_health =
{
local entity e = spawn ();
e.owner = src;
e.origin = org;
e.velocity = vel;
e.spawnflags = flags;
item_health_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) item_health_init =
{
e.classname = "item_health";
e.classtype = CT_ITEM_HEALTH;
e.touch = base_item_health_touch;

if (e.spawnflags & HEALTH_ROTTEN)
{
// dumptruck_ds custom health models and sounds START
if (world.style)
{
precache_body_model (e,
"progs/health/m_h15.mdl");
body_model (e, "progs/health/m_h15.mdl");
}
else
{
precache_body_model (e, "maps/b_bh10.bsp");
body_model (e, "maps/b_bh10.bsp");
}

precache_sound_misc (e, "items/r_item1.wav");
// e.noise = "items/r_item1.wav";
if !(e.snd_misc)
// set the custom noise in editor
// -- dumptruck_ds
e.snd_misc = "items/r_item1.wav";
e.noise = e.snd_misc;

// if !(e.healamount)
// set your custom health amount here
// -- dumptruck_ds

e.healamount = HEALTH_ROTTEN_AMOUNT;
e.healtype = HEALTH_TYPE_ROTTEN;
if !(e.particles_offset)
e.particles_offset = '16 16 8';
// dumptruck_ds custom health models and sounds END
}
else
{
if (e.spawnflags & HEALTH_MEGA)
{
// precache_model ("maps/b_bh100.bsp");
if (world.style)
{
// models courtesy Lunaran
// -- dumptruck_ds
precache_body_model (e,
"progs/health/m_h100.mdl");
body_model (e,
"progs/health/m_h100.mdl");
}
else
{
// setmodel(e, "maps/b_bh100.bsp");
precache_body_model (e,
"maps/b_bh100.bsp");
body_model (e, "maps/b_bh100.bsp");
}

precache_sound_misc (e, "items/r_item2.wav");
// e.noise = "items/r_item2.wav";
if !(e.snd_misc)
// set the custom noise in editor
// -- dumptruck_ds
e.snd_misc = "items/r_item2.wav";
e.noise = e.snd_misc;

// if !(e.healamount)
// custom health amount
// -- dumptruck_ds

e.healamount = HEALTH_MEGA_AMOUNT;
e.healtype = HEALTH_TYPE_MEGA;
if !(e.particles_offset)
e.particles_offset = '16 16 16';
}
else
{
if (world.style)
{
// models courtesy Lunaran
// -- dumptruck_ds
precache_body_model (e,
"progs/health/m_h25.mdl");
body_model (e,
"progs/health/m_h25.mdl");
}
else
{
precache_body_model (e,
"maps/b_bh25.bsp");
body_model (e, "maps/b_bh25.bsp");
}
precache_sound_misc (e, "items/health1.wav");
if !(e.snd_misc)
// set custom noise in editor
// -- dumptruck_ds
e.snd_misc = "items/health1.wav";
e.noise = e.snd_misc;

e.healamount = HEALTH_NORMAL_AMOUNT;
e.healtype = HEALTH_TYPE_NORMAL;
if !(e.particles_offset)
e.particles_offset = '16 16 8';
// dumptruck_ds custom health models and sounds
}
}

e.pos1 = '0 0 0';
e.pos2 = '32 32 56';

// StartItem
base_item_health_init (e);
};

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

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

#ifdef SSQC
//----------------------------------------------------------------------
// item_health_vial
//----------------------------------------------------------------------
// class item_health_vial: base_item_health
// {
//--------------------------------------------------------------
entity(entity src) item_health_vial_drop =
{
local vector vel;
vel_x = -100 + (random() * 200);
vel_y = -100 + (random() * 200);
vel_z = 300;
return spawn_item_health_vial (src, src.origin - '0 0 24', vel);
};

//--------------------------------------------------------------
entity(entity src, vector org, vector vel) spawn_item_health_vial =
{
local entity e = spawn ();
e.owner = src;
e.origin = org;
e.velocity = vel;
item_health_vial_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) item_health_vial_init =
{
e.classname = "item_health_vial";
e.classtype = CT_ITEM_HEALTH_VIAL;
e.touch = base_item_health_touch;

// model from Hexen 2 -- dumptruck_ds
precache_body_model (e, "progs/health/pd_vial.mdl");
body_model (e, "progs/health/pd_vial.mdl");
precache_sound_misc (e, "items/r_item1.wav");
if !(e.snd_misc)
// set the custom noise in editor -- dumptruck_ds
e.snd_misc = "items/r_item1.wav";
e.noise = e.snd_misc;

e.healamount = HEALTH_VIAL_AMOUNT;
// over heal and count down like mega health -- dumptruck_ds
e.healtype = HEALTH_TYPE_MEGA;
e.pos1 = '-16 -16 0';
e.pos2 = '16 16 56';

if !(e.particles_offset)
e.particles_offset = '0 0 0';

// StartItem
base_item_health_init (e);
};

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

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

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

Log health.qc

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