· 9 years ago · Jan 10, 2017, 10:32 AM
1SWEP.Author = "SK1RM1SHER"
2SWEP.Category = "SK1RM1SHERS Weapons"
3
4SWEP.Spawnable = true
5SWEP.AdminSpawnable = true
6
7SWEP.WorldModel = "models/weapons/w_physics.mdl"
8
9//Alternative viewmodel
10//SWEP.ViewModel = "models/weapons/v_superphyscannon.mdl"
11//SWEP.WorldModel = "models/weapons/w_superphyscannon.mdl"
12
13SWEP.HoldType = "ar2"
14SWEP.ViewModelFOV = 60.100502512563
15SWEP.ViewModelFlip = false
16SWEP.ViewModel = "models/weapons/c_irifle.mdl"
17SWEP.WorldModel = "models/weapons/w_physics.mdl"
18SWEP.ShowViewModel = true
19SWEP.ShowWorldModel = false
20SWEP.ViewModelBoneMods = {
21 ["Base"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(-6.832, 0, 0.75), angle = Angle(0, 0, 0) }
22}
23
24SWEP.VElements = {
25 ["gun"] = { type = "Model", model = "models/weapons/w_flamethrower.mdl", bone = "Base", rel = "", pos = Vector(0.479, 10.595, 12.336), angle = Angle(88.247, -86.689, 1.251), size = Vector(0.751, 0.751, 0.751), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
26 ["flame"] = { type = "Model", model = "models/hunter/blocks/cube025x025x025.mdl", bone = "Base", rel = "", pos = Vector(0.358, 3.368, 28.076), angle = Angle(0, 0, 0), size = Vector(0.054, 0.054, 0.054), color = Color(0, 0, 255, 255), surpresslightning = false, material = "models/alyx/emptool_glow", skin = 0, bodygroup = {} }
27}
28
29SWEP.WElements = {
30 ["gun"] = { type = "Model", model = "models/weapons/w_flamethrower.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(14.487, 0.716, 7.153), angle = Angle(-3.935, 2.048, 180), size = Vector(1.019, 1.019, 1.019), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
31}
32
33
34SWEP.HoldType = "smg"
35SWEP.Primary.Automatic = true
36SWEP.Primary.ClipSize = -1
37SWEP.Primary.DefaultClip = -1
38SWEP.Primary.Ammo = "none"
39SWEP.Secondary.ClipSize = 75
40SWEP.Secondary.DefaultClip = -1
41SWEP.Secondary.Automatic = true
42SWEP.Secondary.Ammo = "ar2"
43
44SWEP.ReloadDelay = 0
45
46
47//Precache everything
48function SWEP:Precache()
49
50util.PrecacheSound("ambient/machines/keyboard2_clicks.wav")
51
52util.PrecacheSound("ambient/machines/thumper_dust.wav")
53util.PrecacheSound("ambient/fire/mtov_flame2.wav")
54util.PrecacheSound("ambient/fire/ignite.wav")
55
56util.PrecacheSound("vehicles/tank_readyfire1.wav")
57
58end
59
60
61//Primary attack
62function SWEP:PrimaryAttack()
63
64if (SERVER) then
65if (self.Owner:GetAmmoCount("ar2") < 1) || (self.ReloadDelay == 1) then
66self:RunoutReload()
67return end
68end
69
70if (self.Owner:GetAmmoCount("ar2") > 0) && (self.ReloadDelay == 0) then
71
72self.Owner:RemoveAmmo( 1, self.Weapon:GetSecondaryAmmoType() )
73
74self.Owner:MuzzleFlash()
75
76self.Weapon:SetNextPrimaryFire( CurTime() + 0.08 )
77
78if (SERVER) then
79
80 local trace = self.Owner:GetEyeTrace()
81 local Distance = self.Owner:GetPos():Distance(trace.HitPos)
82
83 if Distance < 520 then
84
85
86 //This is how we ignite stuff
87 local Ignite = function()
88
89 //Safeguard
90 if !self:IsValid() then return end
91
92 //Damage things in radius of impact
93 local flame = ents.Create("point_hurt")
94 flame:SetPos(trace.HitPos)
95 flame:SetOwner(self.Owner)
96 flame:SetKeyValue("DamageRadius",128)
97 flame:SetKeyValue("Damage",4)
98 flame:SetKeyValue("DamageDelay",0.32)
99 flame:SetKeyValue("DamageType",8)
100 flame:Spawn()
101 flame:Fire("TurnOn","",0)
102 flame:Fire("kill","",0.72)
103
104 //Create actual fire - doesn't work very well in practice
105 //if trace.HitWorld then
106 //local fire = ents.Create("env_fire")
107 //fire:SetPos(trace.HitPos + Vector(0,0, -8))
108 //fire:SetAngles(Angle(0,0, math.random(-360, 360)))
109 //fire:SetKeyValue("health", 1)
110 //fire:SetKeyValue("firesize", math.random(82,128))
111 //fire:SetKeyValue("fireattack", tostring(math.random(0.72,1.32)))
112 //fire:SetKeyValue("damagescale", 8)
113 //fire:SetKeyValue("spawnflags","178") //162
114 //fire:Spawn()
115 //fire:Activate()
116 //fire:Fire("StartFire","", 0)
117 //end
118
119 if trace.HitWorld then
120 local nearbystuff = ents.FindInSphere(trace.HitPos, 100)
121
122 for _, stuff in pairs(nearbystuff) do
123
124 if stuff != self.Owner then
125
126 if stuff:GetPhysicsObject():IsValid() && !stuff:IsNPC() && !stuff:IsPlayer() then
127 if !stuff:IsOnFire() then stuff:Ignite(math.random(16,32), 100) end end
128
129 if stuff:IsPlayer() then
130 if stuff:GetPhysicsObject():IsValid() then
131 stuff:Ignite(1, 100) end end
132
133 if stuff:IsNPC() then
134 if stuff:GetPhysicsObject():IsValid() then
135 local npc = stuff:GetClass()
136 if npc == "npc_antlionguard" || npc == "npc_hunter" || npc == "npc_kleiner"
137 || npc == "npc_gman" || npc == "npc_eli" || npc == "npc_alyx"
138 || npc == "npc_mossman" || npc == "npc_breen" || npc == "npc_monk"
139 || npc == "npc_vortigaunt" || npc == "npc_citizen" || npc == "npc_rebel"
140 || npc == "npc_barney" || npc == "npc_magnusson" then
141 stuff:Fire("Ignite","",1)
142 end
143 stuff:Ignite(math.random(12,16), 100) end end
144
145 end
146 end
147 end
148
149 if trace.Entity:IsValid() then
150
151 if trace.Entity:GetPhysicsObject():IsValid() && !trace.Entity:IsNPC() && !trace.Entity:IsPlayer() then
152 if !trace.Entity:IsOnFire() then trace.Entity:Ignite(math.random(16,32), 100) end end
153
154 if trace.Entity:IsPlayer() then
155 if trace.Entity:GetPhysicsObject():IsValid() then
156 trace.Entity:Ignite(math.random(1,2), 100) end end
157
158 if trace.Entity:IsNPC() then
159 if trace.Entity:GetPhysicsObject():IsValid() then
160 local npc = trace.Entity:GetClass()
161 if npc == "npc_antlionguard" || npc == "npc_hunter" || npc == "npc_kleiner"
162 || npc == "npc_gman" || npc == "npc_eli" || npc == "npc_alyx"
163 || npc == "npc_mossman" || npc == "npc_breen" || npc == "npc_monk"
164 || npc == "npc_vortigaunt" || npc == "npc_citizen" || npc == "npc_rebel"
165 || npc == "npc_barney" || npc == "npc_magnusson" then
166 trace.Entity:Fire("Ignite","",1)
167 end
168 trace.Entity:Ignite(math.random(12,16), 100) end end
169
170 end
171
172 if (SERVER) then
173 local firefx = EffectData()
174 firefx:SetOrigin(trace.HitPos)
175 util.Effect("swep_flamethrower_explosion",firefx,true,true)
176 end
177
178 end
179
180
181 //Ignite stuff; based on how long it takes for flame to reach it
182 timer.Simple(Distance/1520, Ignite)
183
184 end
185
186end
187end
188end
189
190
191//Unused
192function SWEP:SecondaryAttack()
193end
194
195
196//Play a nice sound on deployment
197function SWEP:Deploy()
198self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
199if (SERVER) then
200self.Owner:EmitSound( "ambient/machines/keyboard2_clicks.wav", 42, 100 )
201end
202return true
203end
204
205
206//Think function
207function SWEP:Think()
208
209if self.Owner:KeyReleased(IN_ATTACK) && (self.Owner:GetAmmoCount("ar2") > 1) && (self.ReloadDelay != 1) then
210if (SERVER) then
211self.Owner:EmitSound( "ambient/fire/mtov_flame2.wav", 24, 100 )
212end
213end
214
215if (self.Owner:GetAmmoCount("ar2") > 0) && (self.ReloadDelay == 0) then
216
217if self.Owner:KeyPressed(IN_ATTACK) then
218if (SERVER) then
219self.Owner:EmitSound( "ambient/machines/thumper_dust.wav", 100, 100 )
220end
221end
222
223if self.Owner:KeyDown(IN_ATTACK) then
224if (SERVER) then
225self.Owner:EmitSound( "ambient/fire/mtov_flame2.wav", math.random(27,35), math.random(32,152) )
226end
227local trace = self.Owner:GetEyeTrace()
228if (SERVER) then
229local flamefx = EffectData()
230flamefx:SetOrigin(trace.HitPos)
231flamefx:SetStart(self.Owner:GetShootPos())
232flamefx:SetAttachment(1)
233flamefx:SetEntity(self.Weapon)
234util.Effect("swep_flamethrower_flame",flamefx,true,true)
235end
236end
237
238end
239end
240
241
242//Reload function
243function SWEP:Reload()
244
245if (self.Owner:GetAmmoCount("ar2") > 74) || (self.ReloadDelay == 1) then return end
246
247self.ReloadDelay = 1
248
249if (SERVER) then
250self.Owner:EmitSound( "vehicles/tank_readyfire1.wav", 30, 100 )
251end
252
253timer.Simple(1.82, function() if self:IsValid() then self:ReloadSelf() end end)
254
255end
256
257
258//How to reload if running out of ammo
259function SWEP:RunoutReload()
260
261if (self.Owner:GetAmmoCount("ar2") > 74) || (self.ReloadDelay == 1) then return end
262
263self.ReloadDelay = 1
264
265if (SERVER) then
266self.Owner:EmitSound( "ambient/machines/thumper_dust.wav", 48, 100 )
267self.Owner:EmitSound( "vehicles/tank_readyfire1.wav", 30, 100 )
268end
269
270timer.Simple(1.82, function() if self:IsValid() then self:ReloadSelf() end end)
271
272end
273
274
275//Finish reloading
276function SWEP:ReloadSelf()
277
278//Safeguards
279if !self then return end
280if !self:IsValid() then return end
281
282if (SERVER) then
283local ammo = math.Clamp( (75 - self.Owner:GetAmmoCount("ar2")), 0, 75)
284self.Owner:GiveAmmo(ammo, "ar2")
285end
286self.ReloadDelay = 0
287if self.Owner:KeyDown(IN_ATTACK) then
288if (SERVER) then
289self.Owner:EmitSound( "ambient/machines/thumper_dust.wav", 46, 100 )
290end
291end
292
293end
294
295/********************************************************
296 SWEP Construction Kit base code
297 Created by Clavus
298 Available for public use, thread at:
299 facepunch.com/threads/1032378
300
301
302 DESCRIPTION:
303 This script is meant for experienced scripters
304 that KNOW WHAT THEY ARE DOING. Don't come to me
305 with basic Lua questions.
306
307 Just copy into your SWEP or SWEP base of choice
308 and merge with your own code.
309
310 The SWEP.VElements, SWEP.WElements and
311 SWEP.ViewModelBoneMods tables are all optional
312 and only have to be visible to the client.
313********************************************************/
314
315function SWEP:Initialize()
316self:SetWeaponHoldType("ar2")
317
318 if CLIENT then
319
320 // Create a new table for every weapon instance
321 self.VElements = table.FullCopy( self.VElements )
322 self.WElements = table.FullCopy( self.WElements )
323 self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
324
325 self:CreateModels(self.VElements) // create viewmodels
326 self:CreateModels(self.WElements) // create worldmodels
327
328 // init view model bone build function
329 if IsValid(self.Owner) then
330 local vm = self.Owner:GetViewModel()
331 if IsValid(vm) then
332 self:ResetBonePositions(vm)
333
334 // Init viewmodel visibility
335 if (self.ShowViewModel == nil or self.ShowViewModel) then
336 vm:SetColor(Color(255,255,255,255))
337 else
338 // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
339 vm:SetColor(Color(255,255,255,1))
340 // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
341 // 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
342 vm:SetMaterial("Debug/hsv")
343 end
344 end
345 end
346
347 end
348
349end
350
351function SWEP:Holster()
352
353 if CLIENT and IsValid(self.Owner) then
354 local vm = self.Owner:GetViewModel()
355 if IsValid(vm) then
356 self:ResetBonePositions(vm)
357 end
358 end
359
360 return true
361end
362
363function SWEP:OnRemove()
364 self:Holster()
365end
366
367if CLIENT then
368
369 SWEP.vRenderOrder = nil
370 function SWEP:ViewModelDrawn()
371
372 local vm = self.Owner:GetViewModel()
373 if !IsValid(vm) then return end
374
375 if (!self.VElements) then return end
376
377 self:UpdateBonePositions(vm)
378
379 if (!self.vRenderOrder) then
380
381 // we build a render order because sprites need to be drawn after models
382 self.vRenderOrder = {}
383
384 for k, v in pairs( self.VElements ) do
385 if (v.type == "Model") then
386 table.insert(self.vRenderOrder, 1, k)
387 elseif (v.type == "Sprite" or v.type == "Quad") then
388 table.insert(self.vRenderOrder, k)
389 end
390 end
391
392 end
393
394 for k, name in ipairs( self.vRenderOrder ) do
395
396 local v = self.VElements[name]
397 if (!v) then self.vRenderOrder = nil break end
398 if (v.hide) then continue end
399
400 local model = v.modelEnt
401 local sprite = v.spriteMaterial
402
403 if (!v.bone) then continue end
404
405 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
406
407 if (!pos) then continue end
408
409 if (v.type == "Model" and IsValid(model)) then
410
411 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
412 ang:RotateAroundAxis(ang:Up(), v.angle.y)
413 ang:RotateAroundAxis(ang:Right(), v.angle.p)
414 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
415
416 model:SetAngles(ang)
417 //model:SetModelScale(v.size)
418 local matrix = Matrix()
419 matrix:Scale(v.size)
420 model:EnableMatrix( "RenderMultiply", matrix )
421
422 if (v.material == "") then
423 model:SetMaterial("")
424 elseif (model:GetMaterial() != v.material) then
425 model:SetMaterial( v.material )
426 end
427
428 if (v.skin and v.skin != model:GetSkin()) then
429 model:SetSkin(v.skin)
430 end
431
432 if (v.bodygroup) then
433 for k, v in pairs( v.bodygroup ) do
434 if (model:GetBodygroup(k) != v) then
435 model:SetBodygroup(k, v)
436 end
437 end
438 end
439
440 if (v.surpresslightning) then
441 render.SuppressEngineLighting(true)
442 end
443
444 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
445 render.SetBlend(v.color.a/255)
446 model:DrawModel()
447 render.SetBlend(1)
448 render.SetColorModulation(1, 1, 1)
449
450 if (v.surpresslightning) then
451 render.SuppressEngineLighting(false)
452 end
453
454 elseif (v.type == "Sprite" and sprite) then
455
456 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
457 render.SetMaterial(sprite)
458 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
459
460 elseif (v.type == "Quad" and v.draw_func) then
461
462 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
463 ang:RotateAroundAxis(ang:Up(), v.angle.y)
464 ang:RotateAroundAxis(ang:Right(), v.angle.p)
465 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
466
467 cam.Start3D2D(drawpos, ang, v.size)
468 v.draw_func( self )
469 cam.End3D2D()
470
471 end
472
473 end
474
475 end
476
477 SWEP.wRenderOrder = nil
478 function SWEP:DrawWorldModel()
479
480 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
481 self:DrawModel()
482 end
483
484 if (!self.WElements) then return end
485
486 if (!self.wRenderOrder) then
487
488 self.wRenderOrder = {}
489
490 for k, v in pairs( self.WElements ) do
491 if (v.type == "Model") then
492 table.insert(self.wRenderOrder, 1, k)
493 elseif (v.type == "Sprite" or v.type == "Quad") then
494 table.insert(self.wRenderOrder, k)
495 end
496 end
497
498 end
499
500 if (IsValid(self.Owner)) then
501 bone_ent = self.Owner
502 else
503 // when the weapon is dropped
504 bone_ent = self
505 end
506
507 for k, name in pairs( self.wRenderOrder ) do
508
509 local v = self.WElements[name]
510 if (!v) then self.wRenderOrder = nil break end
511 if (v.hide) then continue end
512
513 local pos, ang
514
515 if (v.bone) then
516 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
517 else
518 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
519 end
520
521 if (!pos) then continue end
522
523 local model = v.modelEnt
524 local sprite = v.spriteMaterial
525
526 if (v.type == "Model" and IsValid(model)) then
527
528 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
529 ang:RotateAroundAxis(ang:Up(), v.angle.y)
530 ang:RotateAroundAxis(ang:Right(), v.angle.p)
531 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
532
533 model:SetAngles(ang)
534 //model:SetModelScale(v.size)
535 local matrix = Matrix()
536 matrix:Scale(v.size)
537 model:EnableMatrix( "RenderMultiply", matrix )
538
539 if (v.material == "") then
540 model:SetMaterial("")
541 elseif (model:GetMaterial() != v.material) then
542 model:SetMaterial( v.material )
543 end
544
545 if (v.skin and v.skin != model:GetSkin()) then
546 model:SetSkin(v.skin)
547 end
548
549 if (v.bodygroup) then
550 for k, v in pairs( v.bodygroup ) do
551 if (model:GetBodygroup(k) != v) then
552 model:SetBodygroup(k, v)
553 end
554 end
555 end
556
557 if (v.surpresslightning) then
558 render.SuppressEngineLighting(true)
559 end
560
561 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
562 render.SetBlend(v.color.a/255)
563 model:DrawModel()
564 render.SetBlend(1)
565 render.SetColorModulation(1, 1, 1)
566
567 if (v.surpresslightning) then
568 render.SuppressEngineLighting(false)
569 end
570
571 elseif (v.type == "Sprite" and sprite) then
572
573 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
574 render.SetMaterial(sprite)
575 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
576
577 elseif (v.type == "Quad" and v.draw_func) then
578
579 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
580 ang:RotateAroundAxis(ang:Up(), v.angle.y)
581 ang:RotateAroundAxis(ang:Right(), v.angle.p)
582 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
583
584 cam.Start3D2D(drawpos, ang, v.size)
585 v.draw_func( self )
586 cam.End3D2D()
587
588 end
589
590 end
591
592 end
593
594 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
595
596 local bone, pos, ang
597 if (tab.rel and tab.rel != "") then
598
599 local v = basetab[tab.rel]
600
601 if (!v) then return end
602
603 // Technically, if there exists an element with the same name as a bone
604 // you can get in an infinite loop. Let's just hope nobody's that stupid.
605 pos, ang = self:GetBoneOrientation( basetab, v, ent )
606
607 if (!pos) then return end
608
609 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
610 ang:RotateAroundAxis(ang:Up(), v.angle.y)
611 ang:RotateAroundAxis(ang:Right(), v.angle.p)
612 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
613
614 else
615
616 bone = ent:LookupBone(bone_override or tab.bone)
617
618 if (!bone) then return end
619
620 pos, ang = Vector(0,0,0), Angle(0,0,0)
621 local m = ent:GetBoneMatrix(bone)
622 if (m) then
623 pos, ang = m:GetTranslation(), m:GetAngles()
624 end
625
626 if (IsValid(self.Owner) and self.Owner:IsPlayer() and
627 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
628 ang.r = -ang.r // Fixes mirrored models
629 end
630
631 end
632
633 return pos, ang
634 end
635
636 function SWEP:CreateModels( tab )
637
638 if (!tab) then return end
639
640 // Create the clientside models here because Garry says we can't do it in the render hook
641 for k, v in pairs( tab ) do
642 if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
643 string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
644
645 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
646 if (IsValid(v.modelEnt)) then
647 v.modelEnt:SetPos(self:GetPos())
648 v.modelEnt:SetAngles(self:GetAngles())
649 v.modelEnt:SetParent(self)
650 v.modelEnt:SetNoDraw(true)
651 v.createdModel = v.model
652 else
653 v.modelEnt = nil
654 end
655
656 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
657 and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
658
659 local name = v.sprite.."-"
660 local params = { ["$basetexture"] = v.sprite }
661 // make sure we create a unique name based on the selected options
662 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
663 for i, j in pairs( tocheck ) do
664 if (v[j]) then
665 params["$"..j] = 1
666 name = name.."1"
667 else
668 name = name.."0"
669 end
670 end
671
672 v.createdSprite = v.sprite
673 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
674
675 end
676 end
677
678 end
679
680 local allbones
681 local hasGarryFixedBoneScalingYet = false
682
683 function SWEP:UpdateBonePositions(vm)
684
685 if self.ViewModelBoneMods then
686
687 if (!vm:GetBoneCount()) then return end
688
689 // !! WORKAROUND !! //
690 // We need to check all model names :/
691 local loopthrough = self.ViewModelBoneMods
692 if (!hasGarryFixedBoneScalingYet) then
693 allbones = {}
694 for i=0, vm:GetBoneCount() do
695 local bonename = vm:GetBoneName(i)
696 if (self.ViewModelBoneMods[bonename]) then
697 allbones[bonename] = self.ViewModelBoneMods[bonename]
698 else
699 allbones[bonename] = {
700 scale = Vector(1,1,1),
701 pos = Vector(0,0,0),
702 angle = Angle(0,0,0)
703 }
704 end
705 end
706
707 loopthrough = allbones
708 end
709 // !! ----------- !! //
710
711 for k, v in pairs( loopthrough ) do
712 local bone = vm:LookupBone(k)
713 if (!bone) then continue end
714
715 // !! WORKAROUND !! //
716 local s = Vector(v.scale.x,v.scale.y,v.scale.z)
717 local p = Vector(v.pos.x,v.pos.y,v.pos.z)
718 local ms = Vector(1,1,1)
719 if (!hasGarryFixedBoneScalingYet) then
720 local cur = vm:GetBoneParent(bone)
721 while(cur >= 0) do
722 local pscale = loopthrough[vm:GetBoneName(cur)].scale
723 ms = ms * pscale
724 cur = vm:GetBoneParent(cur)
725 end
726 end
727
728 s = s * ms
729 // !! ----------- !! //
730
731 if vm:GetManipulateBoneScale(bone) != s then
732 vm:ManipulateBoneScale( bone, s )
733 end
734 if vm:GetManipulateBoneAngles(bone) != v.angle then
735 vm:ManipulateBoneAngles( bone, v.angle )
736 end
737 if vm:GetManipulateBonePosition(bone) != p then
738 vm:ManipulateBonePosition( bone, p )
739 end
740 end
741 else
742 self:ResetBonePositions(vm)
743 end
744
745 end
746
747 function SWEP:ResetBonePositions(vm)
748
749 if (!vm:GetBoneCount()) then return end
750 for i=0, vm:GetBoneCount() do
751 vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
752 vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
753 vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
754 end
755
756 end
757
758 /**************************
759 Global utility code
760 **************************/
761
762 // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
763 // Does not copy entities of course, only copies their reference.
764 // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
765 function table.FullCopy( tab )
766
767 if (!tab) then return nil end
768
769 local res = {}
770 for k, v in pairs( tab ) do
771 if (type(v) == "table") then
772 res[k] = table.FullCopy(v) // recursion ho!
773 elseif (type(v) == "Vector") then
774 res[k] = Vector(v.x, v.y, v.z)
775 elseif (type(v) == "Angle") then
776 res[k] = Angle(v.p, v.y, v.r)
777 else
778 res[k] = v
779 end
780 end
781
782 return res
783
784 end
785
786end
787
788SWEP.HoldType = "ar2"
789SWEP.ViewModelFOV = 60.100502512563
790SWEP.ViewModelFlip = false
791SWEP.ViewModel = "models/weapons/c_irifle.mdl"
792SWEP.WorldModel = "models/weapons/w_physics.mdl"
793SWEP.ShowViewModel = true
794SWEP.ShowWorldModel = false
795SWEP.ViewModelBoneMods = {
796 ["Base"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(-6.832, 0, 0.75), angle = Angle(0, 0, 0) }
797}
798
799SWEP.VElements = {
800 ["gun"] = { type = "Model", model = "models/weapons/w_flamethrower.mdl", bone = "Base", rel = "", pos = Vector(0.479, 10.595, 12.336), angle = Angle(88.247, -86.689, 1.251), size = Vector(0.751, 0.751, 0.751), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
801 ["flame"] = { type = "Model", model = "models/hunter/blocks/cube025x025x025.mdl", bone = "Base", rel = "", pos = Vector(0.358, 3.368, 28.076), angle = Angle(0, 0, 0), size = Vector(0.054, 0.054, 0.054), color = Color(0, 0, 255, 255), surpresslightning = false, material = "models/alyx/emptool_glow", skin = 0, bodygroup = {} }
802}
803
804SWEP.WElements = {
805 ["gun"] = { type = "Model", model = "models/weapons/w_flamethrower.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(14.487, 0.716, 7.153), angle = Angle(-3.935, 2.048, 180), size = Vector(1.019, 1.019, 1.019), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
806}