· 7 years ago · Jan 18, 2019, 02:06 PM
1
2 return end
3
4 if self.Owner:KeyDown(IN_USE) then return end
5
6 if self.Silenced then
7 self.Weapon:DefaultReload(ACT_VM_RELOAD_SILENCED)
8 else
9 self.Weapon:DefaultReload(ACT_VM_RELOAD)
10 end
11
12 if !self.Owner:IsNPC() then
13 if self.Owner:GetViewModel() == nil then self.ResetSights = CurTime() + 3 else
14 self.ResetSights = CurTime() + self.Owner:GetViewModel():SequenceDuration()
15 end
16 end
17
18 if SERVER and self.Weapon != nil then
19 if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and !self.Owner:IsNPC() then
20 -- //When the current clip < full clip and the rest of your ammo > 0, then
21 self.Owner:SetFOV( 0, 0.3 )
22 -- //Zoom = 0
23 self:SetIronsights(false)
24 -- //Set the ironsight to false
25 self.Weapon:SetNWBool("Reloading", true)
26 end
27 local waitdammit = (self.Owner:GetViewModel():SequenceDuration())
28 timer.Simple(waitdammit + .1,
29 function()
30 if self.Weapon == nil then return end
31 self.Weapon:SetNWBool("Reloading", false)
32 if self.Owner:KeyDown(IN_ATTACK2) and self.Weapon:GetClass() == self.Gun then
33 if CLIENT then return end
34 if self.Scoped == false then
35 self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
36 self.IronSightsPos = self.SightsPos -- Bring it up
37 self.IronSightsAng = self.SightsAng -- Bring it up
38 self:SetIronsights(true, self.Owner)
39 self.DrawCrosshair = false
40 else return end
41 elseif self.Owner:KeyDown(IN_SPEED) and self.Weapon:GetClass() == self.Gun then
42 if self.Weapon:GetNextPrimaryFire() <= (CurTime() + .03) then
43 self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
44 end
45 self.IronSightsPos = self.RunSightsPos -- Hold it down
46 self.IronSightsAng = self.RunSightsAng -- Hold it down
47 self:SetIronsights(true, self.Owner) -- Set the ironsight true
48 self.Owner:SetFOV( 0, 0.3 )
49 else return end
50 end)
51 end
52end
53
54function SWEP:PostReloadScopeCheck()
55 if self.Weapon == nil then return end
56 self.Weapon:SetNWBool("Reloading", false)
57 if self.Owner:KeyDown(IN_ATTACK2) and self.Weapon:GetClass() == self.Gun then
58 if CLIENT then return end
59 if self.Scoped == false then
60 self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
61 self.IronSightsPos = self.SightsPos -- Bring it up
62 self.IronSightsAng = self.SightsAng -- Bring it up
63 self:SetIronsights(true, self.Owner)
64 self.DrawCrosshair = false
65 else return end
66 elseif self.Owner:KeyDown(IN_SPEED) and self.Weapon:GetClass() == self.Gun then
67 if self.Weapon:GetNextPrimaryFire() <= (CurTime() + .03) then
68 self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
69 end
70 self.IronSightsPos = self.RunSightsPos -- Hold it down
71 self.IronSightsAng = self.RunSightsAng -- Hold it down
72 self:SetIronsights(true, self.Owner) -- Set the ironsight true
73 self.Owner:SetFOV( 0, 0.3 )
74 else return end
75end
76
77function SWEP:Silencer()
78
79 if self.NextSilence > CurTime() then return end
80
81 if self.Weapon != nil then
82 self.Owner:SetFOV( 0, 0.3 )
83 self:SetIronsights(false)
84 self.Weapon:SetNWBool("Reloading", true) -- i know we're not reloading but it works
85 end
86
87 if self.Silenced then
88 self:SendWeaponAnim(ACT_VM_DETACH_SILENCER)
89 self.Silenced = false
90 elseif not self.Silenced then
91 self:SendWeaponAnim(ACT_VM_ATTACH_SILENCER)
92 self.Silenced = true
93 end
94
95 siltimer = CurTime() + (self.Owner:GetViewModel():SequenceDuration()) + 0.1
96 if self.Weapon:GetNextPrimaryFire() <= siltimer then
97 self.Weapon:SetNextPrimaryFire(siltimer)
98 end
99 self.NextSilence = siltimer
100
101 timer.Simple( ((self.Owner:GetViewModel():SequenceDuration()) + 0.1),
102 function()
103 if self.Weapon != nil then
104 self.Weapon:SetNWBool("Reloading", false)
105 if self.Owner:KeyDown(IN_ATTACK2) and self.Weapon:GetClass() == self.Gun then
106 if CLIENT then return end
107 if self.Scoped == false then
108 self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
109 self.IronSightsPos = self.SightsPos -- Bring it up
110 self.IronSightsAng = self.SightsAng -- Bring it up
111 self:SetIronsights(true, self.Owner)
112 self.DrawCrosshair = false
113 else return end
114 elseif self.Owner:KeyDown(IN_SPEED) and self.Weapon:GetClass() == self.Gun then
115 if self.Weapon:GetNextPrimaryFire() <= (CurTime()+0.3) then
116 self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
117 end
118 self.IronSightsPos = self.RunSightsPos -- Hold it down
119 self.IronSightsAng = self.RunSightsAng -- Hold it down
120 self:SetIronsights(true, self.Owner) -- Set the ironsight true
121 self.Owner:SetFOV( 0, 0.3 )
122 else return end
123 end
124 end)
125
126end
127
128function SWEP:SelectFireMode()
129
130 if self.Primary.Automatic then
131 self.Primary.Automatic = false
132 self.NextFireSelect = CurTime() + .5
133 if CLIENT then
134 self.Owner:PrintMessage(HUD_PRINTTALK, "Semi-automatic selected.")
135 end
136 self.Weapon:EmitSound("Weapon_AR2.Empty")
137 else
138 self.Primary.Automatic = true
139 self.NextFireSelect = CurTime() + .5
140 if CLIENT then
141 self.Owner:PrintMessage(HUD_PRINTTALK, "Automatic selected.")
142 end
143 self.Weapon:EmitSound("Weapon_AR2.Empty")
144 end
145end
146
147
148/*---------------------------------------------------------
149IronSight
150-----------------------------------------------------*/
151function SWEP:IronSight()
152
153 if not IsValid(self) then return end
154 if not IsValid(self.Owner) then return end
155
156 if !self.Owner:IsNPC() then
157 if self.ResetSights and CurTime() >= self.ResetSights then
158 self.ResetSights = nil
159
160 if self.Silenced then
161 self:SendWeaponAnim(ACT_VM_IDLE_SILENCED)
162 else
163 self:SendWeaponAnim(ACT_VM_IDLE)
164 end
165 end end
166
167 if self.CanBeSilenced and self.NextSilence < CurTime() then
168 if self.Owner:KeyDown(IN_USE) and self.Owner:KeyPressed(IN_ATTACK2) then
169 self:Silencer()
170 end
171 end
172
173 if self.SelectiveFire and self.NextFireSelect < CurTime() and not (self.Weapon:GetNWBool("Reloading")) then
174 if self.Owner:KeyDown(IN_USE) and self.Owner:KeyPressed(IN_RELOAD) then
175 self:SelectFireMode()
176 end
177 end
178
179-- //copy this...
180 if self.Owner:KeyPressed(IN_SPEED) and not (self.Weapon:GetNWBool("Reloading")) then -- If you are running
181 if self.Weapon:GetNextPrimaryFire() <= (CurTime()+0.3) then
182 self.Weapon:SetNextPrimaryFire(CurTime()+0.3) -- Make it so you can't shoot for another quarter second
183 end
184 self.IronSightsPos = self.RunSightsPos -- Hold it down
185 self.IronSightsAng = self.RunSightsAng -- Hold it down
186 self:SetIronsights(true, self.Owner) -- Set the ironsight true
187 self.Owner:SetFOV( 0, 0.3 )
188 self.DrawCrosshair = false
189 end
190
191 if self.Owner:KeyReleased (IN_SPEED) then -- If you release run then
192 self:SetIronsights(false, self.Owner) -- Set the ironsight true
193 self.Owner:SetFOV( 0, 0.3 )
194 self.DrawCrosshair = self.OrigCrossHair
195 end -- Shoulder the gun
196
197-- //down to this
198 if !self.Owner:KeyDown(IN_USE) and !self.Owner:KeyDown(IN_SPEED) then
199 -- //If the key E (Use Key) is not pressed, then
200
201 if self.Owner:KeyPressed(IN_ATTACK2) and not (self.Weapon:GetNWBool("Reloading")) then
202 self.Owner:SetFOV( self.Secondary.IronFOV, 0.3 )
203 self.IronSightsPos = self.SightsPos -- Bring it up
204 self.IronSightsAng = self.SightsAng -- Bring it up
205 self:SetIronsights(true, self.Owner)
206 self.DrawCrosshair = false
207 -- //Set the ironsight true
208
209 if CLIENT then return end
210 end
211 end
212
213 if self.Owner:KeyReleased(IN_ATTACK2) and !self.Owner:KeyDown(IN_USE) and !self.Owner:KeyDown(IN_SPEED) then
214 -- //If the right click is released, then
215 self.Owner:SetFOV( 0, 0.3 )
216 self.DrawCrosshair = self.OrigCrossHair
217 self:SetIronsights(false, self.Owner)
218 -- //Set the ironsight false
219
220 if CLIENT then return end
221 end
222
223 if self.Owner:KeyDown(IN_ATTACK2) and !self.Owner:KeyDown(IN_USE) and !self.Owner:KeyDown(IN_SPEED) then
224 self.SwayScale = 0.05
225 self.BobScale = 0.05
226 else
227 self.SwayScale = 1.0
228 self.BobScale = 1.0
229 end
230end
231
232/*---------------------------------------------------------
233Think
234-----------------------------------------------------*/
235function SWEP:Think()
236
237self:IronSight()
238
239end
240
241/*---------------------------------------------------------
242GetViewModelPosition
243-----------------------------------------------------*/
244local IRONSIGHT_TIME = 0.3
245-- //Time to enter in the ironsight mod
246
247function SWEP:GetViewModelPosition(pos, ang)
248
249 if (not self.IronSightsPos) then return pos, ang end
250
251 local bIron = self.Weapon:GetNWBool("M9K_Ironsights")
252
253 if (bIron != self.bLastIron) then
254 self.bLastIron = bIron
255 self.fIronTime = CurTime()
256
257 end
258
259 local fIronTime = self.fIronTime or 0
260
261 if (not bIron and fIronTime < CurTime() - IRONSIGHT_TIME) then
262 return pos, ang
263 end
264
265 local Mul = 1.0
266
267 if (fIronTime > CurTime() - IRONSIGHT_TIME) then
268 Mul = math.Clamp((CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1)
269
270 if not bIron then Mul = 1 - Mul end
271 end
272
273 local Offset = self.IronSightsPos
274
275 if (self.IronSightsAng) then
276 ang = ang * 1
277 ang:RotateAroundAxis(ang:Right(), self.IronSightsAng.x * Mul)
278 ang:RotateAroundAxis(ang:Up(), self.IronSightsAng.y * Mul)
279 ang:RotateAroundAxis(ang:Forward(), self.IronSightsAng.z * Mul)
280 end
281
282 local Right = ang:Right()
283 local Up = ang:Up()
284 local Forward = ang:Forward()
285
286 pos = pos + Offset.x * Right * Mul
287 pos = pos + Offset.y * Forward * Mul
288 pos = pos + Offset.z * Up * Mul
289
290 return pos, ang
291end
292
293/*---------------------------------------------------------
294SetIronsights
295-----------------------------------------------------*/
296function SWEP:SetIronsights(b)
297 self.Weapon:SetNWBool("M9K_Ironsights", b)
298end
299
300function SWEP:GetIronsights()
301 return self.Weapon:GetNWBool("M9K_Ironsights")
302end
303
304
305if CLIENT then
306
307 SWEP.vRenderOrder = nil
308 function SWEP:ViewModelDrawn()
309
310 if not IsValid(self) then return end
311 if not IsValid(self.Owner) then return end
312 local vm = self.Owner:GetViewModel()
313 if !IsValid(vm) then return end
314
315 if (!self.VElements) then return end
316
317 self:UpdateBonePositions(vm)
318
319 if (!self.vRenderOrder) then
320
321 -- // we build a render order because sprites need to be drawn after models
322 self.vRenderOrder = {}
323
324 for k, v in pairs( self.VElements ) do
325 if (v.type == "Model") then
326 table.insert(self.vRenderOrder, 1, k)
327 elseif (v.type == "Sprite" or v.type == "Quad") then
328 table.insert(self.vRenderOrder, k)
329 end
330 end
331
332 end
333
334 for k, name in ipairs( self.vRenderOrder ) do
335
336 local v = self.VElements[name]
337 if (!v) then self.vRenderOrder = nil break end
338 if (v.hide) then continue end
339
340 local model = v.modelEnt
341 local sprite = v.spriteMaterial
342
343 if (!v.bone) then continue end
344
345 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
346
347 if (!pos) then continue end
348
349 if (v.type == "Model" and IsValid(model)) then
350
351 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
352 ang:RotateAroundAxis(ang:Up(), v.angle.y)
353 ang:RotateAroundAxis(ang:Right(), v.angle.p)
354 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
355
356 model:SetAngles(ang)
357 -- //model:SetModelScale(v.size)
358 local matrix = Matrix()
359 matrix:Scale(v.size)
360 model:EnableMatrix( "RenderMultiply", matrix )
361
362 if (v.material == "") then
363 model:SetMaterial("")
364 elseif (model:GetMaterial() != v.material) then
365 model:SetMaterial( v.material )
366 end
367
368 if (v.skin and v.skin != model:GetSkin()) then
369 model:SetSkin(v.skin)
370 end
371
372 if (v.bodygroup) then
373 for k, v in pairs( v.bodygroup ) do
374 if (model:GetBodygroup(k) != v) then
375 model:SetBodygroup(k, v)
376 end
377 end
378 end
379
380 if (v.surpresslightning) then
381 render.SuppressEngineLighting(true)
382 end
383
384 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
385 render.SetBlend(v.color.a/255)
386 model:DrawModel()
387 render.SetBlend(1)
388 render.SetColorModulation(1, 1, 1)
389
390 if (v.surpresslightning) then
391 render.SuppressEngineLighting(false)
392 end
393
394 elseif (v.type == "Sprite" and sprite) then
395
396 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
397 render.SetMaterial(sprite)
398 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
399
400 elseif (v.type == "Quad" and v.draw_func) then
401
402 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
403 ang:RotateAroundAxis(ang:Up(), v.angle.y)
404 ang:RotateAroundAxis(ang:Right(), v.angle.p)
405 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
406
407 cam.Start3D2D(drawpos, ang, v.size)
408 v.draw_func( self )
409 cam.End3D2D()
410
411 end
412
413 end
414
415 end
416
417 SWEP.wRenderOrder = nil
418 function SWEP:DrawWorldModel()
419
420 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
421 self:DrawModel()
422 end
423
424 if (!self.WElements) then return end
425
426 if (!self.wRenderOrder) then
427
428 self.wRenderOrder = {}
429
430 for k, v in pairs( self.WElements ) do
431 if (v.type == "Model") then
432 table.insert(self.wRenderOrder, 1, k)
433 elseif (v.type == "Sprite" or v.type == "Quad") then
434 table.insert(self.wRenderOrder, k)
435 end
436 end
437
438 end
439
440 if (IsValid(self.Owner)) then
441 bone_ent = self.Owner
442 else
443 -- // when the weapon is dropped
444 bone_ent = self
445 end
446
447 for k, name in pairs( self.wRenderOrder ) do
448
449 local v = self.WElements[name]
450 if (!v) then self.wRenderOrder = nil break end
451 if (v.hide) then continue end
452
453 local pos, ang
454
455 if (v.bone) then
456 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
457 else
458 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
459 end
460
461 if (!pos) then continue end
462
463 local model = v.modelEnt
464 local sprite = v.spriteMaterial
465
466 if (v.type == "Model" and IsValid(model)) then
467
468 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
469 ang:RotateAroundAxis(ang:Up(), v.angle.y)
470 ang:RotateAroundAxis(ang:Right(), v.angle.p)
471 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
472
473 model:SetAngles(ang)
474 -- //model:SetModelScale(v.size)
475 local matrix = Matrix()
476 matrix:Scale(v.size)
477 model:EnableMatrix( "RenderMultiply", matrix )
478
479 if (v.material == "") then
480 model:SetMaterial("")
481 elseif (model:GetMaterial() != v.material) then
482 model:SetMaterial( v.material )
483 end
484
485 if (v.skin and v.skin != model:GetSkin()) then
486 model:SetSkin(v.skin)
487 end
488
489 if (v.bodygroup) then
490 for k, v in pairs( v.bodygroup ) do
491 if (model:GetBodygroup(k) != v) then
492 model:SetBodygroup(k, v)
493 end
494 end
495 end
496
497 if (v.surpresslightning) then
498 render.SuppressEngineLighting(true)
499 end
500
501 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
502 render.SetBlend(v.color.a/255)
503 model:DrawModel()
504 render.SetBlend(1)
505 render.SetColorModulation(1, 1, 1)
506
507 if (v.surpresslightning) then
508 render.SuppressEngineLighting(false)
509 end
510
511 elseif (v.type == "Sprite" and sprite) then
512
513 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
514 render.SetMaterial(sprite)
515 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
516
517 elseif (v.type == "Quad" and v.draw_func) then
518
519 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
520 ang:RotateAroundAxis(ang:Up(), v.angle.y)
521 ang:RotateAroundAxis(ang:Right(), v.angle.p)
522 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
523
524 cam.Start3D2D(drawpos, ang, v.size)
525 v.draw_func( self )
526 cam.End3D2D()
527
528 end
529
530 end
531
532 end
533
534 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
535
536 local bone, pos, ang
537 if (tab.rel and tab.rel != "") then
538
539 local v = basetab[tab.rel]
540
541 if (!v) then return end
542
543 -- // Technically, if there exists an element with the same name as a bone
544 -- // you can get in an infinite loop. Let's just hope nobody's that stupid.
545 pos, ang = self:GetBoneOrientation( basetab, v, ent )
546
547 if (!pos) then return end
548
549 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
550 ang:RotateAroundAxis(ang:Up(), v.angle.y)
551 ang:RotateAroundAxis(ang:Right(), v.angle.p)
552 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
553
554 else
555
556 bone = ent:LookupBone(bone_override or tab.bone)
557
558 if (!bone) then return end
559
560 pos, ang = Vector(0,0,0), Angle(0,0,0)
561 local m = ent:GetBoneMatrix(bone)
562 if (m) then
563 pos, ang = m:GetTranslation(), m:GetAngles()
564 end
565
566 if (IsValid(self.Owner) and self.Owner:IsPlayer() and
567 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
568 ang.r = -ang.r --// Fixes mirrored models
569 end
570
571 end
572
573 return pos, ang
574 end
575
576 function SWEP:CreateModels( tab )
577
578 if (!tab) then return end
579
580 -- // Create the clientside models here because Garry says we can't do it in the render hook
581 for k, v in pairs( tab ) do
582 if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
583 string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
584
585 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
586 if (IsValid(v.modelEnt)) then
587 v.modelEnt:SetPos(self:GetPos())
588 v.modelEnt:SetAngles(self:GetAngles())
589 v.modelEnt:SetParent(self)
590 v.modelEnt:SetNoDraw(true)
591 v.createdModel = v.model
592 else
593 v.modelEnt = nil
594 end
595
596 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
597 and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
598
599 local name = v.sprite.."-"
600 local params = { ["$basetexture"] = v.sprite }
601 -- // make sure we create a unique name based on the selected options
602 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
603 for i, j in pairs( tocheck ) do
604 if (v[j]) then
605 params["$"..j] = 1
606 name = name.."1"
607 else
608 name = name.."0"
609 end
610 end
611
612 v.createdSprite = v.sprite
613 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
614
615 end
616 end
617
618 end
619
620 local allbones
621 local hasGarryFixedBoneScalingYet = false
622
623 function SWEP:UpdateBonePositions(vm)
624
625 if self.ViewModelBoneMods then
626
627 if (!vm:GetBoneCount()) then return end
628
629 -- // !! WORKAROUND !! --//
630 -- // We need to check all model names :/
631 local loopthrough = self.ViewModelBoneMods
632 if (!hasGarryFixedBoneScalingYet) then
633 allbones = {}
634 for i=0, vm:GetBoneCount() do
635 local bonename = vm:GetBoneName(i)
636 if (self.ViewModelBoneMods[bonename]) then
637 allbones[bonename] = self.ViewModelBoneMods[bonename]
638 else
639 allbones[bonename] = {
640 scale = Vector(1,1,1),
641 pos = Vector(0,0,0),
642 angle = Angle(0,0,0)
643 }
644 end
645 end
646
647 loopthrough = allbones
648 end
649 //!! ----------- !! --
650
651 for k, v in pairs( loopthrough ) do
652 local bone = vm:LookupBone(k)
653 if (!bone) then continue end
654
655 -- // !! WORKAROUND !! --//
656 local s = Vector(v.scale.x,v.scale.y,v.scale.z)
657 local p = Vector(v.pos.x,v.pos.y,v.pos.z)
658 local ms = Vector(1,1,1)
659 if (!hasGarryFixedBoneScalingYet) then
660 local cur = vm:GetBoneParent(bone)
661 while(cur >= 0) do
662 local pscale = loopthrough[vm:GetBoneName(cur)].scale
663 ms = ms * pscale
664 cur = vm:GetBoneParent(cur)
665 end
666 end
667
668 s = s * ms
669 //!! ----------- !! --
670
671 if vm:GetManipulateBoneScale(bone) != s then
672 vm:ManipulateBoneScale( bone, s )
673 end
674 if vm:GetManipulateBoneAngles(bone) != v.angle then
675 vm:ManipulateBoneAngles( bone, v.angle )
676 end
677 if vm:GetManipulateBonePosition(bone) != p then
678 vm:ManipulateBonePosition( bone, p )
679 end
680 end
681 else
682 self:ResetBonePositions(vm)
683 end
684
685 end
686
687 function SWEP:ResetBonePositions(vm)
688
689 if (!vm:GetBoneCount()) then return end
690 for i=0, vm:GetBoneCount() do
691 vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
692 vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
693 vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
694 end
695
696 end
697
698 /**************************
699 Global utility code
700 **************************/
701
702 -- // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
703 -- // Does not copy entities of course, only copies their reference.
704 -- // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
705 function table.FullCopy( tab )
706
707 if (!tab) then return nil end
708
709 local res = {}
710 for k, v in pairs( tab ) do
711 if (type(v) == "table") then
712 res[k] = table.FullCopy(v) --// recursion ho!
713 elseif (type(v) == "Vector") then
714 res[k] = Vector(v.x, v.y, v.z)
715 elseif (type(v) == "Angle") then
716 res[k] = Angle(v.p, v.y, v.r)
717 else
718 res[k] = v
719 end
720 end
721
722 return res
723
724 end
725
726end