Added Failed/Passed Outputs when picking up items

Added OnPickupFailed and OnPicupPassed to both prop_weapon and
prop_weapon
This commit is contained in:
Ben 2015-01-11 21:50:35 +00:00
parent 57cbcc0b1e
commit c15a087698
3 changed files with 35 additions and 5 deletions

View file

@ -63,6 +63,7 @@ function ENT:GiveToActivator(activator, caller)
end end
if not hasweapon and not self.Forced then if not hasweapon and not self.Forced then
self:Input("OnPickupFailed", activator)
activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "nothing_for_this_ammo")) activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "nothing_for_this_ammo"))
return return
end end
@ -73,11 +74,14 @@ function ENT:GiveToActivator(activator, caller)
if self.PlacedInMap and not self.IgnorePickupCount then if self.PlacedInMap and not self.IgnorePickupCount then
activator.AmmoPickups = (activator.AmmoPickups or 0) + 1 activator.AmmoPickups = (activator.AmmoPickups or 0) + 1
end end
self:Input("OnPickupPassed", activator, caller)
if not self.NeverRemove then self:RemoveNextFrame() end if not self.NeverRemove then self:RemoveNextFrame() end
else else
self:Input("OnPickupFailed", activator)
activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some")) activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some"))
end end
else
self:Input("OnPickupFailed", activator)
end end
end end
@ -93,6 +97,8 @@ function ENT:KeyValue(key, value)
self.NeverRemove = tonumber(value) == 1 self.NeverRemove = tonumber(value) == 1
elseif key == "ignoreuse" then elseif key == "ignoreuse" then
self.IgnoreUse = tonumber(value) == 1 self.IgnoreUse = tonumber(value) == 1
elseif string.sub(key, 1, 2) == "on" then
self:AddOnOutput(key, value)
end end
end end
@ -113,6 +119,8 @@ function ENT:AcceptInput(name, activator, caller, arg)
return true return true
elseif name == "setammotype" then elseif name == "setammotype" then
self:SetAmmoType(arg) self:SetAmmoType(arg)
elseif string.sub(name, 1, 2) == "on" then
self:FireOutput(name, activator, caller, args)
end end
end end

View file

@ -68,10 +68,17 @@ function ENT:GiveToActivator(activator, caller)
or activator:Team() ~= TEAM_HUMAN or activator:Team() ~= TEAM_HUMAN
or self.Removing or self.Removing
or (activator:KeyDown(GAMEMODE.UtilityKey) and not self.Forced) 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() 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 if activator:HasWeapon(weptype) and (self.Forced or not GAMEMODE.MaxWeaponPickups) then
local wep = activator:GetWeapon(weptype) local wep = activator:GetWeapon(weptype)
@ -84,9 +91,9 @@ function ENT:GiveToActivator(activator, caller)
local stored = weapons.GetStored(weptype) local stored = weapons.GetStored(weptype)
if stored and stored.AmmoIfHas then if stored and stored.AmmoIfHas then
self:Input("OnPickupPassed", activator)
if not self.NeverRemove then self:RemoveNextFrame() end if not self.NeverRemove then self:RemoveNextFrame() end
end end
return return
end end
end end
@ -102,10 +109,13 @@ function ENT:GiveToActivator(activator, caller)
if self.PlacedInMap and not self.IgnorePickupCount then if self.PlacedInMap and not self.IgnorePickupCount then
activator.WeaponPickups = (activator.WeaponPickups or 0) + 1 activator.WeaponPickups = (activator.WeaponPickups or 0) + 1
end end
self:Input("OnPickupPassed", activator)
if not self.NeverRemove then self:RemoveNextFrame() end if not self.NeverRemove then self:RemoveNextFrame() end
else
self:Input("OnPickupFailed", activator)
end end
else else
self:Input("OnPickupFailed", activator)
activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some")) activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "you_decide_to_leave_some"))
end end
end end
@ -122,6 +132,8 @@ function ENT:KeyValue(key, value)
self.IgnoreUse = tonumber(value) == 1 self.IgnoreUse = tonumber(value) == 1
elseif key == "empty" then elseif key == "empty" then
self.Empty = tonumber(value) == 1 self.Empty = tonumber(value) == 1
elseif string.sub(key, 1, 2) == "on" then
self:AddOnOutput(key, value)
end end
end end
@ -145,6 +157,8 @@ function ENT:AcceptInput(name, activator, caller, arg)
return true return true
elseif name == "setempty" then elseif name == "setempty" then
self.Empty = tonumber(arg) == 1 self.Empty = tonumber(arg) == 1
elseif string.sub(name, 1, 2) == "on" then
self:FireOutput(name, activator, caller, args)
end end
end end

View file

@ -495,6 +495,10 @@
input setignorepickupcount(integer) : "Set to ignore any max pickup counter." input setignorepickupcount(integer) : "Set to ignore any max pickup counter."
input setignoreuse(integer) : "Set to disable being able to pickup via use key" 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." 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." @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 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 setweapontype(string) : "Set to change the weapon type of this entity."
input setempty(string) : "Set to empty the weapon of any default ammo." 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." @PointClass base(Targetname, Parentname) sphere( range ) = point_worldhint : "ZS: Allows you to create 3D hints and information tags."