Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.75 KB | None | 0 0
  1. // Black Ops Baby Gun
  2.  
  3. AddCSLuaFile( "shared.lua" )
  4.  
  5. SWEP.Author         = "Hoff"
  6. SWEP.Instructions   = ""
  7. SWEP.Base = "weapon_hoff_base_babygun"
  8. SWEP.Spawnable          = true
  9. SWEP.AdminSpawnable     = true
  10.  
  11. SWEP.ViewModel          = "models/hoff/weapons/babygun/v_shrinkray_pow.mdl"
  12. SWEP.WorldModel         = "models/hoff/weapons/babygun/w_shrinkray_pow.mdl"
  13. SWEP.DrawCrosshair = false
  14.  
  15. SWEP.ZoomAmount = 5
  16. SWEP.ViewModelMovementScale = 0.2
  17. SWEP.PlayBackRate = 30
  18. SWEP.PlayBackRateSV = 12
  19. SWEP.SpeedDec = 10
  20. SWEP.BulletDiameter = 11.5
  21. SWEP.CaseLength = 22.8
  22. SWEP.NormalHoldType = "ar2"
  23. SWEP.RunHoldType = "ar2"
  24. SWEP.FireModes = {"semi"}
  25. SWEP.FireDelay = 0.25
  26. SWEP.FireSound = Sound("weapons/bo_1911/fire.wav")
  27. SWEP.Recoil = 1.6
  28. SWEP.DryFire = true
  29.  
  30. SWEP.HipSpread = 0.09
  31. SWEP.AimSpread = 0.009
  32. SWEP.VelocitySensitivity = 1.7
  33. SWEP.MaxSpreadInc = 0.06
  34. SWEP.SpreadPerShot = 0.015
  35. SWEP.SpreadCooldown = 0.28
  36. SWEP.Shots = 1
  37. SWEP.Damage = 40
  38. SWEP.DeployTime = 1
  39.  
  40. SWEP.AimPos = Vector(-10,0,0)
  41. SWEP.AimAng = Vector(0, 0, 0)
  42.  
  43. SWEP.Primary.ClipSize       = 5
  44. SWEP.Primary.DefaultClip    = 50
  45. SWEP.Primary.Automatic      = false
  46. SWEP.Primary.Ammo           = "AirboatGun"
  47. SWEP.Primary.Delay = 1
  48.  
  49. SWEP.Secondary.ClipSize     = 100
  50. SWEP.Secondary.DefaultClip  = 100
  51. SWEP.Secondary.Automatic    = false
  52. SWEP.Secondary.Ammo         = "none"
  53.  
  54. SWEP.Weight             = 5
  55. SWEP.AutoSwitchTo       = false
  56. SWEP.AutoSwitchFrom     = false
  57.  
  58. SWEP.PrintName          = "31-79 JGb215"           
  59. SWEP.Slot               = 3
  60. SWEP.SlotPos            = 1
  61. SWEP.DrawAmmo           = true
  62. SWEP.Category = "CoD Zombies"
  63. SWEP.ViewModelFOV = 70
  64. local ShootSound = Sound("")
  65.  
  66. SWEP.HoldType = "ar2"
  67. SWEP.Distance = 500 * 12
  68.  
  69. function SWEP:Initialize()
  70.     self:SetWeaponHoldType( self.HoldType )
  71. end
  72.  
  73. function SWEP:Equip()
  74.     self.Weapon:EmitSound( "hoff/weapons/babygun/shrinkray/plr/wpn_shrink_plr_equip.wav" )
  75. end
  76.  
  77. function SWEP:Deploy()
  78.     timer.Simple(0.4,function()
  79.         self:SendWeaponAnim(ACT_VM_IDLE)
  80.         -- self:EmitSound("hoff/weapons/babygun/shrinkray/reload/wpn_shrink_fins.wav")
  81.     end)
  82. end
  83.  
  84. function SWEP:ShootLightning( )
  85.  
  86.     local res, start, ende
  87.  
  88.     start = self.Owner:GetPos() + Vector(0,0,55) + (self.Owner:GetForward() * 50)
  89.     ende = start + self.Distance * self.Owner:GetAimVector( )
  90.  
  91.     res = util.TraceLine{ start = start, endpos = ende, filter = self.Owner, mask = MASK_SHOT }
  92.  
  93.     if res.Entity and res.Entity:IsValid( ) and SERVER then
  94.    
  95.     local ent1 = "npc_zombie"
  96.     local ent2 = "npc_monk"
  97.     for a,b in pairs( ents.FindInSphere( self:GetPos(), 500 )) do
  98.         if b:IsNPC() then
  99.         -- self:DispEffect( "tesla_shot", { Origin = start, Normal = b:GetPos(), Start = res.Entity:GetPos(), Scale = 240, Radius = 12 } )
  100.         local effectName = "tesla_shot"
  101.         local vPoint = b:GetPos()
  102.         local effectdata = EffectData()
  103.         effectdata:SetStart( vPoint ) // not sure if ( we need a start and origin ( endpoint ) for this effect, but whatever
  104.         effectdata:SetOrigin( vPoint )
  105.         effectdata:SetEntity( res.Entity:GetPos() + Vector(0,0,35) )
  106.         effectdata:SetScale( 1 )
  107.         util.Effect( effectName, effectdata )
  108.         end
  109.     end
  110.    
  111.     local effectName = "tesla_glow"
  112.     local vPoint = res.Entity:GetPos() + Vector(0,0,35)
  113.     local effectdata = EffectData()
  114.     effectdata:SetStart( vPoint ) // not sure if ( we need a start and origin ( endpoint ) for this effect, but whatever
  115.     effectdata:SetOrigin( vPoint )
  116.     effectdata:SetEntity( self )
  117.     effectdata:SetScale( 1 )
  118.     util.Effect( effectName, effectdata )
  119.    
  120.     for k, v in pairs (ents.FindInSphere(res.Entity:GetPos(),50)) do
  121.         if v:IsNPC() then
  122.             v:SetKeyValue("targetname", "disTarg")
  123.             end
  124.         end
  125.         local dis = ents.Create("env_entity_dissolver")
  126.         dis:SetPos(res.Entity:GetPos())
  127.         dis:SetKeyValue("magnitude", "500")
  128.         dis:SetKeyValue("dissolvetype", "0")
  129.         dis:SetKeyValue("target", "disTarg")
  130.         dis:Spawn()
  131.         dis:Fire("Dissolve", "disTarg", 0)
  132.         dis:Fire("kill", "", 0)
  133.    
  134.         if res.Entity:IsNPC() then
  135.             local npc = res.Entity
  136.         --  npc:TakeDamage( 99999, self.Owner, self )
  137.         end
  138.     end
  139.     self:DispEffect( "tesla_shot", { Origin = start, Normal = self.Owner:GetAimVector( ), Start = res.HitPos, Scale = 240, Radius = 12 } )
  140. end
  141.  
  142. function SWEP:DispEffect( name, data )
  143.     local data2, k, v
  144.     data2 = EffectData( )
  145.     for k, v in pairs( data ) do
  146.         data2[ "Set" .. k ]( data2, v )
  147.     end
  148.     util.Effect( name, data2 )
  149. end
  150.  
  151. function SWEP:BabyGunProjectile()
  152.     if SERVER then
  153.         local aim = self.Owner:GetAimVector( )
  154.         local force  = aim*(3*500)+Vector(0,0,200)
  155.         local tr = self.Owner:GetEyeTrace()
  156.         local projectile = ents.Create ("ent_babygun_proj")
  157.         projectile:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector()))
  158.         projectile:SetAngles (self.Owner:EyeAngles())
  159.         projectile:Spawn()
  160.  
  161.         timer.Simple(1,function() projectile:Remove() end)
  162.         local phys1 = projectile:GetPhysicsObject();
  163.         local shot_length = tr.HitPos:Length();
  164.         if projectile:IsValid() and phys1:IsValid() then
  165.             phys1:ApplyForceCenter ((self.Owner:GetAimVector() * shot_length) * 100);  
  166.         end
  167.     end
  168. end
  169.  
  170. function SWEP:PrimaryAttack()
  171.    if ( !self:CanPrimaryAttack() ) then return end
  172.     self.Owner:ViewPunch( Angle( -0.5, 0, 0 ) )
  173.  
  174.     local aim = self.Owner:GetAimVector( )
  175.     local force  = aim*(3*500)+Vector(0,0,200)
  176.     local tr = self.Owner:GetEyeTrace()
  177.     self:BabyGunProjectile()
  178.     if tr.HitPos:Distance(self.Owner:GetPos()) < 750 then
  179.         timer.Simple(0.2,function()
  180.             ParticleEffect("bbgun_proj_hit",tr.HitPos,Angle(0,0,0),nil)
  181.             for k,v in pairs (ents.FindInSphere(tr.HitPos,125)) do
  182.                 if v ~= self.Owner and v:IsValid() then
  183.                     if (v:IsNPC() or v:IsPlayer()) then
  184.                         if v:GetNWString("IsBaby") ~= "true" and v:GetNWString("IsBaby") ~= "false" then v:SetNWString("IsBaby","false") end
  185.                         if v:GetNWString("IsBaby") == "false" then
  186.                             v:SetModelScale(0.4)
  187.                             timer.Simple(0.25,function() v:EmitSound( "hoff/weapons/babygun/shrinkray/effects/evt_shrink.wav" ) end)
  188.                             if v:LookupBone("ValveBiped.Bip01_Head1") ~= nil then
  189.                                 v:ManipulateBoneScale(v:LookupBone("ValveBiped.Bip01_Head1"),Vector(3.5,3.5,3.5))
  190.                             end
  191.                             v:SetNWString("IsBaby","true")
  192.                             v:SetNWString("ShouldKickBaby","true")
  193.                             v:SetNWString("CanAddVelocity","true") 
  194.                             if v:IsPlayer() then
  195.                                 v:SetViewOffset(Vector(0,0,25))
  196.                             end            
  197.                             v:SetNWString("BabyOnGround","false")              
  198.                             timer.Simple(math.random(3,3.15),function()
  199.                                 if v:IsValid() and v:OnGround() and v:GetNWString("IsBaby") == "true" then
  200.                                     v:SetModelScale(1)
  201.                                     if v:LookupBone("ValveBiped.Bip01_Head1") ~= nil then
  202.                                         v:ManipulateBoneScale(v:LookupBone("ValveBiped.Bip01_Head1"),Vector(1,1,1))
  203.                                     end
  204.                                     if v:IsPlayer() then
  205.                                         v:SetViewOffset(Vector(0,0,64))
  206.                                     end
  207.                                     ParticleEffect("bbgun_proj_hit",v:GetPos(),Angle(0,0,0),nil)
  208.                                     v:SetNWString("ShouldKickBaby","false")    
  209.                                     v:SetNWString("IsBaby","false")
  210.                                     v:EmitSound( "hoff/weapons/babygun/shrinkray/effects/evt_unshrink.wav" )       
  211.                                 end
  212.                             end)   
  213.                         end
  214.                     end
  215.                 end
  216.             end
  217.         end)  
  218.     end
  219.     self:TakePrimaryAmmo( 1 )  
  220.     self.Weapon:EmitSound( "hoff/weapons/babygun/shrinkray/plr/wpn_shrink_plr_quad1.wav" )
  221.     self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
  222.     timer.Simple(0.3,function() if self:IsValid() then self:SendWeaponAnim(ACT_VM_IDLE) end end)
  223.     self:SetNextPrimaryFire(CurTime() + 0.8)
  224. end
  225.  
  226. SWEP.Offset = {
  227.     Pos = {
  228.         Up = 8,
  229.         Right = 0.5,
  230.         Forward = 13,
  231.     },
  232.     Ang = {
  233.         Up = -90,
  234.         Right = 15,
  235.         Forward = 0,
  236.     }
  237. }
  238.  
  239. function SWEP:DrawWorldModel( )
  240.     local hand, offset, rotate
  241.  
  242.     if not IsValid( self.Owner ) then
  243.         self:DrawModel( )
  244.         return
  245.     end
  246.  
  247.     if not self.Hand then
  248.         self.Hand = self.Owner:LookupAttachment( "anim_attachment_rh" )
  249.     end
  250.  
  251.     hand = self.Owner:GetAttachment( self.Hand )
  252.  
  253.     if not hand then
  254.         self:DrawModel( )
  255.         return
  256.     end
  257.  
  258.     offset = hand.Ang:Right( ) * self.Offset.Pos.Right + hand.Ang:Forward( ) * self.Offset.Pos.Forward + hand.Ang:Up( ) * self.Offset.Pos.Up
  259.  
  260.     hand.Ang:RotateAroundAxis( hand.Ang:Right( ), self.Offset.Ang.Right )
  261.     hand.Ang:RotateAroundAxis( hand.Ang:Forward( ), self.Offset.Ang.Forward )
  262.     hand.Ang:RotateAroundAxis( hand.Ang:Up( ), self.Offset.Ang.Up )
  263.  
  264.     self:SetRenderOrigin( hand.Pos + offset )
  265.     self:SetRenderAngles( hand.Ang )
  266.  
  267.     self:DrawModel( )
  268. end
  269.  
  270.  
  271. function SWEP:ShouldDropOnDie()
  272.     return false
  273. end
  274.  
  275.  
  276. SWEP.Primary.Cone = 0.02
  277. SWEP.NextSecondaryAttack = 0
  278.  
  279. function SWEP:OnRestore()
  280.  
  281.     self.NextSecondaryAttack = 0
  282.     self:SetIronsights( false )
  283.    
  284. end
  285.  
  286. function SWEP:Reload()
  287.     if !( ( self.Weapon:Clip1() ) < ( self.Primary.ClipSize ) ) then
  288.         return
  289.     else if self.Owner:GetAmmoCount(self.Owner:GetActiveWeapon():GetPrimaryAmmoType()) == 0 then return end
  290.         timer.Simple(self.Owner:GetViewModel():LookupSequence("reload"),function() if self:IsValid() then self:SendWeaponAnim(ACT_VM_IDLE) end end)
  291.         timer.Simple(0.375,function() self.Weapon:EmitSound("hoff/weapons/babygun/shrinkray/reload/wpn_shrink_mag_out.wav") end)
  292.         timer.Simple(2.4,function() if self.Weapon:IsValid() then self.Weapon:EmitSound("hoff/weapons/babygun/shrinkray/reload/wpn_shrink_mag_in.wav") end end)
  293.         self.Weapon:DefaultReload( ACT_VM_RELOAD )
  294.     end
  295. end
  296.  
  297. function Ragdoll(npc,time)
  298.  
  299.     local hp = npc:Health()
  300.     local mdl = npc:GetModel()
  301.     local skin = npc:GetSkin()
  302.     local class = npc:GetClass()
  303.     local wep = npc:GetActiveWeapon()
  304.     if wep:IsValid() then wep = wep:GetClass() else wep = nil end
  305.     local bones = {}
  306.     for i=1,npc:GetBoneCount() do
  307.         bones[i] = npc:GetBoneMatrix(i)
  308.     end
  309.    
  310.     local rag = ents.Create("prop_ragdoll")
  311.     rag:SetModel(mdl)
  312.     rag:SetPos(npc:GetPos())
  313.     rag:SetAngles(npc:GetAngles())
  314.     npc:Remove()
  315.    
  316.     local tbl = {hp=hp,mdl=mdl,skin=skin,class=class,rag=rag,wep=wep}
  317.    
  318.     rag:Spawn()
  319.     rag:SetSkin(skin)
  320.    
  321.     for k,v in pairs (bones) do
  322.         rag:SetBoneMatrix(k,v)
  323.     end
  324.    
  325.     return rag
  326.  
  327. end
  328.    
  329.    
  330.  
  331. hook.Add("Think","KickBabyGunCheck",function()
  332.     for k,v in pairs(player.GetAll()) do
  333.         for a,b in pairs(ents.FindInSphere( v:GetPos(), 35 )) do
  334.             if (b:IsPlayer() or b:IsNPC()) and v ~= b then
  335.                 if b:GetNWString("ShouldKickBaby") == "true" then
  336.                     local aim = v:GetAimVector()
  337.                     local force  = aim*(3*500)
  338.                     if SERVER then
  339.                         if (b:IsNPC() or b:IsPlayer()) then
  340.                             local OldBoneScale = b:GetModelScale()
  341. --                          rag:GetPhysicsObject():ApplyForceCenter(Vector(0,0,900))
  342.                             if b:GetNWString("CanAddVelocity") == "true" then
  343.                                 local tr = v:GetEyeTrace();
  344.                                 local shot_length = tr.HitPos:Length()
  345.                                 local multiplyscale = math.random(1500,3000)
  346.                                 local kickSoundTable = {"hoff/weapons/babygun/mini/kicked/zmb_mini_kicked01.wav","hoff/weapons/babygun/mini/kicked/zmb_mini_kicked02.wav","hoff/weapons/babygun/mini/kicked/zmb_mini_kicked03.wav","hoff/weapons/babygun/mini/kicked/zmb_mini_kicked08.wav"}
  347.  
  348.                                 b:EmitSound(kickSoundTable[math.random(1,table.Count(kickSoundTable))])
  349.                                 b:SetVelocity( Vector(aim.x*multiplyscale,aim.y*multiplyscale,math.random(200,350)) )
  350.                                 b:SetLocalAngularVelocity(Angle(math.random(250,500),math.random(0,5),0))
  351.                                 b:SetNWString("CanAddVelocity","false")
  352.                                 timer.Simple(0.1,function()
  353.                                     b:SetNWString("BabyOnGround","true")
  354.                                 end)
  355.                             end
  356.                         end
  357.                     end
  358.                 end
  359.             end
  360.         end
  361.     end
  362.     for c,d in pairs(ents.GetAll()) do
  363.  
  364.         if d:IsValid() and d:IsOnGround() and d:GetNWString("BabyOnGround") == "true" and d:GetNWString("IsBaby") == "true" then           
  365.             local dpos = d:GetPos()    
  366.             if d:IsNPC() then
  367.                 d:Remove()
  368.             elseif d:IsPlayer() then
  369.                 d:SetNWString("IsBaby","false")
  370.                 timer.Simple(0.1,function()
  371.             --      d:Spawn()      
  372.                     d:SetViewOffset(Vector(0,0,64))
  373.                     d:SetModelScale(1)
  374.                     if d:LookupBone("ValveBiped.Bip01_Head1") ~= nil then
  375.                         d:ManipulateBoneScale(d:LookupBone("ValveBiped.Bip01_Head1"),Vector(1,1,1))
  376.                     end
  377.                 end)
  378.                 if SERVER then
  379.                     d:Kill()
  380.                     d:Spawn()
  381.                 end
  382.             end
  383.             local babyDieTable = {"hoff/weapons/babygun/mini/squashed/zmb_mini_squashed01.wav","hoff/weapons/babygun/mini/squashed/zmb_mini_squashed02.wav","hoff/weapons/babygun/mini/squashed/zmb_mini_squashed03.wav","hoff/weapons/babygun/mini/squashed/zmb_mini_squashed04.wav"}
  384.             d:EmitSound(babyDieTable[math.random(1,table.Count(babyDieTable))])        
  385.  
  386.  
  387.             local startp = dpos
  388.             local traceinfo = {start = startp, endpos = startp - Vector(0,0,50), filter = ent, mask = MASK_NPCWORLDSTATIC}
  389.             local trace = util.TraceLine(traceinfo)
  390.             local todecal1 = trace.HitPos + trace.HitNormal
  391.             local todecal2 = trace.HitPos - trace.HitNormal
  392.             util.Decal("Blood", todecal1, todecal2)    
  393.             if SERVER then
  394.                 local gib = ents.Create("ent_gib")
  395.                 gib:SetPos(dpos + Vector(0,0,1))
  396.                 gib:Spawn()
  397.                 local phys = gib:GetPhysicsObject()
  398.                 if (phys:IsValid()) then
  399.                     phys:SetVelocity(Vector(math.random(-50,50),math.random(-50,50),150) * math.random(2,3))
  400.                 end
  401.             end
  402.         end
  403.     end
  404. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement