· 8 years ago · Jul 31, 2018, 02:00 PM
1if (SERVER) then --the init.lua stuff goes in here
2
3
4 AddCSLuaFile ("shared.lua");
5
6
7 SWEP.Weight = 5;
8 SWEP.AutoSwitchTo = false;
9 SWEP.AutoSwitchFrom = false;
10
11end
12
13if (CLIENT) then --the cl_init.lua stuff goes in here
14
15
16 SWEP.PrintName = "Orbiter SWEP";
17 SWEP.Slot = 0;
18 SWEP.SlotPos = 4;
19 SWEP.DrawAmmo = false;
20 SWEP.DrawCrosshair = false;
21menu = DermaMenu()
22menu:AddOption( "Gdzie ja jestem", function() wybor = 1 end )
23menu:AddOption( "Ja chce helikopter", function() wybor = 2 end ) -- The menu will remove itself, we don't have to do anything.
24menu:AddOption( "Do cholery", function() wybor = 3 end )
25
26end
27
28
29SWEP.Author = "FeAr";
30SWEP.Contact = "";
31SWEP.Purpose = "Potem";
32SWEP.Instructions = "Potem";
33SWEP.Category = "ZOrbiter"
34
35SWEP.Spawnable = true;
36SWEP.AdminSpawnable = true;
37
38SWEP.ViewModel = "models/weapons/v_grenade.mdl";
39SWEP.WorldModel = "models/weapons/w_grenade.mdl";
40SWEP.ViewModelFOV = 60
41SWEP.HoldType = "grenade"
42SWEP.ShowViewModel = true
43SWEP.ShowWorldModel = false
44SWEP.ViewModelBoneMods = {
45 ["ValveBiped.Grenade_body"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
46}
47
48SWEP.Primary.ClipSize = -1;
49SWEP.Primary.DefaultClip = -1;
50SWEP.Primary.Automatic = false;
51SWEP.Primary.Ammo = "none";
52SWEP.Primary.Delay = 3
53
54
55SWEP.Secondary.ClipSize = -1;
56SWEP.Secondary.DefaultClip = -1;
57SWEP.Secondary.Automatic = false;
58SWEP.Secondary.Ammo = "none";
59SWEP.Secondary.Delay = 6.5
60
61/* Both Reload() and Think() are not needed by this SWEP so we
62 * will provide empty functions for them
63 */
64
65
66function SWEP:Think()
67return false
68end
69
70function SWEP:PrimaryAttack()
71self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
72 if SERVER then
73 local boot=ents.Create("prop_physics")
74 local vec=Vector(0,0,8)
75 boot:SetModel("models/props_junk/shoe001a.mdl")
76 if self.Owner:Crouching() then vec=Vector(0,0,4) end
77 boot:SetPos((self.Owner:EyePos() - vec) + (self.Owner:GetForward() * 16))
78 boot:SetAngles(self.Owner:EyeAngles())
79 boot:Spawn()
80 local bootphys = boot:GetPhysicsObject()
81 bootphys:Wake()
82 bootphys:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * 4500)
83 self.Weapon:SendWeaponAnim( ACT_VM_THROW )
84 timer.Simple(2, function()
85 if self.Owner:IsValid() and self.Owner:GetActiveWeapon():GetClass() == "weapon_angryhobo" then
86 self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
87 end
88 end)
89 local function EraseBoot()
90
91 boot:Remove();
92
93 end
94 timer.Simple( 8, EraseBoot );
95
96
97 end
98 return true
99end
100
101Wybor = 1
102function SWEP:SecondaryAttack()
103menu:Open()
104end
105function SWEP:Reload()
106 self.Weapon:EmitSound( "weapons/orbiter/orbiter" .. Wybor .. ".wav" )
107end
108
109/********************************************************
110 SWEP Construction Kit base code
111 Created by Clavus
112 Available for public use, thread at:
113 facepunch.com/threads/1032378
114
115
116 DESCRIPTION:
117 This script is meant for experienced scripters
118 that KNOW WHAT THEY ARE DOING. Don't come to me
119 with basic Lua questions.
120
121 Just copy into your SWEP or SWEP base of choice
122 and merge with your own code.
123
124 The SWEP.VElements, SWEP.WElements and
125 SWEP.ViewModelBoneMods tables are all optional
126 and only have to be visible to the client.
127********************************************************/
128
129function SWEP:Initialize()
130
131self:SetWeaponHoldType(self.HoldType)
132
133 if CLIENT then
134
135 // Create a new table for every weapon instance
136 self.VElements = table.FullCopy( self.VElements )
137 self.WElements = table.FullCopy( self.WElements )
138 self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
139
140 self:CreateModels(self.VElements) // create viewmodels
141 self:CreateModels(self.WElements) // create worldmodels
142
143 // init view model bone build function
144 if IsValid(self.Owner) then
145 local vm = self.Owner:GetViewModel()
146 if IsValid(vm) then
147 self:ResetBonePositions(vm)
148
149 // Init viewmodel visibility
150 if (self.ShowViewModel == nil or self.ShowViewModel) then
151 vm:SetColor(Color(255,255,255,255))
152 else
153 // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
154 vm:SetColor(Color(255,255,255,1))
155 // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
156 // 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
157 vm:SetMaterial("Debug/hsv")
158 end
159 end
160 end
161
162 end
163
164end
165
166function SWEP:Holster()
167
168 if CLIENT and IsValid(self.Owner) then
169 local vm = self.Owner:GetViewModel()
170 if IsValid(vm) then
171 self:ResetBonePositions(vm)
172 end
173 end
174
175 return true
176end
177
178function SWEP:OnRemove()
179 self:Holster()
180end
181
182if CLIENT then
183
184 SWEP.vRenderOrder = nil
185 function SWEP:ViewModelDrawn()
186
187 local vm = self.Owner:GetViewModel()
188 if !IsValid(vm) then return end
189
190 if (!self.VElements) then return end
191
192 self:UpdateBonePositions(vm)
193
194 if (!self.vRenderOrder) then
195
196 // we build a render order because sprites need to be drawn after models
197 self.vRenderOrder = {}
198
199 for k, v in pairs( self.VElements ) do
200 if (v.type == "Model") then
201 table.insert(self.vRenderOrder, 1, k)
202 elseif (v.type == "Sprite" or v.type == "Quad") then
203 table.insert(self.vRenderOrder, k)
204 end
205 end
206
207 end
208
209 for k, name in ipairs( self.vRenderOrder ) do
210
211 local v = self.VElements[name]
212 if (!v) then self.vRenderOrder = nil break end
213 if (v.hide) then continue end
214
215 local model = v.modelEnt
216 local sprite = v.spriteMaterial
217
218 if (!v.bone) then continue end
219
220 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
221
222 if (!pos) then continue end
223
224 if (v.type == "Model" and IsValid(model)) then
225
226 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
227 ang:RotateAroundAxis(ang:Up(), v.angle.y)
228 ang:RotateAroundAxis(ang:Right(), v.angle.p)
229 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
230
231 model:SetAngles(ang)
232 //model:SetModelScale(v.size)
233 local matrix = Matrix()
234 matrix:Scale(v.size)
235 model:EnableMatrix( "RenderMultiply", matrix )
236
237 if (v.material == "") then
238 model:SetMaterial("")
239 elseif (model:GetMaterial() != v.material) then
240 model:SetMaterial( v.material )
241 end
242
243 if (v.skin and v.skin != model:GetSkin()) then
244 model:SetSkin(v.skin)
245 end
246
247 if (v.bodygroup) then
248 for k, v in pairs( v.bodygroup ) do
249 if (model:GetBodygroup(k) != v) then
250 model:SetBodygroup(k, v)
251 end
252 end
253 end
254
255 if (v.surpresslightning) then
256 render.SuppressEngineLighting(true)
257 end
258
259 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
260 render.SetBlend(v.color.a/255)
261 model:DrawModel()
262 render.SetBlend(1)
263 render.SetColorModulation(1, 1, 1)
264
265 if (v.surpresslightning) then
266 render.SuppressEngineLighting(false)
267 end
268
269 elseif (v.type == "Sprite" and sprite) then
270
271 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
272 render.SetMaterial(sprite)
273 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
274
275 elseif (v.type == "Quad" and v.draw_func) then
276
277 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
278 ang:RotateAroundAxis(ang:Up(), v.angle.y)
279 ang:RotateAroundAxis(ang:Right(), v.angle.p)
280 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
281
282 cam.Start3D2D(drawpos, ang, v.size)
283 v.draw_func( self )
284 cam.End3D2D()
285
286 end
287
288 end
289
290 end
291
292 SWEP.wRenderOrder = nil
293 function SWEP:DrawWorldModel()
294
295 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
296 self:DrawModel()
297 end
298
299 if (!self.WElements) then return end
300
301 if (!self.wRenderOrder) then
302
303 self.wRenderOrder = {}
304
305 for k, v in pairs( self.WElements ) do
306 if (v.type == "Model") then
307 table.insert(self.wRenderOrder, 1, k)
308 elseif (v.type == "Sprite" or v.type == "Quad") then
309 table.insert(self.wRenderOrder, k)
310 end
311 end
312
313 end
314
315 if (IsValid(self.Owner)) then
316 bone_ent = self.Owner
317 else
318 // when the weapon is dropped
319 bone_ent = self
320 end
321
322 for k, name in pairs( self.wRenderOrder ) do
323
324 local v = self.WElements[name]
325 if (!v) then self.wRenderOrder = nil break end
326 if (v.hide) then continue end
327
328 local pos, ang
329
330 if (v.bone) then
331 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
332 else
333 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
334 end
335
336 if (!pos) then continue end
337
338 local model = v.modelEnt
339 local sprite = v.spriteMaterial
340
341 if (v.type == "Model" and IsValid(model)) then
342
343 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
344 ang:RotateAroundAxis(ang:Up(), v.angle.y)
345 ang:RotateAroundAxis(ang:Right(), v.angle.p)
346 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
347
348 model:SetAngles(ang)
349 //model:SetModelScale(v.size)
350 local matrix = Matrix()
351 matrix:Scale(v.size)
352 model:EnableMatrix( "RenderMultiply", matrix )
353
354 if (v.material == "") then
355 model:SetMaterial("")
356 elseif (model:GetMaterial() != v.material) then
357 model:SetMaterial( v.material )
358 end
359
360 if (v.skin and v.skin != model:GetSkin()) then
361 model:SetSkin(v.skin)
362 end
363
364 if (v.bodygroup) then
365 for k, v in pairs( v.bodygroup ) do
366 if (model:GetBodygroup(k) != v) then
367 model:SetBodygroup(k, v)
368 end
369 end
370 end
371
372 if (v.surpresslightning) then
373 render.SuppressEngineLighting(true)
374 end
375
376 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
377 render.SetBlend(v.color.a/255)
378 model:DrawModel()
379 render.SetBlend(1)
380 render.SetColorModulation(1, 1, 1)
381
382 if (v.surpresslightning) then
383 render.SuppressEngineLighting(false)
384 end
385
386 elseif (v.type == "Sprite" and sprite) then
387
388 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
389 render.SetMaterial(sprite)
390 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
391
392 elseif (v.type == "Quad" and v.draw_func) then
393
394 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
395 ang:RotateAroundAxis(ang:Up(), v.angle.y)
396 ang:RotateAroundAxis(ang:Right(), v.angle.p)
397 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
398
399 cam.Start3D2D(drawpos, ang, v.size)
400 v.draw_func( self )
401 cam.End3D2D()
402
403 end
404
405 end
406
407 end
408
409 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
410
411 local bone, pos, ang
412 if (tab.rel and tab.rel != "") then
413
414 local v = basetab[tab.rel]
415
416 if (!v) then return end
417
418 // Technically, if there exists an element with the same name as a bone
419 // you can get in an infinite loop. Let's just hope nobody's that stupid.
420 pos, ang = self:GetBoneOrientation( basetab, v, ent )
421
422 if (!pos) then return end
423
424 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
425 ang:RotateAroundAxis(ang:Up(), v.angle.y)
426 ang:RotateAroundAxis(ang:Right(), v.angle.p)
427 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
428
429 else
430
431 bone = ent:LookupBone(bone_override or tab.bone)
432
433 if (!bone) then return end
434
435 pos, ang = Vector(0,0,0), Angle(0,0,0)
436 local m = ent:GetBoneMatrix(bone)
437 if (m) then
438 pos, ang = m:GetTranslation(), m:GetAngles()
439 end
440
441 if (IsValid(self.Owner) and self.Owner:IsPlayer() and
442 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
443 ang.r = -ang.r // Fixes mirrored models
444 end
445
446 end
447
448 return pos, ang
449 end
450
451 function SWEP:CreateModels( tab )
452
453 if (!tab) then return end
454
455 // Create the clientside models here because Garry says we can't do it in the render hook
456 for k, v in pairs( tab ) do
457 if (v.type == "Model" and v.model and v.model != "" and (!IsValid(v.modelEnt) or v.createdModel != v.model) and
458 string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
459
460 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
461 if (IsValid(v.modelEnt)) then
462 v.modelEnt:SetPos(self:GetPos())
463 v.modelEnt:SetAngles(self:GetAngles())
464 v.modelEnt:SetParent(self)
465 v.modelEnt:SetNoDraw(true)
466 v.createdModel = v.model
467 else
468 v.modelEnt = nil
469 end
470
471 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
472 and file.Exists ("materials/"..v.sprite..".vmt", "GAME")) then
473
474 local name = v.sprite.."-"
475 local params = { ["$basetexture"] = v.sprite }
476 // make sure we create a unique name based on the selected options
477 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
478 for i, j in pairs( tocheck ) do
479 if (v[j]) then
480 params["$"..j] = 1
481 name = name.."1"
482 else
483 name = name.."0"
484 end
485 end
486
487 v.createdSprite = v.sprite
488 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
489
490 end
491 end
492
493 end
494
495 local allbones
496 local hasGarryFixedBoneScalingYet = false
497
498 function SWEP:UpdateBonePositions(vm)
499
500 if self.ViewModelBoneMods then
501
502 if (!vm:GetBoneCount()) then return end
503
504 // !! WORKAROUND !! //
505 // We need to check all model names :/
506 local loopthrough = self.ViewModelBoneMods
507 if (!hasGarryFixedBoneScalingYet) then
508 allbones = {}
509 for i=0, vm:GetBoneCount() do
510 local bonename = vm:GetBoneName(i)
511 if (self.ViewModelBoneMods[bonename]) then
512 allbones[bonename] = self.ViewModelBoneMods[bonename]
513 else
514 allbones[bonename] = {
515 scale = Vector(1,1,1),
516 pos = Vector(0,0,0),
517 angle = Angle(0,0,0)
518 }
519 end
520 end
521
522 loopthrough = allbones
523 end
524 // !! ----------- !! //
525
526 for k, v in pairs( loopthrough ) do
527 local bone = vm:LookupBone(k)
528 if (!bone) then continue end
529
530 // !! WORKAROUND !! //
531 local s = Vector(v.scale.x,v.scale.y,v.scale.z)
532 local p = Vector(v.pos.x,v.pos.y,v.pos.z)
533 local ms = Vector(1,1,1)
534 if (!hasGarryFixedBoneScalingYet) then
535 local cur = vm:GetBoneParent(bone)
536 while(cur >= 0) do
537 local pscale = loopthrough[vm:GetBoneName(cur)].scale
538 ms = ms * pscale
539 cur = vm:GetBoneParent(cur)
540 end
541 end
542
543 s = s * ms
544 // !! ----------- !! //
545
546 if vm:GetManipulateBoneScale(bone) != s then
547 vm:ManipulateBoneScale( bone, s )
548 end
549 if vm:GetManipulateBoneAngles(bone) != v.angle then
550 vm:ManipulateBoneAngles( bone, v.angle )
551 end
552 if vm:GetManipulateBonePosition(bone) != p then
553 vm:ManipulateBonePosition( bone, p )
554 end
555 end
556 else
557 self:ResetBonePositions(vm)
558 end
559
560 end
561
562 function SWEP:ResetBonePositions(vm)
563
564 if (!vm:GetBoneCount()) then return end
565 for i=0, vm:GetBoneCount() do
566 vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
567 vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
568 vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
569 end
570
571 end
572
573 /**************************
574 Global utility code
575 **************************/
576
577 // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
578 // Does not copy entities of course, only copies their reference.
579 // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
580 function table.FullCopy( tab )
581
582 if (!tab) then return nil end
583
584 local res = {}
585 for k, v in pairs( tab ) do
586 if (type(v) == "table") then
587 res[k] = table.FullCopy(v) // recursion ho!
588 elseif (type(v) == "Vector") then
589 res[k] = Vector(v.x, v.y, v.z)
590 elseif (type(v) == "Angle") then
591 res[k] = Angle(v.p, v.y, v.r)
592 else
593 res[k] = v
594 end
595 end
596
597 return res
598
599 end
600
601end
602
603SWEP.VElements = {
604 ["wut"] = { type = "Model", model = "models/props_junk/Shoe001a.mdl", bone = "ValveBiped.Grenade_body", rel = "", pos = Vector(1.241, 3.658, -1.887), angle = Angle(180, 98.248, -12.959), size = Vector(1.133, 1.133, 1.133), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
605}
606
607SWEP.WElements = {
608 ["wut"] = { type = "Model", model = "models/props_junk/Shoe001a.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(5.717, 2.634, 0.07), angle = Angle(0, 0, -13.44), size = Vector(1.049, 1.049, 1.049), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
609}