· 8 years ago · Jun 18, 2018, 04:46 AM
1AddCSLuaFile()
2resource.AddFile("sound/weapons/plasma/end.wav")
3resource.AddFile("sound/weapons/plasma/fire.wav")
4
5
6if CLIENT then
7 SWEP.PrintName = "Hakai"
8 SWEP.Slot = 1
9
10end
11
12
13/********************************************************
14 SWEP Construction Kit base code
15 Created by Clavus
16 Available for public use, thread at:
17 facepunch.com/threads/1032378
18
19
20 DESCRIPTION:
21 This script is meant for experienced scripters
22 that KNOW WHAT THEY ARE DOING. Don't come to me
23 with basic Lua questions.
24
25 Just copy into your SWEP or SWEP base of choice
26 and merge with your own code.
27
28 The SWEP.VElements, SWEP.WElements and
29 SWEP.ViewModelBoneMods tables are all optional
30 and only have to be visible to the client.
31********************************************************/
32
33function SWEP:Initialize()
34 self:SetHoldType( "normal" )
35 // other initialize code goes here
36
37 if CLIENT then
38
39 // Create a new table for every weapon instance
40 self.VElements = table.FullCopy( self.VElements )
41 self.WElements = table.FullCopy( self.WElements )
42 self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
43
44 self:CreateModels(self.VElements) // create viewmodels
45 self:CreateModels(self.WElements) // create worldmodels
46
47 // init view model bone build function
48 if IsValid(self.Owner) then
49 local vm = self.Owner:GetViewModel()
50 if IsValid(vm) then
51 self:ResetBonePositions(vm)
52
53 // Init viewmodel visibility
54 if (self.ShowViewModel == nil or self.ShowViewModel) then
55 vm:SetColor(Color(255,255,255,255))
56 else
57 // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
58 vm:SetColor(Color(255,255,255,1))
59 // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
60 // 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
61 vm:SetMaterial("Debug/hsv")
62 end
63 end
64 end
65
66 end
67
68end
69
70function SWEP:Holster()
71
72 if CLIENT and IsValid(self.Owner) then
73 local vm = self.Owner:GetViewModel()
74 if IsValid(vm) then
75 self:ResetBonePositions(vm)
76 end
77 end
78 if self:IsValid() then self.spin = 0 end
79
80 return true
81end
82
83function SWEP:OnRemove()
84 self:Holster()
85end
86
87if CLIENT then
88
89 SWEP.vRenderOrder = nil
90 function SWEP:ViewModelDrawn()
91
92 local vm = self.Owner:GetViewModel()
93 if !IsValid(vm) then return end
94
95 if (!self.VElements) then return end
96
97 self:UpdateBonePositions(vm)
98
99 if (!self.vRenderOrder) then
100
101 // we build a render order because sprites need to be drawn after models
102 self.vRenderOrder = {}
103
104 for k, v in pairs( self.VElements ) do
105 if (v.type == "Model") then
106 table.insert(self.vRenderOrder, 1, k)
107 elseif (v.type == "Sprite" or v.type == "Quad") then
108 table.insert(self.vRenderOrder, k)
109 end
110 end
111
112 end
113
114 for k, name in ipairs( self.vRenderOrder ) do
115
116 local v = self.VElements[name]
117 if (!v) then self.vRenderOrder = nil break end
118 if (v.hide) then continue end
119
120 local model = v.modelEnt
121 local sprite = v.spriteMaterial
122
123 if (!v.bone) then continue end
124
125 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
126
127 if (!pos) then continue end
128
129 if (v.type == "Model" and IsValid(model)) then
130
131 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
132 ang:RotateAroundAxis(ang:Up(), v.angle.y)
133 ang:RotateAroundAxis(ang:Right(), v.angle.p)
134 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
135
136 model:SetAngles(ang)
137 //model:SetModelScale(v.size)
138 local matrix = Matrix()
139 matrix:Scale(v.size)
140 model:EnableMatrix( "RenderMultiply", matrix )
141
142 if (v.material == "") then
143 model:SetMaterial("")
144 elseif (model:GetMaterial() != v.material) then
145 model:SetMaterial( v.material )
146 end
147
148 if (v.skin and v.skin != model:GetSkin()) then
149 model:SetSkin(v.skin)
150 end
151
152 if (v.bodygroup) then
153 for k, v in pairs( v.bodygroup ) do
154 if (model:GetBodygroup(k) != v) then
155 model:SetBodygroup(k, v)
156 end
157 end
158 end
159
160 if (v.surpresslightning) then
161 render.SuppressEngineLighting(true)
162 end
163
164 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
165 render.SetBlend(v.color.a/255)
166 model:DrawModel()
167 render.SetBlend(1)
168 render.SetColorModulation(1, 1, 1)
169
170 if (v.surpresslightning) then
171 render.SuppressEngineLighting(false)
172 end
173
174 elseif (v.type == "Sprite" and sprite) then
175
176 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
177 render.SetMaterial(sprite)
178 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
179
180 elseif (v.type == "Quad" and v.draw_func) then
181
182 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
183 ang:RotateAroundAxis(ang:Up(), v.angle.y)
184 ang:RotateAroundAxis(ang:Right(), v.angle.p)
185 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
186
187 cam.Start3D2D(drawpos, ang, v.size)
188 v.draw_func( self )
189 cam.End3D2D()
190
191 end
192
193 end
194
195 end
196
197 SWEP.wRenderOrder = nil
198 function SWEP:DrawWorldModel()
199
200 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
201 self:DrawModel()
202 end
203
204 if (!self.WElements) then return end
205
206 if (!self.wRenderOrder) then
207
208 self.wRenderOrder = {}
209
210 for k, v in pairs( self.WElements ) do
211 if (v.type == "Model") then
212 table.insert(self.wRenderOrder, 1, k)
213 elseif (v.type == "Sprite" or v.type == "Quad") then
214 table.insert(self.wRenderOrder, k)
215 end
216 end
217
218 end
219
220 if (IsValid(self.Owner)) then
221 bone_ent = self.Owner
222 else
223 // when the weapon is dropped
224 bone_ent = self
225 end
226
227 for k, name in pairs( self.wRenderOrder ) do
228
229 local v = self.WElements[name]
230 if (!v) then self.wRenderOrder = nil break end
231 if (v.hide) then continue end
232
233 local pos, ang
234
235 if (v.bone) then
236 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
237 else
238 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
239 end
240
241 if (!pos) then continue end
242
243 local model = v.modelEnt
244 local sprite = v.spriteMaterial
245
246 if (v.type == "Model" and IsValid(model)) then
247
248 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
249 ang:RotateAroundAxis(ang:Up(), v.angle.y)
250 ang:RotateAroundAxis(ang:Right(), v.angle.p)
251 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
252
253 model:SetAngles(ang)
254 //model:SetModelScale(v.size)
255 local matrix = Matrix()
256 matrix:Scale(v.size)
257 model:EnableMatrix( "RenderMultiply", matrix )
258
259 if (v.material == "") then
260 model:SetMaterial("")
261 elseif (model:GetMaterial() != v.material) then
262 model:SetMaterial( v.material )
263 end
264
265 if (v.skin and v.skin != model:GetSkin()) then
266 model:SetSkin(v.skin)
267 end
268
269 if (v.bodygroup) then
270 for k, v in pairs( v.bodygroup ) do
271 if (model:GetBodygroup(k) != v) then
272 model:SetBodygroup(k, v)
273 end
274 end
275 end
276
277 if (v.surpresslightning) then
278 render.SuppressEngineLighting(true)
279 end
280
281 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
282 render.SetBlend(v.color.a/255)
283 model:DrawModel()
284 render.SetBlend(1)
285 render.SetColorModulation(1, 1, 1)
286
287 if (v.surpresslightning) then
288 render.SuppressEngineLighting(false)
289 end
290
291 elseif (v.type == "Sprite" and sprite) then
292
293 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
294 render.SetMaterial(sprite)
295 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
296
297 elseif (v.type == "Quad" and v.draw_func) then
298
299 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
300 ang:RotateAroundAxis(ang:Up(), v.angle.y)
301 ang:RotateAroundAxis(ang:Right(), v.angle.p)
302 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
303
304 cam.Start3D2D(drawpos, ang, v.size)
305 v.draw_func( self )
306 cam.End3D2D()
307
308 end
309
310 end
311
312 end
313
314 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
315
316 local bone, pos, ang
317 if (tab.rel and tab.rel != "") then
318
319 local v = basetab[tab.rel]
320
321 if (!v) then return end
322
323 // Technically, if there exists an element with the same name as a bone
324 // you can get in an infinite loop. Let's just hope nobody's that stupid.
325 pos, ang = self:GetBoneOrientation( basetab, v, ent )
326
327 if (!pos) then return end
328
329 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
330 ang:RotateAroundAxis(ang:Up(), v.angle.y)
331 ang:RotateAroundAxis(ang:Right(), v.angle.p)
332 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
333
334 else
335
336 bone = ent:LookupBone(bone_override or tab.bone)
337
338 if (!bone) then return end
339
340 pos, ang = Vector(0,0,0), Angle(0,0,0)
341 local m = ent:GetBoneMatrix(bone)
342 if (m) then
343 pos, ang = m:GetTranslation(), m:GetAngles()
344 end
345
346 if (IsValid(self.Owner) and self.Owner:IsPlayer() and
347 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
348 ang.r = -ang.r // Fixes mirrored models
349 end
350
351 end
352
353 return pos, ang
354 end
355
356 function SWEP:CreateModels( tab )
357
358 if (!tab) then return end
359
360 // Create the clientside models here because Garry says we can't do it in the render hook
361 for k, v in pairs( tab ) do
362 if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
363 string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
364
365 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
366 if (IsValid(v.modelEnt)) then
367 v.modelEnt:SetPos(self:GetPos())
368 v.modelEnt:SetAngles(self:GetAngles())
369 v.modelEnt:SetParent(self)
370 v.modelEnt:SetNoDraw(true)
371 v.createdModel = v.model
372 else
373 v.modelEnt = nil
374 end
375
376 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
377 and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
378
379 local name = v.sprite.."-"
380 local params = { ["$basetexture"] = v.sprite }
381 // make sure we create a unique name based on the selected options
382 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
383 for i, j in pairs( tocheck ) do
384 if (v[j]) then
385 params["$"..j] = 1
386 name = name.."1"
387 else
388 name = name.."0"
389 end
390 end
391
392 v.createdSprite = v.sprite
393 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
394
395 end
396 end
397
398 end
399
400 local allbones
401 local hasGarryFixedBoneScalingYet = false
402
403 function SWEP:UpdateBonePositions(vm)
404
405 if self.ViewModelBoneMods then
406
407 if (!vm:GetBoneCount()) then return end
408
409 // !! WORKAROUND !! //
410 // We need to check all model names :/
411 local loopthrough = self.ViewModelBoneMods
412 if (!hasGarryFixedBoneScalingYet) then
413 allbones = {}
414 for i=0, vm:GetBoneCount() do
415 local bonename = vm:GetBoneName(i)
416 if (self.ViewModelBoneMods[bonename]) then
417 allbones[bonename] = self.ViewModelBoneMods[bonename]
418 else
419 allbones[bonename] = {
420 scale = Vector(1,1,1),
421 pos = Vector(0,0,0),
422 angle = Angle(0,0,0)
423 }
424 end
425 end
426
427 loopthrough = allbones
428 end
429 // !! ----------- !! //
430
431 for k, v in pairs( loopthrough ) do
432 local bone = vm:LookupBone(k)
433 if (!bone) then continue end
434
435 // !! WORKAROUND !! //
436 local s = Vector(v.scale.x,v.scale.y,v.scale.z)
437 local p = Vector(v.pos.x,v.pos.y,v.pos.z)
438 local ms = Vector(1,1,1)
439 if (!hasGarryFixedBoneScalingYet) then
440 local cur = vm:GetBoneParent(bone)
441 while(cur >= 0) do
442 local pscale = loopthrough[vm:GetBoneName(cur)].scale
443 ms = ms * pscale
444 cur = vm:GetBoneParent(cur)
445 end
446 end
447
448 s = s * ms
449 // !! ----------- !! //
450
451 if vm:GetManipulateBoneScale(bone) != s then
452 vm:ManipulateBoneScale( bone, s )
453 end
454 if vm:GetManipulateBoneAngles(bone) != v.angle then
455 vm:ManipulateBoneAngles( bone, v.angle )
456 end
457 if vm:GetManipulateBonePosition(bone) != p then
458 vm:ManipulateBonePosition( bone, p )
459 end
460 end
461 else
462 self:ResetBonePositions(vm)
463 end
464
465 end
466
467 function SWEP:ResetBonePositions(vm)
468
469 if (!vm:GetBoneCount()) then return end
470 for i=0, vm:GetBoneCount() do
471 vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
472 vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
473 vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
474 end
475
476 end
477
478 /**************************
479 Global utility code
480 **************************/
481
482 // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
483 // Does not copy entities of course, only copies their reference.
484 // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
485 function table.FullCopy( tab )
486
487 if (!tab) then return nil end
488
489 local res = {}
490 for k, v in pairs( tab ) do
491 if (type(v) == "table") then
492 res[k] = table.FullCopy(v) // recursion ho!
493 elseif (type(v) == "Vector") then
494 res[k] = Vector(v.x, v.y, v.z)
495 elseif (type(v) == "Angle") then
496 res[k] = Angle(v.p, v.y, v.r)
497 else
498 res[k] = v
499 end
500 end
501
502 return res
503
504 end
505
506end
507
508function SWEP:CanPrimaryAttack()
509
510 if ( self.Weapon:Clip1() <= 0 ) then
511
512 --self:EmitSound( "Weapon_Pistol.Empty" )
513 self:SetNextPrimaryFire( CurTime() + 0.2 )
514 self:Reload()
515 return false
516
517 end
518
519 return true
520
521end
522
523
524
525SWEP.Base = "weapon_base"
526
527
528
529SWEP.VElements = {
530 ["P1"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 2.885), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
531 ["P1++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 4.26), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
532 ["T1"] = { type = "Model", model = "models/props_combine/combinetrain01a.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(1.577, -5.117, 6.006), angle = Angle(90, 0, 0), size = Vector(0.03, 0.009, 0.009), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
533 ["T8"] = { type = "Model", model = "models/props_combine/suit_charger001.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(-0.816, -4.867, 5.864), angle = Angle(0, 180, 0), size = Vector(0.104, 0.149, 0.472), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
534 ["T2"] = { type = "Model", model = "models/props_combine/combine_generator01.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(-0.457, -5.797, 3.941), angle = Angle(180, 0, 0), size = Vector(0.054, 0.014, 0.074), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
535 ["T4"] = { type = "Model", model = "models/props_combine/combine_teleportplatform.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(-0.005, -6.567, 1.891), angle = Angle(0, 0, 0), size = Vector(0.014, 0.014, 0.046), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
536 ["T3"] = { type = "Model", model = "models/props_combine/masterinterface.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(-0.071, -5.773, -0.773), angle = Angle(120, -90, 0), size = Vector(0.023, 0.017, 0.019), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
537 ["P1++++++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 6.591), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
538 ["bb"] = { type = "Model", model = "models/props_lab/labpart.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.045, -4.087, -12.82), angle = Angle(0, 0, 90), size = Vector(0.192, 0.451, 0.192), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
539 ["P1+"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 3.446), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
540 ["P1++++++++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 7.335), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
541 ["P1+++++++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 7.31), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
542 ["b2"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "v_weapon.p90_Parent", rel = "bb", pos = Vector(-1.208, -1.634, 0), angle = Angle(0, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
543 ["b2+"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "v_weapon.p90_Parent", rel = "bb", pos = Vector(1.21, -1.634, 0), angle = Angle(180, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
544 ["P1+++++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 5.703), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
545 ["T6"] = { type = "Model", model = "models/props_combine/combine_tptimer.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.212, -5.499, 9.67), angle = Angle(-90, 0, -90), size = Vector(0.025, 0.014, 0.014), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
546 ["b2++"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "v_weapon.p90_Parent", rel = "bb", pos = Vector(0, -0.76, -1.211), angle = Angle(90, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
547 ["P1++++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 5.061), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
548 ["T7"] = { type = "Model", model = "models/props_combine/combine_lock01.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.573, -5.896, 1.815), angle = Angle(0, 0, 90), size = Vector(0.175, 0.189, 0.092), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
549 ["T5"] = { type = "Model", model = "models/props_combine/weaponstripper.mdl", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.689, -6.582, 8.557), angle = Angle(90, 0, 0), size = Vector(0.1, 0.009, 0.009), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
550 ["P1+++"] = { type = "Sprite", sprite = "sprites/animglow02", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0, -6.677, 4.824), size = { x = 2.219, y = 1.023 }, color = Color(0, 152, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
551 ["b2+++"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "v_weapon.p90_Parent", rel = "bb", pos = Vector(0, -0.76, 1.21), angle = Angle(-90, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
552 ["flash"] = { type = "Sprite", sprite = "sprites/plasmaember", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.72, -3.264, -22.202), size = { x = 1, y = 1 }, color = Color(255, 255, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
553 ["flash+"] = { type = "Sprite", sprite = "sprites/plasmaember", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.72, -3.264, -22.202), size = { x = 1, y = 1 }, color = Color(255, 255, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
554 ["flash++"] = { type = "Sprite", sprite = "sprites/plasmaember", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.72, -3.264, -22.202), size = { x = 1, y = 1 }, color = Color(255, 255, 255, 255), nocull = true, additive = true, vertexalpha = true, vertexcolor = true, ignorez = false},
555 ["screen"] = { type = "Quad", bone = "v_weapon.p90_Parent", rel = "", pos = Vector(0.127, -6.822, 10.965), angle = Angle(0, 0, -22.542), size = 0.035, draw_func = nil}
556
557 }
558
559SWEP.WElements = {
560 ["b2++"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "bb", pos = Vector(0, -0.76, -1.211), angle = Angle(90, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
561 ["b2+++"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "bb", pos = Vector(0, -0.76, 1.21), angle = Angle(-90, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
562 ["bb"] = { type = "Model", model = "models/props_lab/labpart.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(19.219, 1.804, -6.922), angle = Angle(0, 90, 8.576), size = Vector(0.192, 0.451, 0.192), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
563 ["T8"] = { type = "Model", model = "models/props_combine/suit_charger001.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(6.399, 2.13, -4.969), angle = Angle(0, -90, -99.293), size = Vector(0.104, 0.149, 0.472), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
564 ["T2"] = { type = "Model", model = "models/props_combine/combine_generator01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(3.726, -0.56, -5.864), angle = Angle(-97.789, 0, 0), size = Vector(0.097, 0.097, 0.097), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
565 ["T1"] = { type = "Model", model = "models/props_combine/combinetrain01a.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(7.426, 1.037, -3.878), angle = Angle(171.91, 0, 0), size = Vector(0.03, 0.025, 0.009), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
566 ["b2"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "bb", pos = Vector(-1.208, -1.634, 0), angle = Angle(0, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
567 ["b2+"] = { type = "Model", model = "models/props_combine/combine_binocular01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "bb", pos = Vector(1.21, -1.634, 0), angle = Angle(180, 0, -90), size = Vector(0.111, 0.111, 0.338), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
568}
569
570
571
572
573SWEP.Spawnable = true
574
575SWEP.Author = "Seris"
576SWEP.Contact = "AJ10017@hotmail.com"
577SWEP.Purpose = "Beam Weapon, unlimited ammo"
578SWEP.Instructions = "Aim and shoot"
579SWEP.Weight = 3
580SWEP.Category = "Seris"
581SWEP.Slot = 2
582
583SWEP.Primary.Damage = 100000000
584SWEP.Primary.Delay = 0.001
585SWEP.Primary.Cone = 0.0075
586SWEP.Primary.ClipSize = 100
587SWEP.Primary.ClipMax = 100
588SWEP.Primary.DefaultClip = 100
589SWEP.Primary.Automatic = true
590SWEP.Primary.Ammo = ""
591SWEP.Primary.Recoil = 0.2
592SWEP.AmmoDevision = 7
593SWEP.Inc = 1
594SWEP.spin = 0
595local cspin = 0
596
597SWEP.UseHands = true
598SWEP.ViewModelFlip = false
599SWEP.ViewModelFOV = 68
600SWEP.ViewModel = "models/weapons/cstrike/c_smg_p90.mdl"
601SWEP.WorldModel = "models/weapons/w_smg_p90.mdl"
602
603SWEP.IronSightsPos = Vector(-6.421, -4.528, 3.3)
604SWEP.IronSightsAng = Vector(-1, 0, 0)
605SWEP.End = 0
606
607SWEP.CanFire = true
608SWEP.A = 0
609
610function SWEP:SetupDataTables()
611 self:NetworkVar("Float", 0, "Spin")
612 self:NetworkVar("Float", 0, "A")
613end
614
615
616
617
618function SWEP:GetHeadshotMultiplier(victim, dmginfo)
619 local att = dmginfo:GetAttacker()
620 if not IsValid(att) then return 2 end
621
622 local dist = victim:GetPos():Distance(att:GetPos())
623 local d = math.max(0, dist - 150)
624
625 -- decay from 3.2 to 1.7
626 return 1.7 + math.max(0, (1.5 - 0.002 * (d ^ 1.25)))
627end
628
629function SWEP:PrimaryAttack()
630
631 if(!self:CanPrimaryAttack()) then
632 return
633 end
634 local tr = util.GetPlayerTrace( self.Owner )
635 tr.mask = bit.bor( CONTENTS_SOLID, CONTENTS_MOVEABLE, CONTENTS_MONSTER, CONTENTS_WINDOW, CONTENTS_DEBRIS, CONTENTS_GRATE, CONTENTS_AUX )
636 local trace = util.TraceLine( tr )
637
638
639
640 local ang = Angle( math.Rand(-0.27,-0.27) * self.Primary.Recoil, math.Rand(-0.2,0.2) *self.Primary.Recoil, math.Rand(-0.2,0.2) )
641
642
643
644 local bullet = {}
645 bullet.Num = 1
646 bullet.Src = self.Owner:GetShootPos()
647 bullet.Dir = self.Owner:GetAimVector()+Vector(0,0,(self.Owner:GetViewPunchAngles().pitch*-1)/50)
648 bullet.Spread = Vector( self.Primary.Cone*(41-(self.spin*4)), self.Primary.Cone*(41-(self.spin*4)), 0 )
649 bullet.Tracer = 1
650 bullet.TracerName = "beam"
651 bullet.Damage = 3
652 bullet.Force = 1
653 bullet.AmmoType = "Pistol"
654 bullet.Callback = function(ply, tr, dmg)
655 dmg:SetDamageType(DMG_DISSOLVE)
656 if tr.HitPos:Distance(self.Owner:GetPos())>4000 then dmg:ScaleDamage(0.5) end
657
658 end
659 self.Owner:FireBullets( bullet )
660 //self:ShootEffects()
661 self.Owner:ViewPunch( ang * (math.Rand(15,17)-self.spin*1.5) )
662 self.Inc = self.Inc + 1
663 if self.Inc > self.AmmoDevision then
664 self.Inc = 1
665 self:TakePrimaryAmmo(2)
666 end
667 self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
668 self.Owner:MuzzleFlash()
669 if self.spin < 10 then self.spin = self.spin + 0.2 end
670 if self.CanFire == true and self:IsValid() then
671 self.FSound = CreateSound(self.Owner,"weapons/plasma/beam2.wav")
672 self.FSound:PlayEx(1,(self.spin*5))
673 self.FSound:SetSoundLevel(80)
674 self.CanFire = false
675 end
676 local End = function()
677 if self:IsValid() then
678 self.CanFire = true
679 self.FSound:Stop()
680 self.ESound = CreateSound(self.Owner,"weapons/plasma/beamend.wav")
681 self.ESound:PlayEx(1,self.End)
682 self.ESound:SetSoundLevel(80)
683 end
684 end
685 if self.FSound:IsPlaying() and self:IsValid() then
686 self.FSound:ChangePitch((self.spin*9)+60,0)
687 self.End = (self.spin*9)+60
688 end
689
690 local Reg = function()
691 if self:IsValid() then
692 if self:Clip1() < 100 then self:SetClip1(self:Clip1()+1) end
693 end
694 end
695 local SReg = function()
696 if self:IsValid() then
697 timer.Create("res"..self.Owner:EntIndex(),0.02,200,Reg)
698 end
699 end
700 if self:IsValid() then
701 timer.Destroy("stop"..self.Owner:EntIndex())
702 timer.Destroy("regen"..self.Owner:EntIndex())
703 timer.Destroy("res"..self.Owner:EntIndex())
704 timer.Create("Stop"..self.Owner:EntIndex(),0.1,1,End)
705 timer.Create("regen"..self.Owner:EntIndex(),0.7,1,SReg)
706 end
707
708 self.A = 255
709end
710
711function SWEP:SecondaryAttack() return end
712
713function SWEP:Think()
714
715 if !self:IsValid() and (self.FSound:IsPlaying() or self.ESound:IsPlaying()) then
716 if timer.Exists("stop") then timer.Destroy("stop") end
717 if timer.Exists("regen") then timer.Destroy("regen") end
718 if timer.Exists("res") then timer.Destroy("res") end
719 self.ESound:Stop()
720 self.FSound:Stop()
721 self.CanFire=true
722 end
723 cspin = self.spin
724 if self.spin > 0.5 then self.spin = self.spin - 0.05 end
725 if SERVER then
726 self:SetNetworkedFloat("Spin",self.spin)
727 self:SetNetworkedFloat("A",self.A)
728 end
729 if CLIENT then
730 local spin = self:GetNetworkedFloat("Spin",0)
731 local A = self:GetNetworkedFloat("A",0)
732 --print(spin)
733 self.VElements["bb"].angle = self.VElements["bb"].angle - Angle(0,spin*2.5,0)
734 self.VElements["bb"].color = Color(0+(spin*20),0+(spin*20),0+(spin*20),255)
735
736 self.VElements["b2"].angle = Angle(0, spin*-3, -90)
737 self.VElements["b2+"].angle = Angle(180, spin*3, -90)
738 self.VElements["b2++"].angle = Angle(90, 0, -90)
739 self.VElements["b2+++"].angle = Angle(-90, 0, -90)
740
741 self.VElements["P1"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
742 self.VElements["P1+"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
743 self.VElements["P1++"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
744 self.VElements["P1+++"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
745 self.VElements["P1++++"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
746 self.VElements["P1+++++"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
747 self.VElements["P1++++++"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
748 self.VElements["P1+++++++"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
749 self.VElements["P1++++++++"].color = Color(0,155,255,math.Rand(0,60)+(spin*10))
750
751 self.VElements["flash"].size.x = spin*math.Rand(5,14)
752 self.VElements["flash+"].size.x = spin*math.Rand(5,14)
753 self.VElements["flash++"].size.x = spin*math.Rand(5,14)
754
755 self.VElements["flash"].size.y = spin*math.Rand(0.2,3)
756 self.VElements["flash+"].size.y = spin*math.Rand(0.2,3)
757 self.VElements["flash++"].size.y = spin*math.Rand(0.2,3)
758
759 self.VElements["flash"].color = Color(150,150,255,A)
760 self.VElements["flash+"].color = Color(150,150,255,A)
761 self.VElements["flash++"].color = Color(150,150,255,A)
762 end
763
764 if self.A > 0 then self.A = self.A - 5 end
765
766
767 self.VElements["screen"].draw_func = function( weapon )
768 draw.RoundedBox(0,-38,-14,75,15,Color(100,100,255,50))
769 draw.SimpleText("CHARGE: "..self:Clip1(), "default", 0, 0, Color(255,255,255,255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
770
771
772 end
773 self:NextThink( CurTime() + 0.056 )
774 return true
775end
776
777function SWEP:DoImpactEffect(tr,DMG_DISSOLVE)
778 return true;
779end
780
781function SWEP:OnRemove()
782 if self.FSound != nil then
783 self.FSound:Stop()
784 end
785end