· 8 years ago · Apr 02, 2018, 08:10 PM
1/*---------------------------------------------------------
2Think
3---------------------------------------------------------*/
4function SWEP:Think()
5 if self.Owner:KeyDown(IN_SPEED) then
6 self:SetWeaponHoldType("normal")
7 else
8 self:SetWeaponHoldType(self.HoldType)
9 end
10 if self.MoveTime and self.MoveTime < CurTime() and SERVER then
11 self.MoveTime = nil
12 end
13end
14
15
16local ActIndex = {}
17 ActIndex["pistol"] = ACT_HL2MP_IDLE_PISTOL
18 ActIndex["smg"] = ACT_HL2MP_IDLE_SMG1
19 ActIndex["grenade"] = ACT_HL2MP_IDLE_GRENADE
20 ActIndex["ar2"] = ACT_HL2MP_IDLE_AR2
21 ActIndex["shotgun"] = ACT_HL2MP_IDLE_SHOTGUN
22 ActIndex["rpg"] = ACT_HL2MP_IDLE_RPG
23 ActIndex["physgun"] = ACT_HL2MP_IDLE_PHYSGUN
24 ActIndex["crossbow"] = ACT_HL2MP_IDLE_CROSSBOW
25 ActIndex["melee"] = ACT_HL2MP_IDLE_MELEE
26 ActIndex["slam"] = ACT_HL2MP_IDLE_SLAM
27 ActIndex["normal"] = ACT_HL2MP_IDLE
28 ActIndex["knife"] = ACT_HL2MP_IDLE_KNIFE
29 ActIndex["sword"] = ACT_HL2MP_IDLE_MELEE2
30 ActIndex["passive"] = ACT_HL2MP_IDLE_PASSIVE
31 ActIndex["fist"] = ACT_HL2MP_IDLE_FIST
32
33local ActIndex = {
34 [ "pistol" ] = ACT_HL2MP_IDLE_PISTOL,
35 [ "revolver" ] = ACT_HL2MP_IDLE_REVOLVER,
36 [ "smg" ] = ACT_HL2MP_IDLE_SMG1,
37 [ "grenade" ] = ACT_HL2MP_IDLE_GRENADE,
38 [ "ar2" ] = ACT_HL2MP_IDLE_AR2,
39 [ "shotgun" ] = ACT_HL2MP_IDLE_SHOTGUN,
40 [ "rpg" ] = ACT_HL2MP_IDLE_RPG,
41 [ "physgun" ] = ACT_HL2MP_IDLE_PHYSGUN,
42 [ "crossbow" ] = ACT_HL2MP_IDLE_CROSSBOW,
43 [ "melee" ] = ACT_HL2MP_IDLE_MELEE,
44 [ "slam" ] = ACT_HL2MP_IDLE_SLAM,
45 [ "normal" ] = ACT_HL2MP_IDLE,
46 [ "fist" ] = ACT_HL2MP_IDLE_FIST,
47 [ "melee2" ] = ACT_HL2MP_IDLE_MELEE2,
48 [ "passive" ] = ACT_HL2MP_IDLE_PASSIVE,
49 [ "knife" ] = ACT_HL2MP_IDLE_KNIFE
50}
51
52/*---------------------------------------------------------
53Initialize
54---------------------------------------------------------*/
55function SWEP:Initialize()
56self:SetWeaponHoldType( self.HoldType )
57end
58
59
60function SWEP:SetWeaponHoldType( t )
61 local index = ActIndex[ t ]
62 if (index == nil) then
63 Msg( "SWEP:SetWeaponHoldType - ActIndex[ \""..t.."\" ] isn't set! (defaulting to normal)\n" )
64 t = "normal"
65 end
66 if (index ~= nil) then
67 self.ActivityTranslate = {}
68 self.ActivityTranslate [ ACT_MP_STAND_IDLE ] = index
69 self.ActivityTranslate [ ACT_MP_WALK ] = index+1
70 self.ActivityTranslate [ ACT_MP_RUN ] = index+2
71 self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] = index+3
72 self.ActivityTranslate [ ACT_MP_CROUCHWALK ] = index+4
73 self.ActivityTranslate [ ACT_MP_ATTACK_STAND_PRIMARYFIRE ] = index+5
74 self.ActivityTranslate [ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ] = index+5
75 self.ActivityTranslate [ ACT_MP_RELOAD_STAND ] = index+6
76 self.ActivityTranslate [ ACT_MP_RELOAD_CROUCH ] = index+6
77 self.ActivityTranslate [ ACT_MP_JUMP ] = index+7
78 self.ActivityTranslate [ ACT_RANGE_ATTACK1 ] = index+8
79 end
80 if t == "normal" then
81 self.ActivityTranslate [ ACT_MP_JUMP ] = ACT_HL2MP_JUMP_SLAM
82 end
83 if t == "passive" then
84 self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] = ACT_HL2MP_CROUCH_IDLE
85 end
86 if t == "knife" || t == "melee2" then
87 self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] = nil
88 end
89 self:SetupWeaponHoldTypeForAI( t )
90 self._InternalHoldType = t
91end
92
93if (CLIENT) then
94SWEP.VElements = {
95 ["pistol"] = { type = "Model", model = "models/Halokiller38/fallout/weapons/Pistols/rangersequoia.mdl", bone = "MP412", rel = "", pos = Vector(-2.747, -0.25, -2.5), angle = Angle(0, -180, 0), size = Vector(0.75, 0.75, 0.75), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
96}
97SWEP.WElements = {
98 ["pistol"] = { type = "Model", model = "models/Halokiller38/fallout/weapons/Pistols/rangersequoia.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.944, -2.687, 1.498), angle = Angle(180, -90, 1), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
99}
100end
101
102
103
104SWEP.Base = "kermite_base_pistol"
105SWEP.Category = "Fallout Sweps - Pistols"
106
107SWEP.HoldType = "pistol"
108SWEP.ViewModelFOV = 60.000122072103
109SWEP.ViewModelFlip = false
110SWEP.ViewModel = "models/weapons/v_swep_mp412r.mdl"
111SWEP.WorldModel = "models/Halokiller38/fallout/weapons/Pistols/rangersequoia.mdl"
112SWEP.ShowViewModel = true
113SWEP.ShowWorldModel = false
114SWEP.ViewModelBoneMods = {
115 ["MP412_Bullet3"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0.059, 0.149, -0.559), angle = Angle(0, 0, 0) },
116 ["MP412_Cannon"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
117 ["MP412_Hammer"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
118 ["MP412_Bullet5"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0.05, 0.119, -0.151), angle = Angle(0, 0, 0) },
119 ["MP412_SpeedLoader"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
120 ["MP412_Bullet2"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0.059, 0.165, 0.223), angle = Angle(0, 0, 0) },
121 ["MP412"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
122 ["MP412_Trigger"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
123 ["MP412_Bullet4"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0.057, 0.145, -0.457), angle = Angle(0, 0, 0) },
124 ["MP412_Bullet1"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
125 ["MP412_Bullet6"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
126}
127
128SWEP.Spawnable = true
129SWEP.AdminSpawnable = false
130
131SWEP.Primary.Sound = Sound("weapons/pistol44magnum/wpn_44revolver.wav")
132SWEP.Primary.Recoil = 4
133SWEP.Primary.Damage = 65
134SWEP.Primary.NumShots = 1
135SWEP.Primary.Cone = 0.01
136SWEP.Primary.Delay = 0.8
137
138SWEP.Primary.ClipSize = 5 // Size of a clip
139SWEP.Primary.DefaultClip = 0 // Default number of bullets in a clip
140SWEP.Primary.Automatic = false // Automatic/Semi Auto
141SWEP.Primary.Ammo = "45-70Govt"
142
143SWEP.Secondary.ClipSize = -1 // Size of a clip
144SWEP.Secondary.DefaultClip = -1 // Default number of bullets in a clip
145SWEP.Secondary.Automatic = false // Automatic/Semi Auto
146SWEP.Secondary.Ammo = "none"
147
148/*---------------------------------------------------------
149Muzzle Effect + Shell Effect
150---------------------------------------------------------*/
151SWEP.MuzzleEffect = "rg_muzzle_rifle" -- This is an extra muzzleflash effect
152-- Available muzzle effects: rg_muzzle_grenade, rg_muzzle_highcal, rg_muzzle_hmg, rg_muzzle_pistol, rg_muzzle_rifle, rg_muzzle_silenced, none
153
154SWEP.ShellEffect = "rg_shelleject" -- This is a shell ejection effect
155-- Available shell eject effects: rg_shelleject, rg_shelleject_rifle, rg_shelleject_shotgun, none
156
157SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
158SWEP.ShellEjectAttachment = "2" -- Should be "2" for CSS models or "1" for hl2 models
159
160SWEP.EjectDelay = 0
161/*-------------------------------------------------------*/
162
163SWEP.IronSightsPos = Vector(-2.093, -1, -0.22)
164SWEP.IronSightsAng = Vector(0.474, -0.055, 0)
165SWEP.RunSightsPos = Vector (0.0961, 0, 5.9811)
166SWEP.RunSightsAng = Vector (-25.4014, 2.0332, 0)
167
168function SWEP:Reload()
169
170
171 -- If you're firering, you can't reload
172
173 self.Weapon:DefaultReload(ACT_VM_RELOAD)
174 -- Animation when you're reloading
175
176 if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
177 -- When the current clip < full clip and the rest of your ammo > 0, then
178
179 self.Owner:SetFOV( 0, 0.5 )
180 -- Zoom = 0
181 self:EmitSound( "weapons/357revolver/wpn_357revolver_reload.wav" )
182 self:SetIronsights(false)
183 -- Set the ironsight to false
184 end
185end
186
187
188
189
190
191/*---------------------------------------------------------
192 Name: SWEP:TranslateActivity()
193 Desc: Translate a player's activity into a weapon's activity.
194 So for example, ACT_HL2MP_RUN becomes ACT_HL2MP_RUN_PISTOL
195 depending on how you want the player to be holding the weapon.
196---------------------------------------------------------*/
197function SWEP:TranslateActivity(act)
198
199 if (self.Owner:IsNPC()) then
200 if (self.ActivityTranslateAI[act]) then
201 return self.ActivityTranslateAI[act]
202 end
203
204 return -1
205 end
206
207 if (self.ActivityTranslate[act] != nil) then
208 return self.ActivityTranslate[act]
209 end
210
211 return -1
212end
213
214
215function SWEP:Initialize()
216
217 // other initialize code goes here
218
219 if CLIENT then
220
221 // Create a new table for every weapon instance
222 self.VElements = table.FullCopy( self.VElements )
223 self.WElements = table.FullCopy( self.WElements )
224 self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
225
226 self:CreateModels(self.VElements) // create viewmodels
227 self:CreateModels(self.WElements) // create worldmodels
228
229 // init view model bone build function
230 if IsValid(self.Owner) then
231 local vm = self.Owner:GetViewModel()
232 if IsValid(vm) then
233 self:ResetBonePositions(vm)
234
235 // Init viewmodel visibility
236 if (self.ShowViewModel == nil or self.ShowViewModel) then
237 vm:SetColor(Color(255,255,255,255))
238 else
239 // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
240 vm:SetColor(Color(255,255,255,1))
241 // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
242 // 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
243 vm:SetMaterial("Debug/hsv")
244 end
245 end
246 end
247
248 end
249
250end
251
252function SWEP:Holster()
253
254 if CLIENT and IsValid(self.Owner) then
255 local vm = self.Owner:GetViewModel()
256 if IsValid(vm) then
257 self:ResetBonePositions(vm)
258 end
259 end
260
261 return true
262end
263
264function SWEP:OnRemove()
265 self:Holster()
266end
267
268if CLIENT then
269
270 SWEP.vRenderOrder = nil
271 function SWEP:ViewModelDrawn()
272
273 local vm = self.Owner:GetViewModel()
274 if !IsValid(vm) then return end
275
276 if (!self.VElements) then return end
277
278 self:UpdateBonePositions(vm)
279
280 if (!self.vRenderOrder) then
281
282 // we build a render order because sprites need to be drawn after models
283 self.vRenderOrder = {}
284
285 for k, v in pairs( self.VElements ) do
286 if (v.type == "Model") then
287 table.insert(self.vRenderOrder, 1, k)
288 elseif (v.type == "Sprite" or v.type == "Quad") then
289 table.insert(self.vRenderOrder, k)
290 end
291 end
292
293 end
294
295 for k, name in ipairs( self.vRenderOrder ) do
296
297 local v = self.VElements[name]
298 if (!v) then self.vRenderOrder = nil break end
299 if (v.hide) then continue end
300
301 local model = v.modelEnt
302 local sprite = v.spriteMaterial
303
304 if (!v.bone) then continue end
305
306 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
307
308 if (!pos) then continue end
309
310 if (v.type == "Model" and IsValid(model)) then
311
312 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
313 ang:RotateAroundAxis(ang:Up(), v.angle.y)
314 ang:RotateAroundAxis(ang:Right(), v.angle.p)
315 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
316
317 model:SetAngles(ang)
318 //model:SetModelScale(v.size)
319 local matrix = Matrix()
320 matrix:Scale(v.size)
321 model:EnableMatrix( "RenderMultiply", matrix )
322
323 if (v.material == "") then
324 model:SetMaterial("")
325 elseif (model:GetMaterial() != v.material) then
326 model:SetMaterial( v.material )
327 end
328
329 if (v.skin and v.skin != model:GetSkin()) then
330 model:SetSkin(v.skin)
331 end
332
333 if (v.bodygroup) then
334 for k, v in pairs( v.bodygroup ) do
335 if (model:GetBodygroup(k) != v) then
336 model:SetBodygroup(k, v)
337 end
338 end
339 end
340
341 if (v.surpresslightning) then
342 render.SuppressEngineLighting(true)
343 end
344
345 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
346 render.SetBlend(v.color.a/255)
347 model:DrawModel()
348 render.SetBlend(1)
349 render.SetColorModulation(1, 1, 1)
350
351 if (v.surpresslightning) then
352 render.SuppressEngineLighting(false)
353 end
354
355 elseif (v.type == "Sprite" and sprite) then
356
357 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
358 render.SetMaterial(sprite)
359 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
360
361 elseif (v.type == "Quad" and v.draw_func) then
362
363 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
364 ang:RotateAroundAxis(ang:Up(), v.angle.y)
365 ang:RotateAroundAxis(ang:Right(), v.angle.p)
366 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
367
368 cam.Start3D2D(drawpos, ang, v.size)
369 v.draw_func( self )
370 cam.End3D2D()
371
372 end
373
374 end
375
376 end
377
378 SWEP.wRenderOrder = nil
379 function SWEP:DrawWorldModel()
380
381 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
382 self:DrawModel()
383 end
384
385 if (!self.WElements) then return end
386
387 if (!self.wRenderOrder) then
388
389 self.wRenderOrder = {}
390
391 for k, v in pairs( self.WElements ) do
392 if (v.type == "Model") then
393 table.insert(self.wRenderOrder, 1, k)
394 elseif (v.type == "Sprite" or v.type == "Quad") then
395 table.insert(self.wRenderOrder, k)
396 end
397 end
398
399 end
400
401 if (IsValid(self.Owner)) then
402 bone_ent = self.Owner
403 else
404 // when the weapon is dropped
405 bone_ent = self
406 end
407
408 for k, name in pairs( self.wRenderOrder ) do
409
410 local v = self.WElements[name]
411 if (!v) then self.wRenderOrder = nil break end
412 if (v.hide) then continue end
413
414 local pos, ang
415
416 if (v.bone) then
417 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
418 else
419 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
420 end
421
422 if (!pos) then continue end
423
424 local model = v.modelEnt
425 local sprite = v.spriteMaterial
426
427 if (v.type == "Model" and IsValid(model)) then
428
429 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
430 ang:RotateAroundAxis(ang:Up(), v.angle.y)
431 ang:RotateAroundAxis(ang:Right(), v.angle.p)
432 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
433
434 model:SetAngles(ang)
435 //model:SetModelScale(v.size)
436 local matrix = Matrix()
437 matrix:Scale(v.size)
438 model:EnableMatrix( "RenderMultiply", matrix )
439
440 if (v.material == "") then
441 model:SetMaterial("")
442 elseif (model:GetMaterial() != v.material) then
443 model:SetMaterial( v.material )
444 end
445
446 if (v.skin and v.skin != model:GetSkin()) then
447 model:SetSkin(v.skin)
448 end
449
450 if (v.bodygroup) then
451 for k, v in pairs( v.bodygroup ) do
452 if (model:GetBodygroup(k) != v) then
453 model:SetBodygroup(k, v)
454 end
455 end
456 end
457
458 if (v.surpresslightning) then
459 render.SuppressEngineLighting(true)
460 end
461
462 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
463 render.SetBlend(v.color.a/255)
464 model:DrawModel()
465 render.SetBlend(1)
466 render.SetColorModulation(1, 1, 1)
467
468 if (v.surpresslightning) then
469 render.SuppressEngineLighting(false)
470 end
471
472 elseif (v.type == "Sprite" and sprite) then
473
474 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
475 render.SetMaterial(sprite)
476 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
477
478 elseif (v.type == "Quad" and v.draw_func) then
479
480 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
481 ang:RotateAroundAxis(ang:Up(), v.angle.y)
482 ang:RotateAroundAxis(ang:Right(), v.angle.p)
483 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
484
485 cam.Start3D2D(drawpos, ang, v.size)
486 v.draw_func( self )
487 cam.End3D2D()
488
489 end
490
491 end
492
493 end
494
495 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
496
497 local bone, pos, ang
498 if (tab.rel and tab.rel != "") then
499
500 local v = basetab[tab.rel]
501
502 if (!v) then return end
503
504 // Technically, if there exists an element with the same name as a bone
505 // you can get in an infinite loop. Let's just hope nobody's that stupid.
506 pos, ang = self:GetBoneOrientation( basetab, v, ent )
507
508 if (!pos) then return end
509
510 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
511 ang:RotateAroundAxis(ang:Up(), v.angle.y)
512 ang:RotateAroundAxis(ang:Right(), v.angle.p)
513 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
514
515 else
516
517 bone = ent:LookupBone(bone_override or tab.bone)
518
519 if (!bone) then return end
520
521 pos, ang = Vector(0,0,0), Angle(0,0,0)
522 local m = ent:GetBoneMatrix(bone)
523 if (m) then
524 pos, ang = m:GetTranslation(), m:GetAngles()
525 end
526
527 if (IsValid(self.Owner) and self.Owner:IsPlayer() and
528 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
529 ang.r = -ang.r // Fixes mirrored models
530 end
531
532 end
533
534 return pos, ang
535 end
536
537 function SWEP:CreateModels( tab )
538
539 if (!tab) then return end
540
541 // Create the clientside models here because Garry says we can't do it in the render hook
542 for k, v in pairs( tab ) do
543 if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
544 string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
545
546 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
547 if (IsValid(v.modelEnt)) then
548 v.modelEnt:SetPos(self:GetPos())
549 v.modelEnt:SetAngles(self:GetAngles())
550 v.modelEnt:SetParent(self)
551 v.modelEnt:SetNoDraw(true)
552 v.createdModel = v.model
553 else
554 v.modelEnt = nil
555 end
556
557 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
558 and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
559
560 local name = v.sprite.."-"
561 local params = { ["$basetexture"] = v.sprite }
562 // make sure we create a unique name based on the selected options
563 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
564 for i, j in pairs( tocheck ) do
565 if (v[j]) then
566 params["$"..j] = 1
567 name = name.."1"
568 else
569 name = name.."0"
570 end
571 end
572
573 v.createdSprite = v.sprite
574 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
575
576 end
577 end
578
579 end
580
581 local allbones
582 local hasGarryFixedBoneScalingYet = false
583
584 function SWEP:UpdateBonePositions(vm)
585
586 if self.ViewModelBoneMods then
587
588 if (!vm:GetBoneCount()) then return end
589
590 // !! WORKAROUND !! //
591 // We need to check all model names :/
592 local loopthrough = self.ViewModelBoneMods
593 if (!hasGarryFixedBoneScalingYet) then
594 allbones = {}
595 for i=0, vm:GetBoneCount() do
596 local bonename = vm:GetBoneName(i)
597 if (self.ViewModelBoneMods[bonename]) then
598 allbones[bonename] = self.ViewModelBoneMods[bonename]
599 else
600 allbones[bonename] = {
601 scale = Vector(1,1,1),
602 pos = Vector(0,0,0),
603 angle = Angle(0,0,0)
604 }
605 end
606 end
607
608 loopthrough = allbones
609 end
610 // !! ----------- !! //
611
612 for k, v in pairs( loopthrough ) do
613 local bone = vm:LookupBone(k)
614 if (!bone) then continue end
615
616 // !! WORKAROUND !! //
617 local s = Vector(v.scale.x,v.scale.y,v.scale.z)
618 local p = Vector(v.pos.x,v.pos.y,v.pos.z)
619 local ms = Vector(1,1,1)
620 if (!hasGarryFixedBoneScalingYet) then
621 local cur = vm:GetBoneParent(bone)
622 while(cur >= 0) do
623 local pscale = loopthrough[vm:GetBoneName(cur)].scale
624 ms = ms * pscale
625 cur = vm:GetBoneParent(cur)
626 end
627 end
628
629 s = s * ms
630 // !! ----------- !! //
631
632 if vm:GetManipulateBoneScale(bone) != s then
633 vm:ManipulateBoneScale( bone, s )
634 end
635 if vm:GetManipulateBoneAngles(bone) != v.angle then
636 vm:ManipulateBoneAngles( bone, v.angle )
637 end
638 if vm:GetManipulateBonePosition(bone) != p then
639 vm:ManipulateBonePosition( bone, p )
640 end
641 end
642 else
643 self:ResetBonePositions(vm)
644 end
645
646 end
647
648 function SWEP:ResetBonePositions(vm)
649
650 if (!vm:GetBoneCount()) then return end
651 for i=0, vm:GetBoneCount() do
652 vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
653 vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
654 vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
655 end
656
657 end
658
659 /**************************
660 Global utility code
661 **************************/
662
663 // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
664 // Does not copy entities of course, only copies their reference.
665 // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
666 function table.FullCopy( tab )
667
668 if (!tab) then return nil end
669
670 local res = {}
671 for k, v in pairs( tab ) do
672 if (type(v) == "table") then
673 res[k] = table.FullCopy(v) // recursion ho!
674 elseif (type(v) == "Vector") then
675 res[k] = Vector(v.x, v.y, v.z)
676 elseif (type(v) == "Angle") then
677 res[k] = Angle(v.p, v.y, v.r)
678 else
679 res[k] = v
680 end
681 end
682
683 return res
684
685 end
686
687end