ew-progs/ew/items/health.qc
2011-09-06 00:00:00 +00:00

171 lines
No EOL
3.7 KiB
C++

/*
=============================
health.qc
mostly done by id software
small changes by
Robert de Heus a.k.a Koolio
koolio@planetkoolio.com
http://www.planetkoolio.com
Description:
health packs.
=============================
*/
/*
=========================================================================
HEALTH BOX
=========================================================================
*/
//
// 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;
};
/*QUAKED item_health (.3 .3 1) (0 0 0) (32 32 32) rotten megahealth
Health box. Normally gives 25 points.
Rotten box heals 5-10 points,
megahealth will add 100 health, then
rot you down to your maximum health limit,
one point per second.
*/
float H_ROTTEN = 1;
float H_MEGA = 2;
.float healamount, healtype;
void() health_touch;
void() item_megahealth_rot;
void() item_health =
{
self.touch = health_touch;
if (self.spawnflags & H_ROTTEN)
{
precache_model("models/items/health.md2");
precache_sound("items/r_item1.wav");
setmodel(self, "models/items/health.md2");
self.scale = 0.6; //Smaller than normal.
self.noise = "items/r_item1.wav";
self.healamount = 15;
self.healtype = 0;
}
else if (self.spawnflags & H_MEGA)
{
precache_model("models/items/mega.md2");
precache_sound("items/r_item2.wav");
setmodel(self, "models/items/mega.md2");
self.noise = "items/r_item2.wav";
self.healamount = 100;
self.healtype = 2;
}
else
{
precache_model("models/items/health.md2");
precache_sound("items/health1.wav");
setmodel(self, "models/items/health.md2");
self.noise = "items/health1.wav";
self.healamount = 25;
self.healtype = 1;
}
setsize (self, '0 0 0', '32 32 56');
StartItem ();
};
void() health_touch =
{
local float amount;
local string s;
if (other.classname != "player")
return;
if (self.healtype == 2) // Megahealth? Ignore max_health...
{
if (other.health >= 250)
return;
if (!T_Heal(other, self.healamount, 1))
return;
}
else
{
if (!T_Heal(other, self.healamount, 0))
return;
}
sprint(other, "You receive ");
s = ftos(self.healamount);
sprint(other, s);
sprint(other, " health\n");
// health touch sound
sound(other, CHAN_ITEM, self.noise, 1, ATTN_NORM);
stuffcmd (other, "bf\n");
self.model = string_null;
self.solid = SOLID_NOT;
// Megahealth = rot down the player's super health
if (self.healtype == 2)
{
other.items = other.items | IT_SUPERHEALTH;
self.nextthink = time + 5;
self.think = item_megahealth_rot;
self.owner = other;
}
else
{
if (deathmatch != 2) // deathmatch 2 is the silly old rules
{
if (deathmatch)
self.nextthink = time + 20;
self.think = SUB_regen;
}
}
activator = other;
SUB_UseTargets(); // fire all targets / killtargets
};
void() item_megahealth_rot =
{
other = self.owner;
if (other.health > other.max_health)
{
other.health = other.health - 1;
self.nextthink = time + 1;
return;
}
// it is possible for a player to die and respawn between rots, so don't
// just blindly subtract the flag off
other.items = other.items - (other.items & IT_SUPERHEALTH);
if (deathmatch == 1) // deathmatch 2 is silly old rules
{
self.nextthink = time + 20;
self.think = SUB_regen;
}
};