From 9edc7863118aa110e15a380f3b3f43a04fa42073 Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Mon, 16 Sep 2019 14:24:18 -0400 Subject: [PATCH] make backpacks drop keys --- source/items.qc | 164 +++++++++++++++++++++++++++++------------------- 1 file changed, 101 insertions(+), 63 deletions(-) diff --git a/source/items.qc b/source/items.qc index f7e5ba2..5f21803 100644 --- a/source/items.qc +++ b/source/items.qc @@ -1,4 +1,32 @@ +const string WEPNAME_AXE = "Axe"; +const string WEPNAME_SHOTGUN = "Shotgun"; +const string WEPNAME_SUPER_SHOTGUN = "Double-barrelled Shotgun"; +const string WEPNAME_NAILGUN = "Nailgun"; +const string WEPNAME_SUPER_NAILGUN = "Super Nailgun"; +const string WEPNAME_GRENADE_LAUNCHER = "Grenade Launcher"; +const string WEPNAME_ROCKET_LAUNCHER = "Rocket Launcher"; +const string WEPNAME_LIGHTNING = "Thunderbolt"; + void() W_SetCurrentAmmo; + +string() Key1Name = { + switch(world.worldtype) { + case 0: return "silver key"; + case 1: return "silver runekey"; + case 2: return "silver keycard"; + default: return string_null; + } +}; + +string() Key2Name = { + switch(world.worldtype) { + case 0: return "gold key"; + case 1: return "gold runekey"; + case 2: return "gold keycard"; + default: return string_null; + } +}; + /* ALL LIGHTS SHOULD BE 0 1 0 IN COLOR ALL OTHER ITEMS SHOULD BE .8 .3 .4 IN COLOR */ @@ -497,7 +525,7 @@ void() weapon_supershotgun = { precache_model("progs/g_shot.mdl"); setmodel(self, "progs/g_shot.mdl"); self.weapon = IT_SUPER_SHOTGUN; - self.netname = "Double-barrelled Shotgun"; + self.netname = WEPNAME_SUPER_SHOTGUN; self.touch = weapon_touch; setsize(self, '-16 -16 0', '16 16 56'); StartItem(); @@ -510,7 +538,7 @@ void() weapon_nailgun = { precache_model("progs/g_nail.mdl"); setmodel(self, "progs/g_nail.mdl"); self.weapon = IT_NAILGUN; - self.netname = "nailgun"; + self.netname = WEPNAME_NAILGUN; self.touch = weapon_touch; setsize(self, '-16 -16 0', '16 16 56'); StartItem(); @@ -523,7 +551,7 @@ void() weapon_supernailgun = { precache_model("progs/g_nail2.mdl"); setmodel(self, "progs/g_nail2.mdl"); self.weapon = IT_SUPER_NAILGUN; - self.netname = "Super Nailgun"; + self.netname = WEPNAME_SUPER_NAILGUN; self.touch = weapon_touch; setsize(self, '-16 -16 0', '16 16 56'); StartItem(); @@ -536,7 +564,7 @@ void() weapon_grenadelauncher = { precache_model("progs/g_rock.mdl"); setmodel(self, "progs/g_rock.mdl"); self.weapon = 3; - self.netname = "Grenade Launcher"; + self.netname = WEPNAME_GRENADE_LAUNCHER; self.touch = weapon_touch; setsize(self, '-16 -16 0', '16 16 56'); StartItem(); @@ -549,7 +577,7 @@ void() weapon_rocketlauncher = { precache_model("progs/g_rock2.mdl"); setmodel(self, "progs/g_rock2.mdl"); self.weapon = 3; - self.netname = "Rocket Launcher"; + self.netname = WEPNAME_ROCKET_LAUNCHER; self.touch = weapon_touch; setsize(self, '-16 -16 0', '16 16 56'); StartItem(); @@ -563,7 +591,7 @@ void() weapon_lightning = { precache_model("progs/g_light.mdl"); setmodel(self, "progs/g_light.mdl"); self.weapon = 3; - self.netname = "Thunderbolt"; + self.netname = WEPNAME_LIGHTNING; self.touch = weapon_touch; setsize(self, '-16 -16 0', '16 16 56'); StartItem(); @@ -885,18 +913,20 @@ following: */ void() item_key1 = { - if(world.worldtype == 0) { - precache_model("progs/w_s_key.mdl"); - setmodel(self, "progs/w_s_key.mdl"); - self.netname = "silver key"; - } else if(world.worldtype == 1) { - precache_model("progs/m_s_key.mdl"); - setmodel(self, "progs/m_s_key.mdl"); - self.netname = "silver runekey"; - } else if(world.worldtype == 2) { - precache_model2("progs/b_s_key.mdl"); - setmodel(self, "progs/b_s_key.mdl"); - self.netname = "silver keycard"; + self.netname = Key1Name(); + switch(world.worldtype) { + case 0: + precache_model("progs/w_s_key.mdl"); + setmodel(self, "progs/w_s_key.mdl"); + break; + case 1: + precache_model("progs/m_s_key.mdl"); + setmodel(self, "progs/m_s_key.mdl"); + break; + case 2: + precache_model2("progs/b_s_key.mdl"); + setmodel(self, "progs/b_s_key.mdl"); + break; } key_setsounds(); self.touch = key_touch; @@ -917,20 +947,20 @@ following: */ void() item_key2 = { - if(world.worldtype == 0) { - precache_model("progs/w_g_key.mdl"); - setmodel(self, "progs/w_g_key.mdl"); - self.netname = "gold key"; - } - if(world.worldtype == 1) { - precache_model("progs/m_g_key.mdl"); - setmodel(self, "progs/m_g_key.mdl"); - self.netname = "gold runekey"; - } - if(world.worldtype == 2) { - precache_model2("progs/b_g_key.mdl"); - setmodel(self, "progs/b_g_key.mdl"); - self.netname = "gold keycard"; + self.netname = Key2Name(); + switch(world.worldtype) { + case 0: + precache_model("progs/w_g_key.mdl"); + setmodel(self, "progs/w_g_key.mdl"); + break; + case 1: + precache_model("progs/m_g_key.mdl"); + setmodel(self, "progs/m_g_key.mdl"); + break; + case 2: + precache_model2("progs/b_g_key.mdl"); + setmodel(self, "progs/b_g_key.mdl"); + break; } key_setsounds(); self.touch = key_touch; @@ -1167,34 +1197,30 @@ void() BackpackTouch = { local entity stemp; local float acount; - if(other.classname != "player") { - return; - } - if(other.health <= 0) { + if(other.classname != "player" || other.health <= 0) { return; } acount = 0; sprint(other, "You get "); - if(self.items) - if((other.items & self.items) == 0) { - acount = 1; - sprint(other, "the "); - sprint(other, self.netname); - } + if(self.items && (other.items & self.items) == 0) { + acount = 1; + sprint(other, "the "); + sprint(other, self.netname); + } - // if the player was using his best weapon, change up to the new one if better + // if the player was using their best weapon, change up to the new one if better stemp = self; self = other; best = W_BestWeapon(); self = stemp; // change weapons - other.ammo_shells = other.ammo_shells + self.ammo_shells; - other.ammo_nails = other.ammo_nails + self.ammo_nails; + other.ammo_shells = other.ammo_shells + self.ammo_shells; + other.ammo_nails = other.ammo_nails + self.ammo_nails; other.ammo_rockets = other.ammo_rockets + self.ammo_rockets; - other.ammo_cells = other.ammo_cells + self.ammo_cells; + other.ammo_cells = other.ammo_cells + self.ammo_cells; new = self.items; if(!new) { @@ -1241,6 +1267,20 @@ void() BackpackTouch = { sprint(other, s); sprint(other, " cells"); } + if(self.items & IT_KEY1) { + if(acount) { + sprint(other, ", "); + } + acount = 1; + sprint(other, Key1Name()); + } + if(self.items & IT_KEY2) { + if(acount) { + sprint(other, ", "); + } + acount = 1; + sprint(other, Key2Name()); + } sprint(other, "\n"); // backpack touch sound @@ -1266,41 +1306,37 @@ void() BackpackTouch = { DropBackpack =============== */ -void() DropBackpack = { +entity() DropBackpack = { local entity item; - if(!(self.ammo_shells + self.ammo_nails + self.ammo_rockets + self.ammo_cells)) { - return; // nothing in it - } - item = spawn(); item.origin = self.origin - '0 0 24'; + item.items = self.weapon | (self.items & (IT_KEY1 | IT_KEY2)); - item.items = self.weapon; if(item.items == IT_AXE) { - item.netname = "Axe"; + item.netname = WEPNAME_AXE; } else if(item.items == IT_SHOTGUN) { - item.netname = "Shotgun"; + item.netname = WEPNAME_SHOTGUN; } else if(item.items == IT_SUPER_SHOTGUN) { - item.netname = "Double-barrelled Shotgun"; + item.netname = WEPNAME_SUPER_SHOTGUN; } else if(item.items == IT_NAILGUN) { - item.netname = "Nailgun"; + item.netname = WEPNAME_NAILGUN; } else if(item.items == IT_SUPER_NAILGUN) { - item.netname = "Super Nailgun"; + item.netname = WEPNAME_SUPER_NAILGUN; } else if(item.items == IT_GRENADE_LAUNCHER) { - item.netname = "Grenade Launcher"; + item.netname = WEPNAME_GRENADE_LAUNCHER; } else if(item.items == IT_ROCKET_LAUNCHER) { - item.netname = "Rocket Launcher"; + item.netname = WEPNAME_ROCKET_LAUNCHER; } else if(item.items == IT_LIGHTNING) { - item.netname = "Thunderbolt"; + item.netname = WEPNAME_LIGHTNING; } else { item.netname = ""; } - item.ammo_shells = self.ammo_shells; - item.ammo_nails = self.ammo_nails; + item.ammo_shells = self.ammo_shells; + item.ammo_nails = self.ammo_nails; item.ammo_rockets = self.ammo_rockets; - item.ammo_cells = self.ammo_cells; + item.ammo_cells = self.ammo_cells; item.velocity_z = 300; item.velocity_x = -100 + (random() * 200); @@ -1315,4 +1351,6 @@ void() DropBackpack = { item.nextthink = time + 120; // remove after 2 minutes item.think = SUB_Remove; + + return item; };