djcev.com

//

Git Repos / fte_dogmode / qc / triggers / heal.qc

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

Show heal.qc

//==============================================================================
// trigger_heal -- from custents, modified by dumptruck_ds
// Original entity submitted by Jan Martin Mathiassen, aka. TGR
// was in dtmisc.qc -- CEV
//==============================================================================

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

const float TRIGGER_HEAL_START_ON = 1;
const float TRIGGER_HEAL_PLAYER_ONLY = 2;
const float TRIGGER_HEAL_MONSTER_ONLY = 4;

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

.float heal_timer;
.float heal_amount;
.float health_max;

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

void() trigger_heal_think;
void() trigger_heal_touch;
// void() trigger_heal_toggle;
void(entity e) trigger_heal_init;
void() trigger_heal;

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

/*QUAKED trigger_heal (.5 .5 .5) ? TRIGGER_HEAL_START_ON TRIGGER_HEAL_PLAYER_ONLY TRIGGER_HEAL_MONSTER_ONLY 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

Any object touching this will be healed
heal_amount -- the amount to heal each time (default 5)
wait -- the time between each healing (default 1)
health_max -- the upper limit for the healing (default 100, max 250)
sounds -- set to 1 to enable the noise1 field for custom healing sound
noise -- path to custom sound file
message -- message to print on heal
count -- maximum heal before exhausted
speed -- amount to recharge at a time
delay -- time before recharging
message2 -- message to print when exhausted
*/
//----------------------------------------------------------------------
// class trigger_heal: base_trigger
// {
//--------------------------------------------------------------
void() trigger_heal_think =
{
if (self.cnt == self.count)
{
dprint ("trigger_heal think: full\n");
self.think = sub_null;
return;
}

local float recharge_amount = self.speed;

if (self.count < (self.cnt + self.speed))
recharge_amount = self.count - self.cnt;

dprint ("trigger_heal think: [max: ");
dprint (ftos(self.count));
dprint (", current: ");
dprint (ftos(self.cnt));
dprint (", recharging: ");
dprint (ftos(recharge_amount));
dprint ("]\n");

self.cnt = self.cnt + recharge_amount;
self.nextthink = time + self.delay;
};

//--------------------------------------------------------------
void() trigger_heal_touch =
{
if (self.estate != STATE_ACTIVE)
return;

// from Copper -- dumptruck_ds
if (other.movetype == MOVETYPE_NOCLIP)
{
return;
}

if (self.spawnflags & TRIGGER_HEAL_PLAYER_ONLY &&
other.classtype != CT_PLAYER)
{
return;
}

if (self.spawnflags & TRIGGER_HEAL_MONSTER_ONLY &&
!(other.flags & FL_MONSTER))
{
return;
}

if (other.classtype != CT_PLAYER &&
!(other.flags & FL_MONSTER))
{
return;
}

if (other.heal_timer > time)
{
return;
}

if (self.count && self.cnt <= 0)
{
if (self.message2 != __NULL__ && self.message2 != "")
centerprint (other, self.message2);
return;
}

if ((other.takedamage) && (other.health < self.health_max))
{
if (self.noise != "")
sound (self, CHAN_AUTO, self.noise,
1, ATTN_NORM);
else
sound (self, CHAN_AUTO, "items/r_item1.wav",
1, ATTN_NORM);

local float calc_healing;

if ((other.health + self.heal_amount) > self.health_max)
calc_healing = self.health_max - other.health;
else
calc_healing = self.heal_amount;

if (self.count)
{
if (calc_healing > self.cnt)
calc_healing = self.cnt;

self.cnt -= calc_healing;

if (self.delay)
{
self.think = trigger_heal_think;
self.nextthink = time + self.delay;
}

dprint (sprintf("trigger_heal_touch: "
"used [max: %f, current: %f, "
"using: %f]\n",
self.count, self.cnt, calc_healing));
}

if (self.message != __NULL__ && self.message != "")
centerprint (other, self.message);

T_Heal (other, calc_healing, 1);
other.heal_timer = time + self.wait;
}
};

/*
//--------------------------------------------------------------
void() trigger_heal_toggle =
{
if (self.touch)
self.touch = sub_null;
else
self.touch = trigger_heal_touch;
};
*/

//--------------------------------------------------------------
void(entity e) trigger_heal_init =
{
e.classname = "trigger_heal";
e.classtype = CT_TRIGGER_HEAL;

// play custom sound for healing if noise key exists
precache_sound ("items/r_item1.wav");
if (e.noise != "")
precache_sound (e.noise);

base_trigger_init (e);

if (e.wait == 0)
e.wait = 1;

if (e.heal_amount == 0)
e.heal_amount = 5;

if (e.health_max == 0)
e.health_max = 100;
else if (e.health_max > 250)
e.health_max = 250;

if (e.count)
{
e.cnt = e.count;

if (e.speed && !e.delay)
e.delay = 10;
else if (!e.speed && e.delay)
e.speed = 5;
}

/*
if (e.targetname)
{
e.use = trigger_heal_toggle;
if (e.spawnflags & TRIGGER_HEAL_START_ON)
e.touch = trigger_heal_touch;
else
e.touch = sub_null;
}
else
*/
e.touch = trigger_heal_touch;

sub_checkwaiting (e);
};

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

trigger_heal_init (self);
};
// };

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

Log heal.qc

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