diff --git a/src/server/item_healthkit.qc b/src/server/item_healthkit.qc new file mode 100644 index 0000000..257aa5b --- /dev/null +++ b/src/server/item_healthkit.qc @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2022 Marco Cawthorne + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ + +/*QUAKED item_healthkit (0 0 0.8) (-16 -16 -36) (16 16 36) + +TEAM FORTRESS CLASSIC (1999) ENTITY + +Health pickup. Unlike Team Fortress, this is the only one and it provides +25 health at all times. + +-------- KEYS -------- +"targetname" : Name +"areaname" : Name of the specified area +"team_no" : Which team can pick up the armor (0 = all) +"respawn_delay" : Time it takes to respawn after having been picked up +*/ + +class +item_healthkit:NSRenderableEntity +{ + int m_iTeamUses; + float m_flRespawnDelay; + + void(void) item_healthkit; + + virtual void(void) Respawn; + virtual void(entity) Touch; + virtual void(string,string) SpawnKey; +}; + +void +item_healthkit::Touch(entity eToucher) +{ + if (eToucher.classname != "player") { + return; + } + player pl = (player)eToucher; + + /* check for team eligibility */ + if (m_iTeamUses) + if (pl.team != m_iTeamUses) + return; + + /* leave when full */ + if (pl.health >= pl.m_iMaxHealth) + return; + + pl.health = bound(0, pl.health + 25, pl.m_iMaxHealth); + + Sound_Play(this, CHAN_ITEM, "item_healthkit_tfc.pickup"); + + /* hide and respawn */ + Hide(); + think = Respawn; + nextthink = time + m_flRespawnDelay; +} + +void +item_healthkit::SpawnKey(string strKey, string strValue) +{ + switch (strKey) { + case "team_no": + m_iTeamUses = stoi(strValue); + break; + case "respawn_delay": + m_flRespawnDelay = stof(strValue); + break; + default: + super::SpawnKey(strKey, strValue); + } +} + +void +item_healthkit::Respawn(void) +{ + SetModel("models/w_medkit.mdl"); + SetSize([-16,-16,0], [16,16,56]); + SetSolid(SOLID_TRIGGER); + SetOrigin(GetSpawnOrigin()); + DropToFloor(); +} + +void +item_healthkit::item_healthkit(void) +{ + Sound_Precache("item_healthkit_tfc.pickup"); + m_flRespawnDelay = 30.0f; +} \ No newline at end of file diff --git a/src/server/progs.src b/src/server/progs.src index f28c353..43a8fd8 100644 --- a/src/server/progs.src +++ b/src/server/progs.src @@ -36,6 +36,7 @@ item_tfgoal.qc info_tfgoal.qc info_areadef.qc item_armor.qc +item_healthkit.qc gamerules.qc client.qc diff --git a/zpak001.pk3dir/sound/items_tfc.sndshd b/zpak001.pk3dir/sound/items_tfc.sndshd index 91daa0f..56079f6 100644 --- a/zpak001.pk3dir/sound/items_tfc.sndshd +++ b/zpak001.pk3dir/sound/items_tfc.sndshd @@ -1,4 +1,8 @@ item_armor_tfc.pickup { sample items/armoron_1.wav +} +item_healthkit_tfc.pickup +{ + sample items/smallmedkit1.wav } \ No newline at end of file