Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile( "shared.lua" )
- SWEP.Author = "Hoff"
- SWEP.Instructions = ""
- SWEP.Category = "CoD Zombies"
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- SWEP.ViewModel = "models/hoff/weapons/timebomb/c_timebomb.mdl"
- SWEP.WorldModel = "models/hoff/weapons/timebomb/w_timebomb.mdl"
- SWEP.ViewModelFOV = 64
- SWEP.Primary.ClipSize = -1
- SWEP.Primary.DefaultClip = 1
- SWEP.Primary.Automatic = true
- SWEP.Primary.Ammo = "ammo_timebomb"
- SWEP.Primary.Delay = 1
- SWEP.Secondary.ClipSize = 0
- SWEP.Secondary.DefaultClip = 0
- SWEP.Secondary.Automatic = false
- SWEP.Secondary.Ammo = "none"
- SWEP.Weight = 5
- SWEP.AutoSwitchTo = false
- SWEP.AutoSwitchFrom = false
- SWEP.PrintName = "Time Bomb"
- SWEP.Slot = 4
- SWEP.SlotPos = 5
- SWEP.DrawAmmo = false
- SWEP.DrawCrosshair = false
- SWEP.AllowInteraction = true
- SWEP.NoInstantDraw = true
- SWEP.UseHands = true
- SWEP.NZSpecialWeaponData = {MaxAmmo = 1, AmmoType = "ammo_timebomb"}
- SWEP.NZSpecialCategory = "shield"
- function SWEP:NZSpecialHolster(wep)
- return true -- This lets us always holster it even though it is a special weapon
- end
- game.AddAmmoType( {
- name = "ammo_timebomb",
- dmgtype = DMG_BULLET,
- tracer = TRACER_LINE,
- plydmg = 0,
- npcdmg = 0,
- force = 2000,
- minsplash = 10,
- maxsplash = 5
- } )
- if CLIENT then
- language.Add("ammo_timebomb_ammo", "Time Bomb Ammo")
- end
- TimeBombState =
- {
- VM_TIMEBOMB_UNSET = 0,
- VM_TIMEBOMB_TICKERONLY = 1,
- VM_TIMEBOMB_BOTH = 2
- }
- SWEP.CurrentState = TimeBombState.VM_TIMEBOMB_UNSET
- SWEP.Offset = {
- Pos = {
- Up = -1,
- Right = 4.5,
- Forward = 4.5,
- },
- Ang = {
- Up = 90,
- Right = 90,
- Forward = 0,
- }
- }
- function SWEP:DrawWorldModel( )
- if not IsValid( self:GetOwner() ) then
- self:DrawModel( )
- return
- end
- local bone = self:GetOwner():LookupBone( "ValveBiped.Bip01_R_Hand" )
- if not bone then
- self:DrawModel( )
- return
- end
- local pos, ang = self:GetOwner():GetBonePosition( bone )
- pos = pos + ang:Right() * self.Offset.Pos.Right + ang:Forward() * self.Offset.Pos.Forward + ang:Up() * self.Offset.Pos.Up
- ang:RotateAroundAxis( ang:Right(), self.Offset.Ang.Right )
- ang:RotateAroundAxis( ang:Forward(), self.Offset.Ang.Forward )
- ang:RotateAroundAxis( ang:Up(), self.Offset.Ang.Up )
- self:SetRenderOrigin( pos )
- self:SetRenderAngles( ang )
- self:DrawModel()
- end
- function SWEP:ResetBonePositions(val)
- if SERVER then
- self:CallOnClient("ResetBonePositions", "")
- return
- end
- local vm = self:GetOwner():GetViewModel()
- if not IsValid(vm) then return end
- if (not vm:GetBoneCount()) then return end
- for i = 0, vm:GetBoneCount() do
- vm:ManipulateBoneScale(i, Vector(1, 1, 1))
- vm:ManipulateBoneAngles(i, Angle(0, 0, 0))
- vm:ManipulateBonePosition(i, Vector(0,0,0))
- end
- end
- function SWEP:Initialize()
- self:SetModelScale( 0.8, 0 )
- timer.Simple(0.25, function()
- if IsValid(self) and IsValid(self:GetOwner()) then
- for k, v in ipairs( ents.FindByClass( "cod-timebomb" ) ) do
- if v:GetNWString("OwnerID") == self:GetOwner():SteamID() then
- v.BombOwner = self:GetOwner()
- self:SetNWBool("bTimeBombOut", true)
- break
- end
- end
- end
- if IsValid(self) and IsValid(self:GetOwner()) and self:GetOwner():GetAmmoCount(self.Primary.Ammo) > 0 then
- self:SetNWBool("bInitialDeploy", true)
- end
- end)
- end
- function SWEP:Deploy()
- self:ResetBonePositions()
- self:SendWeaponAnim(ACT_VM_HITLEFT)
- self:SetCollisionGroup(COLLISION_GROUP_NONE)
- self:SetHoldType("duel")
- if self:Ammo1() <= 0 then
- self:SetCurrentState(TimeBombState.VM_TIMEBOMB_TICKERONLY)
- else
- self:SetCurrentState(TimeBombState.VM_TIMEBOMB_BOTH)
- end
- timer.Simple(3.25, function()
- if IsValid(self) and IsValid(self:GetOwner()) then
- self:SetNWBool("bInitialDeploy", false)
- end
- end)
- self:SetNextPrimaryFire(CurTime() + 0.6)
- self:SetNextSecondaryFire(CurTime() + 1)
- end
- function SWEP:PrimaryAttack()
- if CLIENT then
- return
- end
- self:PlayPrimaryFireAnim()
- timer.Simple(0.1, function()
- if IsValid(self) then
- self:GetOwner():EmitSound("hoff/zmb/timebomb/watch_click.mp3")
- end
- end)
- local bShouldSaveOwnerOnly = ConVarExists("TimeBomb_AffectSelfOnly") and GetConVar("TimeBomb_AffectSelfOnly"):GetBool() or false
- timer.Simple(0.35, function()
- if not IsValid(self) then
- return
- end
- local bFoundBomb = false
- if self:GetNWBool("bTimeBombOut") then
- for k, v in ipairs( ents.FindByClass( "cod-timebomb" ) ) do
- if v.BombOwner ~= self:GetOwner() then
- continue
- end
- local fx = EffectData()
- fx:SetOrigin(v:GetPos() + v:GetUp() * 25)
- util.Effect("StunstickImpact",fx)
- if not GetConVar("TimeBomb_InstantTravel"):GetBool() then
- if bShouldSaveOwnerOnly then
- net.Start( "CreateTimeBombOverlay" )
- net.Send(self:GetOwner())
- else
- v:FreezeNPCs()
- v:PlayScreenOverlayFX()
- end
- self:SetNWBool("bTimeBombOut", false)
- timer.Simple(4.25, function()
- if IsValid(v) and v:IsValid() then
- v:RewindProps()
- for i,box in ipairs(ents.FindByClass("zombies_mysterybox")) do
- local boxPos = v:GetPos() + v:GetUp() * 770
- local radius = 150
- box:RemoveDupedEnts(boxPos, radius)
- end
- end
- end)
- else
- if IsValid(v) and v:IsValid() then
- v:RewindProps()
- end
- end
- bFoundBomb = true
- end
- end
- if not bFoundBomb then
- self:SetNextPrimaryFire(CurTime() + 0.5)
- self:SetNextSecondaryFire(CurTime() + 0.7)
- return
- end
- if not bShouldSaveOwnerOnly then
- for _, ply in ipairs(player.GetAll()) do
- if not GetConVar("TimeBomb_InstantTravel"):GetBool() then
- ply:AddFlags(FL_NOTARGET)
- ply:Lock()
- end
- ply:SendLua( "hook.Run( \"OnSpawnMenuClose\" )" )
- --ply:SendLua( "surface.PlaySound('hoff/zmb/timebomb/timebomb_activate.wav')")
- end
- else
- if not GetConVar("TimeBomb_InstantTravel"):GetBool() then
- self:GetOwner():AddFlags(FL_NOTARGET)
- self:GetOwner():Lock()
- end
- self:GetOwner():SendLua( "hook.Run( \"OnSpawnMenuClose\" )" )
- end
- end)
- self:SetNextPrimaryFire(CurTime() + 5.5)
- self:SetNextSecondaryFire(CurTime() + 5.5)
- end
- function SWEP:SecondaryAttack()
- if not GetConVar("TimeBomb_Infinite"):GetBool() then
- if self:Ammo1() <= 0 then
- return
- end
- self:GetOwner():RemoveAmmo(1, self.Primary.Ammo)
- end
- self.PlayingAnimation = true
- self:SendWeaponAnim(ACT_VM_THROW)
- timer.Simple(0.5, function()
- if !IsValid(self) or !IsValid(self:GetOwner()) then
- return
- end
- self.PlayingAnimation = false
- if self:GetOwner():GetActiveWeapon() != self then
- return false
- end
- if self:Ammo1() <= 0 then
- self:SetCurrentState(TimeBombState.VM_TIMEBOMB_TICKERONLY)
- else
- self:SetCurrentState(TimeBombState.VM_TIMEBOMB_BOTH)
- end
- end)
- self:GetOwner():SetAnimation(PLAYER_ATTACK1)
- self:EmitSound("hoff/mpl/seal_c4/whoosh_01.wav")
- timer.Simple(0.095, function()
- if not IsValid(self) then
- return
- end
- if self:GetOwner():GetActiveWeapon() != self then
- return false
- end
- if SERVER then
- local TargetPosition = self:GetOwner():GetShootPos() + (self:GetOwner():GetRight() * -8) + (self:GetOwner():GetUp() * -1) + (self:GetOwner():GetForward() * 10)
- local model = "models/hoff/weapons/timebomb/w_timebomb.mdl"
- util.PrecacheModel(model)
- local TempC4 = ents.Create("prop_physics")
- TempC4:SetModel(model)
- TempC4:SetPos(TargetPosition)
- TempC4:SetCollisionGroup(COLLISION_GROUP_NONE)
- TempC4:Spawn()
- local mins, maxs = TempC4:GetCollisionBounds()
- TempC4:Remove()
- self:DestroyDuplicateTimeBombs()
- -- Use the mins and maxs vectors to check if there is enough space to spawn another c4
- local tr = util.TraceHull({start = TargetPosition, endpos = TargetPosition, mins = mins, maxs = maxs, mask = MASK_BLOCKLOS})
- -- Check if the trace hit something
- if not self:GetOwner():IsLineOfSightClear(TargetPosition) or tr.Hit then
- TargetPosition = self:GetOwner():EyePos()
- end
- local ent = ents.Create("cod-timebomb")
- ent:SetPos(Vector(0,0,0))
- ent:SetOwner(self:GetOwner()) -- Disables collision between the C4 and its owner
- ent:SetPos(TargetPosition)
- ent:SetAngles(Angle(1,0,0))
- ent:Spawn()
- ent:SetOwner(self:GetOwner()) -- Disables collision between the C4 and its owner
- ent.BombOwner = self:GetOwner()
- ent.ThisTrigger = self
- ent.ExplodedViaWorld = false
- ent.QueuedForExplode = false
- ent.UniqueExplodeTimer = "ExplodeTimer" .. self:GetOwner():SteamID() .. math.Rand(1, 1000)
- ent:SetNWString("OwnerID", self:GetOwner():SteamID())
- ent:SetNWString("OwnerNick", self:GetOwner():Nick())
- local phys = ent:GetPhysicsObject()
- --phys:SetMass(0.6)
- -- Compensate for the offcenter spawn
- local aimvector = self:GetOwner():GetAimVector()
- local aimangle = aimvector:Angle()
- aimangle:RotateAroundAxis(aimangle:Up(), -1.5)
- aimvector = aimangle:Forward()
- phys:ApplyForceCenter( aimvector * 1500)
- -- The positive z coordinate emulates the spin from a left underhand throw
- local angvel = Vector(0, math.random(-5000,-2000), math.random(-100,-900))
- angvel:Rotate(-1 * ent:EyeAngles())
- angvel:Rotate(Angle(0, self:GetOwner():EyeAngles().y, 0))
- --local angvel = Vector(0, math.random(-5000,-2000), math.random(-100,-900))
- angvel.x = math.Clamp(angvel.x, -1000, 1000)
- angvel.y = math.Clamp(angvel.y, -1000, 1000)
- angvel.z = math.Clamp(angvel.z, -1000, 1000)
- phys:SetAngleVelocity(Vector(math.Clamp(angvel.x, -2000, 2000), math.Clamp(angvel.y, -2000, 2000), math.Clamp(angvel.z, -2000, 2000)))
- if engine.ActiveGamemode() ~= "nzombies" then
- --undo.Create("Time Bomb")
- -- undo.AddEntity(ent)
- -- undo.SetPlayer(self:GetOwner())
- --undo.Finish()
- self:GetOwner():AddCount("sents", ent) -- Add to the SENTs count ( ownership )
- self:GetOwner():AddCount("my_props", ent) -- Add count to our personal count
- self:GetOwner():AddCleanup("sents", ent) -- Add item to the sents cleanup
- self:GetOwner():AddCleanup("my_props", ent) -- Add item to the cleanup
- end
- end
- end)
- self:SetNextPrimaryFire(CurTime() + 1.1)
- self:SetNextSecondaryFire(CurTime() + 1.35)
- end
- function SWEP:DestroyDuplicateTimeBombs()
- for k, v in ipairs( ents.FindByClass( "cod-timebomb" ) ) do
- if v.BombOwner == self:GetOwner() then
- v:StopSound("hoff/zmb/timebomb/timebomb_plant_2d.mp3")
- v:Remove()
- end
- end
- end
- function SWEP:ShouldDropOnDie()
- return false
- end
- if CLIENT then
- surface.CreateFont( "TimeBombFont", {
- font = "Arial",
- antialias = true,
- size = 30,
- outline = true
- } )
- end
- SWEP.RelativeTime = 0
- function SWEP:UpdateRelativeClock()
- self.RelativeTime = os.clock()
- end
- SWEP.ReticleMaterial = Material("models/hoff/weapons/timebomb/timebomb_reticle.png")
- SWEP.BombMaterial = Material("models/hoff/weapons/timebomb/zm_hud_icon_time_bomb_64")
- function SWEP:DrawHUD()
- surface.SetDrawColor( 255, 255, 255, 255 )
- surface.SetMaterial( self.ReticleMaterial )
- surface.DrawTexturedRect( ScrW() / 2 - 24, ScrH() / 2 - 24, 46, 46 )
- if self:GetNWBool("bInitialDeploy") then
- local y = ScrH() / 2
- draw.DrawText("Press RMB to save, then press LMB to restore", "Trebuchet24", ScrW() / 2, y - 65, Color(255, 255, 255, 255),TEXT_ALIGN_CENTER)
- end
- if self:GetNWBool("bTimeBombOut") and engine.ActiveGamemode() ~= "nzombies" then
- local BombIconPosY = (ScrH() - ScrH() / 4 - 81)
- surface.SetMaterial(self.BombMaterial)
- surface.SetDrawColor( 255, 255, 255, 255 )
- surface.DrawTexturedRect(80, BombIconPosY, 70, 70)
- local TimeSinceBomb = self.RelativeTime >= 0 and os.difftime(os.clock(), self.RelativeTime) or "-1"
- local FormattedTime = string.FormattedTime( TimeSinceBomb )
- local PrettyTime = FormattedTime.m < 1 and FormattedTime.s .. "s" or FormattedTime.m .. "m"
- if FormattedTime.h > 0 then
- PrettyTime = FormattedTime.m > 0 and FormattedTime.h .. "h " .. FormattedTime.m .. "m" or FormattedTime.h .. "h"
- end
- draw.DrawText(PrettyTime, "TimeBombFont", 115, BombIconPosY + 20, Color(255, 255, 255, 255),TEXT_ALIGN_CENTER)
- end
- end
- function SWEP:Think()
- if CLIENT then
- return
- end
- if self:Ammo1() <= 0 then
- if self.CurrentState ~= TimeBombState.VM_TIMEBOMB_TICKERONLY then
- self:SetCurrentState(TimeBombState.VM_TIMEBOMB_TICKERONLY)
- end
- else
- if self.CurrentState ~= TimeBombState.VM_TIMEBOMB_BOTH then
- self:SetCurrentState(TimeBombState.VM_TIMEBOMB_BOTH)
- end
- end
- end
- SWEP.ChangingStates = false
- SWEP.PlayingAnimation = false
- function SWEP:SetCurrentState(NewState)
- if self.ChangingStates or self.PlayingAnimation then
- return false
- end
- self.CurrentState = NewState
- self.ChangingStates = true
- if NewState == TimeBombState.VM_TIMEBOMB_TICKERONLY then
- self:SetHoldType("Slam")
- self:SendWeaponAnim(ACT_VM_HITLEFT)
- timer.Simple(0.5, function()
- if not IsValid(self) then
- return false
- end
- self.ChangingStates = false
- if self:GetOwner():GetActiveWeapon() != self then
- return false
- end
- self:SendWeaponAnim(ACT_VM_IDLE_LOWERED)
- self:StopSound("hoff/zmb/timebomb/timebomb_hold_loop_low.wav")
- end)
- elseif NewState == TimeBombState.VM_TIMEBOMB_BOTH then
- self:SetHoldType("duel")
- self:SendWeaponAnim(ACT_VM_DRAW)
- self:SetNextPrimaryFire(CurTime() + 0.6)
- self:SetNextSecondaryFire(CurTime() + 0.6)
- timer.Simple(0.5, function()
- if not IsValid(self) then
- return false
- end
- self.ChangingStates = false
- if self:GetOwner():GetActiveWeapon() != self then
- return false
- end
- self:SendWeaponAnim(ACT_VM_IDLE)
- self:EmitSound("hoff/zmb/timebomb/timebomb_hold_loop_low.wav", 45)
- end)
- end
- return true
- end
- function SWEP:PlayAnim(NewAnim)
- if self.PlayingAnimation then
- return false
- end
- self.PlayingAnimation = true
- self:SendWeaponAnim(NewAnim)
- if NewAnim == ACT_VM_DRYFIRE then
- timer.Simple(0.67,function()
- if not IsValid(self) then
- return
- end
- self.PlayingAnimation = false
- if self:GetOwner():GetActiveWeapon() != self then
- return false
- end
- self:SendWeaponAnim(ACT_VM_IDLE_LOWERED)
- end)
- elseif NewAnim == ACT_VM_PRIMARYATTACK then
- timer.Simple(0.67,function()
- if not IsValid(self) then
- return
- end
- self.PlayingAnimation = false
- if self:GetOwner():GetActiveWeapon() != self then
- return false
- end
- self:SendWeaponAnim(ACT_VM_IDLE)
- end)
- end
- return true
- end
- function SWEP:PlayPrimaryFireAnim()
- if self.ChangingStates or self.PlayingAnimation then
- return false
- end
- if self.CurrentState == TimeBombState.VM_TIMEBOMB_TICKERONLY then
- return self:PlayAnim(ACT_VM_DRYFIRE)
- elseif self.CurrentState == TimeBombState.VM_TIMEBOMB_BOTH then
- return self:PlayAnim(ACT_VM_PRIMARYATTACK)
- end
- end
- function SWEP:Holster()
- self:StopSound("hoff/zmb/timebomb/timebomb_hold_loop_low.wav")
- return true
- end
- function SWEP:OnRemove()
- self:StopSound("hoff/zmb/timebomb/timebomb_hold_loop_low.wav")
- end
- hook.Add("PlayerDroppedWeapon", "StopTimeBombSound", function(owner, wep)
- if IsValid(wep) and wep:GetClass() == "seal6-timebomb" then
- wep:StopSound("hoff/zmb/timebomb/timebomb_hold_loop_low.wav")
- end
- end)
- function SWEP:Equip(ply)
- if engine.ActiveGamemode() == "nzombies" then
- timer.Simple(0.1, function()
- ply:SetAmmo(1, "nz_specialgrenade")
- end)
- end
- end
- if engine.ActiveGamemode() == "nzombies" then
- if SERVER then
- util.AddNetworkString("DisplayTimeBombRound")
- util.AddNetworkString("RemoveTimeBombRound")
- else
- net.Receive("DisplayTimeBombRound", function()
- local Round = net.ReadInt(16)
- local BombWep = net.ReadEntity()
- local OwnerIndex = BombWep.Owner:SteamID()
- hook.Add( "HUDPaint", "ShowTimeBombRound" .. OwnerIndex, function()
- if !IsValid(BombWep) then
- hook.Remove("HUDPaint", "ShowTimeBombRound" .. OwnerIndex)
- return
- end
- local BombIconPosY = (ScrH() - ScrH() / 4 - 75)
- surface.SetMaterial(Material("models/hoff/weapons/timebomb/zm_hud_icon_time_bomb_64"))
- surface.SetDrawColor( 255, 255, 255, 255 )
- surface.DrawTexturedRect(15, BombIconPosY, 70, 70)
- draw.DrawText(Round, "Arialfbomb", 50, BombIconPosY + 18, Color(255, 255, 255, 255),TEXT_ALIGN_CENTER)
- end)
- end)
- net.Receive("RemoveTimeBombRound", function()
- local BombOwner = net.ReadEntity()
- local OwnerIndex = BombOwner:SteamID()
- hook.Remove("HUDPaint", "ShowTimeBombRound" .. OwnerIndex)
- end)
- end
- end
- function SWEP:Precache()
- util.PrecacheSound( "hoff/zmb/timebomb/timebomb_hold_loop_low.wav" )
- util.PrecacheSound( "hoff/zmb/timebomb/timebomb_plant_2d.mp3" )
- util.PrecacheSound( "hoff/zmb/timebomb/timebomb_activate_1.mp3" )
- util.PrecacheSound( "hoff/zmb/timebomb/timebomb_activate_2.mp3" )
- util.PrecacheModel( "models/hoff/weapons/timebomb/c_timebomb.mdl" )
- util.PrecacheModel( "models/hoff/weapons/timebomb/w_timebomb.mdl" )
- end
- SWEP.ViewModelBoneMods = {
- ["tag_view"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
- ["ValveBiped.Bip01_R_Forearm"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
- ["ValveBiped.Bip01_L_Forearm"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
- }
Advertisement
Add Comment
Please, Sign In to add comment