Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.50 KB | None | 0 0
  1. -- Variables that are used on both client and server
  2. SWEP.Category = ""
  3. SWEP.Gun = ""
  4. SWEP.Author = "Generic Default, Worshipper, Clavus, and Bob"
  5. SWEP.Contact = ""
  6. SWEP.Purpose = ""
  7. SWEP.Instructions = ""
  8. SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
  9. SWEP.DrawCrosshair = true -- Hell no, crosshairs r 4 nubz!
  10. SWEP.ViewModelFOV = 65 -- How big the gun will look
  11. SWEP.ViewModelFlip = true -- True for CSS models, False for HL2 models
  12.  
  13. SWEP.Spawnable = false
  14. SWEP.AdminSpawnable = false
  15.  
  16. SWEP.Primary.Sound = Sound("") -- Sound of the gun
  17. SWEP.Primary.Round = ("") -- What kind of bullet?
  18. SWEP.Primary.Cone = 0.2 -- Accuracy of NPCs
  19. SWEP.Primary.Recoil = 10
  20. SWEP.Primary.Damage = 10
  21. SWEP.Primary.Spread = .01 --define from-the-hip accuracy (1 is terrible, .0001 is exact)
  22. SWEP.Primary.NumShots = 1
  23. SWEP.Primary.RPM = 0 -- This is in Rounds Per Minute
  24. SWEP.Primary.ClipSize = 0 -- Size of a clip
  25. SWEP.Primary.DefaultClip = 0 -- Default number of bullets in a clip
  26. SWEP.Primary.KickUp = 0 -- Maximum up recoil (rise)
  27. SWEP.Primary.KickDown = 0 -- Maximum down recoil (skeet)
  28. SWEP.Primary.KickHorizontal = 0 -- Maximum side recoil (koolaid)
  29. SWEP.Primary.Automatic = true -- Automatic/Semi Auto
  30. SWEP.Primary.Ammo = "none" -- What kind of ammo
  31.  
  32. SWEP.Secondary.ClipSize = 0 -- Size of a clip
  33. SWEP.Secondary.DefaultClip = 0 -- Default number of bullets in a clip
  34. SWEP.Secondary.Automatic = false -- Automatic/Semi Auto
  35. SWEP.Secondary.Ammo = "none"
  36. SWEP.Secondary.IronFOV = 0 -- How much you 'zoom' in. Less is more!
  37.  
  38. SWEP.Penetration = false
  39. SWEP.Ricochet = false
  40. SWEP.MaxRicochet = 0
  41. SWEP.RicochetCoin = 0
  42. SWEP.BoltAction = false
  43. SWEP.Scoped = false
  44. SWEP.ShellTime = .35
  45. SWEP.Tracer = 0
  46. SWEP.CanBeSilenced = false
  47. SWEP.Silenced = false
  48. SWEP.NextSilence = 0
  49. SWEP.SelectiveFire = false
  50. SWEP.NextFireSelect = 0
  51.  
  52. SWEP.IronSightsPos = Vector (2.4537, 1.0923, 0.2696)
  53. SWEP.IronSightsAng = Vector (0.0186, -0.0547, 0)
  54.  
  55. SWEP.VElements = {}
  56. SWEP.WElements = {}
  57.  
  58. function SWEP:Initialize()
  59. self.Reloadaftershoot = 0 -- Can't reload when firing
  60. self:SetWeaponHoldType(self.HoldType)
  61. self.Weapon:SetNetworkedBool("Reloading", false)
  62. if SERVER and self.Owner:IsNPC() then
  63. self:SetNPCMinBurst(3)
  64. self:SetNPCMaxBurst(10) -- None of this really matters but you need it here anyway
  65. self:SetNPCFireRate(1/(self.Primary.RPM/60))
  66. self:SetCurrentWeaponProficiency( WEAPON_PROFICIENCY_VERY_GOOD )
  67. end
  68.  
  69. if CLIENT then
  70.  
  71. -- // Create a new table for every weapon instance
  72. self.VElements = table.FullCopy( self.VElements )
  73. self.WElements = table.FullCopy( self.WElements )
  74. self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
  75.  
  76. self:CreateModels(self.VElements) -- create viewmodels
  77. self:CreateModels(self.WElements) -- create worldmodels
  78.  
  79. -- // init view model bone build function
  80. if IsValid(self.Owner) and self.Owner:IsPlayer() then
  81. if self.Owner:Alive() then
  82. local vm = self.Owner:GetViewModel()
  83. if IsValid(vm) then
  84. self:ResetBonePositions(vm)
  85. -- // Init viewmodel visibility
  86. if (self.ShowViewModel == nil or self.ShowViewModel) then
  87. vm:SetColor(Color(255,255,255,255))
  88. else
  89. -- // however for some reason the view model resets to render mode 0 every frame so we just apply a debug material to prevent it from drawing
  90. vm:SetMaterial("Debug/hsv")
  91. end
  92. end
  93.  
  94. end
  95. end
  96.  
  97. end
  98.  
  99. if CLIENT then
  100. local oldpath = "vgui/hud/name" -- the path goes here
  101. local newpath = string.gsub(oldpath, "name", self.Gun)
  102. self.WepSelectIcon = surface.GetTextureID(newpath)
  103. end
  104.  
  105. end
  106.  
  107. function SWEP:Deploy()
  108. self:SetIronsights(false, self.Owner) -- Set the ironsight false
  109.  
  110. if self.Silenced then
  111. self.Weapon:SendWeaponAnim( ACT_VM_DRAW_SILENCED )
  112. else
  113. self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
  114. end
  115.  
  116. self.Weapon:SetNetworkedBool("Reloading", false)
  117.  
  118. if !self.Owner:IsNPC() and self.Owner != nil then
  119. if self.ResetSights and self.Owner:GetViewModel() != nil then
  120. self.ResetSights = CurTime() + self.Owner:GetViewModel():SequenceDuration()
  121. end
  122. end
  123. return true
  124. end
  125.  
  126. function SWEP:Holster()
  127.  
  128. if CLIENT and IsValid(self.Owner) and not self.Owner:IsNPC() then
  129. local vm = self.Owner:GetViewModel()
  130. if IsValid(vm) then
  131. self:ResetBonePositions(vm)
  132. end
  133. end
  134.  
  135. return true
  136. end
  137.  
  138. function SWEP:OnRemove()
  139.  
  140. if CLIENT and IsValid(self.Owner) and not self.Owner:IsNPC() then
  141. local vm = self.Owner:GetViewModel()
  142. if IsValid(vm) then
  143. self:ResetBonePositions(vm)
  144. end
  145. end
  146.  
  147. end
  148.  
  149. function SWEP:GetCapabilities()
  150. return CAP_WEAPON_RANGE_ATTACK1, CAP_INNATE_RANGE_ATTACK1
  151. end
  152.  
  153. function SWEP:Precache()
  154. util.PrecacheSound(self.Primary.Sound)
  155. util.PrecacheModel(self.ViewModel)
  156. util.PrecacheModel(self.WorldModel)
  157. end
  158.  
  159. function SWEP:PrimaryAttack()
  160. if self:CanPrimaryAttack() and self.Owner:IsPlayer() then
  161. if !self.Owner:KeyDown(IN_SPEED) and !self.Owner:KeyDown(IN_RELOAD) then
  162. self:ShootBulletInformation()
  163. self.Weapon:TakePrimaryAmmo(1)
  164.  
  165. if self.Silenced then
  166. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK_SILENCED )
  167. self.Weapon:EmitSound(self.Primary.SilencedSound)
  168. else
  169. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  170. self.Weapon:EmitSound(self.Primary.Sound)
  171. end
  172.  
  173. local fx = EffectData()
  174. fx:SetEntity(self.Weapon)
  175. fx:SetOrigin(self.Owner:GetShootPos())
  176. fx:SetNormal(self.Owner:GetAimVector())
  177. fx:SetAttachment(self.MuzzleAttachment)
  178. if GetConVar("M9KGasEffect") != nil then
  179. if GetConVar("M9KGasEffect"):GetBool() then
  180. util.Effect("m9k_rg_muzzle_rifle",fx)
  181. end
  182. end
  183. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  184. self.Owner:MuzzleFlash()
  185. self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
  186. self:CheckWeaponsAndAmmo()
  187. self.RicochetCoin = (math.random(1,4))
  188. if self.BoltAction then self:BoltBack() end
  189. end
  190. elseif self:CanPrimaryAttack() and self.Owner:IsNPC() then
  191. self:ShootBulletInformation()
  192. self.Weapon:TakePrimaryAmmo(1)
  193. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  194. self.Weapon:EmitSound(self.Primary.Sound)
  195. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  196. self.Owner:MuzzleFlash()
  197. self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
  198. self.RicochetCoin = (math.random(1,4))
  199. end
  200. end
  201.  
  202. function SWEP:CheckWeaponsAndAmmo()
  203. if SERVER and self.Weapon != nil and (GetConVar("M9KWeaponStrip"):GetBool()) then
  204. if self.Weapon:Clip1() == 0 && self.Owner:GetAmmoCount( self.Weapon:GetPrimaryAmmoType() ) == 0 then
  205. timer.Simple(.1, function() if SERVER then if not IsValid(self) then return end
  206. if self.Owner == nil then return end
  207. self.Owner:StripWeapon(self.Gun)
  208. end end)
  209. end
  210. end
  211. end
  212.  
  213.  
  214. /*---------------------------------------------------------
  215. Name: SWEP:ShootBulletInformation()
  216. Desc: This func add the damage, the recoil, the number of shots and the cone on the bullet.
  217. ---------------------------------------------------------*/
  218. function SWEP:ShootBulletInformation()
  219.  
  220. local CurrentDamage
  221. local CurrentRecoil
  222. local CurrentCone
  223.  
  224. if (self:GetIronsights() == true) and self.Owner:KeyDown(IN_ATTACK2) then
  225. CurrentCone = self.Primary.IronAccuracy
  226. else
  227. CurrentCone = self.Primary.Spread
  228. end
  229. local damagedice = math.Rand(.85,1.3)
  230.  
  231. CurrentDamage = self.Primary.Damage * damagedice
  232. CurrentRecoil = self.Primary.Recoil
  233.  
  234. -- Player is aiming
  235. if (self:GetIronsights() == true) and self.Owner:KeyDown(IN_ATTACK2) then
  236. self:ShootBullet(CurrentDamage, CurrentRecoil / 6, self.Primary.NumShots, CurrentCone)
  237. -- Player is not aiming
  238. else
  239. self:ShootBullet(CurrentDamage, CurrentRecoil, self.Primary.NumShots, CurrentCone)
  240. end
  241.  
  242. end
  243.  
  244. /*---------------------------------------------------------
  245. Name: SWEP:ShootBullet()
  246. Desc: A convenience func to shoot bullets.
  247. ---------------------------------------------------------*/
  248. local TracerName = "Tracer"
  249.  
  250. function SWEP:ShootBullet(damage, recoil, num_bullets, aimcone)
  251.  
  252. num_bullets = num_bullets or 1
  253. aimcone = aimcone or 0
  254.  
  255. self:ShootEffects()
  256.  
  257. if self.Tracer == 1 then
  258. TracerName = "ar2Tracer"
  259. elseif self.Tracer == 2 then
  260. TracerName = "AirboatGunHeavyTracer"
  261. else
  262. TracerName = "Tracer"
  263. end
  264.  
  265. local bullet = {}
  266. bullet.Num = num_bullets
  267. bullet.Src = self.Owner:GetShootPos() -- Source
  268. bullet.Dir = self.Owner:GetAimVector() -- Dir of bullet
  269. bullet.Spread = Vector(aimcone, aimcone, 0) -- Aim Cone
  270. bullet.Tracer = 3 -- Show a tracer on every x bullets
  271. bullet.TracerName = TracerName
  272. bullet.Force = damage * 0.5 -- Amount of force to give to phys objects
  273. bullet.Damage = damage
  274. bullet.Callback = function(attacker, tracedata, dmginfo)
  275.  
  276. return self:RicochetCallback(0, attacker, tracedata, dmginfo)
  277. end
  278.  
  279. self.Owner:FireBullets(bullet)
  280. if SERVER and !self.Owner:IsNPC() then
  281. local anglo = Angle(math.Rand(-self.Primary.KickDown,-self.Primary.KickUp), math.Rand(-self.Primary.KickHorizontal,self.Primary.KickHorizontal), 0)
  282. self.Owner:ViewPunch(anglo)
  283.  
  284. local eyes = self.Owner:EyeAngles()
  285. eyes.pitch = eyes.pitch + anglo.pitch
  286. eyes.yaw = eyes.yaw + anglo.yaw
  287. if game.SinglePlayer() then self.Owner:SetEyeAngles(eyes) end
  288. end
  289.  
  290. end
  291.  
  292. /*---------------------------------------------------------
  293. Name: SWEP:RicochetCallback()
  294. ---------------------------------------------------------*/
  295.  
  296. function SWEP:RicochetCallback(bouncenum, attacker, tr, dmginfo)
  297.  
  298. if GetConVar("M9KDisablePenetration") != nil then
  299. if GetConVar("M9KDisablePenetration"):GetBool() then return end
  300. end
  301.  
  302. bulletmiss = {}
  303. bulletmiss[1]=Sound("weapons/fx/nearmiss/bulletLtoR03.wav")
  304. bulletmiss[2]=Sound("weapons/fx/nearmiss/bulletLtoR04.wav")
  305. bulletmiss[3]=Sound("weapons/fx/nearmiss/bulletLtoR06.wav")
  306. bulletmiss[4]=Sound("weapons/fx/nearmiss/bulletLtoR07.wav")
  307. bulletmiss[5]=Sound("weapons/fx/nearmiss/bulletLtoR09.wav")
  308. bulletmiss[6]=Sound("weapons/fx/nearmiss/bulletLtoR10.wav")
  309. bulletmiss[7]=Sound("weapons/fx/nearmiss/bulletLtoR13.wav")
  310. bulletmiss[8]=Sound("weapons/fx/nearmiss/bulletLtoR14.wav")
  311.  
  312. local DoDefaultEffect = true
  313. if (tr.HitSky) then return end
  314.  
  315. // -- Can we go through whatever we hit?
  316. if (self.Penetration) and (self:BulletPenetrate(bouncenum, attacker, tr, dmginfo)) then
  317. return {damage = true, effects = DoDefaultEffect}
  318. end
  319.  
  320. // -- Your screen will shake and you'll hear the savage hiss of an approaching bullet which passing if someone is shooting at you.
  321. if (tr.MatType != MAT_METAL) then
  322. if (SERVER) then
  323. util.ScreenShake(tr.HitPos, 0, 0, 0.0, 0)
  324. sound.Play(table.Random(bulletmiss), tr.HitPos, 75, math.random(75,150), 1)
  325. end
  326.  
  327. if self.Tracer == 0 or self.Tracer == 1 or self.Tracer == 2 then
  328. local effectdata = EffectData()
  329. effectdata:SetOrigin(tr.HitPos)
  330. effectdata:SetNormal(tr.HitNormal)
  331. effectdata:SetScale(20)
  332. util.Effect("pistolImpact", effectdata)
  333. elseif self.Tracer == 3 then
  334. local effectdata = EffectData()
  335. effectdata:SetOrigin(tr.HitPos)
  336. effectdata:SetNormal(tr.HitNormal)
  337. effectdata:SetScale(20)
  338. util.Effect("StunstickImpact", effectdata)
  339. end
  340.  
  341. return
  342. end
  343.  
  344. if (self.Ricochet == false) then return {damage = true, effects = DoDefaultEffect} end
  345.  
  346. if self.Primary.Ammo == "SniperPenetratedRound" then -- .50 Ammo
  347. self.MaxRicochet = 20
  348. elseif self.Primary.Ammo == "pistol" then -- pistols
  349. self.MaxRicochet = 2
  350. elseif self.Primary.Ammo == "357" then -- revolvers with big ass bullets
  351. self.MaxRicochet = 4
  352. elseif self.Primary.Ammo == "smg1" then -- smgs
  353. self.MaxRicochet = 5
  354. elseif self.Primary.Ammo == "ar2" then -- assault rifles
  355. self.MaxRicochet = 8
  356. elseif self.Primary.Ammo == "buckshot" then -- shotguns
  357. self.MaxRicochet = 3
  358. elseif self.Primary.Ammo == "slam" then -- secondary shotguns
  359. self.MaxRicochet = 3
  360. elseif self.Primary.Ammo == "AirboatGun" then -- metal piercing shotgun pellet
  361. self.MaxRicochet = 20
  362. end
  363.  
  364. if (bouncenum > self.MaxRicochet) then return end
  365.  
  366. // -- Bounce vector
  367. local trace = {}
  368. trace.start = tr.HitPos
  369. trace.endpos = trace.start + (tr.HitNormal * 16384)
  370.  
  371. local trace = util.TraceLine(trace)
  372.  
  373. local DotProduct = tr.HitNormal:Dot(tr.Normal * -1)
  374.  
  375. local ricochetbullet = {}
  376. ricochetbullet.Num = 1
  377. ricochetbullet.Src = tr.HitPos + (tr.HitNormal * 5)
  378. ricochetbullet.Dir = ((2 * tr.HitNormal * DotProduct) + tr.Normal) + (VectorRand() * 0.05)
  379. ricochetbullet.Spread = Vector(0, 0, 0)
  380. ricochetbullet.Tracer = 1
  381. ricochetbullet.TracerName = "m9k_effect_mad_ricochet_trace"
  382. ricochetbullet.Force = dmginfo:GetDamage() * 0.25
  383. ricochetbullet.Damage = dmginfo:GetDamage() * 0.5
  384. ricochetbullet.Callback = function(a, b, c)
  385. if (self.Ricochet) then
  386. local impactnum
  387. if tr.MatType == MAT_GLASS then impactnum = 0 else impactnum = 1 end
  388. return self:RicochetCallback(bouncenum + impactnum, a, b, c) end
  389. end
  390.  
  391. timer.Simple(0.05, function() attacker:FireBullets(ricochetbullet) end)
  392.  
  393. return {damage = true, effects = DoDefaultEffect}
  394. end
  395.  
  396.  
  397. /*---------------------------------------------------------
  398. Name: SWEP:BulletPenetrate()
  399. ---------------------------------------------------------*/
  400. function SWEP:BulletPenetrate(bouncenum, attacker, tr, paininfo)
  401.  
  402. if GetConVar("M9KDisablePenetration") != nil then
  403. if GetConVar("M9KDisablePenetration"):GetBool() then return end
  404. end
  405.  
  406. local MaxPenetration
  407.  
  408. if self.Primary.Ammo == "SniperPenetratedRound" then -- .50 Ammo
  409. MaxPenetration = 20
  410. elseif self.Primary.Ammo == "pistol" then -- pistols
  411. MaxPenetration = 8
  412. elseif self.Primary.Ammo == "357" then -- revolvers with big ass bullets
  413. MaxPenetration = 12
  414. elseif self.Primary.Ammo == "smg1" then -- smgs
  415. MaxPenetration = 14
  416. elseif self.Primary.Ammo == "ar2" then -- assault rifles
  417. MaxPenetration = 16
  418. elseif self.Primary.Ammo == "buckshot" then -- shotguns
  419. MaxPenetration = 8
  420. elseif self.Primary.Ammo == "slam" then -- secondary shotguns
  421. MaxPenetration = 8
  422. elseif self.Primary.Ammo == "AirboatGun" then -- metal piercing shotgun pellet
  423. MaxPenetration = 20
  424. else
  425. MaxPenetration = 16
  426. end
  427.  
  428. local DoDefaultEffect = true
  429. // -- Don't go through metal, sand or player
  430.  
  431. if self.Primary.Ammo == "pistol" or
  432. self.Primary.Ammo == "buckshot" or
  433. self.Primary.Ammo == "slam" then self.Ricochet = true
  434. else
  435. if self.RicochetCoin == 1 then
  436. self.Ricochet = true
  437. elseif self.RicochetCoin >= 2 then
  438. self.Ricochet = false
  439. end
  440. end
  441.  
  442. if self.Primary.Ammo == "SniperPenetratedRound" then self.Ricochet = false end
  443.  
  444. if self.Primary.Ammo == "SniperPenetratedRound" then -- .50 Ammo
  445. self.MaxRicochet = 20
  446. elseif self.Primary.Ammo == "pistol" then -- pistols
  447. self.MaxRicochet = 2
  448. elseif self.Primary.Ammo == "357" then -- revolvers with big ass bullets
  449. self.MaxRicochet = 4
  450. elseif self.Primary.Ammo == "smg1" then -- smgs
  451. self.MaxRicochet = 5
  452. elseif self.Primary.Ammo == "ar2" then -- assault rifles
  453. self.MaxRicochet = 8
  454. elseif self.Primary.Ammo == "buckshot" then -- shotguns
  455. self.MaxRicochet = 3
  456. elseif self.Primary.Ammo == "slam" then -- secondary shotguns
  457. self.MaxRicochet = 3
  458. elseif self.Primary.Ammo == "AirboatGun" then -- metal piercing shotgun pellet
  459. self.MaxRicochet = 20
  460. end
  461.  
  462. if (tr.MatType == MAT_METAL and self.Ricochet == true ) then return false end
  463.  
  464. // -- Don't go through more than 3 times
  465. if (bouncenum > self.MaxRicochet) then return false end
  466.  
  467. // -- Direction (and length) that we are going to penetrate
  468. local PenetrationDirection = tr.Normal * MaxPenetration
  469.  
  470. if (tr.MatType == MAT_GLASS or tr.MatType == MAT_PLASTIC or tr.MatType == MAT_WOOD or tr.MatType == MAT_FLESH or tr.MatType == MAT_ALIENFLESH) then
  471. PenetrationDirection = tr.Normal * (MaxPenetration * 2)
  472. end
  473.  
  474. local trace = {}
  475. trace.endpos = tr.HitPos
  476. trace.start = tr.HitPos + PenetrationDirection
  477. trace.mask = MASK_SHOT
  478. trace.filter = {self.Owner}
  479.  
  480. local trace = util.TraceLine(trace)
  481.  
  482. // -- Bullet didn't penetrate.
  483. if (trace.StartSolid or trace.Fraction >= 1.0 or tr.Fraction <= 0.0) then return false end
  484.  
  485. // -- Damage multiplier depending on surface
  486. local fDamageMulti = 0.5
  487.  
  488. if self.Primary.Ammo == "SniperPenetratedBullet" then
  489. fDamageMulti = 1
  490. elseif(tr.MatType == MAT_CONCRETE or tr.MatType == MAT_METAL) then
  491. fDamageMulti = 0.3
  492. elseif (tr.MatType == MAT_WOOD or tr.MatType == MAT_PLASTIC or tr.MatType == MAT_GLASS) then
  493. fDamageMulti = 0.8
  494. elseif (tr.MatType == MAT_FLESH or tr.MatType == MAT_ALIENFLESH) then
  495. fDamageMulti = 0.9
  496. end
  497.  
  498. local damagedice = math.Rand(.85,1.3)
  499. local newdamage = self.Primary.Damage * damagedice
  500.  
  501. // -- Fire bullet from the exit point using the original trajectory
  502. local penetratedbullet = {}
  503. penetratedbullet.Num = 1
  504. penetratedbullet.Src = trace.HitPos
  505. penetratedbullet.Dir = tr.Normal
  506. penetratedbullet.Spread = Vector(0, 0, 0)
  507. penetratedbullet.Tracer = 1
  508. penetratedbullet.TracerName = "m9k_effect_mad_penetration_trace"
  509. penetratedbullet.Force = 5
  510. penetratedbullet.Damage = paininfo:GetDamage() * fDamageMulti
  511. penetratedbullet.Callback = function(a, b, c) if (self.Ricochet) then
  512. local impactnum
  513. if tr.MatType == MAT_GLASS then impactnum = 0 else impactnum = 1 end
  514. return self:RicochetCallback(bouncenum + impactnum, a,b,c) end end
  515.  
  516. timer.Simple(0.05, function() if attacker != nil then attacker:FireBullets(penetratedbullet) end end)
  517.  
  518. return true
  519. end
  520.  
  521.  
  522. function SWEP:SecondaryAttack()
  523. return false
  524. end
  525.  
  526. function SWEP:Reload()
  527. if not IsValid(self) then return end if not IsValid(self.Owner) then return end
  528.  
  529. if self.Owner:IsNPC() then
  530. self.Weapon:DefaultReload(ACT_VM_RELOAD)
  531. return end
  532.  
  533. if self.Owner:KeyDown(IN_USE) then return end
  534.  
  535. if self.Silenced then
  536. self.Weapon:DefaultReload(ACT_VM_RELOAD_SILENCED)
  537. else
  538. self.Weapon:DefaultReload(ACT_VM_RELOAD)
  539. end
  540.  
  541. if !self.Owner:IsNPC() then
  542. if self.Owner:GetViewModel() == nil then self.ResetSights = CurTime() + 3 else
  543. self.ResetSights = CurTime() + self.Owner:GetViewModel():SequenceDuration()
  544. end
  545. end
  546.  
  547. if SERVER and self.Weapon != nil then
  548. if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and !self.Owner:IsNPC() then
  549. -- When the current clip < full clip and the rest of your ammo > 0, then
  550. self.Owner:SetFOV( 0, 0.3 )
  551. -- Zoom = 0
  552. self:SetIronsights(false)
  553. -- Set the ironsight to false
  554. self.Weapon:SetNetworkedBool("Reloading", true)
  555. end
  556. local waitdammit = (self.Owner:GetViewModel():SequenceDuration())
  557. timer.Simple(waitdammit + .1,
  558. function()
  559. if self.Weapon == nil then return end
  560. self.Weapon:SetNetworkedBool("Reloading", false)
  561. if self.Owner:KeyDown(IN_ATTACK2) and self.Weapon:GetClass() == self.Gun then
  562. if CLIENT then return end
  563. if self.Scoped == false then
  564. self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
  565. self.IronSightsPos = self.SightsPos -- Bring it up
  566. self.IronSightsAng = self.SightsAng -- Bring it up
  567. self:SetIronsights(true, self.Owner)
  568. self.DrawCrosshair = false
  569. else return end
  570. elseif self.Owner:KeyDown(IN_SPEED) and self.Weapon:GetClass() == self.Gun then
  571. self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
  572. self.IronSightsPos = self.RunSightsPos -- Hold it down
  573. self.IronSightsAng = self.RunSightsAng -- Hold it down
  574. self:SetIronsights(true, self.Owner) -- Set the ironsight true
  575. self.Owner:SetFOV( 0, 0.3 )
  576. else return end
  577. end)
  578. end
  579. end
  580.  
  581. function SWEP:PostReloadScopeCheck()
  582. if self.Weapon == nil then return end
  583. self.Weapon:SetNetworkedBool("Reloading", false)
  584. if self.Owner:KeyDown(IN_ATTACK2) and self.Weapon:GetClass() == self.Gun then
  585. if CLIENT then return end
  586. if self.Scoped == false then
  587. self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
  588. self.IronSightsPos = self.SightsPos -- Bring it up
  589. self.IronSightsAng = self.SightsAng -- Bring it up
  590. self:SetIronsights(true, self.Owner)
  591. self.DrawCrosshair = false
  592. else return end
  593. elseif self.Owner:KeyDown(IN_SPEED) and self.Weapon:GetClass() == self.Gun then
  594. self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
  595. self.IronSightsPos = self.RunSightsPos -- Hold it down
  596. self.IronSightsAng = self.RunSightsAng -- Hold it down
  597. self:SetIronsights(true, self.Owner) -- Set the ironsight true
  598. self.Owner:SetFOV( 0, 0.3 )
  599. else return end
  600. end
  601.  
  602. function SWEP:Silencer()
  603.  
  604. if self.NextSilence > CurTime() then return end
  605.  
  606. if self.Weapon != nil then
  607. self.Owner:SetFOV( 0, 0.3 )
  608. self:SetIronsights(false)
  609. self.Weapon:SetNetworkedBool("Reloading", true) -- i know we're not reloading but it works
  610. end
  611.  
  612. if self.Silenced then
  613. self:SendWeaponAnim(ACT_VM_DETACH_SILENCER)
  614. self.Silenced = false
  615. elseif not self.Silenced then
  616. self:SendWeaponAnim(ACT_VM_ATTACH_SILENCER)
  617. self.Silenced = true
  618. end
  619.  
  620. siltimer = CurTime() + (self.Owner:GetViewModel():SequenceDuration()) + 0.1
  621. self.Weapon:SetNextPrimaryFire(siltimer)
  622. self.NextSilence = siltimer
  623.  
  624. timer.Simple( ((self.Owner:GetViewModel():SequenceDuration()) + 0.1),
  625. function()
  626. if self.Weapon != nil then
  627. self.Weapon:SetNetworkedBool("Reloading", false)
  628. if self.Owner:KeyDown(IN_ATTACK2) and self.Weapon:GetClass() == self.Gun then
  629. if CLIENT then return end
  630. if self.Scoped == false then
  631. self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
  632. self.IronSightsPos = self.SightsPos -- Bring it up
  633. self.IronSightsAng = self.SightsAng -- Bring it up
  634. self:SetIronsights(true, self.Owner)
  635. self.DrawCrosshair = false
  636. else return end
  637. elseif self.Owner:KeyDown(IN_SPEED) and self.Weapon:GetClass() == self.Gun then
  638. self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
  639. self.IronSightsPos = self.RunSightsPos -- Hold it down
  640. self.IronSightsAng = self.RunSightsAng -- Hold it down
  641. self:SetIronsights(true, self.Owner) -- Set the ironsight true
  642. self.Owner:SetFOV( 0, 0.3 )
  643. else return end
  644. end
  645. end)
  646.  
  647. end
  648.  
  649. function SWEP:SelectFireMode()
  650.  
  651. if self.Primary.Automatic then
  652. self.Primary.Automatic = false
  653. self.NextFireSelect = CurTime() + .5
  654. if CLIENT then
  655. self.Owner:PrintMessage(HUD_PRINTTALK, "Semi-automatic selected.")
  656. end
  657. self.Weapon:EmitSound("Weapon_AR2.Empty")
  658. else
  659. self.Primary.Automatic = true
  660. self.NextFireSelect = CurTime() + .5
  661. if CLIENT then
  662. self.Owner:PrintMessage(HUD_PRINTTALK, "Automatic selected.")
  663. end
  664. self.Weapon:EmitSound("Weapon_AR2.Empty")
  665. end
  666. end
  667.  
  668. /*---------------------------------------------------------
  669. IronSight
  670. ---------------------------------------------------------*/
  671. function SWEP:IronSight()
  672.  
  673. if !self.Owner:IsNPC() then
  674. if self.ResetSights and CurTime() >= self.ResetSights then
  675. self.ResetSights = nil
  676.  
  677. if self.Silenced then
  678. self:SendWeaponAnim(ACT_VM_IDLE_SILENCED)
  679. else
  680. self:SendWeaponAnim(ACT_VM_IDLE)
  681. end
  682. end end
  683.  
  684. if self.CanBeSilenced and self.NextSilence < CurTime() then
  685. if self.Owner:KeyDown(IN_USE) and self.Owner:KeyPressed(IN_ATTACK2) then
  686. self:Silencer()
  687. end
  688. end
  689.  
  690. if self.SelectiveFire and self.NextFireSelect < CurTime() and not (self.Weapon:GetNWBool("Reloading")) then
  691. if self.Owner:KeyDown(IN_USE) and self.Owner:KeyPressed(IN_RELOAD) then
  692. self:SelectFireMode()
  693. end
  694. end
  695.  
  696. --copy this...
  697. if self.Owner:KeyDown(IN_SPEED) and not (self.Weapon:GetNWBool("Reloading")) then -- If you are running
  698. self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
  699. self.IronSightsPos = self.RunSightsPos -- Hold it down
  700. self.IronSightsAng = self.RunSightsAng -- Hold it down
  701. self:SetIronsights(true, self.Owner) -- Set the ironsight true
  702. self.Owner:SetFOV( 0, 0.3 )
  703. end
  704.  
  705. if self.Owner:KeyReleased (IN_SPEED) then -- If you release run then
  706. self:SetIronsights(false, self.Owner) -- Set the ironsight true
  707. self.Owner:SetFOV( 0, 0.3 )
  708. end -- Shoulder the gun
  709.  
  710. --down to this
  711. if !self.Owner:KeyDown(IN_USE) and !self.Owner:KeyDown(IN_SPEED) then
  712. -- If the key E (Use Key) is not pressed, then
  713.  
  714. if self.Owner:KeyPressed(IN_ATTACK2) and not (self.Weapon:GetNWBool("Reloading")) then
  715. self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
  716. self.IronSightsPos = self.SightsPos -- Bring it up
  717. self.IronSightsAng = self.SightsAng -- Bring it up
  718. self:SetIronsights(true, self.Owner)
  719. self.DrawCrosshair = false
  720. -- Set the ironsight true
  721.  
  722. if CLIENT then return end
  723. end
  724. end
  725.  
  726. if self.Owner:KeyReleased(IN_ATTACK2) and !self.Owner:KeyDown(IN_USE) and !self.Owner:KeyDown(IN_SPEED) then
  727. -- If the right click is released, then
  728. self.Owner:SetFOV( 0, 0.3 )
  729. self.DrawCrosshair = true
  730. self:SetIronsights(false, self.Owner)
  731. -- Set the ironsight false
  732.  
  733. if CLIENT then return end
  734. end
  735.  
  736. if self.Owner:KeyDown(IN_ATTACK2) and !self.Owner:KeyDown(IN_USE) and !self.Owner:KeyDown(IN_SPEED) then
  737. self.SwayScale = 0.05
  738. self.BobScale = 0.05
  739. else
  740. self.SwayScale = 1.0
  741. self.BobScale = 1.0
  742. end
  743. end
  744.  
  745. /*---------------------------------------------------------
  746. Think
  747. ---------------------------------------------------------*/
  748. function SWEP:Think()
  749.  
  750. self:IronSight()
  751.  
  752. end
  753.  
  754. /*---------------------------------------------------------
  755. GetViewModelPosition
  756. ---------------------------------------------------------*/
  757. local IRONSIGHT_TIME = 0.3
  758. -- Time to enter in the ironsight mod
  759.  
  760. function SWEP:GetViewModelPosition(pos, ang)
  761.  
  762. if (not self.IronSightsPos) then return pos, ang end
  763.  
  764. local bIron = self.Weapon:GetNWBool("Ironsights")
  765.  
  766. if (bIron != self.bLastIron) then
  767. self.bLastIron = bIron
  768. self.fIronTime = CurTime()
  769.  
  770. end
  771.  
  772. local fIronTime = self.fIronTime or 0
  773.  
  774. if (not bIron and fIronTime < CurTime() - IRONSIGHT_TIME) then
  775. return pos, ang
  776. end
  777.  
  778. local Mul = 1.0
  779.  
  780. if (fIronTime > CurTime() - IRONSIGHT_TIME) then
  781. Mul = math.Clamp((CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1)
  782.  
  783. if not bIron then Mul = 1 - Mul end
  784. end
  785.  
  786. local Offset = self.IronSightsPos
  787.  
  788. if (self.IronSightsAng) then
  789. ang = ang * 1
  790. ang:RotateAroundAxis(ang:Right(), self.IronSightsAng.x * Mul)
  791. ang:RotateAroundAxis(ang:Up(), self.IronSightsAng.y * Mul)
  792. ang:RotateAroundAxis(ang:Forward(), self.IronSightsAng.z * Mul)
  793. end
  794.  
  795. local Right = ang:Right()
  796. local Up = ang:Up()
  797. local Forward = ang:Forward()
  798.  
  799. pos = pos + Offset.x * Right * Mul
  800. pos = pos + Offset.y * Forward * Mul
  801. pos = pos + Offset.z * Up * Mul
  802.  
  803. return pos, ang
  804. end
  805.  
  806. /*---------------------------------------------------------
  807. SetIronsights
  808. ---------------------------------------------------------*/
  809. function SWEP:SetIronsights(b)
  810. self.Weapon:SetNetworkedBool("Ironsights", b)
  811. end
  812.  
  813. function SWEP:GetIronsights()
  814. return self.Weapon:GetNWBool("Ironsights")
  815. end
  816.  
  817.  
  818. if CLIENT then
  819.  
  820. SWEP.vRenderOrder = nil
  821. function SWEP:ViewModelDrawn()
  822.  
  823. local vm = self.Owner:GetViewModel()
  824. if !IsValid(vm) then return end
  825.  
  826. if (!self.VElements) then return end
  827.  
  828. self:UpdateBonePositions(vm)
  829.  
  830. if (!self.vRenderOrder) then
  831.  
  832. -- // we build a render order because sprites need to be drawn after models
  833. self.vRenderOrder = {}
  834.  
  835. for k, v in pairs( self.VElements ) do
  836. if (v.type == "Model") then
  837. table.insert(self.vRenderOrder, 1, k)
  838. elseif (v.type == "Sprite" or v.type == "Quad") then
  839. table.insert(self.vRenderOrder, k)
  840. end
  841. end
  842.  
  843. end
  844.  
  845. for k, name in ipairs( self.vRenderOrder ) do
  846.  
  847. local v = self.VElements[name]
  848. if (!v) then self.vRenderOrder = nil break end
  849. if (v.hide) then continue end
  850.  
  851. local model = v.modelEnt
  852. local sprite = v.spriteMaterial
  853.  
  854. if (!v.bone) then continue end
  855.  
  856. local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
  857.  
  858. if (!pos) then continue end
  859.  
  860. if (v.type == "Model" and IsValid(model)) then
  861.  
  862. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  863. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  864. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  865. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  866.  
  867. model:SetAngles(ang)
  868. -- //model:SetModelScale(v.size)
  869. local matrix = Matrix()
  870. matrix:Scale(v.size)
  871. model:EnableMatrix( "RenderMultiply", matrix )
  872.  
  873. if (v.material == "") then
  874. model:SetMaterial("")
  875. elseif (model:GetMaterial() != v.material) then
  876. model:SetMaterial( v.material )
  877. end
  878.  
  879. if (v.skin and v.skin != model:GetSkin()) then
  880. model:SetSkin(v.skin)
  881. end
  882.  
  883. if (v.bodygroup) then
  884. for k, v in pairs( v.bodygroup ) do
  885. if (model:GetBodygroup(k) != v) then
  886. model:SetBodygroup(k, v)
  887. end
  888. end
  889. end
  890.  
  891. if (v.surpresslightning) then
  892. render.SuppressEngineLighting(true)
  893. end
  894.  
  895. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  896. render.SetBlend(v.color.a/255)
  897. model:DrawModel()
  898. render.SetBlend(1)
  899. render.SetColorModulation(1, 1, 1)
  900.  
  901. if (v.surpresslightning) then
  902. render.SuppressEngineLighting(false)
  903. end
  904.  
  905. elseif (v.type == "Sprite" and sprite) then
  906.  
  907. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  908. render.SetMaterial(sprite)
  909. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  910.  
  911. elseif (v.type == "Quad" and v.draw_func) then
  912.  
  913. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  914. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  915. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  916. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  917.  
  918. cam.Start3D2D(drawpos, ang, v.size)
  919. v.draw_func( self )
  920. cam.End3D2D()
  921.  
  922. end
  923.  
  924. end
  925.  
  926. end
  927.  
  928. SWEP.wRenderOrder = nil
  929. function SWEP:DrawWorldModel()
  930.  
  931. if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  932. self:DrawModel()
  933. end
  934.  
  935. if (!self.WElements) then return end
  936.  
  937. if (!self.wRenderOrder) then
  938.  
  939. self.wRenderOrder = {}
  940.  
  941. for k, v in pairs( self.WElements ) do
  942. if (v.type == "Model") then
  943. table.insert(self.wRenderOrder, 1, k)
  944. elseif (v.type == "Sprite" or v.type == "Quad") then
  945. table.insert(self.wRenderOrder, k)
  946. end
  947. end
  948.  
  949. end
  950.  
  951. if (IsValid(self.Owner)) then
  952. bone_ent = self.Owner
  953. else
  954. -- // when the weapon is dropped
  955. bone_ent = self
  956. end
  957.  
  958. for k, name in pairs( self.wRenderOrder ) do
  959.  
  960. local v = self.WElements[name]
  961. if (!v) then self.wRenderOrder = nil break end
  962. if (v.hide) then continue end
  963.  
  964. local pos, ang
  965.  
  966. if (v.bone) then
  967. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
  968. else
  969. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
  970. end
  971.  
  972. if (!pos) then continue end
  973.  
  974. local model = v.modelEnt
  975. local sprite = v.spriteMaterial
  976.  
  977. if (v.type == "Model" and IsValid(model)) then
  978.  
  979. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  980. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  981. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  982. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  983.  
  984. model:SetAngles(ang)
  985. -- //model:SetModelScale(v.size)
  986. local matrix = Matrix()
  987. matrix:Scale(v.size)
  988. model:EnableMatrix( "RenderMultiply", matrix )
  989.  
  990. if (v.material == "") then
  991. model:SetMaterial("")
  992. elseif (model:GetMaterial() != v.material) then
  993. model:SetMaterial( v.material )
  994. end
  995.  
  996. if (v.skin and v.skin != model:GetSkin()) then
  997. model:SetSkin(v.skin)
  998. end
  999.  
  1000. if (v.bodygroup) then
  1001. for k, v in pairs( v.bodygroup ) do
  1002. if (model:GetBodygroup(k) != v) then
  1003. model:SetBodygroup(k, v)
  1004. end
  1005. end
  1006. end
  1007.  
  1008. if (v.surpresslightning) then
  1009. render.SuppressEngineLighting(true)
  1010. end
  1011.  
  1012. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  1013. render.SetBlend(v.color.a/255)
  1014. model:DrawModel()
  1015. render.SetBlend(1)
  1016. render.SetColorModulation(1, 1, 1)
  1017.  
  1018. if (v.surpresslightning) then
  1019. render.SuppressEngineLighting(false)
  1020. end
  1021.  
  1022. elseif (v.type == "Sprite" and sprite) then
  1023.  
  1024. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  1025. render.SetMaterial(sprite)
  1026. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  1027.  
  1028. elseif (v.type == "Quad" and v.draw_func) then
  1029.  
  1030. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  1031. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  1032. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  1033. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  1034.  
  1035. cam.Start3D2D(drawpos, ang, v.size)
  1036. v.draw_func( self )
  1037. cam.End3D2D()
  1038.  
  1039. end
  1040.  
  1041. end
  1042.  
  1043. end
  1044.  
  1045. function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
  1046.  
  1047. local bone, pos, ang
  1048. if (tab.rel and tab.rel != "") then
  1049.  
  1050. local v = basetab[tab.rel]
  1051.  
  1052. if (!v) then return end
  1053.  
  1054. -- // Technically, if there exists an element with the same name as a bone
  1055. -- // you can get in an infinite loop. Let's just hope nobody's that stupid.
  1056. pos, ang = self:GetBoneOrientation( basetab, v, ent )
  1057.  
  1058. if (!pos) then return end
  1059.  
  1060. pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  1061. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  1062. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  1063. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  1064.  
  1065. else
  1066.  
  1067. bone = ent:LookupBone(bone_override or tab.bone)
  1068.  
  1069. if (!bone) then return end
  1070.  
  1071. pos, ang = Vector(0,0,0), Angle(0,0,0)
  1072. local m = ent:GetBoneMatrix(bone)
  1073. if (m) then
  1074. pos, ang = m:GetTranslation(), m:GetAngles()
  1075. end
  1076.  
  1077. if (IsValid(self.Owner) and self.Owner:IsPlayer() and
  1078. ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
  1079. ang.r = -ang.r --// Fixes mirrored models
  1080. end
  1081.  
  1082. end
  1083.  
  1084. return pos, ang
  1085. end
  1086.  
  1087. function SWEP:CreateModels( tab )
  1088.  
  1089. if (!tab) then return end
  1090.  
  1091. -- // Create the clientside models here because Garry says we can't do it in the render hook
  1092. for k, v in pairs( tab ) do
  1093. if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
  1094. string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
  1095.  
  1096. v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  1097. if (IsValid(v.modelEnt)) then
  1098. v.modelEnt:SetPos(self:GetPos())
  1099. v.modelEnt:SetAngles(self:GetAngles())
  1100. v.modelEnt:SetParent(self)
  1101. v.modelEnt:SetNoDraw(true)
  1102. v.createdModel = v.model
  1103. else
  1104. v.modelEnt = nil
  1105. end
  1106.  
  1107. elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  1108. and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
  1109.  
  1110. local name = v.sprite.."-"
  1111. local params = { ["$basetexture"] = v.sprite }
  1112. -- // make sure we create a unique name based on the selected options
  1113. local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  1114. for i, j in pairs( tocheck ) do
  1115. if (v[j]) then
  1116. params["$"..j] = 1
  1117. name = name.."1"
  1118. else
  1119. name = name.."0"
  1120. end
  1121. end
  1122.  
  1123. v.createdSprite = v.sprite
  1124. v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  1125.  
  1126. end
  1127. end
  1128.  
  1129. end
  1130.  
  1131. local allbones
  1132. local hasGarryFixedBoneScalingYet = false
  1133.  
  1134. function SWEP:UpdateBonePositions(vm)
  1135.  
  1136. if self.ViewModelBoneMods then
  1137.  
  1138. if (!vm:GetBoneCount()) then return end
  1139.  
  1140. -- // !! WORKAROUND !! --//
  1141. -- // We need to check all model names :/
  1142. local loopthrough = self.ViewModelBoneMods
  1143. if (!hasGarryFixedBoneScalingYet) then
  1144. allbones = {}
  1145. for i=0, vm:GetBoneCount() do
  1146. local bonename = vm:GetBoneName(i)
  1147. if (self.ViewModelBoneMods[bonename]) then
  1148. allbones[bonename] = self.ViewModelBoneMods[bonename]
  1149. else
  1150. allbones[bonename] = {
  1151. scale = Vector(1,1,1),
  1152. pos = Vector(0,0,0),
  1153. angle = Angle(0,0,0)
  1154. }
  1155. end
  1156. end
  1157.  
  1158. loopthrough = allbones
  1159. end
  1160. //!! ----------- !! --
  1161.  
  1162. for k, v in pairs( loopthrough ) do
  1163. local bone = vm:LookupBone(k)
  1164. if (!bone) then continue end
  1165.  
  1166. -- // !! WORKAROUND !! --//
  1167. local s = Vector(v.scale.x,v.scale.y,v.scale.z)
  1168. local p = Vector(v.pos.x,v.pos.y,v.pos.z)
  1169. local ms = Vector(1,1,1)
  1170. if (!hasGarryFixedBoneScalingYet) then
  1171. local cur = vm:GetBoneParent(bone)
  1172. while(cur >= 0) do
  1173. local pscale = loopthrough[vm:GetBoneName(cur)].scale
  1174. ms = ms * pscale
  1175. cur = vm:GetBoneParent(cur)
  1176. end
  1177. end
  1178.  
  1179. s = s * ms
  1180. //!! ----------- !! --
  1181.  
  1182. if vm:GetManipulateBoneScale(bone) != s then
  1183. vm:ManipulateBoneScale( bone, s )
  1184. end
  1185. if vm:GetManipulateBoneAngles(bone) != v.angle then
  1186. vm:ManipulateBoneAngles( bone, v.angle )
  1187. end
  1188. if vm:GetManipulateBonePosition(bone) != p then
  1189. vm:ManipulateBonePosition( bone, p )
  1190. end
  1191. end
  1192. else
  1193. self:ResetBonePositions(vm)
  1194. end
  1195.  
  1196. end
  1197.  
  1198. function SWEP:ResetBonePositions(vm)
  1199.  
  1200. if (!vm:GetBoneCount()) then return end
  1201. for i=0, vm:GetBoneCount() do
  1202. vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
  1203. vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
  1204. vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
  1205. end
  1206.  
  1207. end
  1208.  
  1209. /**************************
  1210. Global utility code
  1211. **************************/
  1212.  
  1213. -- // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
  1214. -- // Does not copy entities of course, only copies their reference.
  1215. -- // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
  1216. function table.FullCopy( tab )
  1217.  
  1218. if (!tab) then return nil end
  1219.  
  1220. local res = {}
  1221. for k, v in pairs( tab ) do
  1222. if (type(v) == "table") then
  1223. res[k] = table.FullCopy(v) --// recursion ho!
  1224. elseif (type(v) == "Vector") then
  1225. res[k] = Vector(v.x, v.y, v.z)
  1226. elseif (type(v) == "Angle") then
  1227. res[k] = Angle(v.p, v.y, v.r)
  1228. else
  1229. res[k] = v
  1230. end
  1231. end
  1232.  
  1233. return res
  1234.  
  1235. end
  1236.  
  1237. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement