· 7 years ago · Sep 09, 2018, 06:14 AM
1-- Basic Stuff
2SWEP.PrintName = "baby_maker"
3SWEP.ClassName = "baby_maker"
4SWEP.Slot = 3
5SWEP.SlotPos = 0
6SWEP.DrawAmmo = true
7SWEP.DrawCrosshair = true
8SWEP.ViewModel = "models/weapons/v_smg1.mdl"
9SWEP.WorldModel = "models/weapons/w_smg1.mdl"
10
11-- Settings
12SWEP.HoldType = "ar2"
13SWEP.Weight = 5 --
14SWEP.AutoSwitchTo = true --
15SWEP.AutoSwitchFrom = false --
16SWEP.Spawnable = true --
17SWEP.AdminSpawnable = true --
18--SWEP.AutoReload = false --
19
20-- Weapon info
21SWEP.Author = "Ramificate" --
22SWEP.Contact = "Indian tech support" --
23SWEP.Purpose = "Turn props into babies" --
24SWEP.Instructions = "Left click to change prop into a baby" --
25
26-- Primary fire settings
27SWEP.Primary.Sound = "/weapons/airboat/airboat_gun_energy1.wav" --
28SWEP.Primary.Damage = -1 --
29SWEP.Primary.NumShots = 0 --
30SWEP.Primary.Recoil = 0.6 --
31SWEP.Primary.Cone = 0 --
32SWEP.Primary.Delay = 0.7 --
33SWEP.Primary.ClipSize = 100 --
34SWEP.Primary.DefaultClip = 500 --
35SWEP.Primary.Tracer = 0 --
36SWEP.Primary.Force = 100 --
37SWEP.Primary.TakeAmmoPerBullet = true --
38SWEP.Primary.Automatic = true --
39SWEP.Primary.Ammo = "smg1" -- --
40
41-- Secondary fire settings
42SWEP.Secondary.Sound = "/weapons/shotgun/shotgun_cock.wav" --
43SWEP.Secondary.Damage = 10 --
44SWEP.Secondary.NumShots = 1 --
45SWEP.Secondary.Recoil = 8.5 --
46SWEP.Secondary.Cone = 0.5 --
47SWEP.Secondary.Delay = 1 --
48SWEP.Secondary.ClipSize = 100 --
49SWEP.Secondary.DefaultClip = 500 --
50SWEP.Secondary.Tracer = 0 --
51SWEP.Secondary.Force = 0 --
52SWEP.Secondary.TakeAmmoPerBullet = true --
53SWEP.Secondary.Automatic = false --
54SWEP.Secondary.Ammo = "smg1" -- --
55
56--
57--
58
59function SWEP:Initialize()
60
61 // other initialize code goes here
62
63 if CLIENT then
64
65 // Create a new table for every weapon instance
66 self.VElements = table.FullCopy( self.VElements )
67 self.WElements = table.FullCopy( self.WElements )
68 self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
69
70 self:CreateModels(self.VElements) // create viewmodels
71 self:CreateModels(self.WElements) // create worldmodels
72
73 // init view model bone build function
74 self.BuildViewModelBones = function( s )
75 if LocalPlayer():GetActiveWeapon() == self and self.ViewModelBoneMods then
76 for k, v in pairs( self.ViewModelBoneMods ) do
77 local bone = s:LookupBone(k)
78 if (!bone) then continue end
79 local m = s:GetBoneMatrix(bone)
80 if (!m) then continue end
81 m:Scale(v.scale)
82 m:Rotate(v.angle)
83 m:Translate(v.pos)
84 s:SetBoneMatrix(bone, m)
85 end
86 end
87 end
88
89 end
90
91end
92
93if CLIENT then
94
95 SWEP.vRenderOrder = nil
96 function SWEP:ViewModelDrawn()
97
98 local vm = self.Owner:GetViewModel()
99 if !ValidEntity(vm) then return end
100
101 if (!self.VElements) then return end
102
103 if vm.BuildBonePositions != self.BuildViewModelBones then
104 vm.BuildBonePositions = self.BuildViewModelBones
105 end
106
107 if (self.ShowViewModel == nil or self.ShowViewModel) then
108 vm:SetColor(255,255,255,255)
109 else
110 // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
111 vm:SetColor(255,255,255,1)
112 end
113
114 if (!self.vRenderOrder) then
115
116 // we build a render order because sprites need to be drawn after models
117 self.vRenderOrder = {}
118
119 for k, v in pairs( self.VElements ) do
120 if (v.type == "Model") then
121 table.insert(self.vRenderOrder, 1, k)
122 elseif (v.type == "Sprite" or v.type == "Quad") then
123 table.insert(self.vRenderOrder, k)
124 end
125 end
126
127 end
128
129 for k, name in ipairs( self.vRenderOrder ) do
130
131 local v = self.VElements[name]
132 if (!v) then self.vRenderOrder = nil break end
133
134 local model = v.modelEnt
135 local sprite = v.spriteMaterial
136
137 if (!v.bone) then continue end
138
139 local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
140
141 if (!pos) then continue end
142
143 if (v.type == "Model" and ValidEntity(model)) then
144
145 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
146 ang:RotateAroundAxis(ang:Up(), v.angle.y)
147 ang:RotateAroundAxis(ang:Right(), v.angle.p)
148 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
149
150 model:SetAngles(ang)
151 model:SetModelScale(v.size)
152
153 if (v.material == "") then
154 model:SetMaterial("")
155 elseif (model:GetMaterial() != v.material) then
156 model:SetMaterial( v.material )
157 end
158
159 if (v.skin and v.skin != model:GetSkin()) then
160 model:SetSkin(v.skin)
161 end
162
163 if (v.bodygroup) then
164 for k, v in pairs( v.bodygroup ) do
165 if (model:GetBodygroup(k) != v) then
166 model:SetBodygroup(k, v)
167 end
168 end
169 end
170
171 if (v.surpresslightning) then
172 render.SuppressEngineLighting(true)
173 end
174
175 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
176 render.SetBlend(v.color.a/255)
177 model:DrawModel()
178 render.SetBlend(1)
179 render.SetColorModulation(1, 1, 1)
180
181 if (v.surpresslightning) then
182 render.SuppressEngineLighting(false)
183 end
184
185 elseif (v.type == "Sprite" and sprite) then
186
187 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
188 render.SetMaterial(sprite)
189 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
190
191 elseif (v.type == "Quad" and v.draw_func) then
192
193 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
194 ang:RotateAroundAxis(ang:Up(), v.angle.y)
195 ang:RotateAroundAxis(ang:Right(), v.angle.p)
196 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
197
198 cam.Start3D2D(drawpos, ang, v.size)
199 v.draw_func( self )
200 cam.End3D2D()
201
202 end
203
204 end
205
206 end
207
208 SWEP.wRenderOrder = nil
209 function SWEP:DrawWorldModel()
210
211 if (self.ShowWorldModel == nil or self.ShowWorldModel) then
212 self:DrawModel()
213 end
214
215 if (!self.WElements) then return end
216
217 if (!self.wRenderOrder) then
218
219 self.wRenderOrder = {}
220
221 for k, v in pairs( self.WElements ) do
222 if (v.type == "Model") then
223 table.insert(self.wRenderOrder, 1, k)
224 elseif (v.type == "Sprite" or v.type == "Quad") then
225 table.insert(self.wRenderOrder, k)
226 end
227 end
228
229 end
230
231 if (ValidEntity(self.Owner)) then
232 bone_ent = self.Owner
233 else
234 // when the weapon is dropped
235 bone_ent = self
236 end
237
238 for k, name in pairs( self.wRenderOrder ) do
239
240 local v = self.WElements[name]
241 if (!v) then self.wRenderOrder = nil break end
242
243 local pos, ang
244
245 if (v.bone) then
246 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
247 else
248 pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
249 end
250
251 if (!pos) then continue end
252
253 local model = v.modelEnt
254 local sprite = v.spriteMaterial
255
256 if (v.type == "Model" and ValidEntity(model)) then
257
258 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
259 ang:RotateAroundAxis(ang:Up(), v.angle.y)
260 ang:RotateAroundAxis(ang:Right(), v.angle.p)
261 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
262
263 model:SetAngles(ang)
264 model:SetModelScale(v.size)
265
266 if (v.material == "") then
267 model:SetMaterial("")
268 elseif (model:GetMaterial() != v.material) then
269 model:SetMaterial( v.material )
270 end
271
272 if (v.skin and v.skin != model:GetSkin()) then
273 model:SetSkin(v.skin)
274 end
275
276 if (v.bodygroup) then
277 for k, v in pairs( v.bodygroup ) do
278 if (model:GetBodygroup(k) != v) then
279 model:SetBodygroup(k, v)
280 end
281 end
282 end
283
284 if (v.surpresslightning) then
285 render.SuppressEngineLighting(true)
286 end
287
288 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
289 render.SetBlend(v.color.a/255)
290 model:DrawModel()
291 render.SetBlend(1)
292 render.SetColorModulation(1, 1, 1)
293
294 if (v.surpresslightning) then
295 render.SuppressEngineLighting(false)
296 end
297
298 elseif (v.type == "Sprite" and sprite) then
299
300 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
301 render.SetMaterial(sprite)
302 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
303
304 elseif (v.type == "Quad" and v.draw_func) then
305
306 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
307 ang:RotateAroundAxis(ang:Up(), v.angle.y)
308 ang:RotateAroundAxis(ang:Right(), v.angle.p)
309 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
310
311 cam.Start3D2D(drawpos, ang, v.size)
312 v.draw_func( self )
313 cam.End3D2D()
314
315 end
316
317 end
318
319 end
320
321 function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
322
323 local bone, pos, ang
324 if (tab.rel and tab.rel != "") then
325
326 local v = basetab[tab.rel]
327
328 if (!v) then return end
329
330 // Technically, if there exists an element with the same name as a bone
331 // you can get in an infinite loop. Let's just hope nobody's that stupid.
332 pos, ang = self:GetBoneOrientation( basetab, v, ent )
333
334 if (!pos) then return end
335
336 pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
337 ang:RotateAroundAxis(ang:Up(), v.angle.y)
338 ang:RotateAroundAxis(ang:Right(), v.angle.p)
339 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
340
341 else
342
343 bone = ent:LookupBone(bone_override or tab.bone)
344
345 if (!bone) then return end
346
347 pos, ang = Vector(0,0,0), Angle(0,0,0)
348 local m = ent:GetBoneMatrix(bone)
349 if (m) then
350 pos, ang = m:GetTranslation(), m:GetAngle()
351 end
352
353 if (ValidEntity(self.Owner) and self.Owner:IsPlayer() and
354 ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
355 ang.r = -ang.r // Fixes mirrored models
356 end
357
358 end
359
360 return pos, ang
361 end
362
363 function SWEP:CreateModels( tab )
364
365 if (!tab) then return end
366
367 // Create the clientside models here because Garry says we can't do it in the render hook
368 for k, v in pairs( tab ) do
369 if (v.type == "Model" and v.model and v.model != "" and (!ValidEntity(v.modelEnt) or v.createdModel != v.model) and
370 string.find(v.model, ".mdl") and file.Exists ("../"..v.model) ) then
371
372 v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
373 if (ValidEntity(v.modelEnt)) then
374 v.modelEnt:SetPos(self:GetPos())
375 v.modelEnt:SetAngles(self:GetAngles())
376 v.modelEnt:SetParent(self)
377 v.modelEnt:SetNoDraw(true)
378 v.createdModel = v.model
379 else
380 v.modelEnt = nil
381 end
382
383 elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
384 and file.Exists ("../materials/"..v.sprite..".vmt")) then
385
386 local name = v.sprite.."-"
387 local params = { ["$basetexture"] = v.sprite }
388 // make sure we create a unique name based on the selected options
389 local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
390 for i, j in pairs( tocheck ) do
391 if (v[j]) then
392 params["$"..j] = 1
393 name = name.."1"
394 else
395 name = name.."0"
396 end
397 end
398
399 v.createdSprite = v.sprite
400 v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
401
402 end
403 end
404
405 end
406
407 /**************************
408 Global utility code
409 **************************/
410
411 // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
412 // Does not copy entities of course, only copies their reference.
413 // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
414 function table.FullCopy( tab )
415
416 if (!tab) then return nil end
417
418 local res = {}
419 for k, v in pairs( tab ) do
420 if (type(v) == "table") then
421 res[k] = table.FullCopy(v) // recursion ho!
422 elseif (type(v) == "Vector") then
423 res[k] = Vector(v.x, v.y, v.z)
424 elseif (type(v) == "Angle") then
425 res[k] = Angle(v.p, v.y, v.r)
426 else
427 res[k] = v
428 end
429 end
430
431 return res
432
433 end
434 SWEP.VElements = {
435 ["Nozzle"] = { type = "Model", model = "models/Items/combine_rifle_ammo01.mdl", bone = "ValveBiped.base", rel = "", pos = Vector(0.15, -0.663, 8.626), angle = Angle(0, 0, -2.056), size = Vector(0.497, 0.497, 0.497), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
436 ["BabyBaby"] = { type = "Model", model = "models/props_c17/doll01.mdl", bone = "ValveBiped.base", rel = "", pos = Vector(-0.905, -0.53, 2.882), angle = Angle(169.742, 0, -90), size = Vector(0.611, 0.611, 0.611), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
437 }
438
439 SWEP.WElements = {
440 ["models/props_c17/doll01.mdl"] = { type = "Model", model = "models/props_c17/doll01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(9.005, 0, -6.276), angle = Angle(170, -90, 0), size = Vector(0.485, 0.485, 0.485), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
441 ["Nozzlel"] = { type = "Model", model = "models/Items/combine_rifle_ammo01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(13.512, 1.399, -6.808), angle = Angle(-1.545, -90, -102.776), size = Vector(0.5, 0.5, 0.5), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
442 ["Glow"] = { type = "Model", model = "models/Effects/combineball.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(16.406, 2.13, -7.433), angle = Angle(-8.832, 0, 0), size = Vector(0.165, 0.165, 0.165), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
443 }
444
445end
446
447
448function SWEP:ShootBullet( damage, num_bullets, aimcone )
449
450 local bullet = {}
451 bullet.Num = num_bullets
452 bullet.Src = self.Owner:GetShootPos() // Source
453 bullet.Dir = self.Owner:GetAimVector() // Dir of bullet
454 bullet.Spread = Vector( aimcone, aimcone, 0 ) // Aim Cone
455 bullet.Tracer = 1 // Show a tracer on every x bullets
456 bullet.TracerName = "ToolTracer" // what Tracer Effect should be used
457 bullet.Force = 1 // Amount of force to give to phys objects
458 bullet.Damage = damage
459 bullet.AmmoType = "Pistol"
460
461 self.Owner:FireBullets( bullet )
462
463 self:ShootEffects()
464
465end
466function WasShot( entity1, weapon, shooter, howmany )
467 // if(entity1:IsValid() == true and shooter:GetClass() == "player") then
468 // if(shooter:GetActiveWeapon():GetClass() == "baby_maker" and entity1:GetClass() == "prop_physics") then
469 Velocityvec = entity1:GetVelocity()
470 Pos = entity1:GetPos()
471 //Velocityang = ent:GetAngleVelocity()
472 EntOwner = entity1:GetOwner()
473 entity1:Remove()
474 object = ents.Create("prop_physics")
475 object:SetName("Bobbaby")
476 object:SetKeyValue("physdamagescale","500")
477 object:SetModel("models/props_c17/doll01.mdl")
478 object:SetOwner(EntOwner)
479 object:SetPos(Pos)
480 object:SetAngles(Vector(math.random(-180,181),math.random(-180,181),math.random(-180,181)):Angle())
481 object:Spawn()
482 local physobj = object:GetPhysicsObject()
483 physobj:SetVelocity(Velocityvec)
484 undo.Create("Baby")
485 undo.AddEntity(object)
486 undo.SetPlayer(attacker)
487 undo.Finish()
488 // end
489 // end
490end
491
492hook.Add("EntityTakeDamage","Baby making process",WasShot)
493
494function SWEP:PrimaryAttack() --
495 if ( !self:CanPrimaryAttack() ) then return end --
496 self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) --
497 self.Owner:MuzzleFlash() --
498 self.Owner:SetAnimation( PLAYER_ATTACK1 ) --
499 self.Weapon:EmitSound(Sound(self.Primary.Sound)) --
500 self.Owner:ViewPunch(Angle( -self.Primary.Recoil, 0, 0 ))
501 if ( SERVER ) then
502 self:ShootBullet(0,1,0)
503 self:TakePrimaryAmmo(1)
504 self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
505 end
506end
507function SWEP:SecondaryAttack()
508end
509function SWEP:Think()
510end
511
512function SWEP:Reload()
513 if (self.Weapon:DefaultReload()) then return end --
514 self.Weapon:DefaultReload( ACT_VM_RELOAD ) --
515end
516
517function SWEP:Deploy()
518 self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
519 return true
520end
521
522function SWEP:Holster()
523 return true
524end
525
526function SWEP:OnRemove()
527end
528
529function SWEP:OnRestore()
530end
531
532function SWEP:Precache()
533end
534
535function SWEP:OwnerChanged()
536end
537
538function SWEP:ContextScreenClick( aimvec, mousecode, pressed, ply )
539end