Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile( "shared.lua" )
- SWEP.Author = "Hoff"
- SWEP.Instructions = ""
- SWEP.Category = "CoD Multiplayer"
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- SWEP.ViewModel = "models/hoff/weapons/seal6_c4/v_c4.mdl"
- SWEP.WorldModel = "models/hoff/weapons/seal6_c4/w_c4_0-5.mdl"
- SWEP.ViewModelFOV = 70
- SWEP.Primary.ClipSize = -1
- SWEP.Primary.DefaultClip = -1
- SWEP.Primary.Automatic = true
- SWEP.Primary.Ammo = "slam"
- SWEP.Primary.Delay = 1
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = true
- SWEP.Secondary.Ammo = "none"
- SWEP.Weight = 5
- SWEP.AutoSwitchTo = false
- SWEP.AutoSwitchFrom = false
- SWEP.PrintName = "C4"
- SWEP.Slot = 4
- SWEP.SlotPos = 1
- SWEP.DrawAmmo = false
- SWEP.DrawCrosshair = false
- hook.Add("Initialize","createc4convar",function()
- if ConVarExists( "c4_infinite" ) == false then
- CreateConVar("c4_infinite", 1)
- end
- end)
- SWEP.Offset = {
- Pos = {
- Up = 0,
- Right = -2,
- Forward = 0,
- },
- Ang = {
- Up = 0,
- Right = 0,
- Forward = -45,
- }
- }
- function SWEP:DrawWorldModel( )
- local hand, offset, rotate
- if not IsValid( self.Owner ) then
- self:DrawModel( )
- return
- end
- if not self.Hand then
- self.Hand = self.Owner:LookupAttachment( "anim_attachment_rh" )
- end
- hand = self.Owner:GetAttachment( self.Hand )
- if not hand then
- self:DrawModel( )
- return
- end
- offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up
- hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right )
- hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward )
- hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up )
- self:SetRenderOrigin( hand.Pos + offset )
- self:SetRenderAngles( hand.Ang )
- self:DrawModel( )
- end
- function SWEP:Deploy()
- --if !IsValid(self.Owner.C4s) then self.Owner.C4s = {} end
- end
- local reg = debug.getregistry()
- local GetVelocity = reg.Entity.GetVelocity
- local Length = reg.Vector.Length
- local GetAimVector = reg.Player.GetAimVector
- local inRun = false
- function SWEP:Think()
- vel = Length(GetVelocity(self.Owner))
- if self.Owner:OnGround() then
- if !inRun and vel > 2.4 and self.Owner:KeyDown(IN_SPEED) then
- self.Weapon:SendWeaponAnim(ACT_VM_PULLPIN)
- inRun = true
- elseif( inRun and !self.Owner:KeyDown(IN_SPEED) ) then
- self:SendWeaponAnim(ACT_VM_IDLE)
- inRun = false
- end
- if self.Owner:KeyDown(IN_SPEED) and vel == 0 then
- self:SendWeaponAnim(ACT_VM_IDLE)
- inRun = false
- end
- end
- end
- function SWEP:Equip(NewOwner)
- if self.Owner.C4s == nil then self.Owner.C4s = {} end
- if GetConVar("c4_infinite"):GetInt() == 0 then
- self.Owner:GiveAmmo(5,"slam")
- end
- end
- function SWEP:PrimaryAttack()
- self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
- timer.Simple(0.1,function()
- if IsValid(self) then
- self:EmitSound("hoff/mpl/seal_c4/c4_click.wav")
- end
- end)
- if self.Owner:Alive() and self.Owner:IsValid() then
- local Owner = self.Owner
- if SERVER then
- for k, v in pairs( Owner.C4s ) do
- timer.Simple( .05 * k, function()
- if IsValid( v ) then
- v:Explode()
- table.remove( Owner.C4s, k )
- Owner.C4s[k] = null
- end
- end )
- end
- end
- end
- self:SetNextPrimaryFire(CurTime() + 1.1)
- self:SetNextSecondaryFire(CurTime() + 1.2)
- end
- function SWEP:SecondaryAttack()
- if GetConVar("c4_infinite"):GetInt() == 0 then
- if ( self:Ammo1() <= 0 ) then
- return false
- end
- end
- self:SendWeaponAnim(ACT_VM_THROW)
- self:EmitSound("hoff/mpl/seal_c4/whoosh_00.wav")
- --self:TakePrimaryAmmo(1)
- local tr = self.Owner:GetEyeTrace()
- if SERVER then
- local ent = ents.Create("cod-c4")
- ent:SetPos(self.Owner:GetShootPos())
- ent:SetAngles(Angle(1,0,0))
- ent:Spawn()
- ent.C4Owner = self.Owner
- local phys = ent:GetPhysicsObject()
- phys:SetMass(0.6)
- local shot_length = tr.HitPos:Length()
- local aimvector = self.Owner:GetAimVector()
- -- phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
- -- phys:ApplyForceCenter(aimvector*500000)
- phys:ApplyForceCenter( self.Owner:GetAimVector()*1500)
- local angvel = Vector(0,math.random(-5000,-2000),math.random(-100,-900)) //The positive z coordinate emulates the spin from a right-handed overhand throw
- angvel:Rotate(-1*ent:EyeAngles())
- angvel:Rotate(Angle(0,self.Owner:EyeAngles().y,0))
- phys:AddAngleVelocity(angvel)
- --ent:SetVelocity(ent:GetForward()*50000 + ent:GetRight()*50 + ent:GetUp()*50)
- ent:SetGravity(50)
- table.insert( self.Owner.C4s, ent )
- end
- if GetConVar("c4_infinite"):GetInt() == 0 then
- self.Owner:RemoveAmmo(1,"slam")
- end
- self:SetNextPrimaryFire(CurTime() + 1.1)
- self:SetNextSecondaryFire(CurTime() + 1.2)
- end
- function SWEP:ShouldDropOnDie()
- return false
- end
- function SWEP:OnRemove()
- local owner = self.Owner
- --[[ timer.Simple(0.5,function()
- if owner:IsValid() == false then
- if SERVER then
- for k, v in pairs( owner.C4s ) do
- timer.Simple( .05 * k, function()
- if IsValid( v ) then
- v:Remove()
- end
- end)
- end
- end
- end
- end) ]]
- end
- function SWEP:Reload()
- end
- function SWEP:DrawHUD()
- surface.SetDrawColor( 255, 255, 255, 255 )
- surface.SetMaterial( Material("models/hoff/weapons/seal6_c4/c4_reticle.png") )
- surface.DrawTexturedRect( ScrW() / 2 - 16, ScrH() / 2 - 16, 32, 32 )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement