LUModder

FWP Base

Sep 1st, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.77 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. if CLIENT then
  4.     surface.CreateFont("CSSelectIcons", { font="csd", weight="500", size=ScreenScale(60),antialiasing=true,additive=true })
  5. end
  6.  
  7. SWEP.Base                   = "weapon_base"
  8. SWEP.PrintName              = "Flex's Weapon Base"
  9. SWEP.Author                 = "Flex"
  10. SWEP.Category               = "FWP"
  11.  
  12. SWEP.Slot                   = 1
  13. SWEP.SlotPos                = 1
  14.  
  15. SWEP.HoldType               = "smg"
  16.  
  17. SWEP.Spawnable              = false
  18. SWEP.AdminOnly              = false
  19.  
  20. SWEP.ViewModel              = "models/weapons/c_smg1.mdl"
  21. SWEP.WorldModel             = "models/weapons/w_smg1.mdl"
  22. SWEP.UseHands               = true
  23.  
  24. SWEP.Primary.Sound          = Sound("Weapon_SMG1.Single")
  25. SWEP.Primary.Delay          = 0.1
  26. SWEP.Primary.Damage         = 10
  27. SWEP.Primary.Spread         = 0
  28. SWEP.Primary.Recoil         = 0.5
  29. SWEP.Primary.Bullets        = 1
  30.  
  31. SWEP.Primary.ClipSize       = 6
  32. SWEP.Primary.DefaultClip    = 36
  33. SWEP.Primary.Automatic      = true
  34. SWEP.Primary.Ammo           = "smg1"
  35.  
  36. SWEP.Secondary.ClipSize     = -1
  37. SWEP.Secondary.DefaultClip  = -1
  38. SWEP.Secondary.Automatic    = false
  39. SWEP.Secondary.Ammo         = "none"
  40.  
  41. SWEP.SelectionFont = "CreditsLogo"
  42. SWEP.SelectionLetter = "f"
  43.  
  44. function SWEP:DrawWeaponSelection(x,y,w,h,a)
  45.  
  46.     // Borders
  47.     y = y + 10
  48.     x = x + 10
  49.     w = w - 20
  50.  
  51.     if self.SelectionFont == "CSSelectIcons" then y = y + 30 end
  52.  
  53.     draw.DrawText(self.SelectionLetter,self.SelectionFont,x+w/2,y,Color(255,220,0),TEXT_ALIGN_CENTER)
  54.  
  55.     // Draw weapon info box
  56.     self:PrintWeaponInfo(x + w + 20, y + h * 0.95, a)
  57. end
  58.  
  59. function SWEP:PrintWeaponInfo(x, y, alpha)
  60.  
  61.     if (self.DrawWeaponInfoBox == false) then return end
  62.  
  63.     if (self.InfoMarkup == nil) then
  64.         local str
  65.         local title_color = "<color=128,220,0,255>"
  66.         local text_color = "<color=255,255,255,255>"
  67.  
  68.         str = "<font=HudSelectionText>"
  69.         if (self.Author ~= "") then str = str .. title_color .. "Author:</color>\t" .. text_color .. self.Author .. "</color>\n" end
  70.         if (self.Contact ~= "") then str = str .. title_color .. "Contact:</color>\t" .. text_color .. self.Contact .. "</color>\n\n" end
  71.         if (self.Purpose ~= "") then str = str .. title_color .. "Purpose:</color>\n" .. text_color .. self.Purpose .. "</color>\n\n" end
  72.         if (self.Instructions~= "") then str = str .. title_color .. "Instructions:</color>\n" .. text_color .. self.Instructions .. "</color>\n" end
  73.         str = str .. "</font>"
  74.  
  75.         self.InfoMarkup = markup.Parse(str, 250)
  76.     end
  77.  
  78.     alpha = 180
  79.  
  80.     surface.SetDrawColor(0, 0, 0, alpha)
  81.     surface.SetTexture(self.SpeechBubbleLid)
  82.  
  83.     surface.DrawTexturedRect(x, y - 69.5, 128, 64)
  84.     draw.RoundedBox(8, x - 5, y - 6, 260, self.InfoMarkup:GetHeight() + 18, Color(0, 0, 0, alpha))
  85.  
  86.     self.InfoMarkup:Draw(x + 5, y + 5, nil, nil, alpha)
  87. end
  88.  
  89. function SWEP:Initialize()
  90.     self:SetHoldType(self.HoldType)
  91. end
  92.  
  93. function SWEP:ShootBullet(damage,recoil,num_bullets,aimcone)
  94.     local bullet = {}
  95.  
  96.     bullet.Num  = self.Primary.Bullets
  97.     bullet.Src  = self.Owner:GetShootPos()
  98.     bullet.Dir  = self.Owner:GetAimVector()
  99.     bullet.Spread   = Vector( self.Primary.Spread, self.Primary.Spread, 0 )
  100.     bullet.Tracer   = 5
  101.     bullet.Force    = 1
  102.     bullet.Damage   = self.Primary.Damage
  103.     bullet.AmmoType = self.Primary.Ammo
  104.  
  105.     self.Owner:FireBullets(bullet)
  106.     self:ShootEffects()
  107.  
  108.     if (not self.Owner:IsNPC()) and ((game.SinglePlayer() and SERVER) or (not game.SinglePlayer() and CLIENT)) then
  109.         local eyeangle  = self.Owner:EyeAngles()
  110.         eyeangle.pitch  = eyeangle.pitch - self.Primary.Recoil
  111.         self.Owner:SetEyeAngles(eyeangle)
  112.     end
  113. end
  114.  
  115. function SWEP:PrimaryAttack()
  116.     if self:Clip1() <= 0 then
  117.         self:Reload()
  118.     else
  119.         self:SetNextPrimaryFire(CurTime()+self.Primary.Delay)
  120.         self:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
  121.         self:EmitSound(self.Primary.Sound)
  122.         self:TakePrimaryAmmo(1)
  123.  
  124.         self:ShootBullet()
  125.     end
  126. end
  127.  
  128. function SWEP:Reload()
  129.     self:DefaultReload(ACT_VM_RELOAD)
  130.  
  131.     if (self:Clip1() < self.Primary.ClipSize) and (self.Owner:GetAmmoCount(self.Primary.Ammo) > 0) then
  132.         self:SendWeaponAnim(ACT_VM_RELOAD)
  133.         self:EmitSound(Sound("Weapon_SMG1.Reload"))
  134.         self:SetIronsights(false)
  135.     end
  136. end
  137.  
  138. local IRONSIGHT_TIME = 0.25
  139.  
  140. function SWEP:GetViewModelPosition( pos, ang )
  141.  
  142.     if ( !self.IronSightsPos ) then return pos, ang end
  143.  
  144.     local bIron = self:GetNWBool( "Ironsights" )
  145.  
  146.     if ( bIron != self.bLastIron ) then
  147.  
  148.         self.bLastIron = bIron
  149.         self.fIronTime = CurTime()
  150.  
  151.         if ( bIron ) then
  152.             self.SwayScale  = 0.3
  153.             self.BobScale   = 0.1
  154.         else
  155.             self.SwayScale  = 1.0
  156.             self.BobScale   = 1.0
  157.         end
  158.  
  159.     end
  160.  
  161.     local fIronTime = self.fIronTime or 0
  162.  
  163.     if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then
  164.         return pos, ang
  165.     end
  166.  
  167.     local Mul = 1.0
  168.  
  169.     if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then
  170.  
  171.         Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 )
  172.  
  173.         if (!bIron) then Mul = 1 - Mul end
  174.  
  175.     end
  176.  
  177.     local Offset    = self.IronSightsPos
  178.  
  179.     if ( self.IronSightsAng ) then
  180.  
  181.         ang = ang * 1
  182.         ang:RotateAroundAxis( ang:Right(),      self.IronSightsAng.x * Mul )
  183.         ang:RotateAroundAxis( ang:Up(),         self.IronSightsAng.y * Mul )
  184.         ang:RotateAroundAxis( ang:Forward(),    self.IronSightsAng.z * Mul )
  185.  
  186.  
  187.     end
  188.  
  189.     local Right     = ang:Right()
  190.     local Up        = ang:Up()
  191.     local Forward   = ang:Forward()
  192.  
  193.  
  194.  
  195.     pos = pos + Offset.x * Right * Mul
  196.     pos = pos + Offset.y * Forward * Mul
  197.     pos = pos + Offset.z * Up * Mul
  198.  
  199.     return pos, ang
  200.  
  201. end
  202.  
  203. function SWEP:SetIronsights( b )
  204.     self:SetNWBool("Ironsights",b)
  205. end
  206.  
  207. function SWEP:SecondaryAttack()
  208.  
  209.     if !self.IronSightsPos then return end
  210.     if self:GetNextSecondaryFire() > CurTime() then return end
  211.  
  212.     bIronsights = !self:GetNWBool("Ironsights",false)
  213.  
  214.     self:EmitSound("weapons/draw_default.wav")
  215.  
  216.     self:SetIronsights(bIronsights)
  217.     if self:GetNWBool("Ironsights") == true then
  218.         self.Owner:SetFOV(65,0.2)
  219.     else
  220.         self.Owner:SetFOV(0,0.2)
  221.     end
  222.  
  223.     self:SetNextSecondaryFire(CurTime()+0.3)
  224.  
  225. end
  226.  
  227. function SWEP:OnRestore()
  228.  
  229.     self:SetNextSecondaryFire(0)
  230.     self:SetIronsights(false)
  231.  
  232. end
Advertisement
Add Comment
Please, Sign In to add comment