· 8 years ago · Jan 13, 2018, 02:04 PM
1AddCSLuaFile()
2CreateConVar( "disguise_swep_time", 900, {FCVAR_ARCHIVE,FCVAR_REPLICATED}, "")
3
4if SERVER then
5
6 util.AddNetworkString( "use_agentweapon" )
7 util.AddNetworkString( "timer_agentweapon" )
8
9 net.Receive("use_agentweapon",function(len,ply)
10 if not IsValid(ply) then return end
11 if ply:GetActiveWeapon():GetClass() != "weapon_agent" then return end
12 local num = net.ReadFloat()
13 local model
14 local old = ply:GetModel()
15
16
17 if type(RPExtraTeams[num].model) == "table" then
18 model = RPExtraTeams[num].model[1]
19 else
20 model = RPExtraTeams[num].model
21 end
22
23 if model == nil then return end
24
25 ply:GetActiveWeapon():SendWeaponAnim( ACT_VM_PRIMARYATTACK )
26
27 if ply:LookupBone("ValveBiped.Bip01_R_Foot") != nil then
28 ParticleEffectAttach( "generic_smoke", 4, ply, ply:LookupBone("ValveBiped.Bip01_R_Foot") )
29 ParticleEffectAttach( "generic_smoke", 4, ply, ply:LookupBone("ValveBiped.Bip01_L_Foot") )
30 ParticleEffectAttach( "generic_smoke", 4, ply, ply:LookupBone("ValveBiped.Bip01_R_Foot") )
31 end
32 ply:Freeze(true)
33 timer.Simple(4.4,function()
34 if IsValid(ply) then
35 ply:SetModel(model)
36 ply:StopParticles()
37 ply:SetNWBool("istransformed",true)
38 ply:Freeze(false)
39
40 net.Start("timer_agentweapon") net.WriteString(model) net.Send(ply)
41
42
43
44 ply:StripWeapon("weapon_agent")
45
46 timer.Simple(GetConVar("disguise_swep_time"):GetFloat(),function()
47 if ply:GetNWBool("istransformed") == false then return end
48 if ply:LookupBone("ValveBiped.Bip01_R_Foot") != nil then
49 ParticleEffectAttach( "generic_smoke", 4, ply, ply:LookupBone("ValveBiped.Bip01_R_Foot") )
50 ParticleEffectAttach( "generic_smoke", 4, ply, ply:LookupBone("ValveBiped.Bip01_L_Foot") )
51 ParticleEffectAttach( "generic_smoke", 4, ply, ply:LookupBone("ValveBiped.Bip01_R_Foot") )
52 end
53 ply:Freeze(true)
54 timer.Simple(4.4,function()
55 ply:SetModel(old)
56 ply:SetNWBool("istransformed",false)
57
58 ply:Freeze(false)
59
60
61 end)
62
63
64 end)
65
66
67 end
68 end)
69
70
71
72
73
74 end)
75
76
77end
78
79
80
81
82
83SWEP.PrintName = "МаÑкировка"
84SWEP.Author = ""
85SWEP.Instructions = ""
86SWEP.Spawnable = true
87SWEP.Category = "МаÑкировка"
88
89SWEP.Primary.ClipSize = -1
90SWEP.Primary.DefaultClip = -1
91SWEP.Primary.Automatic = false
92SWEP.Primary.Ammo = "none"
93
94SWEP.Secondary.ClipSize = -1
95SWEP.Secondary.DefaultClip = -1
96SWEP.Secondary.Automatic = false
97SWEP.Secondary.Ammo = "none"
98
99
100
101SWEP.HoldType = "slam"
102SWEP.ViewModelFOV = 70
103SWEP.ViewModelFlip = false
104SWEP.UseHands = false
105SWEP.ViewModel = "models/weapons/v_c4.mdl"
106SWEP.WorldModel = "models/weapons/w_c4.mdl"
107SWEP.ShowViewModel = true
108SWEP.ShowWorldModel = true
109SWEP.ViewModelBoneMods = {}
110
111
112
113
114SWEP.VElements = {
115 ["screen"] = { type = "Quad", bone = "v_weapon.c4", rel = "", pos = Vector(2.786, 0.390, 8.5), angle = Angle(174.967, 3.197, -46.361), size = 1, draw_func = nil}
116}
117
118
119if CLIENT then
120
121
122
123
124
125
126
127
128
129 net.Receive("timer_agentweapon",function()
130 local time = GetConVar("disguise_swep_time"):GetFloat()
131 local mdl = net.ReadString()
132 local finish = CurTime()+time
133
134
135 local p2 = vgui.Create("DPanel")
136 p2:SetSize(365,25)
137 p2:SetPos(5,ScrH( ) - 175)
138 function p2:Paint(w,h)
139 draw.RoundedBox(0,5,5,365,15,Color(0,0,0,240))
140 draw.RoundedBox(0,5,5,(finish-CurTime())*(300/time),15,Color(100,100,100,240))
141 draw.SimpleText("МаÑкировка","DebugFixedSmall",182,10,Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
142 end
143
144 timer.Simple(time,function()
145 p2:Remove()
146 end)
147
148
149
150
151 end)
152
153
154
155end
156
157
158
159
160
161
162
163
164
165
166
167
168function SWEP:Initialize()
169 self:SetHoldType( "slam" )
170 // other initialize code goes here
171
172 if CLIENT then
173
174
175 // Create a new table for every weapon instance
176 self.VElements = table.FullCopy( self.VElements )
177 self.WElements = table.FullCopy( self.WElements )
178 self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
179
180 self:CreateModels(self.VElements) // create viewmodels
181 self:CreateModels(self.WElements) // create worldmodels
182
183 // init view model bone build function
184 if IsValid(self.Owner) then
185 local vm = self.Owner:GetViewModel()
186 if IsValid(vm) then
187 self:ResetBonePositions(vm)
188
189 // Init viewmodel visibility
190 if (self.ShowViewModel == nil or self.ShowViewModel) then
191 vm:SetColor(Color(255,255,255,255))
192 else
193 // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
194 vm:SetColor(Color(255,255,255,1))
195 // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
196 // 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
197 vm:SetMaterial("Debug/hsv")
198 end
199 end
200 end
201
202 end
203
204end
205
206function SWEP:Holster()
207
208 if CLIENT and IsValid(self.Owner) then
209 local vm = self.Owner:GetViewModel()
210 if IsValid(vm) then
211 self:ResetBonePositions(vm)
212 end
213 end
214
215 return true
216end
217
218function SWEP:OnRemove()
219 self:Holster()
220end
221
222if CLIENT then
223
224 local num = 1
225 local nextone = CurTime()+1
226 local SELECTSCREEN = {}
227 local alp = 0
228 local c =0
229
230
231 SELECTSCREEN.stat = false
232
233
234
235
236 function SWEP:SecondaryAttack()
237
238 num = 1
239 nextone = CurTime()+0.3
240 SELECTSCREEN.stat = false
241 c = 0
242 end
243
244 function SWEP:PrimaryAttack()
245
246 num = 1
247 nextone = CurTime()+0.3
248 SELECTSCREEN.stat = true
249
250 c = 0
251 end
252
253
254
255
256 SWEP.vRenderOrder = nil
257
258 function SWEP:ViewModelDrawn()
259
260 local vm = self.Owner:GetViewModel()
261 if !IsValid(vm) then return end
262
263
264
265
266
267
268
269
270
271
272
273
274 if (!self.VElements) then return end
275
276 self:UpdateBonePositions(vm)
277
278 if (!self.vRenderOrder) then
279
280 // we build a render order because sprites need to be drawn after models
281 self.vRenderOrder = {}
282
283 for k, v in pairs( self.VElements ) do
284 if (v.type == "Model") then
285 table.insert(self.vRenderOrder, 1, k)
286 elseif (v.type == "Sprite" or v.type == "Quad") then
287 table.insert(self.vRenderOrder, k)
288 end
289 end
290
291 end
292
293
294 for k, name in ipairs( self.vRenderOrder ) do
295
296
297
298
299
300 local v = self.VElements[name]
301 if (!v) then self.vRenderOrder = nil break end
302 if (v.hide) then continue end
303
304 local model = v.modelEnt
305 local sprite = v.spriteMaterial
306
307 if (!v.bone) then continue end
308
309 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
310
311 if (!pos) then continue end
312
313 if (v.type == "Model" and IsValid(model)) then
314
315 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
316 ang:RotateAroundAxis(ang:Up(), v.angle.y)
317 ang:RotateAroundAxis(ang:Right(), v.angle.p)
318 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
319
320 model:SetAngles(ang)
321 //model:SetModelScale(v.size)
322 local matrix = Matrix()
323 matrix:Scale(v.size)
324 model:EnableMatrix( "RenderMultiply", matrix )
325
326 if (v.material == "") then
327 model:SetMaterial("")
328 elseif (model:GetMaterial() != v.material) then
329 model:SetMaterial( v.material )
330 end
331
332 if (v.skin and v.skin != model:GetSkin()) then
333 model:SetSkin(v.skin)
334 end
335
336 if (v.bodygroup) then
337 for k, v in pairs( v.bodygroup ) do
338 if (model:GetBodygroup(k) != v) then
339 model:SetBodygroup(k, v)
340 end
341 end
342 end
343
344 if (v.surpresslightning) then
345 render.SuppressEngineLighting(true)
346 end
347
348 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
349 render.SetBlend(v.color.a/255)
350 model:DrawModel()
351 render.SetBlend(1)
352 render.SetColorModulation(1, 1, 1)
353
354 if (v.surpresslightning) then
355 render.SuppressEngineLighting(false)
356 end
357
358 elseif (v.type == "Sprite" and sprite) then
359
360 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
361 render.SetMaterial(sprite)
362 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
363
364 elseif (v.type == "Quad") then
365
366 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
367 ang:RotateAroundAxis(ang:Up(), v.angle.y)
368 ang:RotateAroundAxis(ang:Right(), v.angle.p)
369 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
370
371
372
373
374 cam.Start3D2D(drawpos, ang,0.06)
375 if SELECTSCREEN.stat == true then
376 for i = 1,9 do
377
378 if not input.IsKeyDown(1) then
379 if input.IsKeyDown(i) and CurTime() > nextone then
380
381
382
383
384 net.Start("use_agentweapon")
385 net.WriteFloat(num+i-2)
386 net.SendToServer()
387
388 SELECTSCREEN.stat = false
389
390 c = 0
391 nextone = CurTime()+1
392 end
393 elseif CurTime() > nextone then
394 if num+9 < #team.GetAllTeams() then
395 num = num+9
396 nextone = CurTime()+1
397 else
398 num = 1
399 nextone = CurTime()+1
400 end
401
402 end
403 end
404 end
405
406
407 if SELECTSCREEN.stat == false then
408 c = c+0.001
409 alp = Lerp( c, alp, 0 )
410
411 else
412 c = c+0.01
413 alp = Lerp( c, alp, 1 )
414 end
415
416 draw.RoundedBox(0,-80,-80,300,150,Color(10,10,10,200*alp))
417 local t = team.GetAllTeams()
418
419 for i = num ,num+8 do
420
421 if t[i] != nil then
422 --draw.RoundedBox(0,-70,(-70)+(i-num)*12,280,10,ColorAlpha(t[i].Color,255*alp))
423 --draw.RoundedBox(0,-70,(-70)+(i-num)*12,10,10,Color(255,0,0,255*alp))
424 draw.SimpleText((i-num+1),"DebugFixedSmall",-69,(-70)+(i-num)*11.6,Color(255,255,255,255*alp))
425 draw.SimpleText(t[i].Name,"DebugFixedSmall",-40,(-72)+(i-num)*11.6,Color(255,255,255,255*alp))
426 end
427
428 if i > num+7 then
429 --draw.RoundedBox(0,-70,(-70)+(i-num+1)*12,280,10,Color(0,255,0,255*alp))
430 draw.RoundedBox(0,-72,(-75)+(i-num+2)*12,15,15,Color(255,0,0,255*alp))
431 draw.SimpleText(tostring(0),"DebugFixedSmall",-69,(-70)+(i-num+2)*11.6,Color(255,255,255,255*alp))
432 draw.SimpleText("Ð¡Ð»ÐµÐ´ÑƒÑŽÑ‰Ð°Ñ Ñтраница","DebugFixedSmall",-40,(-72)+(i-num+2)*12,Color(255,255,255,255*alp))
433 end
434 end
435
436
437
438
439 cam.End3D2D()
440
441
442
443
444 end
445
446 end
447
448 end
449
450 SWEP.wRenderOrder = nil
451 function SWEP:DrawWorldModel()
452
453 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
454 self:DrawModel()
455 end
456
457 if (!self.WElements) then return end
458
459 if (!self.wRenderOrder) then
460
461 self.wRenderOrder = {}
462
463 for k, v in pairs( self.WElements ) do
464 if (v.type == "Model") then
465 table.insert(self.wRenderOrder, 1, k)
466 elseif (v.type == "Sprite" or v.type == "Quad") then
467 table.insert(self.wRenderOrder, k)
468 end
469 end
470
471 end
472
473 if (IsValid(self.Owner)) then
474 bone_ent = self.Owner
475 else
476 // when the weapon is dropped
477 bone_ent = self
478 end
479
480 for k, name in pairs( self.wRenderOrder ) do
481
482 local v = self.WElements[name]
483 if (!v) then self.wRenderOrder = nil break end
484 if (v.hide) then continue end
485
486 local pos, ang
487
488 if (v.bone) then
489 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
490 else
491 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
492 end
493
494 if (!pos) then continue end
495
496 local model = v.modelEnt
497 local sprite = v.spriteMaterial
498
499 if (v.type == "Model" and IsValid(model)) then
500
501 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
502 ang:RotateAroundAxis(ang:Up(), v.angle.y)
503 ang:RotateAroundAxis(ang:Right(), v.angle.p)
504 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
505
506 model:SetAngles(ang)
507 //model:SetModelScale(v.size)
508 local matrix = Matrix()
509 matrix:Scale(v.size)
510 model:EnableMatrix( "RenderMultiply", matrix )
511
512 if (v.material == "") then
513 model:SetMaterial("")
514 elseif (model:GetMaterial() != v.material) then
515 model:SetMaterial( v.material )
516 end
517
518 if (v.skin and v.skin != model:GetSkin()) then
519 model:SetSkin(v.skin)
520 end
521
522 if (v.bodygroup) then
523 for k, v in pairs( v.bodygroup ) do
524 if (model:GetBodygroup(k) != v) then
525 model:SetBodygroup(k, v)
526 end
527 end
528 end
529
530 if (v.surpresslightning) then
531 render.SuppressEngineLighting(true)
532 end
533
534 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
535 render.SetBlend(v.color.a/255)
536 model:DrawModel()
537 render.SetBlend(1)
538 render.SetColorModulation(1, 1, 1)
539
540 if (v.surpresslightning) then
541 render.SuppressEngineLighting(false)
542 end
543
544 elseif (v.type == "Sprite" and sprite) then
545
546 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
547 render.SetMaterial(sprite)
548 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
549
550 elseif (v.type == "Quad" ) then
551
552 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
553 ang:RotateAroundAxis(ang:Up(), v.angle.y)
554 ang:RotateAroundAxis(ang:Right(), v.angle.p)
555 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
556
557 cam.Start3D2D(drawpos, ang, 0.1)
558
559 cam.End3D2D()
560
561 end
562
563 end
564
565 end
566
567 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
568
569 local bone, pos, ang
570 if (tab.rel and tab.rel != "") then
571
572 local v = basetab[tab.rel]
573
574 if (!v) then return end
575
576 // Technically, if there exists an element with the same name as a bone
577 // you can get in an infinite loop. Let's just hope nobody's that stupid.
578 pos, ang = self:GetBoneOrientation( basetab, v, ent )
579
580 if (!pos) then return end
581
582 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
583 ang:RotateAroundAxis(ang:Up(), v.angle.y)
584 ang:RotateAroundAxis(ang:Right(), v.angle.p)
585 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
586
587 else
588
589 bone = ent:LookupBone(bone_override or tab.bone)
590
591 if (!bone) then return end
592
593 pos, ang = Vector(0,0,0), Angle(0,0,0)
594 local m = ent:GetBoneMatrix(bone)
595 if (m) then
596 pos, ang = m:GetTranslation(), m:GetAngles()
597 end
598
599 if (IsValid(self.Owner) and self.Owner:IsPlayer() and
600 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
601 ang.r = -ang.r // Fixes mirrored models
602 end
603
604 end
605
606 return pos, ang
607 end
608
609 function SWEP:CreateModels( tab )
610
611 if (!tab) then return end
612
613 // Create the clientside models here because Garry says we can't do it in the render hook
614 for k, v in pairs( tab ) do
615 if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
616 string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
617
618 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
619 if (IsValid(v.modelEnt)) then
620 v.modelEnt:SetPos(self:GetPos())
621 v.modelEnt:SetAngles(self:GetAngles())
622 v.modelEnt:SetParent(self)
623 v.modelEnt:SetNoDraw(true)
624 v.createdModel = v.model
625 else
626 v.modelEnt = nil
627 end
628
629 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
630 and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
631
632 local name = v.sprite.."-"
633 local params = { ["$basetexture"] = v.sprite }
634 // make sure we create a unique name based on the selected options
635 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
636 for i, j in pairs( tocheck ) do
637 if (v[j]) then
638 params["$"..j] = 1
639 name = name.."1"
640 else
641 name = name.."0"
642 end
643 end
644
645 v.createdSprite = v.sprite
646 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
647
648 end
649 end
650
651 end
652
653 local allbones
654 local hasGarryFixedBoneScalingYet = false
655
656 function SWEP:UpdateBonePositions(vm)
657
658 if self.ViewModelBoneMods then
659
660 if (!vm:GetBoneCount()) then return end
661
662 // !! WORKAROUND !! //
663 // We need to check all model names :/
664 local loopthrough = self.ViewModelBoneMods
665 if (!hasGarryFixedBoneScalingYet) then
666 allbones = {}
667 for i=0, vm:GetBoneCount() do
668 local bonename = vm:GetBoneName(i)
669 if (self.ViewModelBoneMods[bonename]) then
670 allbones[bonename] = self.ViewModelBoneMods[bonename]
671 else
672 allbones[bonename] = {
673 scale = Vector(1,1,1),
674 pos = Vector(0,0,0),
675 angle = Angle(0,0,0)
676 }
677 end
678 end
679
680 loopthrough = allbones
681 end
682 // !! ----------- !! //
683
684 for k, v in pairs( loopthrough ) do
685 local bone = vm:LookupBone(k)
686 if (!bone) then continue end
687
688 // !! WORKAROUND !! //
689 local s = Vector(v.scale.x,v.scale.y,v.scale.z)
690 local p = Vector(v.pos.x,v.pos.y,v.pos.z)
691 local ms = Vector(1,1,1)
692 if (!hasGarryFixedBoneScalingYet) then
693 local cur = vm:GetBoneParent(bone)
694 while(cur >= 0) do
695 local pscale = loopthrough[vm:GetBoneName(cur)].scale
696 ms = ms * pscale
697 cur = vm:GetBoneParent(cur)
698 end
699 end
700
701 s = s * ms
702 // !! ----------- !! //
703
704 if vm:GetManipulateBoneScale(bone) != s then
705 vm:ManipulateBoneScale( bone, s )
706 end
707 if vm:GetManipulateBoneAngles(bone) != v.angle then
708 vm:ManipulateBoneAngles( bone, v.angle )
709 end
710 if vm:GetManipulateBonePosition(bone) != p then
711 vm:ManipulateBonePosition( bone, p )
712 end
713 end
714 else
715 self:ResetBonePositions(vm)
716 end
717
718 end
719
720 function SWEP:ResetBonePositions(vm)
721
722 if (!vm:GetBoneCount()) then return end
723 for i=0, vm:GetBoneCount() do
724 vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
725 vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
726 vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
727 end
728
729 end
730
731 /**************************
732 Global utility code
733 **************************/
734
735 // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
736 // Does not copy entities of course, only copies their reference.
737 // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
738 function table.FullCopy( tab )
739
740 if (!tab) then return nil end
741
742 local res = {}
743 for k, v in pairs( tab ) do
744 if (type(v) == "table") then
745 res[k] = table.FullCopy(v) // recursion ho!
746 elseif (type(v) == "Vector") then
747 res[k] = Vector(v.x, v.y, v.z)
748 elseif (type(v) == "Angle") then
749 res[k] = Angle(v.p, v.y, v.r)
750 else
751 res[k] = v
752 end
753 end
754
755 return res
756
757 end
758
759 end