Advertisement
karatewalrus

Dragon's Breath

Jul 17th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.60 KB | None | 0 0
  1. //TTT Convertion Code \\
  2.  
  3. SWEP.BASE = "weapon_tttbase"
  4. SWEP.Kind = WEAPON_HEAVY
  5. SWEP.CanBuy = { ROLE_TRAITOR }
  6. SWEP.AutoSpawnable = false
  7. SWEP.InLoadoutFor = nil
  8. SWEP.AllowDrop = true
  9. SWEP.IsSilent = false
  10. SWEP.NoSights = true
  11. SWEP.AmmoEnt = "item_box_buckshot_ttt"
  12. SWEP.LimitedStock = false
  13.  
  14. if CLIENT then
  15. SWEP.PrintName = "Dragons Breath"
  16. SWEP.Slot = 6
  17.  
  18. SWEP.EquipMenuData = {
  19. type = "Dragons Breath",
  20. desc = "A shotgun with the power of a dragon"
  21. };
  22.  
  23. SWEP.Icon = "vgui/ttt/icon_nades"
  24. end
  25.  
  26.  
  27. if SERVER then
  28. AddCSLuaFile( "dragons_breath20.lua" )
  29. SWEP.HoldType = "shotgun"
  30. end
  31. if CLIENT then
  32.  
  33. surface.CreateFont( "dragon_digital", {
  34. font = "Digital-7",
  35. size = 45,
  36. antialias = true
  37. } )
  38.  
  39. SWEP.HoldType = "shotgun"
  40.  
  41. SWEP.Author = "Zikerd,Bombobux"
  42. SWEP.PrintName = "Dragon's breath"
  43. SWEP.Category = "Dragon's breath"
  44. SWEP.Contact = ""
  45. SWEP.Purpose = ""
  46. SWEP.Instructions = ""
  47.  
  48. SWEP.AdminOnly = false
  49.  
  50. SWEP.AutoSwitchTo = false
  51. SWEP.AutoSwitchFrom = false
  52. SWEP.FiresUnderwater = false
  53. SWEP.Spawnable = true
  54. SWEP.Weight = 1
  55. SWEP.DrawCrosshair = false
  56. SWEP.Slot = 6
  57. SWEP.SlotPos = 0
  58. SWEP.UseHands = true
  59. SWEP.ViewModelFOV = 50
  60. end
  61.  
  62. SWEP.ViewModel = "models/weapons/dragons_breath/xm1014_dragons_breath.mdl"
  63. SWEP.WorldModel = "models/weapons/w_shotgun.mdl"
  64.  
  65. SWEP.ViewModelFlip = false
  66.  
  67. SWEP.ShowViewModel = true
  68. SWEP.ShowWorldModel = true
  69.  
  70. SWEP.Primary.Damage = 9
  71. SWEP.Primary.ClipSize = 7
  72. SWEP.Primary.DefaultClip = 7
  73. SWEP.Primary.Spread = 1.2
  74. SWEP.Primary.Ammo = "none"
  75. SWEP.Primary.Automatic = true
  76. SWEP.Primary.NumberofShots = 7
  77. SWEP.Primary.Recoil = 12
  78. SWEP.Primary.Delay = 1.07
  79. SWEP.Primary.Force = 18
  80.  
  81. SWEP.Secondary.ClipSize = -1
  82. SWEP.Secondary.DefaultClip = -1
  83. SWEP.Secondary.Ammo = "Buckshot"
  84. SWEP.Secondary.Automatic = false
  85. SWEP.Secondary.Recoil = 0
  86. SWEP.Secondary.Delay = 1
  87.  
  88. SWEP.Charge = 0
  89. SWEP.Shootanim = 0
  90. SWEP.DragonsEnergy = 0
  91.  
  92. --SCK WE/VE models-
  93.  
  94. SWEP.VElements = {
  95. ["base_misc"] = { type = "Model", model = "models/props_combine/combine_mortar01a.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(0, -4.651, 0), angle = Angle(180, 0, 0), size = Vector(0.028, 0.028, 0.028), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
  96. ["base_decor1++"] = { type = "Model", model = "models/props_combine/breenlight.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(-0.35, -3.5, -3), angle = Angle(30, 90, 165), size = Vector(0.15, 0.1, 0.15), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/weapons/dragons_breath/breenlight_edit", skin = 0, bodygroup = {} },
  97. ["charge+"] = { type = "Model", model = "models/props_combine/breenlight.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(1.5, -4.651, -22), angle = Angle(-180, -180, 0), size = Vector(0.4, 0.3, 0.4), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/weapons/dragons_breath/breenlight_edit", skin = 0, bodygroup = {} },
  98. ["base_decor1"] = { type = "Model", model = "models/props_combine/breenlight.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(-0.35, -4, -1.9), angle = Angle(15, 90, 165), size = Vector(0.15, 0.1, 0.15), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/weapons/dragons_breath/breenlight_edit", skin = 0, bodygroup = {} },
  99. ["charge_hud"] = { type = "Quad", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(1, -6.5, 0), angle = Angle(45, 0, -10), size = 0.025, draw_func = nil},
  100. ["base_decor1+++"] = { type = "Model", model = "models/props_combine/breenlight.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(0.349, -4.6, -1.5), angle = Angle(0, 90, -165), size = Vector(0.15, 0.1, 0.15), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/weapons/dragons_breath/breenlight_edit", skin = 0, bodygroup = {} },
  101. ["base_decor1+"] = { type = "Model", model = "models/props_combine/breenlight.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(-0.35, -4.6, -1.5), angle = Angle(0, 90, 165), size = Vector(0.15, 0.1, 0.15), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/weapons/dragons_breath/breenlight_edit", skin = 0, bodygroup = {} },
  102. ["radiator"] = { type = "Model", model = "models/props_c17/metalladder001.mdl", bone = "v_weapon.xm1014_Parent", rel = "charge", pos = Vector(0.4, 0, -3.6), angle = Angle(90, 0, 0), size = Vector(0.029, 0.035, 0.029), color = Color(15, 15, 15, 255), surpresslightning = true, material = "", skin = 0, bodygroup = {} },
  103. ["charge"] = { type = "Model", model = "models/props_combine/breenlight.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(-1.5, -4.651, -22), angle = Angle(-180, 0, 0), size = Vector(0.4, 0.3, 0.4), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/weapons/dragons_breath/breenlight_edit", skin = 0, bodygroup = {} },
  104. ["base_decor_light+++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.xm1014_Parent", rel = "base_decor1+++", pos = Vector(0, 0, -1.5), size = { x = 1.5, y = 1.5 }, color = Color(0, 155, 255, 100), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
  105. ["base_decor_light++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.xm1014_Parent", rel = "base_decor1++", pos = Vector(0, 0, -1.5), size = { x = 1.5, y = 1.5 }, color = Color(0, 155, 255, 100), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = true},
  106. ["charge_decor_light"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.xm1014_Parent", rel = "charge", pos = Vector(0, 0, -4.5), size = { x = 4, y = 4 }, color = Color(0, 155, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
  107. ["base_decor_light"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.xm1014_Parent", rel = "base_decor1", pos = Vector(0, 0, -1.5), size = { x = 1.5, y = 1.5 }, color = Color(0, 155, 255, 100), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = true},
  108. ["base_decor_light+"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.xm1014_Parent", rel = "base_decor1+", pos = Vector(0, 0, -1.5), size = { x = 1.5, y = 1.5 }, color = Color(0, 155, 255, 100), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = true},
  109. ["charge_decor_light+"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.xm1014_Parent", rel = "charge+", pos = Vector(0, 0, -4.5), size = { x = 4, y = 4 }, color = Color(0, 155, 255, 150), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
  110. ["ring"] = { type = "Model", model = "models/props_combine/combine_mortar01b.mdl", bone = "v_weapon.xm1014_Parent", rel = "", pos = Vector(-0.801, -4, -2), angle = Angle(100, 0, -8), size = Vector(0.039, 0.039, 0.019), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
  111. }
  112. SWEP.WElements = {}
  113. --SCK END--
  114.  
  115. function SWEP:Deploy()
  116. self.Owner:EmitSound("dragonsbreath/Dragon_charging.wav",45)
  117. self:SendWeaponAnim( ACT_VM_DRAW )
  118. end
  119.  
  120. function SWEP:Initialize()
  121. local viewmodel = self.Owner:GetViewModel()
  122. self.Charge = 0
  123. self.Shootanim = 0
  124. self.DragonsEnergy = 0
  125. if SERVER then
  126. self:SetWeaponHoldType( self.HoldType )
  127. end
  128. end
  129.  
  130. function SWEP:PrimaryAttack()
  131. if ( !self:CanPrimaryAttack() ) then return end
  132. local bullet = {}
  133. bullet.Num = self.Primary.NumberofShots
  134. bullet.Src = self.Owner:GetShootPos()
  135. bullet.Dir = self.Owner:GetAimVector()
  136. bullet.Spread = Vector( self.Primary.Spread * 0.1 ,0, 0)
  137. bullet.Tracer = 1
  138. bullet.TracerName = "shotgun_trace"
  139. bullet.Force = 4
  140. bullet.Damage = self.Primary.Damage
  141. bullet.AmmoType = self.Primary.Ammo
  142. if SERVER then
  143. bullet.Callback = function(ent,tr,dmginfo) if IsValid(tr.Entity) then tr.Entity:Ignite(5)
  144. ParticleEffectAttach( "dragon_ignition", 1, tr.Entity, 1 )
  145. end
  146. dmginfo:SetDamageType(DMG_BLAST)
  147. end
  148. end
  149. local rnda = self.Primary.Recoil * -0.3
  150. local rndb = self.Primary.Recoil * math.random(-0.3, 0.3)
  151. self:ShootEffects()
  152. self.Owner:FireBullets( bullet )
  153. if SERVER then
  154. self.Owner:EmitSound("dragonsbreath/dragon_primary_" .. math.random( 1, 4 ) .. ".wav", 100, math.random( 85, 100 ))
  155. end
  156. self.Owner:ViewPunch( Angle( rnda,rndb,-5 ) )
  157. self:TakePrimaryAmmo(1)
  158.  
  159. self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  160. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  161.  
  162. self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  163. self:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
  164. self.Charge = 0
  165. if SERVER then
  166. self.Owner:SendLua( "LocalPlayer():GetActiveWeapon():Shootanim1()" )
  167. ParticleEffectAttach( "dragon_muzzle", PATTACH_POINT_FOLLOW, self.Owner:GetViewModel(), self.Owner:GetViewModel():LookupAttachment("1") )
  168.  
  169. self.Owner:SetVelocity(self.Owner:GetAngles():Forward()*-190)
  170. end
  171. end
  172.  
  173.  
  174. function SWEP:Think()
  175. self:SetWeaponHoldType( self.HoldType )
  176. //SCK ANIMS//
  177. self.VElements["charge"].pos = Vector(-1.5, -4.651,-self.Shootanim/1.5)
  178. self.VElements["charge+"].pos = Vector(1.5, -4.651,-self.Shootanim/1.5)
  179. self.VElements["charge_decor_light+"].color = Color(self.DragonsEnergy*1.2, 155-self.DragonsEnergy/1.5, 255-self.DragonsEnergy, 150)
  180. self.VElements["charge_decor_light"].color = Color(self.DragonsEnergy*1.2, 155-self.DragonsEnergy/1.5, 255-self.DragonsEnergy, 150)
  181. self.VElements["base_decor_light"].color = Color(self.DragonsEnergy*1.2, 155-self.DragonsEnergy/1.5, 255-self.DragonsEnergy, 150)
  182. self.VElements["base_decor_light+"].color = Color(self.DragonsEnergy*1.2, 155-self.DragonsEnergy/1.5, 255-self.DragonsEnergy, 150)
  183. self.VElements["base_decor_light++"].color = Color(self.DragonsEnergy*1.2, 155-self.DragonsEnergy/1.5, 255-self.DragonsEnergy, 150)
  184. self.VElements["base_decor_light+++"].color = Color(self.DragonsEnergy*1.2, 155-self.DragonsEnergy/1.5, 255-self.DragonsEnergy, 150)
  185. //SCK MODELS END//
  186.  
  187. //MUZZLE CHARGE PARTICLE+SOUND//
  188. if( self.Owner:KeyPressed( IN_ATTACK2 ) ) and self:Clip1() > 0 then
  189. self.Charge = 0
  190. ParticleEffectAttach( "dragon_charge", PATTACH_POINT_FOLLOW, self.Owner:GetViewModel(), self.Owner:GetViewModel():LookupAttachment("1") )
  191. self.Owner:EmitSound("dragonsbreath/Dragon_charging.wav",80)
  192. end
  193. //CHARGING//
  194. if( self.Owner:KeyDown( IN_ATTACK2 ) ) and self:Clip1() > 0 then
  195. self:Charger1()
  196. end
  197. //SHOOT//
  198. if ( self.Owner:KeyReleased( IN_ATTACK2 ) ) and self:Clip1() > 0 then
  199. self:SecondaryAttack()
  200. end
  201. //CHARING FIX//
  202. if( !self.Owner:KeyDown( IN_ATTACK2 ) ) and self.DragonsEnergy > 0 then
  203. self.DragonsEnergy = 0
  204. end
  205. //I HOPE//
  206.  
  207. //RELOAD//
  208. if self:Clip1() < 7 and self.Charge > 0 then
  209. self:Reload()
  210. end
  211. if self:Clip1() > 6 then
  212. self.Charge = 0
  213. end
  214. if self.Shootanim < 33 then
  215. self.Shootanim = self.Shootanim + 1
  216. end
  217. end
  218.  
  219. function SWEP:Shootanim1()
  220. self.Shootanim = 10
  221. end
  222.  
  223. function SWEP:Charger1()
  224. local chargemax = self:Clip1() * 30
  225. if self.DragonsEnergy < chargemax then
  226. self.DragonsEnergy = self.DragonsEnergy + 1
  227. end
  228. end
  229.  
  230. function SWEP:Reload()
  231. //
  232. if self.ReloadingTime and CurTime() <= self.ReloadingTime then return end
  233. if ( self:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
  234. if self:Clip1() < 7 then
  235. self.Charge = 1
  236. self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )
  237. self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
  238. self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
  239. local AnimationTime = self.Owner:GetViewModel():SequenceDuration()
  240. self.ReloadingTime = (CurTime() + AnimationTime)
  241. self:SetNextPrimaryFire(CurTime() + AnimationTime -0.2)
  242. self:SetNextSecondaryFire(CurTime() + AnimationTime -0.2)
  243. if self:Clip1() > 6 then
  244. timer.Create( "timer1", AnimationTime, 1, function() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end )
  245. else
  246. timer.Create( "timer2", AnimationTime, 1, function() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end )
  247. end
  248. end
  249. end
  250. end
  251.  
  252. function SWEP:SecondaryAttack()
  253. local Ammotake = math.Round(self.DragonsEnergy/30,0)
  254.  
  255. if self.DragonsEnergy > 29 then
  256.  
  257. if self:Clip1() > self.DragonsEnergy/30
  258. then
  259. self:TakePrimaryAmmo(Ammotake)
  260. else
  261. self:TakePrimaryAmmo(self:Clip1())
  262. end
  263.  
  264. //CHERT YA ETO DNO TROGARY VTOROY RAZ NE BUDU//
  265. if SERVER then
  266. local blastdamage = self.DragonsEnergy*2
  267.  
  268. local ent = ents.Create( "dragon_fireball" )
  269. if ( IsValid( ent ) ) then
  270.  
  271. ent:SetPos( self.Owner:GetShootPos())
  272. end
  273.  
  274. ent:SetAngles( self.Owner:EyeAngles() )
  275. ent:SetOwner( self.Owner )
  276. ent:Spawn()
  277. ent:Activate()
  278. self.Owner:EmitSound("dragonsbreath/tf_dragonsfury_shoot.wav", 100, math.random( 75, 100 ))
  279. local phys = ent:GetPhysicsObject()
  280. if ( IsValid( phys ) ) then phys:Wake() phys:AddVelocity( ent:GetForward() * 3500 ) end
  281. //KABOOM CODE//
  282. function ent:DragonsBoom()
  283. if SERVER then
  284. local DragonsBoom = EffectData()
  285. DragonsBoom:SetOrigin( ent:GetPos() )
  286. DragonsBoom:SetNormal( ent:GetPos():GetNormal() )
  287. DragonsBoom:SetEntity( ent )
  288. util.BlastDamage(ent, self.Owner, self:GetPos(), blastdamage, blastdamage)
  289. ent:Remove()
  290. end
  291. end
  292. //PONYATNO?//
  293.  
  294. self.Owner:ViewPunch( Angle( -6,-1,-8 ) )
  295. self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  296. self.Owner:SetAnimation( PLAYER_ATTACK1 )
  297. //ZAPARTICLISHSYA ETO DELATY//
  298. ParticleEffectAttach( "dragon_muzzle_alt", PATTACH_POINT_FOLLOW, self.Owner:GetViewModel(), self.Owner:GetViewModel():LookupAttachment("1") )
  299. end
  300. end
  301. end
  302.  
  303. function SWEP:DoImpactEffect( tr, nDamageType )
  304. if ( tr.HitSky ) then return end
  305. ParticleEffect( "dragons_breath_impact", tr.HitPos, self.Owner:EyeAngles(), self )
  306. return false
  307. end
  308.  
  309. function SWEP:GetViewModelPosition( EyePos, EyeAng )
  310. local sineus = math.sin( CurTime() * 0.9 ) / 10000
  311. local sinevec = 1 + -sineus
  312. return EyePos*sinevec, EyeAng
  313. end
  314.  
  315. /********************************************************
  316. SWEP Construction Kit base code
  317. Created by Clavus
  318. Available for public use, thread at:
  319. facepunch.com/threads/1032378
  320.  
  321.  
  322. DESCRIPTION:
  323. This script is meant for experienced scripters
  324. that KNOW WHAT THEY ARE DOING. Don't come to me
  325. with basic Lua questions.
  326.  
  327. Just copy into your SWEP or SWEP base of choice
  328. and merge with your own code.
  329.  
  330. The SWEP.VElements, SWEP.WElements and
  331. SWEP.ViewModelBoneMods tables are all optional
  332. and only have to be visible to the client.
  333. ********************************************************/
  334.  
  335. function SWEP:Initialize()
  336. if CLIENT then
  337. self.VElements["charge_hud"].draw_func = function( weapon )
  338. draw.SimpleText(math.Round(self.DragonsEnergy/30,1), "dragon_digital", 0, 0, Color(self.DragonsEnergy*1.2, 155-self.DragonsEnergy/1.5, 255-self.DragonsEnergy, self.DragonsEnergy*3), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
  339. end
  340. end
  341. // other initialize code goes here
  342.  
  343. if CLIENT then
  344.  
  345. // Create a new table for every weapon instance
  346. self.VElements = table.FullCopy( self.VElements )
  347. self.WElements = table.FullCopy( self.WElements )
  348. self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
  349.  
  350. self:CreateModels(self.VElements) // create viewmodels
  351. self:CreateModels(self.WElements) // create worldmodels
  352.  
  353. // init view model bone build function
  354. if IsValid(self.Owner) then
  355. local vm = self.Owner:GetViewModel()
  356. if IsValid(vm) then
  357. self:ResetBonePositions(vm)
  358.  
  359. // Init viewmodel visibility
  360. if (self.ShowViewModel == nil or self.ShowViewModel) then
  361. vm:SetColor(Color(255,255,255,255))
  362. else
  363. // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
  364. vm:SetColor(Color(255,255,255,1))
  365. // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
  366. // 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
  367. vm:SetMaterial("Debug/hsv")
  368. end
  369. end
  370. end
  371.  
  372. end
  373.  
  374. end
  375.  
  376. function SWEP:Holster()
  377. timer.Remove("timer1")
  378. timer.Remove("timer2")
  379.  
  380. if CLIENT and IsValid(self.Owner) then
  381. local vm = self.Owner:GetViewModel()
  382. if IsValid(vm) then
  383. self:ResetBonePositions(vm)
  384. end
  385. end
  386.  
  387. return true
  388. end
  389.  
  390. function SWEP:OnRemove()
  391. self:Holster()
  392. end
  393.  
  394. if CLIENT then
  395.  
  396. SWEP.vRenderOrder = nil
  397. function SWEP:ViewModelDrawn()
  398.  
  399. local vm = self.Owner:GetViewModel()
  400. if !IsValid(vm) then return end
  401.  
  402. if (!self.VElements) then return end
  403.  
  404. self:UpdateBonePositions(vm)
  405.  
  406. if (!self.vRenderOrder) then
  407.  
  408. // we build a render order because sprites need to be drawn after models
  409. self.vRenderOrder = {}
  410.  
  411. for k, v in pairs( self.VElements ) do
  412. if (v.type == "Model") then
  413. table.insert(self.vRenderOrder, 1, k)
  414. elseif (v.type == "Sprite" or v.type == "Quad") then
  415. table.insert(self.vRenderOrder, k)
  416. end
  417. end
  418.  
  419. end
  420.  
  421. for k, name in ipairs( self.vRenderOrder ) do
  422.  
  423. local v = self.VElements[name]
  424. if (!v) then self.vRenderOrder = nil break end
  425. if (v.hide) then continue end
  426.  
  427. local model = v.modelEnt
  428. local sprite = v.spriteMaterial
  429.  
  430. if (!v.bone) then continue end
  431.  
  432. local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
  433.  
  434. if (!pos) then continue end
  435.  
  436. if (v.type == "Model" and IsValid(model)) then
  437.  
  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.  
  443. model:SetAngles(ang)
  444. //model:SetModelScale(v.size)
  445. local matrix = Matrix()
  446. matrix:Scale(v.size)
  447. model:EnableMatrix( "RenderMultiply", matrix )
  448.  
  449. if (v.material == "") then
  450. model:SetMaterial("")
  451. elseif (model:GetMaterial() != v.material) then
  452. model:SetMaterial( v.material )
  453. end
  454.  
  455. if (v.skin and v.skin != model:GetSkin()) then
  456. model:SetSkin(v.skin)
  457. end
  458.  
  459. if (v.bodygroup) then
  460. for k, v in pairs( v.bodygroup ) do
  461. if (model:GetBodygroup(k) != v) then
  462. model:SetBodygroup(k, v)
  463. end
  464. end
  465. end
  466.  
  467. if (v.surpresslightning) then
  468. render.SuppressEngineLighting(true)
  469. end
  470.  
  471. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  472. render.SetBlend(v.color.a/255)
  473. model:DrawModel()
  474. render.SetBlend(1)
  475. render.SetColorModulation(1, 1, 1)
  476.  
  477. if (v.surpresslightning) then
  478. render.SuppressEngineLighting(false)
  479. end
  480.  
  481. elseif (v.type == "Sprite" and sprite) then
  482.  
  483. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  484. render.SetMaterial(sprite)
  485. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  486.  
  487. elseif (v.type == "Quad" and v.draw_func) then
  488.  
  489. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  490. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  491. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  492. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  493.  
  494. cam.Start3D2D(drawpos, ang, v.size)
  495. v.draw_func( self )
  496. cam.End3D2D()
  497.  
  498. end
  499.  
  500. end
  501.  
  502. end
  503.  
  504. SWEP.wRenderOrder = nil
  505. function SWEP:DrawWorldModel()
  506.  
  507. if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  508. self:DrawModel()
  509. end
  510.  
  511. if (!self.WElements) then return end
  512.  
  513. if (!self.wRenderOrder) then
  514.  
  515. self.wRenderOrder = {}
  516.  
  517. for k, v in pairs( self.WElements ) do
  518. if (v.type == "Model") then
  519. table.insert(self.wRenderOrder, 1, k)
  520. elseif (v.type == "Sprite" or v.type == "Quad") then
  521. table.insert(self.wRenderOrder, k)
  522. end
  523. end
  524.  
  525. end
  526.  
  527. if (IsValid(self.Owner)) then
  528. bone_ent = self.Owner
  529. else
  530. // when the weapon is dropped
  531. bone_ent = self
  532. end
  533.  
  534. for k, name in pairs( self.wRenderOrder ) do
  535.  
  536. local v = self.WElements[name]
  537. if (!v) then self.wRenderOrder = nil break end
  538. if (v.hide) then continue end
  539.  
  540. local pos, ang
  541.  
  542. if (v.bone) then
  543. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
  544. else
  545. pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
  546. end
  547.  
  548. if (!pos) then continue end
  549.  
  550. local model = v.modelEnt
  551. local sprite = v.spriteMaterial
  552.  
  553. if (v.type == "Model" and IsValid(model)) then
  554.  
  555. model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  556. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  557. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  558. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  559.  
  560. model:SetAngles(ang)
  561. //model:SetModelScale(v.size)
  562. local matrix = Matrix()
  563. matrix:Scale(v.size)
  564. model:EnableMatrix( "RenderMultiply", matrix )
  565.  
  566. if (v.material == "") then
  567. model:SetMaterial("")
  568. elseif (model:GetMaterial() != v.material) then
  569. model:SetMaterial( v.material )
  570. end
  571.  
  572. if (v.skin and v.skin != model:GetSkin()) then
  573. model:SetSkin(v.skin)
  574. end
  575.  
  576. if (v.bodygroup) then
  577. for k, v in pairs( v.bodygroup ) do
  578. if (model:GetBodygroup(k) != v) then
  579. model:SetBodygroup(k, v)
  580. end
  581. end
  582. end
  583.  
  584. if (v.surpresslightning) then
  585. render.SuppressEngineLighting(true)
  586. end
  587.  
  588. render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  589. render.SetBlend(v.color.a/255)
  590. model:DrawModel()
  591. render.SetBlend(1)
  592. render.SetColorModulation(1, 1, 1)
  593.  
  594. if (v.surpresslightning) then
  595. render.SuppressEngineLighting(false)
  596. end
  597.  
  598. elseif (v.type == "Sprite" and sprite) then
  599.  
  600. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  601. render.SetMaterial(sprite)
  602. render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  603.  
  604. elseif (v.type == "Quad" and v.draw_func) then
  605.  
  606. local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  607. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  608. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  609. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  610.  
  611. cam.Start3D2D(drawpos, ang, v.size)
  612. v.draw_func( self )
  613. cam.End3D2D()
  614.  
  615. end
  616.  
  617. end
  618.  
  619. end
  620.  
  621. function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
  622.  
  623. local bone, pos, ang
  624. if (tab.rel and tab.rel != "") then
  625.  
  626. local v = basetab[tab.rel]
  627.  
  628. if (!v) then return end
  629.  
  630. // Technically, if there exists an element with the same name as a bone
  631. // you can get in an infinite loop. Let's just hope nobody's that stupid.
  632. pos, ang = self:GetBoneOrientation( basetab, v, ent )
  633.  
  634. if (!pos) then return end
  635.  
  636. pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  637. ang:RotateAroundAxis(ang:Up(), v.angle.y)
  638. ang:RotateAroundAxis(ang:Right(), v.angle.p)
  639. ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  640.  
  641. else
  642.  
  643. bone = ent:LookupBone(bone_override or tab.bone)
  644.  
  645. if (!bone) then return end
  646.  
  647. pos, ang = Vector(0,0,0), Angle(0,0,0)
  648. local m = ent:GetBoneMatrix(bone)
  649. if (m) then
  650. pos, ang = m:GetTranslation(), m:GetAngles()
  651. end
  652.  
  653. if (IsValid(self.Owner) and self.Owner:IsPlayer() and
  654. ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
  655. ang.r = -ang.r // Fixes mirrored models
  656. end
  657.  
  658. end
  659.  
  660. return pos, ang
  661. end
  662.  
  663. function SWEP:CreateModels( tab )
  664.  
  665. if (!tab) then return end
  666.  
  667. // Create the clientside models here because Garry says we can't do it in the render hook
  668. for k, v in pairs( tab ) do
  669. if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
  670. string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
  671.  
  672. v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  673. if (IsValid(v.modelEnt)) then
  674. v.modelEnt:SetPos(self:GetPos())
  675. v.modelEnt:SetAngles(self:GetAngles())
  676. v.modelEnt:SetParent(self)
  677. v.modelEnt:SetNoDraw(true)
  678. v.createdModel = v.model
  679. else
  680. v.modelEnt = nil
  681. end
  682.  
  683. elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  684. and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
  685.  
  686. local name = v.sprite.."-"
  687. local params = { ["$basetexture"] = v.sprite }
  688. // make sure we create a unique name based on the selected options
  689. local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  690. for i, j in pairs( tocheck ) do
  691. if (v[j]) then
  692. params["$"..j] = 1
  693. name = name.."1"
  694. else
  695. name = name.."0"
  696. end
  697. end
  698.  
  699. v.createdSprite = v.sprite
  700. v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  701.  
  702. end
  703. end
  704.  
  705. end
  706.  
  707. local allbones
  708. local hasGarryFixedBoneScalingYet = false
  709.  
  710. function SWEP:UpdateBonePositions(vm)
  711.  
  712. if self.ViewModelBoneMods then
  713.  
  714. if (!vm:GetBoneCount()) then return end
  715.  
  716. // !! WORKAROUND !! //
  717. // We need to check all model names :/
  718. local loopthrough = self.ViewModelBoneMods
  719. if (!hasGarryFixedBoneScalingYet) then
  720. allbones = {}
  721. for i=0, vm:GetBoneCount() do
  722. local bonename = vm:GetBoneName(i)
  723. if (self.ViewModelBoneMods[bonename]) then
  724. allbones[bonename] = self.ViewModelBoneMods[bonename]
  725. else
  726. allbones[bonename] = {
  727. scale = Vector(1,1,1),
  728. pos = Vector(0,0,0),
  729. angle = Angle(0,0,0)
  730. }
  731. end
  732. end
  733.  
  734. loopthrough = allbones
  735. end
  736. // !! ----------- !! //
  737.  
  738. for k, v in pairs( loopthrough ) do
  739. local bone = vm:LookupBone(k)
  740. if (!bone) then continue end
  741.  
  742. // !! WORKAROUND !! //
  743. local s = Vector(v.scale.x,v.scale.y,v.scale.z)
  744. local p = Vector(v.pos.x,v.pos.y,v.pos.z)
  745. local ms = Vector(1,1,1)
  746. if (!hasGarryFixedBoneScalingYet) then
  747. local cur = vm:GetBoneParent(bone)
  748. while(cur >= 0) do
  749. local pscale = loopthrough[vm:GetBoneName(cur)].scale
  750. ms = ms * pscale
  751. cur = vm:GetBoneParent(cur)
  752. end
  753. end
  754.  
  755. s = s * ms
  756. // !! ----------- !! //
  757.  
  758. if vm:GetManipulateBoneScale(bone) != s then
  759. vm:ManipulateBoneScale( bone, s )
  760. end
  761. if vm:GetManipulateBoneAngles(bone) != v.angle then
  762. vm:ManipulateBoneAngles( bone, v.angle )
  763. end
  764. if vm:GetManipulateBonePosition(bone) != p then
  765. vm:ManipulateBonePosition( bone, p )
  766. end
  767. end
  768. else
  769. self:ResetBonePositions(vm)
  770. end
  771.  
  772. end
  773.  
  774. function SWEP:ResetBonePositions(vm)
  775.  
  776. if (!vm:GetBoneCount()) then return end
  777. for i=0, vm:GetBoneCount() do
  778. vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
  779. vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
  780. vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
  781. end
  782.  
  783. end
  784.  
  785. /**************************
  786. Global utility code
  787. **************************/
  788.  
  789. // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
  790. // Does not copy entities of course, only copies their reference.
  791. // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
  792. function table.FullCopy( tab )
  793.  
  794. if (!tab) then return nil end
  795.  
  796. local res = {}
  797. for k, v in pairs( tab ) do
  798. if (type(v) == "table") then
  799. res[k] = table.FullCopy(v) // recursion ho!
  800. elseif (type(v) == "Vector") then
  801. res[k] = Vector(v.x, v.y, v.z)
  802. elseif (type(v) == "Angle") then
  803. res[k] = Angle(v.p, v.y, v.r)
  804. else
  805. res[k] = v
  806. end
  807. end
  808.  
  809. return res
  810.  
  811. end
  812.  
  813. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement