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
This commit is contained in:
parent
53e454fe1b
commit
2dd3f322e1
2 changed files with 51 additions and 4 deletions
|
@ -7,6 +7,10 @@ ENT.CleanupPriority = 2
|
||||||
|
|
||||||
function ENT:Initialize()
|
function ENT:Initialize()
|
||||||
self.m_Health = 50
|
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:PhysicsInit(SOLID_VPHYSICS)
|
||||||
self:SetSolid(SOLID_VPHYSICS)
|
self:SetSolid(SOLID_VPHYSICS)
|
||||||
|
@ -42,8 +46,12 @@ function ENT:GetAmmo()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ENT:Use(activator, caller)
|
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 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
|
if self.PlacedInMap and GAMEMODE.WeaponRequiredForAmmo and team.NumPlayers(TEAM_HUMAN) > 1 then
|
||||||
local hasweapon = false
|
local hasweapon = false
|
||||||
for _, wep in pairs(activator:GetWeapons()) do
|
for _, wep in pairs(activator:GetWeapons()) do
|
||||||
|
@ -54,7 +62,7 @@ function ENT:Use(activator, caller)
|
||||||
end
|
end
|
||||||
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"))
|
activator:CenterNotify(COLOR_RED, translate.ClientGet(activator, "nothing_for_this_ammo"))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -62,11 +70,11 @@ function ENT:Use(activator, caller)
|
||||||
|
|
||||||
activator:GiveAmmo(self:GetAmmo(), self:GetAmmoType())
|
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
|
activator.AmmoPickups = (activator.AmmoPickups or 0) + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
self:RemoveNextFrame(0)
|
if not self.NeverRemove then self:RemoveNextFrame() end
|
||||||
else
|
else
|
||||||
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
|
||||||
|
@ -79,10 +87,37 @@ function ENT:KeyValue(key, value)
|
||||||
self:SetAmmoType(value)
|
self:SetAmmoType(value)
|
||||||
elseif key == "amount" then
|
elseif key == "amount" then
|
||||||
self:SetAmmo(math.ceil(tonumber(value) or 0))
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
function ENT:OnTakeDamage(dmginfo)
|
function ENT:OnTakeDamage(dmginfo)
|
||||||
|
if self.NeverRemove then return end
|
||||||
self:TakePhysicsDamage(dmginfo)
|
self:TakePhysicsDamage(dmginfo)
|
||||||
|
|
||||||
self.m_Health = self.m_Health - dmginfo:GetDamage()
|
self.m_Health = self.m_Health - dmginfo:GetDamage()
|
||||||
|
|
|
@ -11,6 +11,7 @@ function ENT:Initialize()
|
||||||
self.IgnorePickupCount = self.IgnorePickupCount or false
|
self.IgnorePickupCount = self.IgnorePickupCount or false
|
||||||
self.Forced = self.Forced or false
|
self.Forced = self.Forced or false
|
||||||
self.NeverRemove = self.NeverRemove or false
|
self.NeverRemove = self.NeverRemove or false
|
||||||
|
self.IgnoreUse = self.IgnoreUse or false
|
||||||
|
|
||||||
local weptab = weapons.GetStored(self:GetWeaponType())
|
local weptab = weapons.GetStored(self:GetWeaponType())
|
||||||
if weptab and not weptab.BoxPhysicsMax then
|
if weptab and not weptab.BoxPhysicsMax then
|
||||||
|
@ -56,6 +57,7 @@ function ENT:GetShouldRemoveAmmo()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ENT:Use(activator, caller)
|
function ENT:Use(activator, caller)
|
||||||
|
if self.IgnoreUse then return end
|
||||||
self:GiveToActivator(activator, caller)
|
self:GiveToActivator(activator, caller)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -115,6 +117,8 @@ function ENT:KeyValue(key, value)
|
||||||
self.IgnorePickupCount = tonumber(value) == 1
|
self.IgnorePickupCount = tonumber(value) == 1
|
||||||
elseif key == "neverremove" then
|
elseif key == "neverremove" then
|
||||||
self.NeverRemove = tonumber(value) == 1
|
self.NeverRemove = tonumber(value) == 1
|
||||||
|
elseif key == "ignoreuse" then
|
||||||
|
self.IgnoreUse = tonumber(value) == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -126,8 +130,16 @@ function ENT:AcceptInput(name, activator, caller, arg)
|
||||||
return true
|
return true
|
||||||
elseif name == "setneverremove" then
|
elseif name == "setneverremove" then
|
||||||
self.NeverRemove = tonumber(arg) == 1
|
self.NeverRemove = tonumber(arg) == 1
|
||||||
|
return true
|
||||||
elseif name == "setignorepickupcount" then
|
elseif name == "setignorepickupcount" then
|
||||||
self.IgnorePickupCount = tonumber(arg) == 1
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue