zombiesurvival-evolved/gamemodes/zombiesurvival/entities/weapons/weapon_zs_arsenalcrate/init.lua

84 lines
1.6 KiB
Lua
Raw Normal View History

2014-10-02 08:49:54 +08:00
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function SWEP:Deploy()
gamemode.Call("WeaponDeployed", self.Owner, self)
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_arsenalcrate")
end
end
function SWEP:RemoveGhost()
local owner = self.Owner
if owner and owner:IsValid() then
owner:RemoveStatus("ghost_arsenalcrate", false, true)
end
end
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
local owner = self.Owner
local status = owner.status_ghost_arsenalcrate
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 ent = ents.Create("prop_arsenalcrate")
if ent:IsValid() then
ent:SetPos(pos)
ent:SetAngles(ang)
ent:Spawn()
ent:SetObjectOwner(owner)
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
if self:GetPrimaryAmmoCount() <= 0 then
owner:StripWeapon(self:GetClass())
end
end
end
function SWEP:Think()
local count = self:GetPrimaryAmmoCount()
if count ~= self:GetReplicatedAmmo() then
self:SetReplicatedAmmo(count)
self.Owner:ResetSpeed()
end
end