1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
if CLIENT then
CreateClientConVar("zone_tall",200,false,true)
CreateClientConVar("zone_class","",false,true)
CreateClientConVar("zone_editmode",1,false,true)
CreateClientConVar("zone_filter",0,false,true)
surface.CreateFont( "zones_save", {
font = "Roboto", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
size = 20,
weight = 1000,
} )
surface.CreateFont( "zones_screen", {
font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
size = 20,
weight = 1000,
} )
else
concommand.Add("zone_swep",function(p,c,a)
if p:IsAdmin() then
p:Give("weapon_zone_designator")
end
end)
end
if engine.ActiveGamemode() == "terrortown" then
SWEP.Base = "weapon_tttbase"
SWEP.Kind = WEAPON_EQUIP2
end
SWEP.NoSights = true
SWEP.PrintName = "Zone Designator"
SWEP.Author = "Bobblehead"
SWEP.Purpose = "Creates zones. Reload for menu. Right click to remove a point/zone."
SWEP.Slot = 5
SWEP.SlotPos = 5
SWEP.Spawnable = true
SWEP.AdminOnly = true
SWEP.HoldType = "pistol"
SWEP.ViewModelFOV = 51
SWEP.ViewModelFlip = false
SWEP.UseHands = true
SWEP.ViewModel = "models/weapons/c_toolgun.mdl"
SWEP.WorldModel = "models/weapons/w_toolgun.mdl"
SWEP.AutoSwitchFrom = true
SWEP.AutoSwitchTo = true
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Delay = .5
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
function SWEP:SetupDataTables()
self:NetworkVar("Float",0,"Tall")
self:NetworkVar("String",0,"ZoneClass")
self:NetworkVar("Entity",0,"CurrentPoint")
self:NetworkVar("Int",0,"Mode")
end
function SWEP:Initialize()
self:SetTall(150)
self:SetMode(1)
self:SetCurrentPoint(NULL)
end
function SWEP:Deploy()
if SERVER then
local points = ents.FindByClass("ent_zone_point")
local ct = 0
for k,v in pairs(zones.List) do
for k2,v2 in pairs(v.points)do
for k3, v3 in pairs(v2) do
ct = ct + 1
end
end
end
if #points != ct then
zones.CreatePointEnts(points)
end
end
end
function SWEP:Holster()
if SERVER then
local none = true
for k, ply in pairs(player.GetAll()) do
if ply == self.Owner then continue end
local wep = ply:GetActiveWeapon()
if IsValid(wep) and wep:GetClass() == "weapon_zone_designator" then
none = false
break
end
end
if none then
for k,v in pairs(ents.FindByClass("ent_zone_point"))do
v:Remove()
end
end
self:SetCurrentPoint(NULL)
return true
end
end
function SWEP:DrawHUD()
local z,id = LocalPlayer():GetCurrentZone(GetConVarNumber("zone_filter") == 1 and self:GetZoneClass() or nil)
z = z and z.class.."(# "..id..")" or "NONE"
surface.SetFont("DermaLarge")
local w = math.max(360,surface.GetTextSize("Current Zone: "..z)+40)
draw.RoundedBox(8,ScrW()/2-w/2,ScrH()-160,w,100,Color(0,0,0,150))
draw.SimpleText("Current Zone: "..z, "DermaLarge", ScrW()/2,ScrH()-130,color_white,TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
draw.SimpleText("Hold "..input.LookupBinding("+reload"):upper().." to change modes", "DermaLarge",ScrW()/2,ScrH()-90,color_white,TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
end
function SWEP:PrimaryAttack()
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
if SERVER then
self.Owner:EmitSound("buttons/button15.wav")
end
self:UpdateSettings()
local mode = self:GetMode()
if mode == 1 then //Create
if CLIENT then return end
self:PlacePoint()
elseif mode == 2 then //Merge
if CLIENT then return end
self:MergeZones()
elseif mode == 3 then //Edit
local curr = self:GetCurrentPoint()
if IsValid(curr) then
if CLIENT then return end
local next = curr
repeat
next.Resizing = nil
next = next:GetNext()
until ( next == curr )
zones.List[curr:GetZoneID()].height[curr:GetAreaNumber()] = curr:GetTall()
zones.CalcBounds(zones.List[curr:GetZoneID()])
self:SetCurrentPoint(NULL)
elseif CLIENT then
local tr = self.Owner:GetEyeTrace()
if !tr.HitWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "ent_zone_point" then
if IsValid(zones.optionsFrame) then return end
zones.ShowOptions(tr.Entity:GetZoneID())
else
local _,id = self.Owner:GetCurrentZone(GetConVarNumber("zone_filter") == 1 and self:GetZoneClass())
if IsValid(zones.optionsFrame) then return end
if id != -1 then
zones.ShowOptions(id)
end
end
end
elseif mode == 4 then
if CLIENT then return end
local curr = self:GetCurrentPoint()
local tr = self.Owner:GetEyeTrace()
if !tr.HitWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "ent_zone_point" then
self:SetCurrentPoint(tr.Entity)
elseif IsValid(curr) then
local id,areanum = curr:GetZoneID(), curr:GetAreaNumber()
local next = curr:GetNext()
local new = ents.Create("ent_zone_point")
local p = curr:GetPos()
tr.HitPos.z = p.z
new:SetPos(tr.HitPos)
curr:SetNext(new)
-- self:GetCurrentPoint():DeleteOnRemove(new)
new.LastPoint = self:GetCurrentPoint()
self:SetCurrentPoint(new)
new:SetTall(curr:GetTall())
new:SetZoneClass(curr:GetZoneClass())
new:SetZoneID(id)
new:SetAreaNumber(areanum)
new:Spawn()
new:SetNext(next)
next.LastPoint = new
local n = new
local pts = {}
repeat
pts[#pts+1] = n:GetPos() - Vector(0,0,2)
n = n:GetNext()
until (n == new)
zones.List[id].points[areanum] = pts
zones.CalcBounds(zones.List[id])
zones.Sync()
end
end
end
function SWEP:SecondaryAttack()
self:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
if CLIENT then return end
self.Owner:EmitSound("buttons/button16.wav")
local tr = self.Owner:GetEyeTrace()
local mode = self:GetMode()
if mode == 1 then //delete
if !tr.HitWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "ent_zone_point" then
local point = tr.Entity
local last = point.LastPoint
local id = point:GetZoneID()
if id != -1 then
if #zones.List[id].points > 1 then
id = select(2,zones.Split(id, point:GetAreaNumber()))
end
zones.Remove(id)
end
point:Remove()
self:SetCurrentPoint(last)
elseif self:GetCurrentPoint():IsValid() then
local point, last = self:GetCurrentPoint(), self:GetCurrentPoint().LastPoint
point:Remove()
self:SetCurrentPoint(last or NULL)
end
elseif mode == 2 then //split
if !tr.HitWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "ent_zone_point" then
local point = tr.Entity
local id = point:GetZoneID()
if #zones.List[id].points == 1 then
return
end
local zone, newid = zones.Split(id, point:GetAreaNumber())
local next = point
repeat
next:SetZoneID(newid)
next:SetAreaNumber(next:GetAreaNumber() - #zones.List[id].points)
next = next:GetNext()
until ( next == point )
end
elseif mode == 3 then //resize
local curr = self:GetCurrentPoint()
if IsValid(curr) then
local next = curr
repeat
next.Resizing = nil
next = next:GetNext()
until ( next == curr )
zones.List[curr:GetZoneID()].height[curr:GetAreaNumber()] = curr:GetTall()
zones.CalcBounds(zones.List[curr:GetZoneID()])
zones.Sync()
self:SetCurrentPoint(NULL)
else
if !tr.HitWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "ent_zone_point" then
local next = tr.Entity
repeat
next.Resizing = self.Owner
next = next:GetNext()
until ( next == tr.Entity )
self:SetCurrentPoint(tr.Entity)
else
local z, id = self.Owner:GetCurrentZone(GetConVarNumber("zone_filter") == 1 and self:GetZoneClass())
if id != -1 then
local curr
for k,v in pairs(ents.FindByClass("ent_zone_point"))do
if v:GetZoneID() == id then curr = v break end
end
local next = curr
repeat
next.Resizing = self.Owner
next = next:GetNext()
until ( next == curr )
self:SetCurrentPoint(curr)
end
end
end
elseif mode == 4 then //Remove a point
if !tr.HitWorld and IsValid(tr.Entity) and tr.Entity:GetClass() == "ent_zone_point" or IsValid(self:GetCurrentPoint()) then
local hit = tr.Entity:IsValid() and tr.Entity or self:GetCurrentPoint()
local id,areanum = hit:GetZoneID(), hit:GetAreaNumber()
if #zones.List[id].points[areanum] > 3 then
local last = hit.LastPoint
local next = hit:GetNext()
next.LastPoint = last
last:SetNext(next)
hit:SetNext(NULL)
hit.LastPoint = nil
hit:Remove()
local n = next
local pts = {}
repeat
pts[#pts+1] = n:GetPos() - Vector(0,0,2)
n = n:GetNext()
until (n == next)
zones.List[id].points[areanum] = pts
zones.CalcBounds(zones.List[id])
zones.Sync()
self:SetCurrentPoint(last)
end
end
end
end
local mx,my
if CLIENT then
mx, my = ScrW()/2, ScrH()/2
end
function SWEP:Reload() --show menu.
self:UpdateSettings()
if SERVER then
if game.SinglePlayer() then
self:CallOnClient("Reload")
end
return
end
if IsValid(self.frame) then return end
input.SetCursorPos(mx,my)
self:OpenMenu()
end
function SWEP:PlacePoint() --mode == 1
local tr = self.Owner:GetEyeTrace()
local curr = self:GetCurrentPoint()
if tr.HitWorld then
--fill the wall.
if self.Owner:KeyDown(IN_USE) and tr.HitNormal.z == 0 then
local left,right = self:GetWallFill(tr)
if IsValid(curr) then
local next = ents.Create("ent_zone_point")
local p = curr:GetPos()
local pos
-- if left:DistToSqr(p) > right:DistToSqr(p) then
if left:DistToSqr(tr.HitPos) < right:DistToSqr(tr.HitPos) then
left.z = p.z
pos = left
else
right.z = p.z
pos = right
end
next:SetPos(pos)
curr:SetNext(next)
next.LastPoint = curr
self:SetCurrentPoint(next)
next:SetTall(self:GetTall())
next:SetZoneClass(self:GetZoneClass())
next:SetZoneID(-1)
next:SetAreaNumber(1)
next:Spawn()
else
local pos = util.TraceLine({start=left,endpos=left+Vector(0,0,-2000),filter=self.Owner}).HitPos
local ceil = util.TraceLine({start=pos,endpos=pos+Vector(0,0,2000),filter=self.Owner})
if ceil.Hit and !ceil.HitSky then
local height = math.floor(ceil.Fraction * 2000)
self.Owner:ConCommand("zone_tall "..height)
self:SetTall(height)
end
local next = ents.Create("ent_zone_point")
next:SetPos(pos-Vector(0,0,1))
next.LastPoint = curr
self:SetCurrentPoint(next)
next:SetTall(self:GetTall())
next:SetZoneClass(self:GetZoneClass())
next:SetZoneID(-1)
next:SetAreaNumber(1)
next:Spawn()
end
else --place a point normally
local next = ents.Create("ent_zone_point")
if IsValid(curr) then
local p = curr:GetPos()
tr.HitPos.z = p.z
next:SetPos(tr.HitPos)
curr:SetNext(next)
else
next:SetPos(tr.HitPos+Vector(0,0,1))
end
next.LastPoint = curr
self:SetCurrentPoint(next)
next:SetTall(self:GetTall())
next:SetZoneClass(self:GetZoneClass())
next:SetZoneID(-1)
next:SetAreaNumber(1)
next:Spawn()
end
elseif tr.Entity:IsValid() and tr.Entity:GetClass() == "ent_zone_point" and tr.Entity != curr then
if IsValid(curr) then
local next = tr.Entity
if !IsValid(next.LastPoint) then
curr:SetNext(next)
if IsValid(next:GetNext()) then //we've come full circle.
next.LastPoint = curr
local id = select(2,zones.CreateZoneFromPoint(curr))
-- curr:DeleteOnRemove(next)
self:SetCurrentPoint(NULL)
local o = self.Owner
timer.Simple(.1,function() -- wait for it to sync.
if IsValid(o) then
o:SendLua("zones.ShowOptions("..id..")")
end
end)
end
end
end
end
end
function SWEP:GetWallFill(tr)
local hitpos,norm = tr.HitPos,tr.HitNormal
local up = Vector(0,0,1)
local left = norm:Cross(up)
local right = -left
local curleft,curright = hitpos+norm, hitpos+norm
local trace = {filter=self.Owner}
local wall = {filter=self.Owner}
local dist = 2
for i=1, 1000, dist do --scan left.
trace.start = curleft
trace.endpos = curleft + dist*left
local L = util.TraceLine(trace)
curleft = trace.endpos
if L.Hit then
curleft = L.HitPos
break
else
wall.start = curleft
wall.endpos = curleft - norm*2
if not util.TraceLine(wall).Hit then
-- curleft = curleft - left
break
end
end
end
for i=1, 1000, dist do --scan right.
trace.start = curright
trace.endpos = curright + dist*right
local r = util.TraceLine(trace)
curright = trace.endpos
if r.Hit then
curleft = r.HitPos
break
else
wall.start = curright
wall.endpos = curright - norm*2
if not util.TraceLine(wall).Hit then
-- curright = curright - right
break
end
end
end
return curleft, curright
end
function SWEP:MergeZones()
local tr = self.Owner:GetEyeTrace()
if tr.HitWorld then
self:SetCurrentPoint(NULL)
elseif IsValid(tr.Entity) and tr.Entity:GetClass() == "ent_zone_point" then
local curr = self:GetCurrentPoint()
local trent = tr.Entity
if not IsValid(curr) then
self:SetCurrentPoint(trent)
else
//Merge the zones.
if curr:GetZoneID() != trent:GetZoneID() then
local cid = curr:GetZoneID()
--Change the points.
for k,next in pairs(ents.FindByClass("ent_zone_point")) do
if next:GetZoneID() == cid then
next:SetZoneID(trent:GetZoneID())
next:SetAreaNumber(next:GetAreaNumber() + #zones.List[trent:GetZoneID()].points)
next:SetZoneClass(zones.List[trent:GetZoneID()].class)
end
end
self:SetCurrentPoint(NULL)
zones.Merge(cid,trent:GetZoneID()) --from, to
else
self:SetCurrentPoint(trent)
end
end
end
end
function SWEP:UpdateSettings()
--load convars
local new_tall = SERVER and self.Owner:GetInfoNum("zone_tall",200) or GetConVarNumber("zone_tall")
local new_class = SERVER and self.Owner:GetInfo("zone_class") or GetConVarString("zone_class")
local new_mode = SERVER and self.Owner:GetInfoNum("zone_editmode",1) or GetConVarNumber("zone_editmode")
if new_class == "" then
for k,v in pairs(zones.Classes)do
new_class = k
self.Owner:ConCommand('zone_class "'..k..'"')
break
end
end
--If changed, remove current building area
if new_class != self:GetZoneClass() or new_tall != self:GetTall() or new_mode != self:GetMode() then
self:ResetTool()
end
assert(new_class != "", "No class is set for the zone designator! Did you call zones.RegisterClass()?\n")
--apply convars
self:SetTall(new_tall)
self:SetZoneClass(new_class)
self:SetMode(new_mode)
end
function SWEP:ResetTool()
if self:GetMode() == 1 and SERVER then
local cur = self:GetCurrentPoint()
if IsValid(cur) and cur:GetZoneID() == -1 then
while IsValid(cur) do
local last = cur.LastPoint
cur:Remove()
cur = last
end
end
end
self:SetCurrentPoint(NULL)
end
function SWEP:OpenMenu()
local zc = self:GetZoneClass()
local frame = vgui.Create("DFrame")
self.frame = frame
frame:SetSize(300,400)
frame:Center()
frame:MakePopup()
frame:ShowCloseButton(false)
frame:SetTitle("Zone Designator Options")
function frame:Think()
if not input.IsButtonDown(_G["KEY_"..input.LookupBinding("+reload"):upper()]) then
mx,my = gui.MousePos()
self:Close()
end
end
local ztitle = vgui.Create("DLabel",frame)
ztitle:Dock(TOP)
ztitle:DockMargin(7,0,5,0)
ztitle:SetText("Zone Class:")
ztitle:SizeToContents()
local zclass = vgui.Create("DComboBox",frame)
zclass:Dock(TOP)
zclass:DockMargin(5,0,5,0)
for k,v in pairs(zones.Classes) do
zclass:AddChoice(k,nil,k==zc)
end
function zclass:OnSelect(i,class)
RunConsoleCommand("zone_class",class)
end
local filter = vgui.Create("DCheckBoxLabel",frame)
filter:Dock(TOP)
filter:DockMargin(6,5,5,5)
filter:SetText("Filter zones of a different class.")
filter:SizeToContents()
filter:SetConVar("zone_filter")
local height = vgui.Create( "DNumSlider", frame )
height:Dock(TOP)
height:DockMargin(7,0,0,0)
height:SetText( "Zone Height:" )
height:SetMin( 0 )
height:SetMax( 1000 )
height:SetDecimals( 0 )
height:SetConVar( "zone_tall" )
local modetitle = vgui.Create("DLabel",frame)
modetitle:Dock(TOP)
modetitle:DockMargin(7,0,5,0)
modetitle:SetText("Tool Mode:")
modetitle:SizeToContents()
local mode = vgui.Create("DListView",frame)
mode:Dock(TOP)
mode:DockMargin(5,0,5,5)
mode:AddColumn("Mode")
mode:AddColumn("Info"):SetFixedWidth(180)
mode:SetTall(200)
mode:SetMultiSelect(false)
mode:AddLine("Create / Delete","Create new zones")
mode:AddLine("Merge / Split","Turn two zones into one.")
mode:AddLine("Edit / Resize","Change zone properties.")
mode:AddLine("Insert / Remove","Insert points into existing zones.")
mode:SelectItem(mode:GetLine(self:GetMode()))
function mode:OnRowSelected(id)
RunConsoleCommand("zone_editmode",id)
end
local save = vgui.Create("DButton",frame)
save:Dock(BOTTOM)
save:DockMargin(5,0,5,5)
save:SetText("SAVE ALL ZONES")
save:SetFont("zones_save")
save:SetTextColor(color_black)
save:SetTall(50)
function save:DoClick()
Derma_Query("Are you sure you want to save? This can't be undone.", "Save Confirmation",
"Yes", function()
RunConsoleCommand("zone_save")
end,
"No", function()
end
)
end
end
local modes = {
{ --create
"Create",
"Delete"
},
{ --merge
"Merge",
"Split"
},
{ --edit
"Edit",
"Resize"
},
{ --insert
"Insert",
"Remove"
},
}
local lmb, rmb = Material("gui/lmb.png","unlitgeneric"), Material("gui/rmb.png","unlitgeneric")
function SWEP:DrawScreen(x,y,w,h)
local mode = self:GetMode()
local txt = modes[mode]
draw.SimpleText(txt[1], "zones_screen", x+w/4, -h/5, _, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
draw.SimpleText(txt[2], "zones_screen", w+x-w/4, -h/5, _, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
surface.SetDrawColor(color_white)
surface.DrawRect(x+w/2-1,y+h*.125,2,h*.75)
surface.SetMaterial(lmb)
surface.DrawTexturedRect(x+w/4-16,y+h*.55-16,32,32)
surface.SetMaterial(rmb)
surface.DrawTexturedRect(x+w*.75-16,y+h*.55-16,32,32)
end
local function GetBoneOrientation(self,ent)
local bone, pos, ang
bone = ent:LookupBone("Hand")
if (!bone) then return end
pos, ang = Vector(0,0,0), Angle(0,0,0)
local m = ent:GetBoneMatrix(bone)
if (m) then
pos, ang = m:GetTranslation(), m:GetAngles()
end
if (IsValid(self.Owner) and self.Owner:IsPlayer() and
ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
ang.r = -ang.r // Fixes mirrored models
end
return pos, ang
end
function SWEP:ViewModelDrawn()
local vm = self.Owner:GetViewModel()
if !IsValid(vm) then return end
local pos, ang = GetBoneOrientation(self, vm )
local offset = Vector(.08, -5.16, 3.43)
local offsetAng = Angle(180, 0, -46)
local size = 0.0159
local drawpos = pos + ang:Forward() * offset.x + ang:Right() * offset.y + ang:Up() * offset.z
ang:RotateAroundAxis(ang:Up(), offsetAng.y)
ang:RotateAroundAxis(ang:Right(), offsetAng.p)
ang:RotateAroundAxis(ang:Forward(), offsetAng.r)
cam.Start3D2D(drawpos, ang, size)
local x,y,w,h = -72,-72
local w,h = 2*-x, 2*-y
//Draw Background:
surface.SetDrawColor( 200, 200, 200, 255 )
surface.SetDrawColor( 40,40,40,255 )
surface.DrawRect( x, y, w, h )
//Draw foreground:
self:DrawScreen(x,y,w,h)
cam.End3D2D()
end
|