From 53e454fe1b22ff77e988c1cdac66f1656b832e95 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 31 Dec 2014 03:21:29 +0000 Subject: [PATCH 1/2] Added forcepickup functions to weapons +Added givetoactivator input so mappers can give weapons to a specific person. +Also added neverremove and ignorepickupcounters so that the weapons can be picked up (or forced) on multiple people. --- .../entities/entities/prop_weapon/init.lua | 39 +++++++++++++++---- gamemodes/zombiesurvival/zombiesurvival.fgd | 17 +++++++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua b/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua index df8f21b..666ccf6 100644 --- a/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua +++ b/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua @@ -8,7 +8,10 @@ ENT.CleanupPriority = 1 function ENT:Initialize() self.m_Health = 200 - + self.IgnorePickupCount = self.IgnorePickupCount or false + self.Forced = self.Forced or false + self.NeverRemove = self.NeverRemove or false + local weptab = weapons.GetStored(self:GetWeaponType()) if weptab and not weptab.BoxPhysicsMax then self:PhysicsInit(SOLID_VPHYSICS) @@ -53,17 +56,21 @@ function ENT:GetShouldRemoveAmmo() end function ENT:Use(activator, caller) - if not activator:IsPlayer() + self:GiveToActivator(activator, caller) +end + +function ENT:GiveToActivator(activator, caller) + if not activator:IsPlayer() or not activator:Alive() or activator:Team() ~= TEAM_HUMAN or self.Removing - or activator:KeyDown(GAMEMODE.UtilityKey) + or (activator:KeyDown(GAMEMODE.UtilityKey) and not self.Forced) or self.NoPickupsTime and CurTime() < self.NoPickupsTime and self.NoPickupsOwner ~= activator then return end local weptype = self:GetWeaponType() if not weptype then return end - if activator:HasWeapon(weptype) and not GAMEMODE.MaxWeaponPickups then + if activator:HasWeapon(weptype) and (self.Forced or not GAMEMODE.MaxWeaponPickups) then local wep = activator:GetWeapon(weptype) if wep:IsValid() then local primary = wep:ValidPrimaryAmmo() @@ -74,7 +81,7 @@ function ENT:Use(activator, caller) local stored = weapons.GetStored(weptype) if stored and stored.AmmoIfHas then - self:RemoveNextFrame() + if not self.NeverRemove then self:RemoveNextFrame() end end return @@ -89,11 +96,11 @@ function ENT:Use(activator, caller) wep:SetClip2(self:GetClip2()) end - if self.PlacedInMap then + if self.PlacedInMap and not self.IgnorePickupCount then activator.WeaponPickups = (activator.WeaponPickups or 0) + 1 end - self:RemoveNextFrame() + if not self.NeverRemove then self:RemoveNextFrame() end end else activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some")) @@ -104,10 +111,28 @@ function ENT:KeyValue(key, value) key = string.lower(key) if key == "weapontype" then self:SetWeaponType(value) + elseif key == "ignorepickupcount" then + self.IgnorePickupCount = tonumber(value) == 1 + elseif key == "neverremove" then + self.NeverRemove = tonumber(value) == 1 + end +end + +function ENT:AcceptInput(name, activator, caller, arg) + name = string.lower(name) + if name == "givetoactivator" then + self.Forced = true + self:GiveToActivator(activator,caller) + return true + elseif name == "setneverremove" then + self.NeverRemove = tonumber(arg) == 1 + elseif name == "setignorepickupcount" then + self.IgnorePickupCount = tonumber(arg) == 1 end end function ENT:OnTakeDamage(dmginfo) + if self.NeverRemove then return end self:TakePhysicsDamage(dmginfo) self.m_Health = self.m_Health - dmginfo:GetDamage() diff --git a/gamemodes/zombiesurvival/zombiesurvival.fgd b/gamemodes/zombiesurvival/zombiesurvival.fgd index 6458b0e..89e0a51 100644 --- a/gamemodes/zombiesurvival/zombiesurvival.fgd +++ b/gamemodes/zombiesurvival/zombiesurvival.fgd @@ -478,7 +478,22 @@ @PointClass studio("models/weapons/w_irifle.mdl") base(Targetname, Parentname, Angles) = prop_weapon : "ZS: Game Specific Weapon." [ // Keys - weapontype(string) : "weapon_type" : "weapon_zs_m4" : "Weapon type this entity becomes" + weapontype(string) : "Weapon Type" : "weapon_zs_m4" : "Weapon type this entity becomes" + neverremove(choices) : "Never Remove" : 0 : "Never remove when used or damage, for repeated uses." = + [ + 0 : "No" + 1 : "Yes" + ] + ignorepickupcount(choices) : "Ignore Pickup Counter" : 0 : "Set to ignore a maxpickupcounter, if any." = + [ + 0 : "No" + 1 : "Yes" + ] + + // Inputs + input givetoactivator(void) : "Forces the weapon onto the activator." + input setneverremove(integer) : "Set to make infinite uses." + input setignorepickupcount(integer) : "Set to ignore any max pickup counter." ] @PointClass base(Targetname, Parentname) sphere( range ) = point_worldhint : "ZS: Allows you to create 3D hints and information tags." From 2dd3f322e17b4e9f4c7abbf91ea5d2aa164fa54e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 31 Dec 2014 18:53:13 +0000 Subject: [PATCH 2/2] Added forcepickup functions to ammo +cloned new functions added in prop_weapon to prop_ammo +added "ignoreuse" and ability to change what type of ammo or weapon the entity is --- .../entities/entities/prop_ammo/init.lua | 43 +++++++++++++++++-- .../entities/entities/prop_weapon/init.lua | 12 ++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua b/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua index aaa3ea0..e622cbe 100644 --- a/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua +++ b/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua @@ -7,6 +7,10 @@ ENT.CleanupPriority = 2 function ENT:Initialize() self.m_Health = 50 + self.IgnorePickupCount = self.IgnorePickupCount or false + self.Forced = self.Forced or false + self.NeverRemove = self.NeverRemove or false + self.IgnoreUse = self.IgnoreUse or false self:PhysicsInit(SOLID_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) @@ -42,8 +46,12 @@ function ENT:GetAmmo() end function ENT:Use(activator, caller) + if self.IgnoreUse then return end + self:GiveToActivator(activator, caller) +end +function ENT:GiveToActivator(activator, caller) if activator:IsPlayer() and activator:Alive() and not activator:KeyDown(GAMEMODE.UtilityKey) and activator:Team() ~= TEAM_UNDEAD and not self.Removing then - if not self.PlacedInMap or not GAMEMODE.MaxAmmoPickups or (activator.AmmoPickups or 0) < GAMEMODE.MaxAmmoPickups or team.NumPlayers(TEAM_HUMAN) <= 1 then + if self.IgnorePickupCount or (not self.PlacedInMap or not GAMEMODE.MaxAmmoPickups or (activator.AmmoPickups or 0) < GAMEMODE.MaxAmmoPickups or team.NumPlayers(TEAM_HUMAN) <= 1) then if self.PlacedInMap and GAMEMODE.WeaponRequiredForAmmo and team.NumPlayers(TEAM_HUMAN) > 1 then local hasweapon = false for _, wep in pairs(activator:GetWeapons()) do @@ -54,7 +62,7 @@ function ENT:Use(activator, caller) end end - if not hasweapon then + if not hasweapon and not self.Forced then activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "nothing_for_this_ammo")) return end @@ -62,11 +70,11 @@ function ENT:Use(activator, caller) activator:GiveAmmo(self:GetAmmo(), self:GetAmmoType()) - if self.PlacedInMap then + if self.PlacedInMap and not self.IgnorePickupCount then activator.AmmoPickups = (activator.AmmoPickups or 0) + 1 end - self:RemoveNextFrame(0) + if not self.NeverRemove then self:RemoveNextFrame() end else activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some")) end @@ -79,10 +87,37 @@ function ENT:KeyValue(key, value) self:SetAmmoType(value) elseif key == "amount" then self:SetAmmo(math.ceil(tonumber(value) or 0)) + elseif key == "ignorepickupcount" then + self.IgnorePickupCount = tonumber(value) == 1 + elseif key == "neverremove" then + self.NeverRemove = tonumber(value) == 1 + elseif key == "ignoreuse" then + self.IgnoreUse = tonumber(value) == 1 + end +end + +function ENT:AcceptInput(name, activator, caller, arg) + name = string.lower(name) + if name == "givetoactivator" then + self.Forced = true + self:GiveToActivator(activator,caller) + return true + elseif name == "setneverremove" then + self.NeverRemove = tonumber(arg) == 1 + return true + elseif name == "setignorepickupcount" then + self.IgnorePickupCount = tonumber(arg) == 1 + return true + elseif name == "setignoreuse" then + self.IgnoreUse = tonumber(value) == 1 + return true + elseif name == "setammotype" then + self:SetAmmoType(arg) end end function ENT:OnTakeDamage(dmginfo) + if self.NeverRemove then return end self:TakePhysicsDamage(dmginfo) self.m_Health = self.m_Health - dmginfo:GetDamage() diff --git a/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua b/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua index 666ccf6..85c8f92 100644 --- a/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua +++ b/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua @@ -11,6 +11,7 @@ function ENT:Initialize() self.IgnorePickupCount = self.IgnorePickupCount or false self.Forced = self.Forced or false self.NeverRemove = self.NeverRemove or false + self.IgnoreUse = self.IgnoreUse or false local weptab = weapons.GetStored(self:GetWeaponType()) if weptab and not weptab.BoxPhysicsMax then @@ -56,6 +57,7 @@ function ENT:GetShouldRemoveAmmo() end function ENT:Use(activator, caller) + if self.IgnoreUse then return end self:GiveToActivator(activator, caller) end @@ -115,6 +117,8 @@ function ENT:KeyValue(key, value) self.IgnorePickupCount = tonumber(value) == 1 elseif key == "neverremove" then self.NeverRemove = tonumber(value) == 1 + elseif key == "ignoreuse" then + self.IgnoreUse = tonumber(value) == 1 end end @@ -126,8 +130,16 @@ function ENT:AcceptInput(name, activator, caller, arg) return true elseif name == "setneverremove" then self.NeverRemove = tonumber(arg) == 1 + return true elseif name == "setignorepickupcount" then self.IgnorePickupCount = tonumber(arg) == 1 + return true + elseif name == "setignoreuse" then + self.IgnoreUse = tonumber(value) == 1 + return true + elseif name == "setweapontype" then + self:SetWeaponType(arg) + return true end end