Merge pull request #90 from BClark09/master
Commits to add control to prop_weapon and prop_ammo
This commit is contained in:
commit
4a1e79c8bf
3 changed files with 99 additions and 12 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()
|
||||||
|
|
|
@ -8,7 +8,11 @@ ENT.CleanupPriority = 1
|
||||||
|
|
||||||
function ENT:Initialize()
|
function ENT:Initialize()
|
||||||
self.m_Health = 200
|
self.m_Health = 200
|
||||||
|
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())
|
local weptab = weapons.GetStored(self:GetWeaponType())
|
||||||
if weptab and not weptab.BoxPhysicsMax then
|
if weptab and not weptab.BoxPhysicsMax then
|
||||||
self:PhysicsInit(SOLID_VPHYSICS)
|
self:PhysicsInit(SOLID_VPHYSICS)
|
||||||
|
@ -53,17 +57,22 @@ function ENT:GetShouldRemoveAmmo()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ENT:Use(activator, caller)
|
function ENT:Use(activator, caller)
|
||||||
if not activator:IsPlayer()
|
if self.IgnoreUse then return end
|
||||||
|
self:GiveToActivator(activator, caller)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ENT:GiveToActivator(activator, caller)
|
||||||
|
if not activator:IsPlayer()
|
||||||
or not activator:Alive()
|
or not activator:Alive()
|
||||||
or activator:Team() ~= TEAM_HUMAN
|
or activator:Team() ~= TEAM_HUMAN
|
||||||
or self.Removing
|
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
|
or self.NoPickupsTime and CurTime() < self.NoPickupsTime and self.NoPickupsOwner ~= activator then return end
|
||||||
|
|
||||||
local weptype = self:GetWeaponType()
|
local weptype = self:GetWeaponType()
|
||||||
if not weptype then return end
|
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)
|
local wep = activator:GetWeapon(weptype)
|
||||||
if wep:IsValid() then
|
if wep:IsValid() then
|
||||||
local primary = wep:ValidPrimaryAmmo()
|
local primary = wep:ValidPrimaryAmmo()
|
||||||
|
@ -74,7 +83,7 @@ function ENT:Use(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:RemoveNextFrame()
|
if not self.NeverRemove then self:RemoveNextFrame() end
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -89,11 +98,11 @@ function ENT:Use(activator, caller)
|
||||||
wep:SetClip2(self:GetClip2())
|
wep:SetClip2(self:GetClip2())
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.PlacedInMap 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:RemoveNextFrame()
|
if not self.NeverRemove then self:RemoveNextFrame() end
|
||||||
end
|
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"))
|
||||||
|
@ -104,10 +113,38 @@ function ENT:KeyValue(key, value)
|
||||||
key = string.lower(key)
|
key = string.lower(key)
|
||||||
if key == "weapontype" then
|
if key == "weapontype" then
|
||||||
self:SetWeaponType(value)
|
self:SetWeaponType(value)
|
||||||
|
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 == "setweapontype" then
|
||||||
|
self:SetWeaponType(arg)
|
||||||
|
return true
|
||||||
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()
|
||||||
|
|
|
@ -478,7 +478,22 @@
|
||||||
@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."
|
||||||
[
|
[
|
||||||
// Keys
|
// 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."
|
@PointClass base(Targetname, Parentname) sphere( range ) = point_worldhint : "ZS: Allows you to create 3D hints and information tags."
|
||||||
|
|
Loading…
Reference in a new issue