Advertisement
Guest User

91st bacta injector

a guest
May 26th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.93 KB | None | 0 0
  1. AddCSLuaFile()
  2.  
  3. SWEP.VElements = {
  4. ["element_name++++"] = { type = "Model", model = "models/starwars/items/bacta_small.mdl", bone = "ValveBiped.Grenade_body", rel = "", pos = Vector(0, 0.002, -4.908), angle = Angle(0, 0, 0), size = Vector(0.559, 0.559, 0.559), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
  5. ["Ammo"] = { type = "Model", model = "models/starwars/items/energy_cell.mdl", bone = "ValveBiped.Bip01_L_Hand", rel = "", pos = Vector(4.984, 2.936, 0), angle = Angle(0, 45.988, -4.062), size = Vector(0.367, 0.367, 0.367), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
  6. ["element_name"] = { type = "Model", model = "models/props_phx/construct/glass/glass_curve360x1.mdl", bone = "ValveBiped.Grenade_body", rel = "", pos = Vector(0, 0, -4.4), angle = Angle(0, 0, 0), size = Vector(0.035, 0.035, 0.114), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/props_combine/cit_beacon", skin = 0, bodygroup = {} },
  7. ["element_name+++"] = { type = "Model", model = "models/props_c17/TrapPropeller_Lever.mdl", bone = "ValveBiped.Grenade_body", rel = "", pos = Vector(0, 0, 9.295), angle = Angle(0, 0, -90), size = Vector(0.224, 1.134, 0.224), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
  8. ["element_name+"] = { type = "Model", model = "models/props_c17/TrapPropeller_Lever.mdl", bone = "ValveBiped.Grenade_body", rel = "", pos = Vector(0, 0, 0.737), angle = Angle(0, 0, -90), size = Vector(0.703, 1.223, 0.703), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
  9. ["element_name++"] = { type = "Model", model = "models/props_c17/TrapPropeller_Lever.mdl", bone = "ValveBiped.Grenade_body", rel = "", pos = Vector(0, 0, -3.62), angle = Angle(0, 0, -90), size = Vector(1.582, 0.586, 1.195), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/props_wasteland/lighthouse_stairs", skin = 0, bodygroup = {} }
  10. }
  11. SWEP.WElements = {
  12. ["element_name++"] = { type = "Model", model = "models/props_c17/TrapPropeller_Lever.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.675, 1.557, -2.597), angle = Angle(0, 0, -90), size = Vector(1, 1, 1), color = Color(0, 255, 255, 255), surpresslightning = false, material = "models/props_wasteland/lighthouse_stairs", skin = 0, bodygroup = {} },
  13. ["element_name+"] = { type = "Model", model = "models/props_c17/TrapPropeller_Lever.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.675, 1.557, 2.596), angle = Angle(0, 0, -90), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
  14. ["element_name"] = { type = "Model", model = "models/starwars/items/bacta_small.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.675, 1.557, -6.753), angle = Angle(0, 0, 0), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
  15. }
  16. SWEP.HoldType = "slam"
  17.  
  18. SWEP.ViewModelFlip = false
  19.  
  20. SWEP.ViewModel = "models/weapons/c_grenade.mdl"
  21. SWEP.WorldModel = "models/starwars/items/bacta_small.mdl"
  22. --SWEP.WorldModel = ""
  23. SWEP.ShowViewModel = true
  24. SWEP.ShowWorldModel = false
  25. SWEP.ViewModelBoneMods = {
  26. ["ValveBiped.Bip01_R_UpperArm"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(0.071, 0, 0) },
  27. ["ValveBiped.Bip01_L_Hand"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(-0.673, -1.879, 0) },
  28. ["ValveBiped.Grenade_body"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
  29. ["ValveBiped.Bip01_L_UpperArm"] = { scale = Vector(1.003, 1.003, 1.003), pos = Vector(0, 0, 0), angle = Angle(-37.258, 52.847, 4.78) },
  30. ["ValveBiped.Bip01_R_Forearm"] = { scale = Vector(1, 1, 1), pos = Vector(-3.245, 2.427, 0), angle = Angle(14.444, -16.667, 50) }
  31. }
  32.  
  33.  
  34. SWEP.PrintName = "Bacta Injector"
  35. SWEP.Author = "Bill Nye"
  36. SWEP.Purpose = "Heal people with your primary attack, or yourself with the secondary. Provide ammo with Reload"
  37.  
  38. SWEP.Slot = 5
  39. SWEP.SlotPos = 4
  40.  
  41. SWEP.Spawnable = true
  42.  
  43. --SWEP.ViewModel = Model( "models/weapons/c_medkit.mdl" )
  44. --SWEP.WorldModel = Model( "models/weapons/w_medkit.mdl" )
  45. SWEP.ViewModelFOV = 65
  46. SWEP.UseHands = true
  47.  
  48. SWEP.Primary.ClipSize = 200
  49. SWEP.Primary.DefaultClip = 200
  50. SWEP.Primary.Automatic = true
  51. SWEP.Primary.Ammo = "none"
  52.  
  53. SWEP.Secondary.ClipSize = -1
  54. SWEP.Secondary.DefaultClip = -1
  55. SWEP.Secondary.Automatic = false
  56. SWEP.Secondary.Ammo = "none"
  57.  
  58.  
  59. SWEP.HealAmount = 400 -- Maximum heal amount per use
  60. SWEP.MaxAmmo = 1000 -- Maxumum ammo
  61.  
  62. local HealSound = Sound( "HealthKit.Touch" )
  63. local DenySound = Sound( "WallHealth.Deny" )
  64.  
  65. function SWEP:Initialize()
  66.  
  67. self:SetHoldType( "slam" )
  68. --self.Owner:GetViewModel( ):SetMaterial( "materials/reskin/healthkit01.vtf" )
  69. if ( CLIENT ) then
  70. // Create a new table for every weapon instance
  71. self.VElements = table.FullCopy( self.VElements )
  72. self.WElements = table.FullCopy( self.WElements )
  73. self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
  74. self:CreateModels(self.VElements) // create viewmodels
  75. self:CreateModels(self.WElements) // create worldmodels
  76.  
  77. // init view model bone build function
  78. if IsValid(self.Owner) then
  79. local vm = self.Owner:GetViewModel()
  80. if IsValid(vm) then
  81. self:ResetBonePositions(vm)
  82.  
  83. // Init viewmodel visibility
  84. if (self.ShowViewModel == nil or self.ShowViewModel) then
  85. vm:SetColor(Color(255,255,255,255))
  86. else
  87. // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
  88. vm:SetColor(Color(255,255,255,1))
  89. // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
  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. end
  95. end
  96.  
  97. timer.Create( "medkit_ammo" .. self:EntIndex(), .2, 0, function()
  98. if ( self:Clip1() < self.MaxAmmo ) then self:SetClip1( math.min( self:Clip1() + 100, self.MaxAmmo ) ) end
  99. end )
  100.  
  101. end
  102.  
  103. function SWEP:PrimaryAttack()
  104.  
  105. if ( CLIENT ) then return end
  106.  
  107. if ( self.Owner:IsPlayer() ) then
  108. self.Owner:LagCompensation( true )
  109. end
  110.  
  111. local tr = util.TraceLine( {
  112. start = self.Owner:GetShootPos(),
  113. endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 64,
  114. filter = self.Owner
  115. } )
  116.  
  117. if ( self.Owner:IsPlayer() ) then
  118. self.Owner:LagCompensation( false )
  119. end
  120.  
  121. local ent = tr.Entity
  122.  
  123. local need = self.HealAmount
  124. if ( IsValid( ent ) ) then need = math.min( ent:GetMaxHealth() - ent:Health(), self.HealAmount ) end
  125.  
  126. if ( IsValid( ent ) && self:Clip1() >= need && ( ent:IsPlayer() or ent:IsNPC() ) && ent:Health() < ent:GetMaxHealth() ) then
  127.  
  128. self:TakePrimaryAmmo( need )
  129.  
  130. ent:SetHealth( math.min( ent:GetMaxHealth(), ent:Health() + need ) )
  131. ent:EmitSound( HealSound )
  132.  
  133. self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  134.  
  135. self:SetNextPrimaryFire( CurTime() + self:SequenceDuration() + 0.2 )
  136. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  137.  
  138. -- Even though the viewmodel has looping IDLE anim at all times, we need this to make fire animation work in multiplayer
  139. timer.Create( "weapon_idle" .. self:EntIndex(), self:SequenceDuration(), 1, function() if ( IsValid( self ) ) then self:SendWeaponAnim( ACT_VM_IDLE ) end end )
  140.  
  141. else
  142.  
  143. self.Owner:EmitSound( DenySound )
  144. self:SetNextPrimaryFire( CurTime() + 0.2 )
  145.  
  146. end
  147.  
  148. end
  149.  
  150. function SWEP:SecondaryAttack()
  151.  
  152. if ( CLIENT ) then return end
  153.  
  154. local ent = self.Owner
  155.  
  156. local need = self.HealAmount
  157. if ( IsValid( ent ) ) then need = math.min( ent:GetMaxHealth() - ent:Health(), self.HealAmount ) end
  158.  
  159. if ( IsValid( ent ) && self:Clip1() >= need && ent:Health() < ent:GetMaxHealth() ) then
  160.  
  161. self:TakePrimaryAmmo( need )
  162.  
  163. ent:SetHealth( math.min( ent:GetMaxHealth(), ent:Health() + need ) )
  164. ent:EmitSound( HealSound )
  165.  
  166. self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  167.  
  168. self:SetNextSecondaryFire( CurTime() + self:SequenceDuration() + 0.2 )
  169. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  170.  
  171. timer.Create( "weapon_idle" .. self:EntIndex(), self:SequenceDuration(), 1, function() if ( IsValid( self ) ) then self:SendWeaponAnim( ACT_VM_IDLE ) end end )
  172.  
  173. else
  174.  
  175. ent:EmitSound( DenySound )
  176. self:SetNextSecondaryFire( CurTime() + 0.2 )
  177.  
  178. end
  179.  
  180. end
  181.  
  182. function SWEP:OnRemove()
  183.  
  184. timer.Stop( "medkit_ammo" .. self:EntIndex() )
  185. timer.Stop( "weapon_idle" .. self:EntIndex() )
  186.  
  187. end
  188.  
  189. function SWEP:Holster()
  190.  
  191. timer.Stop( "weapon_idle" .. self:EntIndex() )
  192.  
  193. return true
  194.  
  195. end
  196.  
  197. function SWEP:CustomAmmoDisplay()
  198.  
  199. self.AmmoDisplay = self.AmmoDisplay or {}
  200. self.AmmoDisplay.Draw = true
  201. self.AmmoDisplay.PrimaryClip = self:Clip1()
  202.  
  203. return self.AmmoDisplay
  204.  
  205. end
  206.  
  207.  
  208. function SWEP:Reload()
  209.  
  210. if ( CLIENT ) then return end
  211.  
  212. local tr = util.TraceLine( {
  213. start = self.Owner:GetShootPos(),
  214. endpos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 128,
  215. filter = self.Owner
  216. } )
  217.  
  218. local ent = tr.Entity
  219. local me = self.Owner
  220.  
  221. local need = self.HealAmount
  222.  
  223.  
  224. if ( IsValid( ent ) && self:Clip1() >= 100 && ( ent:IsPlayer())) then
  225.  
  226. self:TakePrimaryAmmo( 100 )
  227.  
  228. ent:GiveAmmo(1000, 1, false)
  229. me:GiveAmmo(1000, 1, false)
  230. //ent:EmitSound( HealSound )
  231.  
  232. self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  233.  
  234. self:SetNextPrimaryFire( CurTime() + self:SequenceDuration() + 0 )
  235. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  236.  
  237. -- Even though the viewmodel has looping IDLE anim at all times, we need this to make fire animation work in multiplayer
  238. timer.Create( "weapon_idle" .. self:EntIndex(), self:SequenceDuration(), 1, function() if ( IsValid( self ) ) then self:SendWeaponAnim( ACT_VM_IDLE ) end end )
  239. --[[
  240. elseif( ( IsValid( ent ) && self:Clip1() >= 100)) then
  241. self.Owner:GiveAmmo(2000, 1, false)
  242. ent:EmitSound( HealSound )
  243.  
  244. self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  245.  
  246. self:SetNextPrimaryFire( CurTime() + self:SequenceDuration() + 0 )
  247. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  248.  
  249. -- Even though the viewmodel has looping IDLE anim at all times, we need this to make fire animation work in multiplayer
  250. timer.Create( "weapon_idle" .. self:EntIndex(), self:SequenceDuration(), 1, function() if ( IsValid( self ) ) then self:SendWeaponAnim( ACT_VM_IDLE ) end end )
  251. ]]--
  252. else
  253.  
  254.  
  255. self:SetNextPrimaryFire( CurTime() + 1 )
  256.  
  257. end
  258.  
  259. end
  260.  
  261. if CLIENT then
  262. SWEP.vRenderOrder = nil
  263. function SWEP:ViewModelDrawn()
  264.  
  265. local vm = self.Owner:GetViewModel()
  266. if !IsValid(vm) then return end
  267.  
  268. if (!self.VElements) then return end
  269.  
  270. self:UpdateBonePositions(vm)
  271. if (!self.vRenderOrder) then
  272.  
  273. // we build a render order because sprites need to be drawn after models
  274. self.vRenderOrder = {}
  275. for k, v in pairs( self.VElements ) do
  276. if (v.type == "Model") then
  277. table.insert(self.vRenderOrder, 1, k)
  278. elseif (v.type == "Sprite" or v.type == "Quad") then
  279. table.insert(self.vRenderOrder, k)
  280. end
  281. end
  282.  
  283. end
  284. for k, name in ipairs( self.vRenderOrder ) do
  285.  
  286. local v = self.VElements[name]
  287. if (!v) then self.vRenderOrder = nil break end
  288. if (v.hide) then continue end
  289.  
  290. local model = v.modelEnt
  291. local sprite = v.spriteMaterial
  292.  
  293. if (!v.bone) then continue end
  294.  
  295. local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
  296.  
  297. if (!pos) then continue end
  298.  
  299. if (v.type == "Model" and IsValid(model)) then
  300. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  301. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  302. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  303. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  304. model:SetAngles(ang)
  305. //model:SetModelScale(v.size)
  306. local matrix = Matrix()
  307. matrix:Scale(v.size)
  308. model:EnableMatrix( "RenderMultiply", matrix )
  309.  
  310. if (v.material == "") then
  311. model:SetMaterial("")
  312. elseif (model:GetMaterial() != v.material) then
  313. model:SetMaterial( v.material )
  314. end
  315.  
  316. if (v.skin and v.skin != model:GetSkin()) then
  317. model:SetSkin(v.skin)
  318. end
  319.  
  320. if (v.bodygroup) then
  321. for k, v in pairs( v.bodygroup ) do
  322. if (model:GetBodygroup(k) != v) then
  323. model:SetBodygroup(k, v)
  324. end
  325. end
  326. end
  327.  
  328. if (v.surpresslightning) then
  329. render.SuppressEngineLighting(true)
  330. end
  331.  
  332. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  333. render.SetBlend(v.color.a/255)
  334. model:DrawModel()
  335. render.SetBlend(1)
  336. render.SetColorModulation(1, 1, 1)
  337.  
  338. if (v.surpresslightning) then
  339. render.SuppressEngineLighting(false)
  340. end
  341.  
  342. elseif (v.type == "Sprite" and sprite) then
  343.  
  344. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  345. render.SetMaterial(sprite)
  346. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  347.  
  348. elseif (v.type == "Quad" and v.draw_func) then
  349.  
  350. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  351. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  352. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  353. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  354.  
  355. cam.Start3D2D(drawpos, ang, v.size)
  356. v.draw_func( self )
  357. cam.End3D2D()
  358. end
  359.  
  360. end
  361.  
  362. end
  363. /**************************
  364. Global utility code
  365. **************************/
  366.  
  367. // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
  368. // Does not copy entities of course, only copies their reference.
  369. // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
  370. function table.FullCopy( tab )
  371. if (!tab) then return nil end
  372.  
  373. local res = {}
  374. for k, v in pairs( tab ) do
  375. if (type(v) == "table") then
  376. res[k] = table.FullCopy(v) // recursion ho!
  377. elseif (type(v) == "Vector") then
  378. res[k] = Vector(v.x, v.y, v.z)
  379. elseif (type(v) == "Angle") then
  380. res[k] = Angle(v.p, v.y, v.r)
  381. else
  382. res[k] = v
  383. end
  384. end
  385.  
  386. return res
  387.  
  388. end
  389.  
  390. end
  391. SWEP.wRenderOrder = nil
  392. function SWEP:DrawWorldModel()
  393.  
  394. if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  395. self:DrawModel()
  396. end
  397.  
  398. if (!self.WElements) then return end
  399.  
  400. if (!self.wRenderOrder) then
  401. self.wRenderOrder = {}
  402. for k, v in pairs( self.WElements ) do
  403. if (v.type == "Model") then
  404. table.insert(self.wRenderOrder, 1, k)
  405. elseif (v.type == "Sprite" or v.type == "Quad") then
  406. table.insert(self.wRenderOrder, k)
  407. end
  408. end
  409. end
  410.  
  411. if (IsValid(self.Owner)) then
  412. bone_ent = self.Owner
  413. else
  414. // when the weapon is dropped
  415. bone_ent = self
  416. end
  417.  
  418. for k, name in pairs( self.wRenderOrder ) do
  419.  
  420. local v = self.WElements[name]
  421. if (!v) then self.wRenderOrder = nil break end
  422. if (v.hide) then continue end
  423.  
  424. local pos, ang
  425.  
  426. if (v.bone) then
  427. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
  428. else
  429. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
  430. end
  431.  
  432. if (!pos) then continue end
  433.  
  434. local model = v.modelEnt
  435. local sprite = v.spriteMaterial
  436.  
  437. if (v.type == "Model" and IsValid(model)) then
  438. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  439. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  440. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  441. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  442. model:SetAngles(ang)
  443. //model:SetModelScale(v.size)
  444. local matrix = Matrix()
  445. matrix:Scale(v.size)
  446. model:EnableMatrix( "RenderMultiply", matrix )
  447.  
  448. if (v.material == "") then
  449. model:SetMaterial("")
  450. elseif (model:GetMaterial() != v.material) then
  451. model:SetMaterial( v.material )
  452. end
  453.  
  454. if (v.skin and v.skin != model:GetSkin()) then
  455. model:SetSkin(v.skin)
  456. end
  457.  
  458. if (v.bodygroup) then
  459. for k, v in pairs( v.bodygroup ) do
  460. if (model:GetBodygroup(k) != v) then
  461. model:SetBodygroup(k, v)
  462. end
  463. end
  464. end
  465.  
  466. if (v.surpresslightning) then
  467. render.SuppressEngineLighting(true)
  468. end
  469.  
  470. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  471. render.SetBlend(v.color.a/255)
  472. model:DrawModel()
  473. render.SetBlend(1)
  474. render.SetColorModulation(1, 1, 1)
  475.  
  476. if (v.surpresslightning) then
  477. render.SuppressEngineLighting(false)
  478. end
  479.  
  480. elseif (v.type == "Sprite" and sprite) then
  481.  
  482. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  483. render.SetMaterial(sprite)
  484. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  485.  
  486. elseif (v.type == "Quad" and v.draw_func) then
  487.  
  488. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  489. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  490. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  491. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  492.  
  493. cam.Start3D2D(drawpos, ang, v.size)
  494. v.draw_func( self )
  495. cam.End3D2D()
  496. end
  497.  
  498. end
  499.  
  500. end
  501. function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
  502.  
  503. local bone, pos, ang
  504. if (tab.rel and tab.rel != "") then
  505.  
  506. local v = basetab[tab.rel]
  507.  
  508. if (!v) then return end
  509.  
  510. // Technically, if there exists an element with the same name as a bone
  511. // you can get in an infinite loop. Let's just hope nobody's that stupid.
  512. pos, ang = self:GetBoneOrientation( basetab, v, ent )
  513.  
  514. if (!pos) then return end
  515.  
  516. pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  517. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  518. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  519. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  520.  
  521. else
  522.  
  523. bone = ent:LookupBone(bone_override or tab.bone)
  524. if (!bone) then return end
  525.  
  526. pos, ang = Vector(0,0,0), Angle(0,0,0)
  527. local m = ent:GetBoneMatrix(bone)
  528. if (m) then
  529. pos, ang = m:GetTranslation(), m:GetAngles()
  530. end
  531.  
  532. if (IsValid(self.Owner) and self.Owner:IsPlayer() and
  533. ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
  534. ang.r = -ang.r // Fixes mirrored models
  535. end
  536.  
  537. end
  538.  
  539. return pos, ang
  540. end
  541. function SWEP:CreateModels( tab )
  542. if (!tab) then return end
  543. // Create the clientside models here because Garry says we can't do it in the render hook
  544. for k, v in pairs( tab ) do
  545. if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
  546. string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
  547.  
  548. v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  549. if (IsValid(v.modelEnt)) then
  550. v.modelEnt:SetPos(self:GetPos())
  551. v.modelEnt:SetAngles(self:GetAngles())
  552. v.modelEnt:SetParent(self)
  553. v.modelEnt:SetNoDraw(true)
  554. v.createdModel = v.model
  555. else
  556. v.modelEnt = nil
  557. end
  558.  
  559. elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  560. and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
  561.  
  562. local name = v.sprite.."-"
  563. local params = { ["$basetexture"] = v.sprite }
  564. // make sure we create a unique name based on the selected options
  565. local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  566. for i, j in pairs( tocheck ) do
  567. if (v[j]) then
  568. params["$"..j] = 1
  569. name = name.."1"
  570. else
  571. name = name.."0"
  572. end
  573. end
  574.  
  575. v.createdSprite = v.sprite
  576. v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  577.  
  578. end
  579. end
  580.  
  581. end
  582.  
  583. local allbones
  584. local hasGarryFixedBoneScalingYet = false
  585.  
  586. function SWEP:UpdateBonePositions(vm)
  587.  
  588. if self.ViewModelBoneMods then
  589.  
  590. if (!vm:GetBoneCount()) then return end
  591.  
  592. // !! WORKAROUND !! //
  593. // We need to check all model names :/
  594. local loopthrough = self.ViewModelBoneMods
  595. if (!hasGarryFixedBoneScalingYet) then
  596. allbones = {}
  597. for i=0, vm:GetBoneCount() do
  598. local bonename = vm:GetBoneName(i)
  599. if (self.ViewModelBoneMods[bonename]) then
  600. allbones[bonename] = self.ViewModelBoneMods[bonename]
  601. else
  602. allbones[bonename] = {
  603. scale = Vector(1,1,1),
  604. pos = Vector(0,0,0),
  605. angle = Angle(0,0,0)
  606. }
  607. end
  608. end
  609.  
  610. loopthrough = allbones
  611. end
  612. // !! ----------- !! //
  613.  
  614. for k, v in pairs( loopthrough ) do
  615. local bone = vm:LookupBone(k)
  616. if (!bone) then continue end
  617.  
  618. // !! WORKAROUND !! //
  619. local s = Vector(v.scale.x,v.scale.y,v.scale.z)
  620. local p = Vector(v.pos.x,v.pos.y,v.pos.z)
  621. local ms = Vector(1,1,1)
  622. if (!hasGarryFixedBoneScalingYet) then
  623. local cur = vm:GetBoneParent(bone)
  624. while(cur >= 0) do
  625. local pscale = loopthrough[vm:GetBoneName(cur)].scale
  626. ms = ms * pscale
  627. cur = vm:GetBoneParent(cur)
  628. end
  629. end
  630.  
  631. s = s * ms
  632. // !! ----------- !! //
  633.  
  634. if vm:GetManipulateBoneScale(bone) != s then
  635. vm:ManipulateBoneScale( bone, s )
  636. end
  637. if vm:GetManipulateBoneAngles(bone) != v.angle then
  638. vm:ManipulateBoneAngles( bone, v.angle )
  639. end
  640. if vm:GetManipulateBonePosition(bone) != p then
  641. vm:ManipulateBonePosition( bone, p )
  642. end
  643. end
  644. else
  645. self:ResetBonePositions(vm)
  646. end
  647.  
  648. end
  649.  
  650. function SWEP:ResetBonePositions(vm)
  651.  
  652. if (!vm:GetBoneCount()) then return end
  653. for i=0, vm:GetBoneCount() do
  654. vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
  655. vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
  656. vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
  657. end
  658.  
  659. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement