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

95 lines
2 KiB
Lua
Raw Normal View History

INC_SERVER()
2014-10-02 08:49:54 +08:00
function SWEP:Deploy()
gamemode.Call("WeaponDeployed", self:GetOwner(), self)
2014-10-02 08:49:54 +08:00
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:GetOwner()
2014-10-02 08:49:54 +08:00
if owner and owner:IsValid() then
owner:GiveStatus("ghost_messagebeacon")
end
end
function SWEP:RemoveGhost()
local owner = self:GetOwner()
2014-10-02 08:49:54 +08:00
if owner and owner:IsValid() then
owner:RemoveStatus("ghost_messagebeacon", false, true)
end
end
function SWEP:SecondaryAttack()
end
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
local owner = self:GetOwner()
2014-10-02 08:49:54 +08:00
local status = owner.status_ghost_messagebeacon
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_messagebeacon")
if ent:IsValid() then
ent:SetPos(pos)
ent:SetAngles(ang)
ent:Spawn()
ent:SetObjectOwner(owner)
ent:SetMessageID(self.MessageID)
ent:EmitSound("npc/dog/dog_servo12.wav")
--ent:GhostAllPlayersInMe(5)
self:TakePrimaryAmmo(1)
local stored = owner:PopPackedItem(ent:GetClass())
if stored then
ent.ObjHealth = stored[1]
2014-10-02 08:49:54 +08:00
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:GetOwner():ResetSpeed()
2014-10-02 08:49:54 +08:00
end
end
SWEP.MessageID = 1
concommand.Add("setmessagebeaconmessage", function(sender, command, arguments)
if not sender:IsValid() then return end
local wep = sender:GetActiveWeapon()
if wep:IsValid() and wep:GetClass() == "weapon_zs_messagebeacon" then
wep.MessageID = math.Clamp(math.floor(tonumbersafe(arguments[1]) or 1), 1, #GAMEMODE.ValidBeaconMessages)
end
end)