Advertisement
Guest User

Untitled

a guest
Mar 1st, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.44 KB | None | 0 0
  1.  
  2. AddCSLuaFile( "shared.lua" )
  3.  
  4. SWEP.Author         = "Hoff"
  5. SWEP.Instructions   = ""
  6.  
  7. SWEP.Category = "CoD Multiplayer"
  8. SWEP.Spawnable          = true
  9. SWEP.AdminSpawnable     = true
  10.  
  11. SWEP.ViewModel          = "models/hoff/weapons/seal6_c4/v_c4.mdl"
  12. SWEP.WorldModel         = "models/hoff/weapons/seal6_c4/w_c4_0-5.mdl"
  13. SWEP.ViewModelFOV = 70
  14.  
  15. SWEP.Primary.ClipSize       = -1
  16. SWEP.Primary.DefaultClip    = -1
  17. SWEP.Primary.Automatic      = true
  18. SWEP.Primary.Ammo       = "slam"
  19. SWEP.Primary.Delay = 1
  20.  
  21. SWEP.Secondary.ClipSize     = -1
  22. SWEP.Secondary.DefaultClip  = -1
  23. SWEP.Secondary.Automatic    = true
  24. SWEP.Secondary.Ammo         = "none"
  25.  
  26. SWEP.Weight             = 5
  27. SWEP.AutoSwitchTo       = false
  28. SWEP.AutoSwitchFrom     = false
  29.  
  30. SWEP.PrintName          = "C4"         
  31. SWEP.Slot               = 4
  32. SWEP.SlotPos            = 1
  33. SWEP.DrawAmmo           = false
  34. SWEP.DrawCrosshair      = false
  35.  
  36. hook.Add("Initialize","createc4convar",function()
  37.     if ConVarExists( "c4_infinite" ) == false then
  38.         CreateConVar("c4_infinite", 1)
  39.     end
  40. end)
  41.  
  42. SWEP.Offset = {
  43.     Pos = {
  44.         Up = 0,
  45.         Right = -2,
  46.         Forward = 0,
  47.     },
  48.     Ang = {
  49.         Up = 0,
  50.         Right = 0,
  51.         Forward = -45,
  52.     }
  53. }
  54.  
  55. function SWEP:DrawWorldModel( )
  56.     local hand, offset, rotate
  57.  
  58.     if not IsValid( self.Owner ) then
  59.         self:DrawModel( )
  60.         return
  61.     end
  62.  
  63.     if not self.Hand then
  64.         self.Hand = self.Owner:LookupAttachment( "anim_attachment_rh" )
  65.     end
  66.  
  67.     hand = self.Owner:GetAttachment( self.Hand )
  68.  
  69.     if not hand then
  70.         self:DrawModel( )
  71.         return 
  72.     end
  73.  
  74.     offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up
  75.  
  76.     hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right )
  77.     hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward )
  78.     hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up )
  79.  
  80.     self:SetRenderOrigin( hand.Pos + offset )
  81.     self:SetRenderAngles( hand.Ang )
  82.  
  83.     self:DrawModel( )
  84. end
  85.  
  86. function SWEP:Deploy()
  87.     --if !IsValid(self.Owner.C4s) then self.Owner.C4s = {} end
  88. end
  89.  
  90. local reg = debug.getregistry()
  91. local GetVelocity = reg.Entity.GetVelocity
  92. local Length = reg.Vector.Length
  93. local GetAimVector = reg.Player.GetAimVector
  94. local inRun = false
  95. function SWEP:Think()
  96.     vel = Length(GetVelocity(self.Owner))
  97.     if self.Owner:OnGround() then
  98.         if !inRun and vel > 2.4 and self.Owner:KeyDown(IN_SPEED) then
  99.             self.Weapon:SendWeaponAnim(ACT_VM_PULLPIN)
  100.             inRun = true
  101.         elseif( inRun and !self.Owner:KeyDown(IN_SPEED) ) then
  102.             self:SendWeaponAnim(ACT_VM_IDLE)
  103.             inRun = false
  104.         end
  105.         if self.Owner:KeyDown(IN_SPEED) and vel == 0 then
  106.             self:SendWeaponAnim(ACT_VM_IDLE)
  107.             inRun = false
  108.         end
  109.     end
  110.  
  111. end  
  112.  
  113. function SWEP:Equip(NewOwner)
  114.     if self.Owner.C4s == nil then self.Owner.C4s = {} end
  115.     if GetConVar("c4_infinite"):GetInt() == 0 then
  116.         self.Owner:GiveAmmo(5,"slam")
  117.     end
  118. end
  119.  
  120.  
  121. function SWEP:PrimaryAttack()
  122.     self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)  
  123.  
  124.     timer.Simple(0.1,function()
  125.         if IsValid(self) then
  126.             self:EmitSound("hoff/mpl/seal_c4/c4_click.wav")
  127.         end
  128.     end)
  129.    
  130.     if self.Owner:Alive() and self.Owner:IsValid() then
  131.         local Owner = self.Owner
  132.         if SERVER then
  133.             for k, v in pairs( Owner.C4s ) do
  134.                 timer.Simple( .05 * k, function()
  135.                     if IsValid( v ) then
  136.                         v:Explode()
  137.                         table.remove( Owner.C4s, k )   
  138.                         Owner.C4s[k] = null
  139.                     end            
  140.                 end )
  141.             end
  142.         end
  143.     end
  144.    
  145.     self:SetNextPrimaryFire(CurTime() + 1.1)
  146.     self:SetNextSecondaryFire(CurTime() + 1.2)
  147. end
  148.  
  149. function SWEP:SecondaryAttack()
  150.     if GetConVar("c4_infinite"):GetInt() == 0 then
  151.         if ( self:Ammo1() <= 0 ) then
  152.             return false
  153.         end
  154.     end
  155.     self:SendWeaponAnim(ACT_VM_THROW)  
  156.     self:EmitSound("hoff/mpl/seal_c4/whoosh_00.wav")
  157.     --self:TakePrimaryAmmo(1)
  158.     local tr = self.Owner:GetEyeTrace()
  159.     if SERVER then
  160.         local ent = ents.Create("cod-c4")
  161.                
  162.         ent:SetPos(self.Owner:GetShootPos())
  163.         ent:SetAngles(Angle(1,0,0))
  164.         ent:Spawn()
  165.         ent.C4Owner = self.Owner       
  166.  
  167.         local phys = ent:GetPhysicsObject()
  168.         phys:SetMass(0.6)
  169.         local shot_length = tr.HitPos:Length()
  170.         local aimvector = self.Owner:GetAimVector()
  171.     --  phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
  172.     --  phys:ApplyForceCenter(aimvector*500000)
  173.         phys:ApplyForceCenter( self.Owner:GetAimVector()*1500)
  174.         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
  175.         angvel:Rotate(-1*ent:EyeAngles())
  176.         angvel:Rotate(Angle(0,self.Owner:EyeAngles().y,0))
  177.         phys:AddAngleVelocity(angvel)
  178.         --ent:SetVelocity(ent:GetForward()*50000 + ent:GetRight()*50 + ent:GetUp()*50)
  179.         ent:SetGravity(50)
  180.         table.insert( self.Owner.C4s, ent )
  181.     end
  182.  
  183.     if GetConVar("c4_infinite"):GetInt() == 0 then
  184.         self.Owner:RemoveAmmo(1,"slam")
  185.     end
  186.    
  187.     self:SetNextPrimaryFire(CurTime() + 1.1)
  188.     self:SetNextSecondaryFire(CurTime() + 1.2)
  189. end
  190.  
  191. function SWEP:ShouldDropOnDie()
  192.     return false
  193. end
  194.  
  195. function SWEP:OnRemove()
  196.     local owner = self.Owner
  197. --[[    timer.Simple(0.5,function()
  198.         if owner:IsValid() == false then
  199.             if SERVER then
  200.                 for k, v in pairs( owner.C4s ) do
  201.                     timer.Simple( .05 * k, function()
  202.                         if IsValid( v ) then
  203.                             v:Remove()
  204.                         end            
  205.                     end)
  206.                 end
  207.             end
  208.         end
  209.     end) ]]
  210. end
  211.  
  212. function SWEP:Reload()
  213. end
  214.  
  215. function SWEP:DrawHUD()
  216.     surface.SetDrawColor( 255, 255, 255, 255 )
  217.     surface.SetMaterial( Material("models/hoff/weapons/seal6_c4/c4_reticle.png") )
  218.     surface.DrawTexturedRect( ScrW() / 2 - 16, ScrH() / 2 - 16, 32, 32 )
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement