· 8 years ago · Dec 26, 2017, 10:12 PM
1--/*************************************************************************************************************\--
2--|------ Basia2's FIVESEVEN FROM CSGO - BASED ON DEADALUS3010'S LUA FILE - ANIMATIONS BY BASIA2 - MODELS/SOUNDS FROM VALVE -------|--
3--\*************************************************************************************************************/--
4
5-- Sound Settings
6-------------------
7local soundData = {
8 name = "fiveseven.Shoot" ,
9 channel = CHAN_USER_BASE+10,
10 volume = 0.5,
11 sound = "Basia2/CSGO Weapons/Fiveseven/shoot.wav"
12}
13sound.Add(soundData)
14
15local soundData = {
16 name = "fiveseven.Shoot2" ,
17 channel = CHAN_USER_BASE+10,
18 volume = 0.5,
19 sound = "Basia2/CSGO Weapons/Fiveseven/shoot.wav"
20}
21sound.Add(soundData)
22
23local soundData = {
24 name = "fiveseven.Shoot3" ,
25 channel = CHAN_USER_BASE+10,
26 volume = 0.5,
27 sound = "Basia2/CSGO Weapons/Fiveseven/shoot.wav"
28}
29sound.Add(soundData)
30
31local soundData = {
32 name = "fiveseven.Draw" ,
33 channel = CHAN_WEAPON,
34 volume = 1.0,
35 soundlevel = 80,
36 pitchstart = 100,
37 pitchend = 100,
38 sound = "Basia2/CSGO Weapons/Fiveseven/draw.wav"
39}
40sound.Add(soundData)
41
42local soundData = {
43 name = "fiveseven.Magout" ,
44 channel = CHAN_WEAPON,
45 volume = 1.0,
46 soundlevel = 80,
47 pitchstart = 100,
48 pitchend = 100,
49 sound = "Basia2/CSGO Weapons/Fiveseven/magout.wav"
50}
51sound.Add(soundData)
52
53local soundData = {
54 name = "fiveseven.Magin" ,
55 channel = CHAN_WEAPON,
56 volume = 1.0,
57 soundlevel = 80,
58 pitchstart = 100,
59 pitchend = 100,
60 sound = "Basia2/CSGO Weapons/Fiveseven/magin.wav"
61}
62sound.Add(soundData)
63
64local soundData = {
65 name = "fiveseven.Sliderelease" ,
66 channel = CHAN_WEAPON,
67 volume = 1.0,
68 soundlevel = 80,
69 pitchstart = 100,
70 pitchend = 100,
71 sound = "Basia2/CSGO Weapons/Fiveseven/sliderelease.wav"
72}
73sound.Add(soundData)
74
75local soundData = {
76 name = "fiveseven.Slideback" ,
77 channel = CHAN_WEAPON,
78 volume = 1.0,
79 soundlevel = 80,
80 pitchstart = 100,
81 pitchend = 100,
82 sound = "Basia2/CSGO Weapons/Fiveseven/slideback.wav"
83}
84sound.Add(soundData)
85
86/* -- Obsolete, allready made with the code above, use it if you want to add something to the reload sound. If you want to activate it, do not forget to delete this.
87local Time = CurTime()
88function SWEP:Reload()
89 if ( self.Weapon:Ammo1() <= 0 ) then return end
90 if ( self.Weapon:Clip1() >= self.Primary.ClipSize ) then return end
91 if (CurTime() < Time + 0) then return end
92 Time = CurTime()
93
94 timer.Simple(0,function() self.Weapon:EmitSound("Basia2/CSGO Weapons/Fiveseven/mag_in.wav") end) --/Work in\--
95 timer.Simple(1.4,function() self.Weapon:EmitSound("Basia2/CSGO Weapons/Fiveseven/slide_release.wav") end) --\progress/--
96
97 self.Owner:SetAnimation(PLAYER_RELOAD)
98 self.Weapon:DefaultReload(ACT_VM_RELOAD)
99end
100*/ -- And delete that
101
102-- AddCSLuaFile()
103-------------------
104if SERVER then
105 AddCSLuaFile( "shared.lua" )
106end
107
108-- Main Settings
109-------------------
110SWEP.Base = "weapon_base"
111SWEP.PrintName = "Fiveseven"
112SWEP.Category = "Basia2's CSGO Weapons"
113SWEP.Slot = 1
114SWEP.SlotPos = 2
115SWEP.Spawnable = true
116SWEP.AdminSpawnable = true
117SWEP.DrawAmmo = false
118SWEP.DrawCrosshair = false
119SWEP.ViewModelFOV = 70
120SWEP.ViewModel = "models/Basia2/CSGO/fiveseven/c_fiveseven.mdl"
121SWEP.WorldModel = "models/weapons/w_pist_p228.mdl"
122SWEP.ShowWorldModel = true
123SWEP.CSMuzzleAttachment = "1"
124SWEP.ShellEjectAttachment = "2"
125SWEP.HoldType = "pistol"
126SWEP.BounceWeaponIcon = true
127
128-- Other Settings
129-------------------
130SWEP.Weight = 1
131SWEP.AutoSwitchTo = false
132SWEP.AutoSwitchFrom = false
133SWEP.UseHands = true
134SWEP.ViewModelFlip = false
135
136/* <-- Just remove these to activate it | Dont forget to delete SWEP.BASE from above, or it wont work
137-- TTT settings
138-------------------
139SWEP.AutoSpawnable = true
140SWEP.Kind = WEAPON_PISTOL
141SWEP.AmmoEnt = "item_ammo_pistol_ttt"
142SWEP.AllowDrop = true
143SWEP.IsSilent = false
144SWEP.NoSights = false
145SWEP.Base = "weapon_tttbase"
146*/
147
148-- Weapon info
149-------------------
150SWEP.Author = "Basia2"
151SWEP.Contact = "http://steamcommunity.com/id/Basia2"
152SWEP.Purpose = "It shoots projectiles."
153SWEP.Instructions = ""
154
155-- Primary fire settings
156-------------------
157SWEP.Primary.Sound = "Basia2/CSGO Weapons/Fiveseven/shoot.wav"
158SWEP.Primary.RPM = 666 -- Rounds Per Minute
159SWEP.Primary.Damage = 25 -- Damage per primary shot
160SWEP.Primary.NumShots = 1
161SWEP.Primary.Recoil = 1.3
162SWEP.Primary.Cone = 0.003
163SWEP.Primary.Delay = 0.1
164SWEP.Primary.Spread = 0.3
165SWEP.Primary.ClipSize = 20
166SWEP.Primary.DefaultClip = 15 -- Reserve Clips
167SWEP.Primary.ClipMax = 21
168SWEP.Primary.Tracer = 1
169SWEP.Primary.Force = 7
170SWEP.Primary.Automatic = false
171SWEP.Primary.Ammo = "pistol" -- The type of ammo you can pick up that matches this gun.
172-- list of ammo types: pistol, 357, smg1, ar2, buckshot, slam, SniperPenetratedRound, AirboatGun
173SWEP.HeadshotMultiplier = 1.5
174SWEP.FiresUnderwater = false
175SWEP.HipSpread = 0.04 -- Spread when hip-firing.
176-- Secondary fire settings
177-------------------
178SWEP.Secondary.ClipSize = -1
179SWEP.Secondary.DefaultClip = 1
180SWEP.Secondary.Ammo = "none"
181
182-- Other fire settings
183-------------------
184SWEP.CrouchModifier = 0.2
185SWEP.IronSightModifier = 0.001
186SWEP.RunModifier = 0.5
187SWEP.JumpModifier = 1.6
188SWEP.Zoom1Cone = 0.001
189SWEP.ConeSpray = 0.001
190SWEP.ConeIncrement = 0.001
191SWEP.ConeMax = 0.001
192SWEP.ConeDecrement = 0.001
193
194-- Sprint
195-------------------
196SWEP.SprintPos = Vector(2.079, -5.87, -4.216)
197SWEP.SprintAng = Vector(43.314, 4.176, 2.367)
198
199-- Sights
200-------------------
201SWEP.IronSightsPos = Vector(-5.841, -14.5, 1.559)
202SWEP.IronSightsAng = Vector(1.1, 1.1, -12)
203
204-- Some other stuff...maybe just leave it as it is
205-- You can break more than you think you could
206-------------------
207function SWEP:PrimaryAttack()
208 if ( !self:CanPrimaryAttack() ) then return end
209 local bullet = {}
210 bullet.Num = self.Primary.NumShots
211 bullet.Src = self.Owner:GetShootPos()
212 bullet.Dir = self.Owner:GetAimVector()
213 bullet.Spread = Vector( self.Primary.Cone / 90, self.Primary.Cone / 90, 0 )
214 bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
215 bullet.Tracer = self.Primary.Tracer
216 bullet.Force = self.Primary.Force
217 bullet.Damage = self.Primary.Damage
218 bullet.AmmoType = self.Primary.Ammo
219 self.Owner:FireBullets( bullet )
220 self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
221 self.Owner:MuzzleFlash()
222 self.Owner:SetAnimation( PLAYER_ATTACK1 )
223 self.Weapon:EmitSound(Sound(self.Primary.Sound))
224 self.Owner:ViewPunch(Angle( -self.Primary.Recoil, 0.5, 1 ))
225 if (self.Primary.TakeAmmoPerBullet) then
226 self:TakePrimaryAmmo(self.Primary.NumShots)
227 else
228 self:TakePrimaryAmmo(1)
229 end
230 self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
231
232 if self.Weapon:Clip1() == 0 then
233 self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK_EMPTY )
234 end
235end
236
237function SWEP:Reload()
238 self:SetIronsights( false )
239
240 if self.ReloadingTime and CurTime() <= self.ReloadingTime then return end
241 if ( self:Clip1() < self.Primary.ClipSize and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
242 self:DefaultReload( ACT_VM_RELOAD )
243 local AnimationTime = self.Owner:GetViewModel():SequenceDuration()
244 self.ReloadingTime = CurTime() + AnimationTime
245 self:SetNextPrimaryFire(CurTime() + AnimationTime)
246 self:SetNextSecondaryFire(CurTime() + AnimationTime)
247 end
248
249 if ( self:Clip1() == 0 and self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
250 self.Weapon:SendWeaponAnim( ACT_VM_RELOAD_EMPTY )
251 local AnimationTime = self.Owner:GetViewModel():SequenceDuration()
252 self.ReloadingTime = CurTime() + AnimationTime
253 self:SetNextPrimaryFire(CurTime() + AnimationTime)
254 self:SetNextSecondaryFire(CurTime() + AnimationTime)
255 end
256
257end
258
259
260--/************************************************************************************************************************\--
261--|------ NOT MY CODE| THANKS TO mescool15| https://facepunch.com/member.php?u=165004 | only slighty modfied ------|--
262--\************************************************************************************************************************/--
263local IRONSIGHT_TIME = 0.2
264/*---------------------------------------------------------
265 Name: GetViewModelPosition
266 Desc: Allows you to re-position the view model
267---------------------------------------------------------*/
268function SWEP:GetViewModelPosition( pos, ang )
269
270 if ( !self.IronSightsPos ) then return pos, ang end
271
272 local bIron = self.Weapon:GetNetworkedBool( "Ironsights" )
273
274 if ( bIron != self.bLastIron ) then
275
276 self.bLastIron = bIron
277 self.fIronTime = CurTime()
278
279 if ( bIron ) then
280 self.SwayScale = 0.3
281 self.BobScale = 0.1
282 else
283 self.SwayScale = 1.0
284 self.BobScale = 1.0
285 end
286
287 end
288
289 local fIronTime = self.fIronTime or 0
290
291 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then
292 return pos, ang
293 end
294
295 local Mul = 1.0
296
297 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then
298
299 Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 )
300
301 if (!bIron) then Mul = 1 - Mul end
302
303 end
304
305 local Offset = self.IronSightsPos
306
307 if ( self.IronSightsAng ) then
308
309 ang = ang * 1
310 ang:RotateAroundAxis( ang:Right(), self.IronSightsAng.x * Mul )
311 ang:RotateAroundAxis( ang:Up(), self.IronSightsAng.y * Mul )
312 ang:RotateAroundAxis( ang:Forward(), self.IronSightsAng.z * Mul )
313
314
315 end
316
317 local Right = ang:Right()
318 local Up = ang:Up()
319 local Forward = ang:Forward()
320
321
322
323 pos = pos + Offset.x * Right * Mul
324 pos = pos + Offset.y * Forward * Mul
325 pos = pos + Offset.z * Up * Mul
326
327 return pos, ang
328
329end
330
331
332/*---------------------------------------------------------
333 SetIronsights
334---------------------------------------------------------*/
335function SWEP:SetIronsights( b )
336 self.Weapon:SetNetworkedBool( "Ironsights", b )
337end
338
339SWEP.NextSecondaryAttack = 0
340
341
342/*---------------------------------------------------------
343 SecondaryAttack
344---------------------------------------------------------*/
345function SWEP:SecondaryAttack()
346
347 if ( !self.IronSightsPos ) then return end
348 if ( self.NextSecondaryAttack > CurTime() ) then return end
349
350 bIronsights = !self.Weapon:GetNetworkedBool( "Ironsights", false )
351
352 self:SetIronsights( bIronsights )
353
354 self.NextSecondaryAttack = CurTime() + 0.1
355
356end
357
358
359/*---------------------------------------------------------
360 DrawHUD
361
362 Just a rough mock up showing how to draw your own crosshair.
363---------------------------------------------------------*/
364function SWEP:DrawHUD()
365
366 // No crosshair when ironsights is on
367 if ( self.Weapon:GetNetworkedBool( "Ironsights" ) ) then return end
368
369 local x = ScrW() / 2.0
370 local y = ScrH() / 2.0
371 local scale = 40 * self.Primary.Cone
372
373 // Scale the size of the crosshair according to how long ago we fired our weapon
374 local LastShootTime = self.Weapon:GetNetworkedFloat( "LastShootTime", 0 )
375 scale = scale * (2 - math.Clamp( (CurTime() - LastShootTime) * 5, 0.0, 1.0 ))
376
377 surface.SetDrawColor( 0, 255, 0, 255 )
378
379 // Draw an awesome crosshair
380 local gap = 40 * scale
381 local length = gap + 20 * scale
382 surface.DrawLine( x - length, y, x - gap, y )
383 surface.DrawLine( x + length, y, x + gap, y )
384 surface.DrawLine( x, y - length, x, y - gap )
385 surface.DrawLine( x, y + length, x, y + gap )
386
387end
388
389
390/*---------------------------------------------------------
391 onRestore
392 Loaded a saved game (or changelevel)
393---------------------------------------------------------*/
394function SWEP:OnRestore()
395 self.NextSecondaryAttack = 0
396 self:SetIronsights( false )
397end
398
399
400--/**************************************************************************************************\--
401--|------ END OF THIS CODE | THANKS TO mescool15| https://facepunch.com/member.php?u=165004 -------|--
402--\**************************************************************************************************/--
403
404 /*-----------------------------
405
406 self.Owner:SetWalkSpeed( 100 )
407 self.Owner:SetRunSpeed ( 150 )
408
409 self.Owner:SetWalkSpeed( 250 )
410 self.Owner:SetRunSpeed ( 500 )
411
412 ----------------------------*/
413
414
415function SWEP:Initialize()
416end
417
418function SWEP:Deploy()
419 if self.Weapon:Clip1() == 0 then
420 self.Weapon:SendWeaponAnim(ACT_VM_DRAW_EMPTY)
421 end
422 return true
423end
424
425function SWEP:Holster()
426 self:SetIronsights( false )
427end
428
429function SWEP:OnRemove()
430 self:SetIronsights( false )
431end
432
433
434function SWEP:Precache()
435end
436
437function SWEP:OwnerChanged()
438 self:SetIronsights( false )
439end
440
441local inRun = false;
442function SWEP:Think()
443 if (!inRun && self.Owner:KeyDown(IN_FORWARD) and self.Weapon:Clip1() > 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
444 self.Weapon:SendWeaponAnim(ACT_SPRINT)
445 inRun = true;
446 elseif (!inRun && self.Owner:KeyDown(IN_BACK) and self.Weapon:Clip1() > 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
447 self.Weapon:SendWeaponAnim(ACT_SPRINT)
448 inRun = true;
449 elseif (!inRun && self.Owner:KeyDown(IN_MOVELEFT) and self.Weapon:Clip1() > 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
450 self.Weapon:SendWeaponAnim(ACT_SPRINT)
451 inRun = true;
452 elseif (!inRun && self.Owner:KeyDown(IN_MOVERIGHT) and self.Weapon:Clip1() > 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
453 self.Weapon:SendWeaponAnim(ACT_SPRINT)
454 inRun = true;
455
456 elseif (self.Weapon:Clip1() > 0 and inRun && !self.Owner:KeyDown(IN_SPEED)) then
457 inRun = false
458 self.Weapon:SendWeaponAnim(ACT_VM_SPRINT_LEAVE)
459
460 elseif (self.Owner:KeyDown(IN_FORWARD) and self.Weapon:Clip1() == 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
461 self.Weapon:SendWeaponAnim(ACT_VM_SPRINT_IDLE) --Placeholder for sprint_empty
462 inRun = true;
463 elseif (self.Owner:KeyDown(IN_BACK) and self.Weapon:Clip1() == 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
464 self.Weapon:SendWeaponAnim(ACT_VM_SPRINT_IDLE) --Placeholder for sprint_empty
465 inRun = true;
466 elseif (self.Owner:KeyDown(IN_MOVELEFT) and self.Weapon:Clip1() == 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
467 self.Weapon:SendWeaponAnim(ACT_VM_SPRINT_IDLE) --Placeholder for sprint_empty
468 inRun = true;
469 elseif (self.Owner:KeyDown(IN_MOVERIGHT) and self.Weapon:Clip1() == 0 and !inRun && self.Owner:KeyDown(IN_SPEED)) then
470 self.Weapon:SendWeaponAnim(ACT_VM_SPRINT_IDLE) --Placeholder for sprint_empty
471 inRun = true;
472 elseif (self.Weapon:Clip1() == 0 and inRun && !self.Owner:KeyDown(IN_SPEED)) then
473 inRun = false
474 self.Weapon:SendWeaponAnim(ACT_VM_SPRINT_ENTER) --Placeholder for sprint_leave_empty
475 --self.Weapon:SendWeaponAnim(ACT_VM_IDLE_EMPTY)
476 end
477
478end
479
480
481/********************************************************
482 SWEP Construction Kit base code
483 Created by Clavus
484 Available for public use, thread at:
485 facepunch.com/threads/1032378
486
487
488 DESCRIPTION:
489 This script is meant for experienced scripters
490 that KNOW WHAT THEY ARE DOING. Don't come to me
491 with basic Lua questions.
492
493 Just copy into your SWEP or SWEP base of choice
494 and merge with your own code.
495
496 The SWEP.VElements, SWEP.WElements and
497 SWEP.ViewModelBoneMods tables are all optional
498 and only have to be visible to the client.
499********************************************************/
500function SWEP:Initialize()
501 // other initialize code goes here
502 if CLIENT then
503
504 // Create a new table for every weapon instance
505 self.VElements = table.FullCopy( self.VElements )
506 self.WElements = table.FullCopy( self.WElements )
507 self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
508 self:CreateModels(self.VElements) // create viewmodels
509 self:CreateModels(self.WElements) // create worldmodels
510
511 // init view model bone build function
512 if IsValid(self.Owner) then
513 local vm = self.Owner:GetViewModel()
514 if IsValid(vm) then
515 self:ResetBonePositions(vm)
516
517 // Init viewmodel visibility
518 if (self.ShowViewModel == nil or self.ShowViewModel) then
519 vm:SetColor(Color(255,255,255,255))
520 else
521 // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
522 vm:SetColor(Color(255,255,255,1))
523 // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
524 // 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
525 vm:SetMaterial("Debug/hsv")
526 end
527 end
528 end
529
530 end
531end
532function SWEP:Holster()
533
534 if CLIENT and IsValid(self.Owner) then
535 local vm = self.Owner:GetViewModel()
536 if IsValid(vm) then
537 self:ResetBonePositions(vm)
538 end
539 end
540
541 return true
542end
543function SWEP:OnRemove()
544 self:Holster()
545end
546if CLIENT then
547 SWEP.vRenderOrder = nil
548 function SWEP:ViewModelDrawn()
549
550 local vm = self.Owner:GetViewModel()
551 if !IsValid(vm) then return end
552
553 if (!self.VElements) then return end
554
555 self:UpdateBonePositions(vm)
556 if (!self.vRenderOrder) then
557
558 // we build a render order because sprites need to be drawn after models
559 self.vRenderOrder = {}
560 for k, v in pairs( self.VElements ) do
561 if (v.type == "Model") then
562 table.insert(self.vRenderOrder, 1, k)
563 elseif (v.type == "Sprite" or v.type == "Quad") then
564 table.insert(self.vRenderOrder, k)
565 end
566 end
567
568 end
569 for k, name in ipairs( self.vRenderOrder ) do
570
571 local v = self.VElements[name]
572 if (!v) then self.vRenderOrder = nil break end
573 if (v.hide) then continue end
574
575 local model = v.modelEnt
576 local sprite = v.spriteMaterial
577
578 if (!v.bone) then continue end
579
580 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
581
582 if (!pos) then continue end
583
584 if (v.type == "Model" and IsValid(model)) then
585 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
586 ang:RotateAroundAxis(ang:Up(), v.angle.y)
587 ang:RotateAroundAxis(ang:Right(), v.angle.p)
588 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
589 model:SetAngles(ang)
590 //model:SetModelScale(v.size)
591 local matrix = Matrix()
592 matrix:Scale(v.size)
593 model:EnableMatrix( "RenderMultiply", matrix )
594
595 if (v.material == "") then
596 model:SetMaterial("")
597 elseif (model:GetMaterial() != v.material) then
598 model:SetMaterial( v.material )
599 end
600
601 if (v.skin and v.skin != model:GetSkin()) then
602 model:SetSkin(v.skin)
603 end
604
605 if (v.bodygroup) then
606 for k, v in pairs( v.bodygroup ) do
607 if (model:GetBodygroup(k) != v) then
608 model:SetBodygroup(k, v)
609 end
610 end
611 end
612
613 if (v.surpresslightning) then
614 render.SuppressEngineLighting(true)
615 end
616
617 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
618 render.SetBlend(v.color.a/255)
619 model:DrawModel()
620 render.SetBlend(1)
621 render.SetColorModulation(1, 1, 1)
622
623 if (v.surpresslightning) then
624 render.SuppressEngineLighting(false)
625 end
626
627 elseif (v.type == "Sprite" and sprite) then
628
629 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
630 render.SetMaterial(sprite)
631 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
632
633 elseif (v.type == "Quad" and v.draw_func) then
634
635 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
636 ang:RotateAroundAxis(ang:Up(), v.angle.y)
637 ang:RotateAroundAxis(ang:Right(), v.angle.p)
638 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
639
640 cam.Start3D2D(drawpos, ang, v.size)
641 v.draw_func( self )
642 cam.End3D2D()
643 end
644
645 end
646
647 end
648 SWEP.wRenderOrder = nil
649 function SWEP:DrawWorldModel()
650
651 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
652 self:DrawModel()
653 end
654
655 if (!self.WElements) then return end
656
657 if (!self.wRenderOrder) then
658 self.wRenderOrder = {}
659 for k, v in pairs( self.WElements ) do
660 if (v.type == "Model") then
661 table.insert(self.wRenderOrder, 1, k)
662 elseif (v.type == "Sprite" or v.type == "Quad") then
663 table.insert(self.wRenderOrder, k)
664 end
665 end
666 end
667
668 if (IsValid(self.Owner)) then
669 bone_ent = self.Owner
670 else
671 // when the weapon is dropped
672 bone_ent = self
673 end
674
675 for k, name in pairs( self.wRenderOrder ) do
676
677 local v = self.WElements[name]
678 if (!v) then self.wRenderOrder = nil break end
679 if (v.hide) then continue end
680
681 local pos, ang
682
683 if (v.bone) then
684 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
685 else
686 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
687 end
688
689 if (!pos) then continue end
690
691 local model = v.modelEnt
692 local sprite = v.spriteMaterial
693
694 if (v.type == "Model" and IsValid(model)) then
695 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
696 ang:RotateAroundAxis(ang:Up(), v.angle.y)
697 ang:RotateAroundAxis(ang:Right(), v.angle.p)
698 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
699 model:SetAngles(ang)
700 //model:SetModelScale(v.size)
701 local matrix = Matrix()
702 matrix:Scale(v.size)
703 model:EnableMatrix( "RenderMultiply", matrix )
704
705 if (v.material == "") then
706 model:SetMaterial("")
707 elseif (model:GetMaterial() != v.material) then
708 model:SetMaterial( v.material )
709 end
710
711 if (v.skin and v.skin != model:GetSkin()) then
712 model:SetSkin(v.skin)
713 end
714
715 if (v.bodygroup) then
716 for k, v in pairs( v.bodygroup ) do
717 if (model:GetBodygroup(k) != v) then
718 model:SetBodygroup(k, v)
719 end
720 end
721 end
722
723 if (v.surpresslightning) then
724 render.SuppressEngineLighting(true)
725 end
726
727 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
728 render.SetBlend(v.color.a/255)
729 model:DrawModel()
730 render.SetBlend(1)
731 render.SetColorModulation(1, 1, 1)
732
733 if (v.surpresslightning) then
734 render.SuppressEngineLighting(false)
735 end
736
737 elseif (v.type == "Sprite" and sprite) then
738
739 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
740 render.SetMaterial(sprite)
741 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
742
743 elseif (v.type == "Quad" and v.draw_func) then
744
745 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
746 ang:RotateAroundAxis(ang:Up(), v.angle.y)
747 ang:RotateAroundAxis(ang:Right(), v.angle.p)
748 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
749
750 cam.Start3D2D(drawpos, ang, v.size)
751 v.draw_func( self )
752 cam.End3D2D()
753 end
754
755 end
756
757 end
758 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
759
760 local bone, pos, ang
761 if (tab.rel and tab.rel != "") then
762
763 local v = basetab[tab.rel]
764
765 if (!v) then return end
766
767 // Technically, if there exists an element with the same name as a bone
768 // you can get in an infinite loop. Let's just hope nobody's that stupid.
769 pos, ang = self:GetBoneOrientation( basetab, v, ent )
770
771 if (!pos) then return end
772
773 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
774 ang:RotateAroundAxis(ang:Up(), v.angle.y)
775 ang:RotateAroundAxis(ang:Right(), v.angle.p)
776 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
777
778 else
779
780 bone = ent:LookupBone(bone_override or tab.bone)
781 if (!bone) then return end
782
783 pos, ang = Vector(0,0,0), Angle(0,0,0)
784 local m = ent:GetBoneMatrix(bone)
785 if (m) then
786 pos, ang = m:GetTranslation(), m:GetAngles()
787 end
788
789 if (IsValid(self.Owner) and self.Owner:IsPlayer() and
790 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
791 ang.r = -ang.r // Fixes mirrored models
792 end
793
794 end
795
796 return pos, ang
797 end
798 function SWEP:CreateModels( tab )
799 if (!tab) then return end
800 // Create the clientside models here because Garry says we can't do it in the render hook
801 for k, v in pairs( tab ) do
802 if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
803 string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
804
805 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
806 if (IsValid(v.modelEnt)) then
807 v.modelEnt:SetPos(self:GetPos())
808 v.modelEnt:SetAngles(self:GetAngles())
809 v.modelEnt:SetParent(self)
810 v.modelEnt:SetNoDraw(true)
811 v.createdModel = v.model
812 else
813 v.modelEnt = nil
814 end
815
816 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
817 and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
818
819 local name = v.sprite.."-"
820 local params = { ["$basetexture"] = v.sprite }
821 // make sure we create a unique name based on the selected options
822 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
823 for i, j in pairs( tocheck ) do
824 if (v[j]) then
825 params["$"..j] = 1
826 name = name.."1"
827 else
828 name = name.."0"
829 end
830 end
831
832 v.createdSprite = v.sprite
833 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
834
835 end
836 end
837
838 end
839
840 local allbones
841 local hasGarryFixedBoneScalingYet = false
842
843 function SWEP:UpdateBonePositions(vm)
844
845 if self.ViewModelBoneMods then
846
847 if (!vm:GetBoneCount()) then return end
848
849 // !! WORKAROUND !! //
850 // We need to check all model names :/
851 local loopthrough = self.ViewModelBoneMods
852 if (!hasGarryFixedBoneScalingYet) then
853 allbones = {}
854 for i=0, vm:GetBoneCount() do
855 local bonename = vm:GetBoneName(i)
856 if (self.ViewModelBoneMods[bonename]) then
857 allbones[bonename] = self.ViewModelBoneMods[bonename]
858 else
859 allbones[bonename] = {
860 scale = Vector(1,1,1),
861 pos = Vector(0,0,0),
862 angle = Angle(0,0,0)
863 }
864 end
865 end
866
867 loopthrough = allbones
868 end
869 // !! ----------- !! //
870
871 for k, v in pairs( loopthrough ) do
872 local bone = vm:LookupBone(k)
873 if (!bone) then continue end
874
875 // !! WORKAROUND !! //
876 local s = Vector(v.scale.x,v.scale.y,v.scale.z)
877 local p = Vector(v.pos.x,v.pos.y,v.pos.z)
878 local ms = Vector(1,1,1)
879 if (!hasGarryFixedBoneScalingYet) then
880 local cur = vm:GetBoneParent(bone)
881 while(cur >= 0) do
882 local pscale = loopthrough[vm:GetBoneName(cur)].scale
883 ms = ms * pscale
884 cur = vm:GetBoneParent(cur)
885 end
886 end
887
888 s = s * ms
889 // !! ----------- !! //
890
891 if vm:GetManipulateBoneScale(bone) != s then
892 vm:ManipulateBoneScale( bone, s )
893 end
894 if vm:GetManipulateBoneAngles(bone) != v.angle then
895 vm:ManipulateBoneAngles( bone, v.angle )
896 end
897 if vm:GetManipulateBonePosition(bone) != p then
898 vm:ManipulateBonePosition( bone, p )
899 end
900 end
901 else
902 self:ResetBonePositions(vm)
903 end
904
905 end
906
907 function SWEP:ResetBonePositions(vm)
908
909 if (!vm:GetBoneCount()) then return end
910 for i=0, vm:GetBoneCount() do
911 vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
912 vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
913 vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
914 end
915
916 end
917
918 /**************************
919 Global utility code
920 **************************/
921
922 // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
923 // Does not copy entities of course, only copies their reference.
924 // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
925 function table.FullCopy( tab )
926 if (!tab) then return nil end
927
928 local res = {}
929 for k, v in pairs( tab ) do
930 if (type(v) == "table") then
931 res[k] = table.FullCopy(v) // recursion ho!
932 elseif (type(v) == "Vector") then
933 res[k] = Vector(v.x, v.y, v.z)
934 elseif (type(v) == "Angle") then
935 res[k] = Angle(v.p, v.y, v.r)
936 else
937 res[k] = v
938 end
939 end
940
941 return res
942
943 end
944
945end