zombiesurvival-evolved/gamemodes/zombiesurvival/entities/weapons/weapon_zs_gunturret/init.lua
JetBoom 33b18089e5 Maximum of 7 turrets active at once
Blaster ammo capacity 6 -> 5
2015-03-09 14:26:27 -04:00

93 lines
2 KiB
Lua

AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function SWEP:Deploy()
gamemode.Call("WeaponDeployed", self.Owner, self)
self.IdleAnimation = CurTime() + self:SequenceDuration()
self:SpawnGhost()
return true
end
function SWEP:OnRemove()
self:RemoveGhost()
end
function SWEP:Holster()
self:RemoveGhost()
return true
end
function SWEP:SpawnGhost()
local owner = self.Owner
if owner and owner:IsValid() then
owner:GiveStatus("ghost_gunturret")
end
end
function SWEP:RemoveGhost()
local owner = self.Owner
if owner and owner:IsValid() then
owner:RemoveStatus("ghost_gunturret", false, true)
end
end
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
local owner = self.Owner
local status = owner.status_ghost_gunturret
if not (status and status:IsValid()) then return end
status:RecalculateValidity()
if not status:GetValidPlacement() then return end
local pos, ang = status:RecalculateValidity()
if not pos or not ang then return end
self:SetNextPrimaryAttack(CurTime() + self.Primary.Delay)
local channel = GAMEMODE:GetFreeChannel("prop_gunturret")
if channel == -1 then
owner:SendLua("surface.PlaySound(\"buttons/button8.wav\")")
owner:CenterNotify(COLOR_RED, translate.ClientGet(owner, "no_free_channel"))
return
end
local ent = ents.Create("prop_gunturret")
if ent:IsValid() then
ent:SetPos(pos)
ent:SetAngles(ang)
ent:Spawn()
ent:SetObjectOwner(owner)
ent:SetChannel(channel)
ent:EmitSound("npc/dog/dog_servo12.wav")
ent:GhostAllPlayersInMe(5)
self:TakePrimaryAmmo(1)
local stored = owner:PopPackedItem(ent:GetClass())
if stored then
ent:SetObjectHealth(stored[1])
end
local ammo = math.min(owner:GetAmmoCount("smg1"), 250)
ent:SetAmmo(ammo)
owner:RemoveAmmo(ammo, "smg1")
if not owner:HasWeapon("weapon_zs_gunturretcontrol") then
owner:Give("weapon_zs_gunturretcontrol")
end
if self:GetPrimaryAmmoCount() <= 0 then
owner:StripWeapon(self:GetClass())
end
end
end