Advertisement
Guest User

Untitled

a guest
Mar 14th, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.19 KB | None | 0 0
  1. -- Variables that are used on both client and server
  2. SWEP.Category = ""
  3. SWEP.Gun = ""
  4. SWEP.Author = ""
  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 = false -- 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.  
  14. SWEP.Base = "weapon_tttbase"
  15. SWEP.Spawnable = false
  16. SWEP.AdminSpawnable = false
  17.  
  18. SWEP.Primary.Sound = Sound("") -- Sound of the gun
  19. SWEP.Primary.Round = ("") -- What kind of bullet?
  20. SWEP.Primary.Cone = 0.2 -- Accuracy of NPCs
  21. SWEP.Primary.Recoil = 10
  22. SWEP.Primary.Damage = 10
  23. SWEP.Primary.Spread = .01 --define from-the-hip accuracy (1 is terrible, .0001 is exact)
  24. SWEP.Primary.NumShots = 1
  25. SWEP.Primary.RPM = 0 -- This is in Rounds Per Minute
  26. SWEP.Primary.ClipSize = 0 -- Size of a clip
  27. SWEP.Primary.DefaultClip = 0 -- Default number of bullets in a clip
  28. SWEP.Primary.KickUp = 0 -- Maximum up recoil (rise)
  29. SWEP.Primary.KickDown = 0 -- Maximum down recoil (skeet)
  30. SWEP.Primary.KickHorizontal = 0 -- Maximum side recoil (koolaid)
  31. SWEP.Primary.Automatic = true -- Automatic/Semi Auto
  32. SWEP.Primary.Ammo = "none" -- What kind of ammo
  33.  
  34. SWEP.Secondary.ClipSize = 0 -- Size of a clip
  35. SWEP.Secondary.DefaultClip = 0 -- Default number of bullets in a clip
  36. SWEP.Secondary.Automatic = false -- Automatic/Semi Auto
  37. SWEP.Secondary.Ammo = "none"
  38. SWEP.Secondary.IronFOV = 0 -- How much you 'zoom' in. Less is more!
  39.  
  40. SWEP.Penetration = false
  41. SWEP.Ricochet = false
  42. SWEP.MaxRicochet = 1
  43. SWEP.RicochetCoin = 1
  44. SWEP.ShellTime = .35
  45. SWEP.Tracer = 0
  46. SWEP.CanBeSilenced = false
  47. SWEP.Silenced = false
  48. SWEP.NextSilence = 0
  49. SWEP.NextFireSelect = 0
  50. SWEP.Primary.RPM = 900
  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. if CLIENT and self.Weapon:Clip1() == -1 then
  62. self.Weapon:SetClip1(self.Primary.DefaultClip)
  63. elseif SERVER then
  64. self.fingerprints = {}
  65.  
  66. self:SetIronsights(false)
  67. end
  68.  
  69. self:SetDeploySpeed(self.DeploySpeed)
  70. if CLIENT then
  71.  
  72. -- // Create a new table for every weapon instance
  73. self.VElements = table.FullCopy( self.VElements )
  74. self.WElements = table.FullCopy( self.WElements )
  75. self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
  76.  
  77. self:CreateModels(self.VElements) -- create viewmodels
  78. self:CreateModels(self.WElements) -- create worldmodels
  79.  
  80. -- // init view model bone build function
  81. if IsValid(self.Owner) and self.Owner:IsPlayer() then
  82. if self.Owner:Alive() then
  83. local vm = self.Owner:GetViewModel()
  84. if IsValid(vm) then
  85. self:ResetBonePositions(vm)
  86. -- // Init viewmodel visibility
  87. if (self.ShowViewModel == nil or self.ShowViewModel) then
  88. vm:SetColor(Color(255,255,255,255))
  89. else
  90. -- // 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
  91. vm:SetMaterial("Debug/hsv")
  92. end
  93. end
  94.  
  95. end
  96. end
  97.  
  98. end
  99. end
  100.  
  101. function SWEP:Deploy()
  102. self:SetIronsights(false) -- Set the ironsight false
  103. self:SetWeaponHoldType(self.HoldType)
  104. self.Weapon:SetNetworkedBool("Reloading", false)
  105. return true
  106. end
  107.  
  108. function SWEP:Holster()
  109.  
  110. if CLIENT and IsValid(self.Owner) and not self.Owner:IsNPC() then
  111. local vm = self.Owner:GetViewModel()
  112. if IsValid(vm) then
  113. self:ResetBonePositions(vm)
  114. end
  115. end
  116.  
  117. return true
  118. end
  119.  
  120. function SWEP:OnRemove()
  121.  
  122. if CLIENT and IsValid(self.Owner) and not self.Owner:IsNPC() then
  123. local vm = self.Owner:GetViewModel()
  124. if IsValid(vm) then
  125. self:ResetBonePositions(vm)
  126. end
  127. end
  128.  
  129. end
  130.  
  131. function SWEP:GetCapabilities()
  132. return CAP_WEAPON_RANGE_ATTACK1, CAP_INNATE_RANGE_ATTACK1
  133. end
  134.  
  135. function SWEP:Precache()
  136. util.PrecacheSound(self.Primary.Sound)
  137. util.PrecacheModel(self.ViewModel)
  138. util.PrecacheModel(self.WorldModel)
  139. end
  140.  
  141. function SWEP:PrimaryAttack()
  142. if self:CanPrimaryAttack() and self.Owner:IsPlayer() then
  143. self.Owner:ViewPunch( Angle( math.Rand(self.Primary.RecoilXRand,-self.Primary.RecoilXRand) * self.Primary.Recoil, math.Rand(self.Primary.RecoilYRand,-self.Primary.RecoilYRand) *self.Primary.Recoil, 0 ) )
  144. if !self.Owner:KeyDown(IN_SPEED) and !self.Owner:KeyDown(IN_RELOAD) then
  145. self:ShootBulletInformation()
  146. self.Weapon:TakePrimaryAmmo(1)
  147.  
  148. local fx = EffectData()
  149. fx:SetEntity(self.Weapon)
  150. fx:SetOrigin(self.Owner:GetShootPos())
  151. fx:SetNormal(self.Owner:GetAimVector())
  152. fx:SetAttachment(self.MuzzleAttachment)
  153. if GetConVar("M9KGasEffect") != nil then
  154. if GetConVar("M9KGasEffect"):GetBool() then
  155. util.Effect("m9k_rg_muzzle_rifle",fx)
  156. end
  157. end
  158. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  159. self.Owner:MuzzleFlash()
  160. self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
  161. self.RicochetCoin = (math.random(1,4))
  162. if self.BoltAction then self:BoltBack() end
  163. end
  164. elseif self:CanPrimaryAttack() and self.Owner:IsNPC() then
  165. self:ShootBulletInformation()
  166. self.Weapon:TakePrimaryAmmo(1)
  167. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  168. self.Weapon:EmitSound(self.Primary.Sound)
  169. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  170. self.Owner:MuzzleFlash()
  171. self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
  172. self.RicochetCoin = (math.random(1,4))
  173. end
  174. end
  175.  
  176. /*---------------------------------------------------------
  177. Name: SWEP:ShootBulletInformation()
  178. Desc: This func add the damage, the recoil, the number of shots and the cone on the bullet.
  179. ---------------------------------------------------------*/
  180. function SWEP:ShootBulletInformation()
  181.  
  182. local CurrentDamage
  183. local CurrentRecoil
  184. local CurrentCone
  185.  
  186. if (self:GetIronsights() == true) and self.Owner:KeyDown(IN_ATTACK2) then
  187. CurrentCone = self.Primary.IronAccuracy
  188. else
  189. CurrentCone = self.Primary.Spread
  190. end
  191. local damagedice = math.Rand(.85,1.3)
  192.  
  193. CurrentDamage = self.Primary.Damage * damagedice
  194. CurrentRecoil = self.Primary.Recoil
  195.  
  196. -- Player is aiming
  197. if (self:GetIronsights() == true) and self.Owner:KeyDown(IN_ATTACK2) then
  198. self:ShootBullet(CurrentDamage, CurrentRecoil * 0.6, self.Primary.NumShots, CurrentCone)
  199. -- Player is not aiming
  200. else
  201. self:ShootBullet(CurrentDamage, CurrentRecoil, self.Primary.NumShots, CurrentCone)
  202. end
  203.  
  204. end
  205.  
  206. function SWEP:SecondaryAttack()
  207. if self.NoSights or (not self.IronSightsPos) then return end
  208. --if self:GetNextSecondaryFire() > CurTime() then return end
  209.  
  210. self:SetIronsights(not self:GetIronsights())
  211.  
  212. self:SetNextSecondaryFire(CurTime() + 0.3)
  213. end
  214.  
  215. function SWEP:Reload()
  216. self.Weapon:DefaultReload(self.ReloadAnim)
  217. self:SetIronsights( false )
  218. self.Owner:SetFOV( 0, 0.3 )
  219. end
  220.  
  221. /*---------------------------------------------------------
  222. IronSight
  223. ---------------------------------------------------------*/
  224. function SWEP:IronSight()
  225.  
  226. if !self.Owner:IsNPC() then
  227. if self.ResetSights and CurTime() >= self.ResetSights then
  228. self.ResetSights = nil
  229.  
  230. if self.Silenced then
  231. self:SendWeaponAnim(ACT_VM_IDLE_SILENCED)
  232. else
  233. self:SendWeaponAnim(ACT_VM_IDLE)
  234. end
  235. end end
  236.  
  237. if self.CanBeSilenced and self.NextSilence < CurTime() then
  238. if self.Owner:KeyDown(IN_USE) and self.Owner:KeyPressed(IN_ATTACK2) then
  239. self:Silencer()
  240. end
  241. end
  242. if self.Owner:KeyDown(IN_ATTACK2) and not (self.Weapon:GetNWBool("Reloading")) and (not self.NoSights) then
  243. self:SetIronsights(true)
  244. self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
  245. self.DrawCrosshair = false
  246. end
  247. if self.Owner:KeyReleased (IN_ATTACK2) then -- If you release then
  248. self:SetIronsights(false) -- Set the ironsight true
  249. self.Owner:SetFOV( 0, 0.3 )
  250. self.DrawCrosshair = false
  251. end
  252. end
  253.  
  254. /*---------------------------------------------------------
  255. Think
  256. ---------------------------------------------------------*/
  257. function SWEP:Think()
  258.  
  259. self:IronSight()
  260.  
  261. end
  262.  
  263. /*---------------------------------------------------------
  264. GetViewModelPosition
  265. ---------------------------------------------------------*/
  266. local IRONSIGHT_TIME = 0.3
  267. -- Time to enter in the ironsight mod
  268.  
  269.  
  270. /*---------------------------------------------------------
  271. SetIronsights
  272. ---------------------------------------------------------*/
  273. function SWEP:SetIronsights(b)
  274. self.Weapon:SetNetworkedBool("Ironsights", b)
  275. end
  276.  
  277. function SWEP:GetIronsights()
  278. return self.Weapon:GetNWBool("Ironsights")
  279. end
  280.  
  281.  
  282. if CLIENT then
  283.  
  284. SWEP.vRenderOrder = nil
  285. function SWEP:ViewModelDrawn()
  286.  
  287. local vm = self.Owner:GetViewModel()
  288. if !IsValid(vm) then return end
  289.  
  290. if (!self.VElements) then return end
  291.  
  292. self:UpdateBonePositions(vm)
  293.  
  294. if (!self.vRenderOrder) then
  295.  
  296. -- // we build a render order because sprites need to be drawn after models
  297. self.vRenderOrder = {}
  298.  
  299. for k, v in pairs( self.VElements ) do
  300. if (v.type == "Model") then
  301. table.insert(self.vRenderOrder, 1, k)
  302. elseif (v.type == "Sprite" or v.type == "Quad") then
  303. table.insert(self.vRenderOrder, k)
  304. end
  305. end
  306.  
  307. end
  308.  
  309. for k, name in ipairs( self.vRenderOrder ) do
  310.  
  311. local v = self.VElements[name]
  312. if (!v) then self.vRenderOrder = nil break end
  313. if (v.hide) then continue end
  314.  
  315. local model = v.modelEnt
  316. local sprite = v.spriteMaterial
  317.  
  318. if (!v.bone) then continue end
  319.  
  320. local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
  321.  
  322. if (!pos) then continue end
  323.  
  324. if (v.type == "Model" and IsValid(model)) then
  325.  
  326. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  327. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  328. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  329. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  330.  
  331. model:SetAngles(ang)
  332. -- //model:SetModelScale(v.size)
  333. local matrix = Matrix()
  334. matrix:Scale(v.size)
  335. model:EnableMatrix( "RenderMultiply", matrix )
  336.  
  337. if (v.material == "") then
  338. model:SetMaterial("")
  339. elseif (model:GetMaterial() != v.material) then
  340. model:SetMaterial( v.material )
  341. end
  342.  
  343. if (v.skin and v.skin != model:GetSkin()) then
  344. model:SetSkin(v.skin)
  345. end
  346.  
  347. if (v.bodygroup) then
  348. for k, v in pairs( v.bodygroup ) do
  349. if (model:GetBodygroup(k) != v) then
  350. model:SetBodygroup(k, v)
  351. end
  352. end
  353. end
  354.  
  355. if (v.surpresslightning) then
  356. render.SuppressEngineLighting(true)
  357. end
  358.  
  359. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  360. render.SetBlend(v.color.a/255)
  361. model:DrawModel()
  362. render.SetBlend(1)
  363. render.SetColorModulation(1, 1, 1)
  364.  
  365. if (v.surpresslightning) then
  366. render.SuppressEngineLighting(false)
  367. end
  368.  
  369. elseif (v.type == "Sprite" and sprite) then
  370.  
  371. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  372. render.SetMaterial(sprite)
  373. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  374.  
  375. elseif (v.type == "Quad" and v.draw_func) then
  376.  
  377. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  378. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  379. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  380. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  381.  
  382. cam.Start3D2D(drawpos, ang, v.size)
  383. v.draw_func( self )
  384. cam.End3D2D()
  385.  
  386. end
  387.  
  388. end
  389.  
  390. end
  391.  
  392. SWEP.wRenderOrder = nil
  393. function SWEP:DrawWorldModel()
  394.  
  395. if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  396. self:DrawModel()
  397. end
  398.  
  399. if (!self.WElements) then return end
  400.  
  401. if (!self.wRenderOrder) then
  402.  
  403. self.wRenderOrder = {}
  404.  
  405. for k, v in pairs( self.WElements ) do
  406. if (v.type == "Model") then
  407. table.insert(self.wRenderOrder, 1, k)
  408. elseif (v.type == "Sprite" or v.type == "Quad") then
  409. table.insert(self.wRenderOrder, k)
  410. end
  411. end
  412.  
  413. end
  414.  
  415. if (IsValid(self.Owner)) then
  416. bone_ent = self.Owner
  417. else
  418. -- // when the weapon is dropped
  419. bone_ent = self
  420. end
  421.  
  422. for k, name in pairs( self.wRenderOrder ) do
  423.  
  424. local v = self.WElements[name]
  425. if (!v) then self.wRenderOrder = nil break end
  426. if (v.hide) then continue end
  427.  
  428. local pos, ang
  429.  
  430. if (v.bone) then
  431. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
  432. else
  433. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
  434. end
  435.  
  436. if (!pos) then continue end
  437.  
  438. local model = v.modelEnt
  439. local sprite = v.spriteMaterial
  440.  
  441. if (v.type == "Model" and IsValid(model)) then
  442.  
  443. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  444. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  445. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  446. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  447.  
  448. model:SetAngles(ang)
  449. -- //model:SetModelScale(v.size)
  450. local matrix = Matrix()
  451. matrix:Scale(v.size)
  452. model:EnableMatrix( "RenderMultiply", matrix )
  453.  
  454. if (v.material == "") then
  455. model:SetMaterial("")
  456. elseif (model:GetMaterial() != v.material) then
  457. model:SetMaterial( v.material )
  458. end
  459.  
  460. if (v.skin and v.skin != model:GetSkin()) then
  461. model:SetSkin(v.skin)
  462. end
  463.  
  464. if (v.bodygroup) then
  465. for k, v in pairs( v.bodygroup ) do
  466. if (model:GetBodygroup(k) != v) then
  467. model:SetBodygroup(k, v)
  468. end
  469. end
  470. end
  471.  
  472. if (v.surpresslightning) then
  473. render.SuppressEngineLighting(true)
  474. end
  475.  
  476. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  477. render.SetBlend(v.color.a/255)
  478. model:DrawModel()
  479. render.SetBlend(1)
  480. render.SetColorModulation(1, 1, 1)
  481.  
  482. if (v.surpresslightning) then
  483. render.SuppressEngineLighting(false)
  484. end
  485.  
  486. elseif (v.type == "Sprite" and sprite) then
  487.  
  488. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  489. render.SetMaterial(sprite)
  490. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  491.  
  492. elseif (v.type == "Quad" and v.draw_func) then
  493.  
  494. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  495. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  496. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  497. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  498.  
  499. cam.Start3D2D(drawpos, ang, v.size)
  500. v.draw_func( self )
  501. cam.End3D2D()
  502.  
  503. end
  504.  
  505. end
  506.  
  507. end
  508.  
  509. function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
  510.  
  511. local bone, pos, ang
  512. if (tab.rel and tab.rel != "") then
  513.  
  514. local v = basetab[tab.rel]
  515.  
  516. if (!v) then return end
  517.  
  518. -- // Technically, if there exists an element with the same name as a bone
  519. -- // you can get in an infinite loop. Let's just hope nobody's that stupid.
  520. pos, ang = self:GetBoneOrientation( basetab, v, ent )
  521.  
  522. if (!pos) then return end
  523.  
  524. pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  525. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  526. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  527. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  528.  
  529. else
  530.  
  531. bone = ent:LookupBone(bone_override or tab.bone)
  532.  
  533. if (!bone) then return end
  534.  
  535. pos, ang = Vector(0,0,0), Angle(0,0,0)
  536. local m = ent:GetBoneMatrix(bone)
  537. if (m) then
  538. pos, ang = m:GetTranslation(), m:GetAngles()
  539. end
  540.  
  541. if (IsValid(self.Owner) and self.Owner:IsPlayer() and
  542. ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
  543. ang.r = -ang.r --// Fixes mirrored models
  544. end
  545.  
  546. end
  547.  
  548. return pos, ang
  549. end
  550.  
  551. function SWEP:CreateModels( tab )
  552.  
  553. if (!tab) then return end
  554.  
  555. -- // Create the clientside models here because Garry says we can't do it in the render hook
  556. for k, v in pairs( tab ) do
  557. if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
  558. string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
  559.  
  560. v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  561. if (IsValid(v.modelEnt)) then
  562. v.modelEnt:SetPos(self:GetPos())
  563. v.modelEnt:SetAngles(self:GetAngles())
  564. v.modelEnt:SetParent(self)
  565. v.modelEnt:SetNoDraw(true)
  566. v.createdModel = v.model
  567. else
  568. v.modelEnt = nil
  569. end
  570.  
  571. elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  572. and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
  573.  
  574. local name = v.sprite.."-"
  575. local params = { ["$basetexture"] = v.sprite }
  576. -- // make sure we create a unique name based on the selected options
  577. local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  578. for i, j in pairs( tocheck ) do
  579. if (v[j]) then
  580. params["$"..j] = 1
  581. name = name.."1"
  582. else
  583. name = name.."0"
  584. end
  585. end
  586.  
  587. v.createdSprite = v.sprite
  588. v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  589.  
  590. end
  591. end
  592.  
  593. end
  594.  
  595. local allbones
  596. local hasGarryFixedBoneScalingYet = false
  597.  
  598. function SWEP:UpdateBonePositions(vm)
  599.  
  600. if self.ViewModelBoneMods then
  601.  
  602. if (!vm:GetBoneCount()) then return end
  603.  
  604. -- // !! WORKAROUND !! --//
  605. -- // We need to check all model names :/
  606. local loopthrough = self.ViewModelBoneMods
  607. if (!hasGarryFixedBoneScalingYet) then
  608. allbones = {}
  609. for i=0, vm:GetBoneCount() do
  610. local bonename = vm:GetBoneName(i)
  611. if (self.ViewModelBoneMods[bonename]) then
  612. allbones[bonename] = self.ViewModelBoneMods[bonename]
  613. else
  614. allbones[bonename] = {
  615. scale = Vector(1,1,1),
  616. pos = Vector(0,0,0),
  617. angle = Angle(0,0,0)
  618. }
  619. end
  620. end
  621.  
  622. loopthrough = allbones
  623. end
  624. //!! ----------- !! --
  625.  
  626. for k, v in pairs( loopthrough ) do
  627. local bone = vm:LookupBone(k)
  628. if (!bone) then continue end
  629.  
  630. -- // !! WORKAROUND !! --//
  631. local s = Vector(v.scale.x,v.scale.y,v.scale.z)
  632. local p = Vector(v.pos.x,v.pos.y,v.pos.z)
  633. local ms = Vector(1,1,1)
  634. if (!hasGarryFixedBoneScalingYet) then
  635. local cur = vm:GetBoneParent(bone)
  636. while(cur >= 0) do
  637. local pscale = loopthrough[vm:GetBoneName(cur)].scale
  638. ms = ms * pscale
  639. cur = vm:GetBoneParent(cur)
  640. end
  641. end
  642.  
  643. s = s * ms
  644. //!! ----------- !! --
  645.  
  646. if vm:GetManipulateBoneScale(bone) != s then
  647. vm:ManipulateBoneScale( bone, s )
  648. end
  649. if vm:GetManipulateBoneAngles(bone) != v.angle then
  650. vm:ManipulateBoneAngles( bone, v.angle )
  651. end
  652. if vm:GetManipulateBonePosition(bone) != p then
  653. vm:ManipulateBonePosition( bone, p )
  654. end
  655. end
  656. else
  657. self:ResetBonePositions(vm)
  658. end
  659.  
  660. end
  661.  
  662. function SWEP:ResetBonePositions(vm)
  663.  
  664. if (!vm:GetBoneCount()) then return end
  665. for i=0, vm:GetBoneCount() do
  666. vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
  667. vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
  668. vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
  669. end
  670.  
  671. end
  672.  
  673. /**************************
  674. Global utility code
  675. **************************/
  676.  
  677. -- // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
  678. -- // Does not copy entities of course, only copies their reference.
  679. -- // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
  680. function table.FullCopy( tab )
  681.  
  682. if (!tab) then return nil end
  683.  
  684. local res = {}
  685. for k, v in pairs( tab ) do
  686. if (type(v) == "table") then
  687. res[k] = table.FullCopy(v) --// recursion ho!
  688. elseif (type(v) == "Vector") then
  689. res[k] = Vector(v.x, v.y, v.z)
  690. elseif (type(v) == "Angle") then
  691. res[k] = Angle(v.p, v.y, v.r)
  692. else
  693. res[k] = v
  694. end
  695. end
  696.  
  697. return res
  698.  
  699. end
  700.  
  701. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement