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