From c15a08769840bac6b7b9275e5125b23d26474943 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 11 Jan 2015 21:50:35 +0000 Subject: [PATCH] Added Failed/Passed Outputs when picking up items Added OnPickupFailed and OnPicupPassed to both prop_weapon and prop_weapon --- .../entities/entities/prop_ammo/init.lua | 10 ++++++++- .../entities/entities/prop_weapon/init.lua | 22 +++++++++++++++---- gamemodes/zombiesurvival/zombiesurvival.fgd | 8 +++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua b/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua index e7a1ab7..22d980e 100644 --- a/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua +++ b/gamemodes/zombiesurvival/entities/entities/prop_ammo/init.lua @@ -63,6 +63,7 @@ function ENT:GiveToActivator(activator, caller) end if not hasweapon and not self.Forced then + self:Input("OnPickupFailed", activator) activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "nothing_for_this_ammo")) return end @@ -73,11 +74,14 @@ function ENT:GiveToActivator(activator, caller) if self.PlacedInMap and not self.IgnorePickupCount then activator.AmmoPickups = (activator.AmmoPickups or 0) + 1 end - + self:Input("OnPickupPassed", activator, caller) if not self.NeverRemove then self:RemoveNextFrame() end else + self:Input("OnPickupFailed", activator) activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some")) end + else + self:Input("OnPickupFailed", activator) end end @@ -93,6 +97,8 @@ function ENT:KeyValue(key, value) self.NeverRemove = tonumber(value) == 1 elseif key == "ignoreuse" then self.IgnoreUse = tonumber(value) == 1 + elseif string.sub(key, 1, 2) == "on" then + self:AddOnOutput(key, value) end end @@ -113,6 +119,8 @@ function ENT:AcceptInput(name, activator, caller, arg) return true elseif name == "setammotype" then self:SetAmmoType(arg) + elseif string.sub(name, 1, 2) == "on" then + self:FireOutput(name, activator, caller, args) end end diff --git a/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua b/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua index 8152211..8f4a5eb 100644 --- a/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua +++ b/gamemodes/zombiesurvival/entities/entities/prop_weapon/init.lua @@ -68,10 +68,17 @@ function ENT:GiveToActivator(activator, caller) or activator:Team() ~= TEAM_HUMAN or self.Removing or (activator:KeyDown(GAMEMODE.UtilityKey) and not self.Forced) - or self.NoPickupsTime and CurTime() < self.NoPickupsTime and self.NoPickupsOwner ~= activator then return end + or self.NoPickupsTime and CurTime() < self.NoPickupsTime and self.NoPickupsOwner ~= activator then + + self:Input("OnPickupFailed", activator) + return + end local weptype = self:GetWeaponType() - if not weptype then return end + if not weptype then + self:Input("OnPickupFailed", activator) + return + end if activator:HasWeapon(weptype) and (self.Forced or not GAMEMODE.MaxWeaponPickups) then local wep = activator:GetWeapon(weptype) @@ -84,9 +91,9 @@ function ENT:GiveToActivator(activator, caller) local stored = weapons.GetStored(weptype) if stored and stored.AmmoIfHas then + self:Input("OnPickupPassed", activator) if not self.NeverRemove then self:RemoveNextFrame() end end - return end end @@ -102,10 +109,13 @@ function ENT:GiveToActivator(activator, caller) if self.PlacedInMap and not self.IgnorePickupCount then activator.WeaponPickups = (activator.WeaponPickups or 0) + 1 end - + self:Input("OnPickupPassed", activator) if not self.NeverRemove then self:RemoveNextFrame() end + else + self:Input("OnPickupFailed", activator) end else + self:Input("OnPickupFailed", activator) activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some")) end end @@ -122,6 +132,8 @@ function ENT:KeyValue(key, value) self.IgnoreUse = tonumber(value) == 1 elseif key == "empty" then self.Empty = tonumber(value) == 1 + elseif string.sub(key, 1, 2) == "on" then + self:AddOnOutput(key, value) end end @@ -145,6 +157,8 @@ function ENT:AcceptInput(name, activator, caller, arg) return true elseif name == "setempty" then self.Empty = tonumber(arg) == 1 + elseif string.sub(name, 1, 2) == "on" then + self:FireOutput(name, activator, caller, args) end end diff --git a/gamemodes/zombiesurvival/zombiesurvival.fgd b/gamemodes/zombiesurvival/zombiesurvival.fgd index 406f04e..011a04a 100644 --- a/gamemodes/zombiesurvival/zombiesurvival.fgd +++ b/gamemodes/zombiesurvival/zombiesurvival.fgd @@ -495,6 +495,10 @@ input setignorepickupcount(integer) : "Set to ignore any max pickup counter." input setignoreuse(integer) : "Set to disable being able to pickup via use key" input setammotype(string) : "Set to change the ammo type of this entity." + + // Outputs + output OnPickupPassed(void) : "Called when the ammo is given to the player." + output OnPickupFailed(void) : "Called when the ammo is not given to the player" ] @PointClass studio("models/weapons/w_irifle.mdl") base(Targetname, Parentname, Angles) = prop_weapon : "ZS: Game Specific Weapon." @@ -529,6 +533,10 @@ input setignoreuse(integer) : "Set to disable being able to pickup via use key" input setweapontype(string) : "Set to change the weapon type of this entity." input setempty(string) : "Set to empty the weapon of any default ammo." + + // Outputs + output OnPickupPassed(void) : "Called when the weapon is given to the player." + output OnPickupFailed(void) : "Called when the weapon is not given to the player" ] @PointClass base(Targetname, Parentname) sphere( range ) = point_worldhint : "ZS: Allows you to create 3D hints and information tags."