2018-05-02 06:32:59 +08:00
|
|
|
INC_SERVER()
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
function SWEP:Deploy()
|
2018-05-02 06:32:59 +08:00
|
|
|
gamemode.Call("WeaponDeployed", self:GetOwner(), self)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
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()
|
2018-05-02 06:32:59 +08:00
|
|
|
local owner = self:GetOwner()
|
2014-10-02 08:49:54 +08:00
|
|
|
if owner and owner:IsValid() then
|
2018-05-02 06:32:59 +08:00
|
|
|
owner:GiveStatus(self.GhostStatus)
|
2014-10-02 08:49:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:RemoveGhost()
|
2018-05-02 06:32:59 +08:00
|
|
|
local owner = self:GetOwner()
|
2014-10-02 08:49:54 +08:00
|
|
|
if owner and owner:IsValid() then
|
2018-05-02 06:32:59 +08:00
|
|
|
owner:RemoveStatus(self.GhostStatus, false, true)
|
2014-10-02 08:49:54 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SWEP:PrimaryAttack()
|
|
|
|
if not self:CanPrimaryAttack() then return end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local owner = self:GetOwner()
|
2014-10-02 08:49:54 +08:00
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local status = owner:GetStatus(self.GhostStatus)
|
2014-10-02 08:49:54 +08:00
|
|
|
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)
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local channel = GAMEMODE:GetFreeChannel(self.Channel)
|
2015-03-10 02:26:27 +08:00
|
|
|
if channel == -1 then
|
|
|
|
owner:SendLua("surface.PlaySound(\"buttons/button8.wav\")")
|
|
|
|
owner:CenterNotify(COLOR_RED, translate.ClientGet(owner, "no_free_channel"))
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local ent = ents.Create(self.DeployClass)
|
2014-10-02 08:49:54 +08:00
|
|
|
if ent:IsValid() then
|
|
|
|
ent:SetPos(pos)
|
|
|
|
ent:SetAngles(ang)
|
2018-05-02 06:32:59 +08:00
|
|
|
ent.PreOwn = owner
|
2014-10-02 08:49:54 +08:00
|
|
|
ent:Spawn()
|
|
|
|
|
|
|
|
ent:SetObjectOwner(owner)
|
2015-03-10 02:26:27 +08:00
|
|
|
ent:SetChannel(channel)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
ent:EmitSound("npc/dog/dog_servo12.wav")
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
--ent:GhostAllPlayersInMe(5)
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
self:TakePrimaryAmmo(1)
|
|
|
|
|
|
|
|
local stored = owner:PopPackedItem(ent:GetClass())
|
|
|
|
if stored then
|
|
|
|
ent:SetObjectHealth(stored[1])
|
|
|
|
end
|
|
|
|
|
2018-05-02 06:32:59 +08:00
|
|
|
local ammo = math.min(owner:GetAmmoCount(self.TurretAmmoType), self.TurretAmmoStartAmount)
|
2014-12-19 13:52:24 +08:00
|
|
|
ent:SetAmmo(ammo)
|
2018-05-02 06:32:59 +08:00
|
|
|
owner:RemoveAmmo(ammo, self.TurretAmmoType)
|
|
|
|
|
|
|
|
ent.TurretDeployableAmmo = self.Primary.Ammo
|
|
|
|
ent.Damage = self.Primary.Damage
|
|
|
|
ent.Spread = self.TurretSpread
|
|
|
|
ent.SWEP = self:GetClass()
|
2014-12-19 13:52:24 +08:00
|
|
|
|
2014-10-02 08:49:54 +08:00
|
|
|
if not owner:HasWeapon("weapon_zs_gunturretcontrol") then
|
|
|
|
owner:Give("weapon_zs_gunturretcontrol")
|
|
|
|
end
|
2018-05-02 06:32:59 +08:00
|
|
|
owner:SelectWeapon("weapon_zs_gunturretcontrol")
|
2014-10-02 08:49:54 +08:00
|
|
|
|
|
|
|
if self:GetPrimaryAmmoCount() <= 0 then
|
|
|
|
owner:StripWeapon(self:GetClass())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|