Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.32 KB | None | 0 0
  1. if ( SERVER ) then
  2.  
  3. AddCSLuaFile( "shared.lua" )
  4.  
  5. end
  6.  
  7. if ( CLIENT ) then
  8.  
  9. SWEP.PrintName = "DC-19 Stealth"
  10. SWEP.Author = "Doctor Jew"
  11. SWEP.ViewModelFOV = 50
  12. SWEP.Slot = 2
  13. SWEP.SlotPos = 3
  14. SWEP.WepSelectIcon = surface.GetTextureID("HUD/killicons/DC15S")
  15.  
  16. killicon.Add( "weapon_jew_dc19", "HUD/killicons/DC15S", Color( 255, 80, 0, 255 ) )
  17.  
  18. SWEP.ViewModelBoneMods = {
  19. ["v_e11_reference001"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
  20. }
  21.  
  22. SWEP.VElements = {
  23. ["dc15s"] = { type = "Model", model = "models/weapons/blaster.mdl", bone = "v_e11_reference001", rel = "", pos = Vector(-0.719, 6.392, -3.484), angle = Angle(0, -90, 0), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
  24. }
  25.  
  26. SWEP.WElements = {
  27. ["dc15_s"] = { type = "Model", model = "models/weapons/blaster.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(10.159, 1.044, 0.764), angle = Angle(-16, 1.636, 180), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
  28. }
  29.  
  30. end
  31.  
  32. SWEP.HoldType = "ar2"
  33. SWEP.Base = "weapon_jew_base"
  34.  
  35. SWEP.Category = "Star Wars (Updated)"
  36.  
  37. SWEP.Spawnable = true
  38. SWEP.AdminSpawnable = true
  39.  
  40. SWEP.ViewModel = "models/weapons/synbf3/c_e11.mdl"
  41. SWEP.WorldModel = "models/weapons/synbf3/w_a280.mdl"
  42.  
  43. SWEP.ViewModelFOV = 47
  44. SWEP.ViewModelFlip = false
  45. SWEP.UseHands = true
  46.  
  47. SWEP.Weight = 10
  48. SWEP.AutoSwitchTo = false
  49. SWEP.AutoSwitchFrom = false
  50.  
  51. local FireSound = Sound ("weapons/DC15S_fire.wav");
  52. local ReloadSound = Sound ("weapons/synbf3/e11_reload.wav")
  53. local EmptySound = Sound ("weapons/sw_noammo.wav")
  54. local FireModeSound = Sound ("weapons/sw_detonator/sw_detonator_select.wav")
  55.  
  56. SWEP.Primary.Recoil = 0.5
  57. SWEP.Primary.Damage = 45
  58. SWEP.Primary.NumShots = 1
  59. SWEP.Primary.Cone = 0.0125
  60. SWEP.Primary.ClipSize = 50
  61. SWEP.Primary.Delay = 0.3
  62. SWEP.Primary.DefaultClip = 150
  63. SWEP.Primary.Automatic = true
  64. SWEP.Primary.Ammo = "ar2"
  65. SWEP.Primary.Tracer = "effect_sw_laser_blue"
  66.  
  67. SWEP.Secondary.Automatic = true
  68. SWEP.Secondary.Ammo = "none"
  69.  
  70. SWEP.IronSightsPos = Vector(-2.655, -9.554, 3.038)
  71. SWEP.IronSightsAng = Vector(0.787, 0.035, 0)
  72.  
  73. // Custom values for fire switching
  74. SWEP.SelectiveFire = true
  75. SWEP.NextFireSelect = CurTime()
  76. SWEP.SMode = 1
  77.  
  78. function SWEP:Precache()
  79. util.PrecacheSound("weapons/DC15S_fire.wav")
  80. util.PrecacheSound("weapons/synbf3/e11_reload.wav")
  81. util.PrecacheSound("weapons/sw_noammo.wav")
  82. util.PrecacheSound("weapons/sw_detonator/sw_detonator_select.wav")
  83. end
  84.  
  85. function SWEP:Think()
  86. if self.SelectiveFire and self.NextFireSelect < CurTime() then
  87. if self.Owner:KeyDown(IN_SPEED) and self.Owner:KeyDown(IN_USE) then
  88. self:SelectFireMode()
  89. elseif self.Owner:KeyDown(IN_WALK) then
  90. self:PrintMode()
  91. end
  92. end
  93. end
  94.  
  95. local FireModeMessage = {"Stealth mode selected.","Stun mode selected.","Vaporize mode selected.","Normal mode selected."}
  96. function SWEP:SelectFireMode()
  97. if CLIENT then
  98. self.Owner:PrintMessage(HUD_PRINTTALK,FireModeMessage[self.SMode])
  99. --self.Owner:PrintMessage(HUD_PRINTTALK,"OLD MODE: " .. self.SMode)
  100. end
  101. self.NextFireSelect = CurTime() + 3
  102. self.Weapon:EmitSound(FireModeSound)
  103. self.SMode = math.fmod((self.SMode + 1), 5)
  104. if self.SMode < 1 then
  105. self.SMode = 1
  106. end
  107. --if CLIENT then
  108. -- self.Owner:PrintMessage(HUD_PRINTTALK,"NEW MODE: " .. self.SMode)
  109. --end
  110. end
  111.  
  112. local PrintModeMessage = {"Normal mode selected.","Stealth mode selected.","Stun mode selected.","Vaporize mode selected."}
  113. function SWEP:PrintMode()
  114. if CLIENT then
  115. self.Owner:PrintMessage(HUD_PRINTTALK,PrintModeMessage[self.SMode])
  116. --self.Owner:PrintMessage(HUD_PRINTTALK,self.SMode)
  117. self.NextFireSelect = CurTime() + 1.5
  118. end
  119. end
  120.  
  121. function SWEP:PrimaryAttack()
  122. if self.SMode == 1 then
  123. self:NormalFire()
  124. elseif self.SMode == 2 then
  125. self:StealthFire()
  126. elseif self.SMode == 3 then
  127. self:Stun()
  128. elseif self.SMode == 4 then
  129. self:Vaporize()
  130. end
  131. end
  132.  
  133. function SWEP:NormalFire()
  134. self.Primary.Recoil = 0.01
  135. self.Primary.Damage = 18.75
  136. self.Primary.NumShots = 1
  137. self.Primary.Cone = 0.0125
  138. self.Primary.ClipSize = 50
  139. self.Primary.Delay = 0.18
  140. self.Primary.DefaultClip = 50
  141. self.Primary.Automatic = true
  142. self.Primary.Ammo = "ar2"
  143. self.Primary.Tracer = "effect_sw_laser_blue"
  144.  
  145. self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
  146. self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  147.  
  148. if ( !self:CanPrimaryAttack() ) then return end
  149.  
  150. if self:Clip1() < 1 then
  151. self.Weapon:EmitSound( EmptyAmmo )
  152. return
  153. end
  154.  
  155. self.Weapon:EmitSound( FireSound )
  156.  
  157. self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone )
  158.  
  159. self:TakePrimaryAmmo( 1 )
  160.  
  161. if ( self.Owner:IsNPC() ) then return end
  162.  
  163. self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
  164.  
  165. // In singleplayer this function doesn't get called on the client, so we use a networked float
  166. // to send the last shoot time. In multiplayer this is predicted clientside so we don't need to
  167. // send the float.
  168. if ( (game.SinglePlayer() && SERVER) || CLIENT ) then
  169. self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
  170. end
  171. end
  172.  
  173. function SWEP:CSShootBullet( dmg, recoil, numbul, cone )
  174.  
  175. numbul = numbul or 1
  176. cone = cone or 0.01
  177.  
  178. local bullet = {}
  179. bullet.Num = numbul
  180. bullet.Src = self.Owner:GetShootPos() // Source
  181. bullet.Dir = self.Owner:GetAimVector() // Dir of bullet
  182. bullet.Spread = Vector( cone, cone, 0 ) // Aim Cone
  183. bullet.Tracer = 1 // Show a tracer on every x bullets
  184. bullet.TracerName = self.Primary.Tracer
  185. bullet.Force = 5 // Amount of force to give to phys objects
  186. bullet.Damage = dmg
  187.  
  188. self.Owner:FireBullets( bullet )
  189. self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) // View model animation
  190. self.Owner:MuzzleFlash() // Crappy muzzle light
  191. self.Owner:SetAnimation( PLAYER_ATTACK1 ) // 3rd Person Animation
  192.  
  193. if ( self.Owner:IsNPC() ) then return end
  194.  
  195. // CUSTOM RECOIL !
  196. if ( (game.SinglePlayer() && SERVER) || ( !game.SinglePlayer() && CLIENT && IsFirstTimePredicted() ) ) then
  197.  
  198. local eyeang = self.Owner:EyeAngles()
  199. eyeang.pitch = eyeang.pitch - recoil
  200. self.Owner:SetEyeAngles( eyeang )
  201. end
  202. end
  203.  
  204. function SWEP:Reload()
  205. if self.SMode == 1 or self.SMode == 2 or self.SMode == 3 or self.SMode == 4 then
  206. if (self.Weapon:Clip1() < self.Primary.ClipSize) then
  207. if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
  208. self.Weapon:EmitSound( ReloadSound )
  209. end
  210. self.Weapon:DefaultReload( ACT_VM_RELOAD );
  211. self:SetIronsights( false )
  212. end
  213. end
  214. end
  215.  
  216. /********************************************************
  217. SWEP Construction Kit base code
  218. Created by Clavus
  219. Available for public use, thread at:
  220. facepunch.com/threads/1032378
  221.  
  222.  
  223. DESCRIPTION:
  224. This script is meant for experienced scripters
  225. that KNOW WHAT THEY ARE DOING. Don't come to me
  226. with basic Lua questions.
  227.  
  228. Just copy into your SWEP or SWEP base of choice
  229. and merge with your own code.
  230.  
  231. The SWEP.VElements, SWEP.WElements and
  232. SWEP.ViewModelBoneMods tables are all optional
  233. and only have to be visible to the client.
  234. ********************************************************/
  235.  
  236. function SWEP:Initialize()
  237.  
  238. self:SetWeaponHoldType( self.HoldType )
  239.  
  240. if CLIENT then
  241.  
  242. // Create a new table for every weapon instance
  243. self.VElements = table.FullCopy( self.VElements )
  244. self.WElements = table.FullCopy( self.WElements )
  245. self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
  246.  
  247. self:CreateModels(self.VElements) // create viewmodels
  248. self:CreateModels(self.WElements) // create worldmodels
  249.  
  250. // init view model bone build function
  251. if IsValid(self.Owner) then
  252. local vm = self.Owner:GetViewModel()
  253. if IsValid(vm) then
  254. self:ResetBonePositions(vm)
  255.  
  256. // Init viewmodel visibility
  257. if (self.ShowViewModel == nil or self.ShowViewModel) then
  258. vm:SetColor(Color(255,255,255,255))
  259. else
  260. // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
  261. vm:SetColor(Color(255,255,255,1))
  262. // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
  263. // 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
  264. vm:SetMaterial("Debug/hsv")
  265. end
  266. end
  267. end
  268.  
  269. end
  270.  
  271. end
  272.  
  273. function SWEP:Holster()
  274.  
  275. if CLIENT and IsValid(self.Owner) then
  276. local vm = self.Owner:GetViewModel()
  277. if IsValid(vm) then
  278. self:ResetBonePositions(vm)
  279. end
  280. end
  281.  
  282. return true
  283. end
  284.  
  285. function SWEP:OnRemove()
  286. self:Holster()
  287. end
  288.  
  289. if CLIENT then
  290.  
  291. SWEP.vRenderOrder = nil
  292. function SWEP:ViewModelDrawn()
  293.  
  294. local vm = self.Owner:GetViewModel()
  295. if !IsValid(vm) then return end
  296.  
  297. if (!self.VElements) then return end
  298.  
  299. self:UpdateBonePositions(vm)
  300.  
  301. if (!self.vRenderOrder) then
  302.  
  303. // we build a render order because sprites need to be drawn after models
  304. self.vRenderOrder = {}
  305.  
  306. for k, v in pairs( self.VElements ) do
  307. if (v.type == "Model") then
  308. table.insert(self.vRenderOrder, 1, k)
  309. elseif (v.type == "Sprite" or v.type == "Quad") then
  310. table.insert(self.vRenderOrder, k)
  311. end
  312. end
  313.  
  314. end
  315.  
  316. for k, name in ipairs( self.vRenderOrder ) do
  317.  
  318. local v = self.VElements[name]
  319. if (!v) then self.vRenderOrder = nil break end
  320. if (v.hide) then continue end
  321.  
  322. local model = v.modelEnt
  323. local sprite = v.spriteMaterial
  324.  
  325. if (!v.bone) then continue end
  326.  
  327. local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
  328.  
  329. if (!pos) then continue end
  330.  
  331. if (v.type == "Model" and IsValid(model)) then
  332.  
  333. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  334. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  335. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  336. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  337.  
  338. model:SetAngles(ang)
  339. //model:SetModelScale(v.size)
  340. local matrix = Matrix()
  341. matrix:Scale(v.size)
  342. model:EnableMatrix( "RenderMultiply", matrix )
  343.  
  344. if (v.material == "") then
  345. model:SetMaterial("")
  346. elseif (model:GetMaterial() != v.material) then
  347. model:SetMaterial( v.material )
  348. end
  349.  
  350. if (v.skin and v.skin != model:GetSkin()) then
  351. model:SetSkin(v.skin)
  352. end
  353.  
  354. if (v.bodygroup) then
  355. for k, v in pairs( v.bodygroup ) do
  356. if (model:GetBodygroup(k) != v) then
  357. model:SetBodygroup(k, v)
  358. end
  359. end
  360. end
  361.  
  362. if (v.surpresslightning) then
  363. render.SuppressEngineLighting(true)
  364. end
  365.  
  366. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  367. render.SetBlend(v.color.a/255)
  368. model:DrawModel()
  369. render.SetBlend(1)
  370. render.SetColorModulation(1, 1, 1)
  371.  
  372. if (v.surpresslightning) then
  373. render.SuppressEngineLighting(false)
  374. end
  375.  
  376. elseif (v.type == "Sprite" and sprite) then
  377.  
  378. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  379. render.SetMaterial(sprite)
  380. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  381.  
  382. elseif (v.type == "Quad" and v.draw_func) then
  383.  
  384. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  385. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  386. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  387. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  388.  
  389. cam.Start3D2D(drawpos, ang, v.size)
  390. v.draw_func( self )
  391. cam.End3D2D()
  392.  
  393. end
  394.  
  395. end
  396.  
  397. end
  398.  
  399. SWEP.wRenderOrder = nil
  400. function SWEP:DrawWorldModel()
  401.  
  402. if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  403. self:DrawModel()
  404. end
  405.  
  406. if (!self.WElements) then return end
  407.  
  408. if (!self.wRenderOrder) then
  409.  
  410. self.wRenderOrder = {}
  411.  
  412. for k, v in pairs( self.WElements ) do
  413. if (v.type == "Model") then
  414. table.insert(self.wRenderOrder, 1, k)
  415. elseif (v.type == "Sprite" or v.type == "Quad") then
  416. table.insert(self.wRenderOrder, k)
  417. end
  418. end
  419.  
  420. end
  421.  
  422. if (IsValid(self.Owner)) then
  423. bone_ent = self.Owner
  424. else
  425. // when the weapon is dropped
  426. bone_ent = self
  427. end
  428.  
  429. for k, name in pairs( self.wRenderOrder ) do
  430.  
  431. local v = self.WElements[name]
  432. if (!v) then self.wRenderOrder = nil break end
  433. if (v.hide) then continue end
  434.  
  435. local pos, ang
  436.  
  437. if (v.bone) then
  438. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
  439. else
  440. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
  441. end
  442.  
  443. if (!pos) then continue end
  444.  
  445. local model = v.modelEnt
  446. local sprite = v.spriteMaterial
  447.  
  448. if (v.type == "Model" and IsValid(model)) then
  449.  
  450. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  451. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  452. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  453. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  454.  
  455. model:SetAngles(ang)
  456. //model:SetModelScale(v.size)
  457. local matrix = Matrix()
  458. matrix:Scale(v.size)
  459. model:EnableMatrix( "RenderMultiply", matrix )
  460.  
  461. if (v.material == "") then
  462. model:SetMaterial("")
  463. elseif (model:GetMaterial() != v.material) then
  464. model:SetMaterial( v.material )
  465. end
  466.  
  467. if (v.skin and v.skin != model:GetSkin()) then
  468. model:SetSkin(v.skin)
  469. end
  470.  
  471. if (v.bodygroup) then
  472. for k, v in pairs( v.bodygroup ) do
  473. if (model:GetBodygroup(k) != v) then
  474. model:SetBodygroup(k, v)
  475. end
  476. end
  477. end
  478.  
  479. if (v.surpresslightning) then
  480. render.SuppressEngineLighting(true)
  481. end
  482.  
  483. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  484. render.SetBlend(v.color.a/255)
  485. model:DrawModel()
  486. render.SetBlend(1)
  487. render.SetColorModulation(1, 1, 1)
  488.  
  489. if (v.surpresslightning) then
  490. render.SuppressEngineLighting(false)
  491. end
  492.  
  493. elseif (v.type == "Sprite" and sprite) then
  494.  
  495. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  496. render.SetMaterial(sprite)
  497. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  498.  
  499. elseif (v.type == "Quad" and v.draw_func) then
  500.  
  501. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  502. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  503. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  504. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  505.  
  506. cam.Start3D2D(drawpos, ang, v.size)
  507. v.draw_func( self )
  508. cam.End3D2D()
  509.  
  510. end
  511.  
  512. end
  513.  
  514. end
  515.  
  516. function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
  517.  
  518. local bone, pos, ang
  519. if (tab.rel and tab.rel != "") then
  520.  
  521. local v = basetab[tab.rel]
  522.  
  523. if (!v) then return end
  524.  
  525. // Technically, if there exists an element with the same name as a bone
  526. // you can get in an infinite loop. Let's just hope nobody's that stupid.
  527. pos, ang = self:GetBoneOrientation( basetab, v, ent )
  528.  
  529. if (!pos) then return end
  530.  
  531. pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  532. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  533. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  534. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  535.  
  536. else
  537.  
  538. bone = ent:LookupBone(bone_override or tab.bone)
  539.  
  540. if (!bone) then return end
  541.  
  542. pos, ang = Vector(0,0,0), Angle(0,0,0)
  543. local m = ent:GetBoneMatrix(bone)
  544. if (m) then
  545. pos, ang = m:GetTranslation(), m:GetAngles()
  546. end
  547.  
  548. if (IsValid(self.Owner) and self.Owner:IsPlayer() and
  549. ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
  550. ang.r = -ang.r // Fixes mirrored models
  551. end
  552.  
  553. end
  554.  
  555. return pos, ang
  556. end
  557.  
  558. function SWEP:CreateModels( tab )
  559.  
  560. if (!tab) then return end
  561.  
  562. // Create the clientside models here because Garry says we can't do it in the render hook
  563. for k, v in pairs( tab ) do
  564. if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
  565. string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
  566.  
  567. v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  568. if (IsValid(v.modelEnt)) then
  569. v.modelEnt:SetPos(self:GetPos())
  570. v.modelEnt:SetAngles(self:GetAngles())
  571. v.modelEnt:SetParent(self)
  572. v.modelEnt:SetNoDraw(true)
  573. v.createdModel = v.model
  574. else
  575. v.modelEnt = nil
  576. end
  577.  
  578. elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  579. and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
  580.  
  581. local name = v.sprite.."-"
  582. local params = { ["$basetexture"] = v.sprite }
  583. // make sure we create a unique name based on the selected options
  584. local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  585. for i, j in pairs( tocheck ) do
  586. if (v[j]) then
  587. params["$"..j] = 1
  588. name = name.."1"
  589. else
  590. name = name.."0"
  591. end
  592. end
  593.  
  594. v.createdSprite = v.sprite
  595. v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  596.  
  597. end
  598. end
  599.  
  600. end
  601.  
  602. local allbones
  603. local hasGarryFixedBoneScalingYet = false
  604.  
  605. function SWEP:UpdateBonePositions(vm)
  606.  
  607. if self.ViewModelBoneMods then
  608.  
  609. if (!vm:GetBoneCount()) then return end
  610.  
  611. // !! WORKAROUND !! //
  612. // We need to check all model names :/
  613. local loopthrough = self.ViewModelBoneMods
  614. if (!hasGarryFixedBoneScalingYet) then
  615. allbones = {}
  616. for i=0, vm:GetBoneCount() do
  617. local bonename = vm:GetBoneName(i)
  618. if (self.ViewModelBoneMods[bonename]) then
  619. allbones[bonename] = self.ViewModelBoneMods[bonename]
  620. else
  621. allbones[bonename] = {
  622. scale = Vector(1,1,1),
  623. pos = Vector(0,0,0),
  624. angle = Angle(0,0,0)
  625. }
  626. end
  627. end
  628.  
  629. loopthrough = allbones
  630. end
  631. // !! ----------- !! //
  632.  
  633. for k, v in pairs( loopthrough ) do
  634. local bone = vm:LookupBone(k)
  635. if (!bone) then continue end
  636.  
  637. // !! WORKAROUND !! //
  638. local s = Vector(v.scale.x,v.scale.y,v.scale.z)
  639. local p = Vector(v.pos.x,v.pos.y,v.pos.z)
  640. local ms = Vector(1,1,1)
  641. if (!hasGarryFixedBoneScalingYet) then
  642. local cur = vm:GetBoneParent(bone)
  643. while(cur >= 0) do
  644. local pscale = loopthrough[vm:GetBoneName(cur)].scale
  645. ms = ms * pscale
  646. cur = vm:GetBoneParent(cur)
  647. end
  648. end
  649.  
  650. s = s * ms
  651. // !! ----------- !! //
  652.  
  653. if vm:GetManipulateBoneScale(bone) != s then
  654. vm:ManipulateBoneScale( bone, s )
  655. end
  656. if vm:GetManipulateBoneAngles(bone) != v.angle then
  657. vm:ManipulateBoneAngles( bone, v.angle )
  658. end
  659. if vm:GetManipulateBonePosition(bone) != p then
  660. vm:ManipulateBonePosition( bone, p )
  661. end
  662. end
  663. else
  664. self:ResetBonePositions(vm)
  665. end
  666.  
  667. end
  668.  
  669. function SWEP:ResetBonePositions(vm)
  670.  
  671. if (!vm:GetBoneCount()) then return end
  672. for i=0, vm:GetBoneCount() do
  673. vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
  674. vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
  675. vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
  676. end
  677.  
  678. end
  679.  
  680. /**************************
  681. Global utility code
  682. **************************/
  683.  
  684. // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
  685. // Does not copy entities of course, only copies their reference.
  686. // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
  687. function table.FullCopy( tab )
  688.  
  689. if (!tab) then return nil end
  690.  
  691. local res = {}
  692. for k, v in pairs( tab ) do
  693. if (type(v) == "table") then
  694. res[k] = table.FullCopy(v) // recursion ho!
  695. elseif (type(v) == "Vector") then
  696. res[k] = Vector(v.x, v.y, v.z)
  697. elseif (type(v) == "Angle") then
  698. res[k] = Angle(v.p, v.y, v.r)
  699. else
  700. res[k] = v
  701. end
  702. end
  703.  
  704. return res
  705.  
  706. end
  707.  
  708. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement