Advertisement
Guest User

Untitled

a guest
May 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.87 KB | None | 0 0
  1. if (SERVER) then
  2.     AddCSLuaFile("shared.lua");
  3.     SWEP.Weight = 5;
  4.     SWEP.AutoSwitchTo = false;
  5.     SWEP.AutoSwitchFrom = false;
  6. end;
  7.  
  8. if (CLIENT) then
  9.     SWEP.DrawAmmo = true; -- Draw our own ammo display?
  10.     SWEP.IconLetter = "SMG"; -- The icon letter of the font.
  11.     SWEP.DrawCrosshair = false; -- Draw the crosshair, or draw our own?
  12.     SWEP.ViewModelFOV = 82;
  13.     SWEP.ViewModelFlip = true; -- Some view models are incorrectly flipped.
  14.     SWEP.CSMuzzleFlashes = true; -- Use Counter-Strike muzzle flashes?
  15.     SWEP.PrintName          = "SMG"        
  16.     SWEP.Slot               = 2
  17.     SWEP.SlotPos            = 1
  18.     SWEP.IconLetter         = "SMG"
  19.    
  20.     --[[ The font used for the killicons. --]]
  21.     surface.CreateFont("CSKillIcons",
  22.     {
  23.         font        = "csd",
  24.         size        = ScreenScale(30),
  25.         weight      = 500,
  26.         antialiase  = true,
  27.         additive    = true
  28.     });
  29.     surface.CreateFont("CSSelectIcons",
  30.     {
  31.         font        = "csd",
  32.         size        = ScreenScale(60),
  33.         weight      = 500,
  34.         antialiase  = true,
  35.         additive    = true
  36.     });
  37. end;
  38.  
  39. --[[ Basic SWEP information to display to the client. --]]
  40. SWEP.Author = ""
  41. SWEP.Contact = ""
  42. SWEP.Purpose = ""
  43. SWEP.Instructions = ""
  44.  
  45. --[[ Set whether the SWEP is spawnable (by users or by admins). --]]
  46. SWEP.Spawnable = false;
  47. SWEP.AdminSpawnable = false;
  48.  
  49. --[[ Set the SWEP's primary fire information. --]]
  50. SWEP.Primary.DefaultClip = -1;
  51. SWEP.Primary.ClipSize = -1;
  52. SWEP.Primary.Automatic = false;
  53. SWEP.Primary.NumShots = 1;
  54. SWEP.Primary.Damage = 10;
  55. SWEP.Primary.Recoil = 1;
  56. SWEP.Primary.Sound = Sound("Weapon_AK47.Single");
  57. SWEP.Primary.Delay = 0.15;
  58. SWEP.Primary.Ammo = "none";
  59. SWEP.Primary.Cone = 0.05;
  60.  
  61. --[[ Set the SWEP's primary fire information. --]]
  62. SWEP.Secondary.DefaultClip = -1;
  63. SWEP.Secondary.ClipSize = -1;
  64. SWEP.Secondary.Automatic = false;
  65. SWEP.Secondary.Ammo = "none";
  66.  
  67. --[[ Define the bullet information for later use. --]]
  68. SWEP.BulletTracerFreq = 1; -- Show a tracer every x bullets.
  69. SWEP.BulletTracerName = nil -- Use a custom effect for the tracer.
  70. SWEP.BulletForce = 5;
  71.  
  72. --[[ Set up the ironsight's position and angles. --]]
  73. SWEP.IronSightsPos = nil;
  74. SWEP.IronSightsAng = nil;
  75.  
  76. --[[Set up the accuracy for the weapon. --]]
  77. SWEP.CrouchCone             = 0.01 -- Accuracy when we're crouching
  78. SWEP.CrouchWalkCone         = 0.02 -- Accuracy when we're crouching and walking
  79. SWEP.WalkCone               = 0.025 -- Accuracy when we're walking
  80. SWEP.AirCone                = 0.1 -- Accuracy when we're in air
  81. SWEP.StandCone              = 0.015 -- Accuracy when we're standing still
  82. SWEP.IronSightsCone         = 0.006 -- Accuracy when we're aiming
  83.  
  84.     /**************************
  85.         Minor Hooks (unused)
  86.     **************************/
  87.  
  88. function SWEP:OnIronSightsChanged(bEnabled) end;
  89.  
  90. -- Called when the SWEP's data tables should be setup.
  91. function SWEP:OnSetupDataTables() end;
  92.  
  93. -- Called when the SWEP has initialized.
  94. function SWEP:OnInitialize() end;
  95.  
  96. --[[
  97.     Called when the muzzle flash effect is handled.
  98.     Return true to override the default effect.
  99. --]]
  100. function SWEP:OnMuzzleFlash() end;
  101.  
  102. function SWEP:OnReload() end;
  103.  
  104. -- Called every frame.
  105. function SWEP:OnThink() end;
  106.  
  107. --[[ Begin giving definitions of base functions and hooks. --]]
  108.  
  109.  
  110. function SWEP:Holster()
  111.     return true
  112. end
  113.  
  114.     /**************************
  115.         Data Tables (setup)
  116.     **************************/
  117.  
  118. -- Called when the SWEP's data tables should be setup.
  119. function SWEP:SetupDataTables()
  120.     self:DTVar("Bool", 0, "IronSights");
  121.     self:DTVar("Float", 0, "LastFire");
  122.    
  123.     if (self.OnSetupDataTables) then
  124.         self:OnSetupDataTables();
  125.     end;
  126. end;
  127.  
  128.     /**************************
  129.         Initialize
  130.     **************************/
  131. function SWEP:Initialize()
  132.  
  133.     if ( SERVER ) then
  134.         self:SetNPCMinBurst( 30 )
  135.         self:SetNPCMaxBurst( 30 )
  136.         self:SetNPCFireRate( 0.01 )
  137.     end;
  138.    
  139.     self.Reloadaftershoot = 0
  140.     self.nextreload = 0
  141.    
  142.     self:SetHoldType(self.HoldType)
  143. end;
  144.  
  145.     /**************************
  146.         Think
  147.     **************************/
  148. function SWEP:Think()
  149.         self:SpreadSystem()
  150.     end;
  151.  
  152.     /**************************
  153.         Bullet Spread
  154.     **************************/
  155.  
  156. function SWEP:SpreadSystem()
  157.  
  158.     if self.Owner:OnGround() and (self.Owner:KeyDown(IN_FORWARD) or self.Owner:KeyDown(IN_BACK) or self.Owner:KeyDown(IN_MOVERIGHT) or self.Owner:KeyDown(IN_MOVELEFT)) then
  159.         if self.Owner:KeyDown(IN_DUCK) then
  160.             self.Primary.Cone = self.CrouchWalkCone
  161.         elseif self.Owner:KeyDown(IN_SPEED) then
  162.         self.Primary.Cone = self.AirCone
  163.         else
  164.             self.Primary.Cone = self.WalkCone
  165.         end;
  166.     elseif self.Owner:OnGround() and self.Owner:KeyDown(IN_DUCK) then
  167.         self.Primary.Cone = self.CrouchCone
  168.     elseif not self.Owner:OnGround() then
  169.         self.Primary.Cone = self.AirCone
  170.     else
  171.             self.Primary.Cone = self.StandCone
  172.     end;
  173.     end;
  174.  
  175.     /**************************
  176.         Deploy
  177.     **************************/
  178.  
  179. function SWEP:Deploy()
  180. self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
  181.  
  182.     self:SetWeaponHoldType( self.HoldType )
  183.    
  184.     self.Reloadaftershoot = CurTime() + 1
  185.    
  186.     if timer.Exists("ReloadTimer") then
  187.         timer.Destroy("ReloadTimer")
  188.     end;
  189.  
  190.     self:SetNWInt("skipthink", false)
  191.                
  192.     return true
  193. end;
  194.  
  195.     /**************************
  196.         Reload
  197.     **************************/
  198.  
  199. function SWEP:Reload()
  200.  
  201.         if self.Owner:KeyDown(IN_ATTACK) then return end;
  202.        
  203.         if( self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 || self.Weapon:Clip1() >= self.Primary.ClipSize)  then return end;
  204.        
  205.         if ( self.Reloadaftershoot > CurTime() ) then return end ;
  206.    
  207.         self.Weapon:DefaultReload( ACT_VM_RELOAD );
  208.    
  209.         self:SetWeaponHoldType( self.HoldType )
  210.    
  211.         if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
  212.        
  213.         if not CLIENT then
  214.             self.Owner:DrawViewModel(true)
  215.         end;
  216.        
  217.         if (self.ReloadSound) then
  218.         self.Weapon:EmitSound(self.Primary.Reload)
  219.         end;
  220.     end;
  221. end;
  222.  
  223.     /**************************
  224.         Primary Attack (LMB)
  225.     **************************/
  226.  
  227. -- Called when the SWEP's primary attack is fired.
  228. function SWEP:PrimaryAttack()
  229.     self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay);
  230.     self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay);
  231.    
  232.     if (!self:CanPrimaryAttack()) then return; end;
  233.    
  234.     self.Weapon:EmitSound(self.Primary.Sound);
  235.    
  236.     self:HandleBullets(self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone);
  237.     self:TakePrimaryAmmo(1);
  238.    
  239.     if (self.Owner:IsNPC()) then return; end;
  240.    
  241.     self.Owner:ViewPunch(
  242.         Angle(math.Rand(-0.2, -0.1) * self.Primary.Recoil, math.Rand(-0.1, 0.1) * self.Primary.Recoil, 0)
  243.     );
  244.    
  245.     if ((game.SinglePlayer() and SERVER) || CLIENT) then
  246.         self.dt.LastFire = CurTime();
  247.     end;
  248. end;
  249.  
  250.     /**************************
  251.         Secondary Attack (RMB)
  252.     **************************/
  253.  
  254. -- Called when the SWEP's secondary attack is fired.
  255. function SWEP:SecondaryAttack()
  256.     if (!self.IronSightsPos) then return; end;
  257.    
  258.     self:SetIronSights(!self.dt.IronSights);
  259.     self.Weapon:SetNextSecondaryFire(CurTime() + 0.3);
  260. end;
  261.  
  262.  
  263.     /**************************
  264.         Bullets
  265.     **************************/
  266.  
  267. function SWEP:HandleBullets(damage, recoil, numShots, cone)
  268.     local bulletInfo = {}
  269.         bulletInfo.TracerName = self.BulletTracerName;
  270.         bulletInfo.Spread = Vector(cone, cone, 0);
  271.         bulletInfo.Tracer = self.BulletTracerFreq;
  272.         bulletInfo.Damage = damage;
  273.         bulletInfo.Force = self.BulletForce;
  274.         bulletInfo.Num = numShots;
  275.         bulletInfo.Src = self.Owner:GetShootPos();
  276.         bulletInfo.Dir = self.Owner:GetAimVector();
  277.     self.Owner:FireBullets(bulletInfo);
  278.    
  279.     self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK);
  280.    
  281.     if (!self.OnMuzzleFlash or self.OnMuzzleFlash() != true) then
  282.         self.Owner:MuzzleFlash();
  283.     end;
  284.    
  285.     self.Owner:SetAnimation(PLAYER_ATTACK1);
  286.    
  287.     if (self.Owner:IsNPC()) then return; end;
  288.    
  289.     if ((game.SinglePlayer() and SERVER) || (!game.SinglePlayer() and CLIENT and IsFirstTimePredicted())) then
  290.         local eyeAngles = self.Owner:EyeAngles();
  291.             eyeAngles.pitch = eyeAngles.pitch - recoil;
  292.         self.Owner:SetEyeAngles(eyeAngles);
  293.     end;
  294. end;
  295.  
  296. local IRONSIGHT_TIME = 0.25;
  297.  
  298.     /**************************
  299.         Set Ironsights
  300.     **************************/
  301.  
  302. function SWEP:SetIronSights(bEnabled)
  303.     self.dt.IronSights = bEnabled;
  304.    
  305.     if (self.OnIronSightsChanged) then
  306.         self.OnIronSightsChanged(bEnabled);
  307.     end;
  308. end;
  309.  
  310.     /**************************
  311.         Viewmodel Position (Ironsights basically.)
  312.     **************************/
  313.  
  314. function SWEP:GetViewModelPosition(origin, angles)
  315.     if (!self.IronSightsPos) then return origin, angles; end;
  316.  
  317.     if (self.dt.IronSights != self.bsLastIronSights) then
  318.         self.bsLastIronSights = self.dt.IronSights;
  319.         self.bsIronSightsTime = CurTime();
  320.        
  321.         if (self.dt.IronSights) then
  322.             self.SwayScale = 0.3;
  323.             self.BobScale = 0.1;
  324.         else
  325.             self.SwayScale = 1.0;
  326.             self.BobScale = 1.0;
  327.         end;
  328.     end;
  329.    
  330.     local ironSightsTime = self.bsIronSightsTime or 0
  331.     local multiplier = 1.0;
  332.     local offsetPos = self.IronSightsPos;
  333.    
  334.     if (!self.dt.IronSights && ironSightsTime < CurTime() - IRONSIGHT_TIME) then
  335.         return origin, angles;
  336.     end;
  337.    
  338.     if (ironSightsTime > CurTime() - IRONSIGHT_TIME) then
  339.         multiplier = math.Clamp((CurTime() - ironSightsTime) / IRONSIGHT_TIME, 0, 1);
  340.        
  341.         if (!self.dt.IronSights) then
  342.             multiplier = 1 - multiplier;
  343.         end;
  344.     end;
  345.  
  346.     if (self.IronSightsAng) then
  347.         angles = angles * 1;
  348.         angles:RotateAroundAxis(angles:Right(), self.IronSightsAng.x * multiplier);
  349.         angles:RotateAroundAxis(angles:Up(), self.IronSightsAng.y * multiplier);
  350.         angles:RotateAroundAxis(angles:Forward(), self.IronSightsAng.z * multiplier);
  351.     end;
  352.    
  353.     local forwardAng = angles:Forward();
  354.     local rightAng = angles:Right();
  355.     local upAng = angles:Up();
  356.  
  357.     origin = origin + offsetPos.x * rightAng * multiplier;
  358.     origin = origin + offsetPos.y * forwardAng * multiplier;
  359.     origin = origin + offsetPos.z * upAng * multiplier;
  360.    
  361.     return origin, angles;
  362. end;
  363.  
  364. /*---------------------------------------------------------
  365.     Draw a CrossHair!
  366. ---------------------------------------------------------*/
  367.  
  368. SWEP.CrosshairScale = 1
  369. function SWEP:DrawHUD()
  370.    
  371.     local x = ScrW() * 0.5
  372.     local y = ScrH() * 0.5
  373.     local scalebywidth = (ScrW() / 1024) * 5
  374.  
  375.     local scale = 2
  376.     local canscale = true
  377.  
  378.  
  379. scale = scalebywidth * self.Primary.Cone + (self:GetNWFloat("SprayAdditive")*0.05)
  380.  
  381.     surface.SetDrawColor(8, 255, 0, 255)
  382.  
  383. local LastShootTime = self.Weapon:GetNetworkedFloat( "LastShootTime", 0 )
  384.     --scale = scale * (2 - math.Clamp( (CurTime() - LastShootTime) * 5, 0.0, 1.0 )) comment the above to get scaling per shot
  385.  
  386.     local dist = math.abs(self.CrosshairScale - scale)
  387.     self.CrosshairScale = math.Approach(self.CrosshairScale, scale, FrameTime() * 2 + dist * 0.05)
  388.  
  389.     local gap = 30 * self.CrosshairScale
  390.     local length = gap + 20 * self.CrosshairScale
  391.     surface.DrawLine(x - length, y, x - gap, y)
  392.     surface.DrawLine(x + length, y, x + gap, y)
  393.     surface.DrawLine(x, y - length, x, y - gap)
  394.     surface.DrawLine(x, y + length, x, y + gap)
  395.  
  396.     //surface.DrawLine(x-2, y, x+2, y)
  397.     //surface.DrawLine(x, y-2, x, y+2)
  398.  
  399. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement