Guest User

Untitled

a guest
Jun 24th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.02 KB | None | 0 0
  1. if SERVER then
  2. AddCSLuaFile( "shared.lua" )
  3. end
  4.  
  5. if CLIENT then
  6. SWEP.Slot = 2
  7. SWEP.SlotPos = 2
  8. SWEP.ViewModelFlip = false --true for CSS, false for non-css
  9. end
  10.  
  11. SWEP.Base = "weapon_base" --weapon_zw_base
  12. SWEP.PrintName = "ZW Weapon Base" --name
  13. SWEP.Author = "Fizzadar"
  14. SWEP.Instructions = "Shoot stuff."
  15.  
  16. SWEP.ViewModel = "models/weapons/v_357.mdl" --view model
  17. SWEP.WorldModel = "models/weapons/w_357.mdl" --world model
  18.  
  19. SWEP.ShootWhileSprinting = true --can they shoot while sprinting?
  20. SWEP.HoldType = "pistol" --pistol, ar2, normal, melee, smg, grenade, shotgun
  21. SWEP.MuzzleEffect = "rg_muzzle_pistol" --rg_muzzle_grenade, rg_muzzle_highcal, rg_muzzle_hmg, rg_muzzle_pistol, rg_muzzle_rifle, rg_muzzle_silenced
  22. SWEP.ShellEffect = "rg_shelleject" --rg_shelleject, rg_shelleject_rifle, rg_shelleject_shotgun
  23. SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
  24. SWEP.ShellEjectAttachment = "2" -- Should be "2" for CSS models or "1" for hl2 models
  25. SWEP.IconLetter = "f" --get from other weps (image that appears in wep selection)
  26.  
  27. SWEP.Primary.ClipSize = 6 --clip size
  28. SWEP.Primary.Ammo = "Pistol" --pistol, buckshot, smg1
  29. SWEP.Primary.Damage = 50 --damage
  30. SWEP.Primary.Spread = 0.03 --bullet spread (make it tiny)
  31. SWEP.Primary.Bullets = 1 --bullets to fire
  32. SWEP.Primary.FireSound = Sound( "Weapon_357.Single" ) --shooting sound
  33. SWEP.Primary.Delay = 0.35 --delay per shot
  34. SWEP.Primary.Automatic = false --automatic fire?
  35. SWEP.Primary.Recoil = 1
  36.  
  37. --//////////////////////////End Config
  38.  
  39. SWEP.Contact = ""
  40. SWEP.Purpose = ""
  41. SWEP.Spawnable = true
  42. SWEP.AdminSpawnable = true
  43.  
  44. if( SERVER ) then
  45. SWEP.AutoSwitchTo = false
  46. SWEP.AutoSwitchFrom = false
  47. end
  48.  
  49. if( CLIENT ) then
  50. SWEP.DrawAmmo = true
  51. SWEP.DrawCrosshair = false
  52. SWEP.ViewModelFOV = 62
  53. end
  54.  
  55. --fixed weapons giving ammo
  56. SWEP.Primary.DefaultClip = SWEP.Primary.ClipSize
  57.  
  58. --secondary ammo (no secondary fire)
  59. SWEP.Secondary.ClipSize = -1
  60. SWEP.Secondary.DefaultClip = -1
  61. SWEP.Secondary.Automatic = false
  62. SWEP.Secondary.Ammo = "none"
  63.  
  64. util.PrecacheSound( SWEP.Primary.FireSound )
  65.  
  66. --startup
  67. function SWEP:Initialize()
  68. if( SERVER ) then
  69. self:SetWeaponHoldType( self.Weapon.HoldType )
  70. end
  71. end
  72.  
  73. --get the wep out
  74. function SWEP:Deploy()
  75. if self.DeploySound then
  76. self.Owner:EmitSound( self.DeploySound )
  77. end
  78. self.Weapon:SendWeaponAnim( ACT_VM_DEPLOY )
  79. return true
  80. end
  81.  
  82. --calculate recoil
  83. function SWEP:CalcRecoil()
  84. --basic start
  85. local RecoilBase = self.Primary.Recoil
  86. if self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) or self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) then
  87. RecoilBase = RecoilBase * 1.2
  88. if self.Owner:KeyDown( IN_SPEED ) then
  89. RecoilBase = RecoilBase * 1.2
  90. end
  91. end
  92. RecoilBase = RecoilBase * 2
  93. --compensate for crouch
  94. if self.Owner:KeyDown( IN_DUCK ) then
  95. RecoilBase = RecoilBase * 0.25
  96. end
  97. --compensate for ironsights
  98. if self.Owner:KeyDown( IN_ATTACK2 ) then
  99. RecoilBase = RecoilBase * 0.75
  100. end
  101. return Angle( ( math.Clamp( math.random( RecoilBase - 10, RecoilBase + 10 ) , 0.3, 100 ) ) * -1, 0, 0 )
  102. end
  103.  
  104. --left click attack
  105. function SWEP:PrimaryAttack()
  106. if not self:CanPrimaryAttack() or self.Owner:WaterLevel() >= 2 then return end
  107. self.Weapon:SetNextPrimaryFire( CurTime() + self.Weapon.Primary.Delay )
  108. self.Owner:MuzzleFlash()
  109. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  110. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  111. if SERVER then self.Owner:EmitSound( self.Primary.FireSound ) end
  112. self:TakePrimaryAmmo( 1 )
  113. self.Owner:ViewPunch( self:CalcRecoil() * 0.2 )
  114. self.Owner:SetEyeAngles( self.Owner:EyeAngles() + ( self:CalcRecoil() * 0.2 ) )
  115. local bullet = {}
  116. bullet.Num = self.Weapon.Primary.Bullets
  117. bullet.Src = self.Owner:GetShootPos()
  118. bullet.Dir = self.Owner:GetAimVector()
  119. bullet.Spread = Vector( self.Weapon.Primary.Spread, self.Weapon.Primary.Spread, 0 )
  120. bullet.Tracer = 1
  121. bullet.Force = self.Weapon.Primary.Damage
  122. bullet.Damage = self.Weapon.Primary.Damage
  123. self.Owner:FireBullets( bullet )
  124. if CLIENT then
  125. if guneffects then
  126. local fx = EffectData()
  127. fx:SetEntity(self.Weapon)
  128. fx:SetOrigin(self.Owner:GetShootPos())
  129. fx:SetNormal(self.Owner:GetAimVector())
  130. fx:SetAttachment(self.MuzzleAttachment)
  131. util.Effect(self.MuzzleEffect,fx)
  132.  
  133. local fx = EffectData()
  134. fx:SetEntity(self.Weapon)
  135. fx:SetNormal(self.Owner:GetAimVector())
  136. fx:SetAttachment(self.ShellEjectAttachment)
  137. util.Effect(self.ShellEffect,fx)
  138. end
  139. end
  140. end
  141.  
  142. function SWEP:CanPrimaryAttack()
  143. if self.Weapon:Clip1() <= 0 then
  144. self.Weapon:SetNextPrimaryFire( CurTime() + 0.5 )
  145. self.Owner:EmitSound( "Weapons/ClipEmpty_Pistol.wav" )
  146. return false
  147. end
  148. local IsMoving = false
  149. if self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) or self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) then
  150. IsMoving = true
  151. end
  152. if self.Owner:KeyDown( IN_SPEED ) and IsMoving and not self.ShootWhileSprinting then
  153. return false
  154. end
  155. return true
  156. end
  157.  
  158. --secondary
  159. function SWEP:SecondaryAttack()
  160. return false
  161. end
  162.  
  163. --think
  164. function SWEP:Think()
  165. if self.Owner:KeyPressed( IN_ATTACK2 ) then
  166. if self.IsSniper then
  167. if not self:GetNWBool( "IsScoped" ) then
  168. self:SetNWBool( "IsScoped", true )
  169. self.Owner:SetFOV( 40, 0.15 )
  170. end
  171. else
  172. self.Owner:SetFOV( 65, 0.15 )
  173. self.DrawCrosshair = true
  174. end
  175. end
  176. if self.Owner:KeyReleased( IN_ATTACK2 ) then
  177. if self.IsSniper then
  178. if self:GetNWBool( "IsScoped" ) then
  179. self:SetNWBool( "IsScoped", false )
  180. self.Owner:SetFOV( 0, 0.15 )
  181. end
  182. else
  183. self.Owner:SetFOV( 0, 0.15 )
  184. self.DrawCrosshair = false
  185. end
  186. end
  187. end
  188.  
  189. --reload
  190. function SWEP:Reload()
  191. self.Weapon:DefaultReload( ACT_VM_RELOAD )
  192. self.Owner:SetFOV( 0, 0.15 )
  193. end
  194.  
  195. --weapon icon in selection bit
  196. function SWEP:DrawWeaponSelection( x, y, wide, tall, alpha )
  197. --draw.SimpleText( self.Weapon.IconLetter, "CSSelectIcons", x + wide/2, y + tall*0.2, Color( 255, 210, 0, 255 ), TEXT_ALIGN_CENTER )
  198. draw.SimpleText( self.Weapon.PrintName, "ZWFontTypeSmall", x + wide/2, y + tall*0.2, Color( 255, 210, 0, 255 ), TEXT_ALIGN_CENTER )
  199. end
  200.  
  201. --scopes
  202. function SWEP:DrawHUD()
  203. if not self.IsSniper then return end
  204. if self:GetNWBool( "IsScoped" ) then
  205. local w = ScrW()
  206. local h = ScrH()
  207. local wr = ( h / 3 ) * 4
  208. --draw scope
  209. surface.SetTexture( surface.GetTextureID( "gmod/scope" ) )
  210. surface.SetDrawColor( 0, 0, 0, 255 )
  211. surface.DrawTexturedRect( ( w / 2 ) - wr / 2, 0, wr, h )
  212.  
  213. surface.SetDrawColor( 0, 0, 0, 255 )
  214. surface.DrawRect( 0, 0, ( w / 2 ) - wr / 2, h )
  215. surface.DrawRect( ( w / 2 ) + wr / 2, 0, w - ( ( w / 2 ) + wr / 2 ), h )
  216. surface.DrawLine( 0, h * 0.50, w, h * 0.50 )
  217. surface.DrawLine( w * 0.50, 0, w * 0.50, h )
  218.  
  219. local tr = util.TraceLine( util.GetPlayerTrace(self.Owner) )
  220. local dist = math.Clamp( math.ceil( tr.HitPos:Distance( self.Owner:GetPos() ) / 16 ), 2, 999999 )
  221. local target = "N/A"
  222. if tr.Entity:IsNPC() then
  223. target = tr.Entity:GetClass()
  224. elseif tr.Entity:IsPlayer() then
  225. target = tr.Entity:GetName()
  226. end
  227.  
  228. surface.SetFont( "Default" )
  229. surface.SetTextColor( 255, 255, 255, 255 )
  230.  
  231. surface.SetTextPos( w * 0.90, h * 0.50 )
  232. surface.DrawText( "Distance: "..dist.." feet" )
  233.  
  234. surface.SetTextPos( w * 0.90, h * 0.52 )
  235. surface.DrawText( "Target: "..target )
  236. end
  237. end
  238.  
  239. --sprint stuff
  240. SWEP.RunArmAngle = Angle( 10, 50, 20 )
  241. SWEP.RunArmOffset = Vector( 1, 2, -5 ) --down, forward, right
  242. function SWEP:GetViewModelPosition( pos, ang )
  243. if self.ShootWhileSprinting then
  244. return pos, ang
  245. end
  246. local Owner = self.Owner
  247. if (!Owner) then
  248. return pos, ang
  249. end
  250. local DashDelta = 0
  251. // If we're running, or have just stopped running, lerp between the
  252. local IsMoving = false
  253. if self.Owner:KeyDown( IN_MOVELEFT ) or self.Owner:KeyDown( IN_MOVERIGHT ) or self.Owner:KeyDown( IN_FORWARD ) or self.Owner:KeyDown( IN_BACK ) then
  254. IsMoving = true
  255. end
  256. if self.Owner:KeyDown( IN_SPEED ) and IsMoving then
  257. if (!self.DashStartTime) then
  258. self.DashStartTime = CurTime()
  259. end
  260. DashDelta = math.Clamp( ((CurTime() - self.DashStartTime) / 0.1) ^ 1.2, 0, 1 )
  261. else
  262. if ( self.DashStartTime ) then
  263. self.DashEndTime = CurTime()
  264. end
  265. if ( self.DashEndTime ) then
  266. DashDelta = math.Clamp( ((CurTime() - self.DashEndTime) / 0.1) ^ 1.2, 0, 1 )
  267. DashDelta = 1 - DashDelta
  268. if ( DashDelta == 0 ) then self.DashEndTime = nil end
  269. end
  270. self.DashStartTime = nil
  271. end
  272. if ( DashDelta ) then
  273. local Down = ang:Up() * -1
  274. local Right = ang:Right()
  275. local Forward = ang:Forward()
  276. // Offset the viewmodel to self.RunArmOffset
  277. pos = pos + ( Down * self.RunArmOffset.x + Forward * self.RunArmOffset.y + Right * self.RunArmOffset.z ) * DashDelta
  278. // Rotate the viewmodel to self.RunArmAngle
  279. ang:RotateAroundAxis( Right, self.RunArmAngle.pitch * DashDelta )
  280. ang:RotateAroundAxis( Down, self.RunArmAngle.yaw * DashDelta )
  281. ang:RotateAroundAxis( Forward, self.RunArmAngle.roll * DashDelta )
  282. end
  283. return pos, ang
  284. end
Add Comment
Please, Sign In to add comment