Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Swep Creator - Bullets N Explosions
- // Made By BummieHead
- -- Have Fun !
- -- Ver 1.0.0
- //General Settings \\
- SWEP.AdminSpawnable = true // Is the swep spawnable for admin
- SWEP.HoldType = "pistol"
- SWEP.ViewModelFOV = 78
- SWEP.ViewModelFlip = true
- SWEP.ViewModel = "models/weapons/v_smg_mac10.mdl"
- SWEP.WorldModel = "models/weapons/w_smg_mac10.mdl"
- SWEP.ShowViewModel = true
- SWEP.ShowWorldModel = true
- SWEP.ViewModelBonescales = {}
- SWEP.AutoSwitchTo = false // when someone walks over the swep, chould i automatectly change to your swep ?
- SWEP.Slot = 0 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
- SWEP.PrintName = "Mac 10 Scope" // your sweps name
- SWEP.Author = "DoubleElite" // Your name
- SWEP.Spawnable = true // Can everybody spawn this swep ? - If you want only admin keep this false and adminsapwnable true.
- SWEP.AutoSwitchFrom = false // Does the weapon get changed by other sweps if you pick them up ?
- SWEP.FiresUnderwater = false // Does your swep fire under water ?
- SWEP.Weight = 5 // Chose the weight of the Swep
- SWEP.DrawCrosshair = true // Do you want it to have a crosshair ?
- SWEP.Category = "Sweps" // Make your own catogory for the swep
- SWEP.SlotPos = 0 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
- SWEP.DrawAmmo = true // Does the ammo show up when you are using it ? True / False
- SWEP.ReloadSound = "Weapon_Pistol.Reload" // Reload sound, you can use the default ones, or you can use your one; Example; "sound/myswepreload.waw"
- SWEP.Instructions = "Point and shoot." // How do pepole use your swep ?
- SWEP.Contact = "" // How Pepole chould contact you if they find bugs, errors, etc
- SWEP.Purpose = "To have fun" // What is the purpose with this swep ?
- SWEP.Base = "weapon_cs_base"
- SWEP.VElements = {
- ["Scope"] = { type = "Model", model = "models/wystan/attachments/acog.mdl", bone = "v_weapon.mac10_parent", pos = Vector(0.287, -2.507, -7.375), angle = Angle(180, -0.401, 91.242), size = Vector(1.105, 1.105, 1.105), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
- }
- SWEP.WElements = {
- ["Scope"] = { type = "Model", model = "models/wystan/attachments/acog.mdl", pos = Vector(-1.195, -0.524, 1.144), angle = Angle(-179.969, 89.313, 4.793), size = Vector(1.105, 1.105, 1.105), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
- }
- //General settings\\
- //PrimaryFire Settings\\
- SWEP.Primary.Sound = "Weapon_Pistol.Single" // The sound that plays when you shoot :]
- SWEP.Primary.Damage = 10 // How much damage the swep is doing
- SWEP.Primary.TakeAmmo = 1 // How much ammo does it take for each shot ?
- SWEP.Primary.ClipSize = 35 // The clipsize
- SWEP.Primary.Ammo = "Pistol" // ammmo type pistol/ smg1
- SWEP.Primary.DefaultClip = 150 // How much ammo does the swep come with `?
- SWEP.Primary.Spread = 0.3 // Does the bullets spread all over, if you want it fire exactly where you are aiming leave it o.1
- SWEP.Primary.NumberofShots = 1 // How many bullets you are firing each shot.
- SWEP.Primary.Automatic = true // Is the swep automatic ?
- SWEP.Primary.Recoil = 2 // How much we should punch the view
- SWEP.Primary.Delay = 0.1 // How long time before you can fire again
- SWEP.Primary.Force = 10 // The force of the shot
- //PrimaryFire settings\\
- //Secondary Fire Variables\\
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = false
- SWEP.Secondary.Ammo = ""
- SWEP.IronSightsPos = Vector (-5.757, -13.0875, 4.0363)
- SWEP.IronSightsAng = Vector (1.5691, 0.3562, -87.6971)
- //Secondary Fire Variables\\
- /**************************************************
- SWEP Construction Kit base code
- Created by Clavus
- Available for public use, thread at:
- facepunch.com/threads/1032378
- **************************************************/
- function SWEP:Initialize()
- // other initialize code goes here
- util.PrecacheSound(self.Primary.Sound)
- util.PrecacheSound(self.Secondary.Sound)
- if ( SERVER ) then
- self:SetWeaponHoldType( self.HoldType )
- end
- if CLIENT then
- self:CreateModels(self.VElements) // create viewmodels
- self:CreateModels(self.WElements) // create worldmodels
- // init view model bone build function
- self.BuildViewModelBones = function( s )
- if LocalPlayer():GetActiveWeapon() == self and self.ViewModelBonescales then
- for k, v in pairs( self.ViewModelBonescales ) do
- local bone = s:LookupBone(k)
- if (!bone) then continue end
- local m = s:GetBoneMatrix(bone)
- if (!m) then continue end
- m:Scale(v)
- s:SetBoneMatrix(bone, m)
- end
- end
- end
- end
- end
- function SWEP:OnRemove()
- // other onremove code goes here
- if CLIENT then
- self:RemoveModels()
- end
- end
- if CLIENT then
- SWEP.vRenderOrder = nil
- function SWEP:ViewModelDrawn()
- local vm = self.Owner:GetViewModel()
- if !ValidEntity(vm) then return end
- if (!self.VElements) then return end
- if vm.BuildBonePositions ~= self.BuildViewModelBones then
- vm.BuildBonePositions = self.BuildViewModelBones
- end
- if (self.ShowViewModel == nil or self.ShowViewModel) then
- vm:SetColor(255,255,255,255)
- else
- // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
- vm:SetColor(255,255,255,1)
- end
- if (!self.vRenderOrder) then
- // we build a render order because sprites need to be drawn after models
- self.vRenderOrder = {}
- for k, v in pairs( self.VElements ) do
- if (v.type == "Model") then
- table.insert(self.vRenderOrder, 1, k)
- elseif (v.type == "Sprite" or v.type == "Quad") then
- table.insert(self.vRenderOrder, k)
- end
- end
- end
- for k, name in ipairs( self.vRenderOrder ) do
- local v = self.VElements[name]
- if (!v) then self.vRenderOrder = nil break end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- if (!v.bone) then continue end
- local bone = vm:LookupBone(v.bone)
- if (!bone) then continue end
- local pos, ang = Vector(0,0,0), Angle(0,0,0)
- local m = vm:GetBoneMatrix(bone)
- if (m) then
- pos, ang = m:GetTranslation(), m:GetAngle()
- end
- if (self.ViewModelFlip) then
- ang.r = -ang.r // Fixes mirrored models
- end
- if (v.type == "Model" and ValidEntity(model)) then
- model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- model:SetAngles(ang)
- model:SetModelScale(v.size)
- if (v.material == "") then
- model:SetMaterial("")
- elseif (model:GetMaterial() != v.material) then
- model:SetMaterial( v.material )
- end
- if (v.skin and v.skin != model:GetSkin()) then
- model:SetSkin(v.skin)
- end
- if (v.bodygroup) then
- for k, v in pairs( v.bodygroup ) do
- if (model:GetBodygroup(k) != v) then
- model:SetBodygroup(k, v)
- end
- end
- end
- if (v.surpresslightning) then
- render.SuppressEngineLighting(true)
- end
- render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
- render.SetBlend(v.color.a/255)
- model:DrawModel()
- render.SetBlend(1)
- render.SetColorModulation(1, 1, 1)
- if (v.surpresslightning) then
- render.SuppressEngineLighting(false)
- end
- elseif (v.type == "Sprite" and sprite) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- render.SetMaterial(sprite)
- render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
- elseif (v.type == "Quad" and v.draw_func) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- cam.Start3D2D(drawpos, ang, v.size)
- v.draw_func( self )
- cam.End3D2D()
- end
- end
- end
- SWEP.wRenderOrder = nil
- function SWEP:DrawWorldModel()
- if (self.ShowWorldModel == nil or self.ShowWorldModel) then
- self:DrawModel()
- end
- if (!self.WElements) then return end
- if (!self.wRenderOrder) then
- self.wRenderOrder = {}
- for k, v in pairs( self.WElements ) do
- if (v.type == "Model") then
- table.insert(self.wRenderOrder, 1, k)
- elseif (v.type == "Sprite" or v.type == "Quad") then
- table.insert(self.wRenderOrder, k)
- end
- end
- end
- local opos, oang = self:GetPos(), self:GetAngles()
- local bone_ent
- if (ValidEntity(self.Owner)) then
- bone_ent = self.Owner
- else
- // when the weapon is dropped
- bone_ent = self
- end
- local bone = bone_ent:LookupBone("ValveBiped.Bip01_R_Hand")
- if (bone) then
- local m = bone_ent:GetBoneMatrix(bone)
- if (m) then
- opos, oang = m:GetTranslation(), m:GetAngle()
- end
- end
- for k, name in pairs( self.wRenderOrder ) do
- local v = self.WElements[name]
- if (!v) then self.wRenderOrder = nil break end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- local pos, ang = Vector(opos.x, opos.y, opos.z), Angle(oang.p, oang.y, oang.r)
- if (v.type == "Model" and ValidEntity(model)) then
- model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- model:SetAngles(ang)
- model:SetModelScale(v.size)
- if (v.material == "") then
- model:SetMaterial("")
- elseif (model:GetMaterial() != v.material) then
- model:SetMaterial( v.material )
- end
- if (v.skin and v.skin != model:GetSkin()) then
- model:SetSkin(v.skin)
- end
- if (v.bodygroup) then
- for k, v in pairs( v.bodygroup ) do
- if (model:GetBodygroup(k) != v) then
- model:SetBodygroup(k, v)
- end
- end
- end
- if (v.surpresslightning) then
- render.SuppressEngineLighting(true)
- end
- render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
- render.SetBlend(v.color.a/255)
- model:DrawModel()
- render.SetBlend(1)
- render.SetColorModulation(1, 1, 1)
- if (v.surpresslightning) then
- render.SuppressEngineLighting(false)
- end
- elseif (v.type == "Sprite" and sprite) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- render.SetMaterial(sprite)
- render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
- elseif (v.type == "Quad" and v.draw_func) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- cam.Start3D2D(drawpos, ang, v.size)
- v.draw_func( self )
- cam.End3D2D()
- end
- end
- end
- function SWEP:CreateModels( tab )
- if (!tab) then return end
- // Create the clientside models here because Garry says we can't do it in the render hook
- for k, v in pairs( tab ) do
- if (v.type == "Model" and v.model and v.model != "" and (!ValidEntity(v.modelEnt) or v.createdModel != v.model) and
- string.find(v.model, ".mdl") and file.Exists ("../"..v.model) ) then
- v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
- if (ValidEntity(v.modelEnt)) then
- v.modelEnt:SetPos(self:GetPos())
- v.modelEnt:SetAngles(self:GetAngles())
- v.modelEnt:SetParent(self)
- v.modelEnt:SetNoDraw(true)
- v.createdModel = v.model
- else
- v.modelEnt = nil
- end
- elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
- and file.Exists ("../materials/"..v.sprite..".vmt")) then
- local name = v.sprite.."-"
- local params = { ["$basetexture"] = v.sprite }
- // make sure we create a unique name based on the selected options
- local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
- for i, j in pairs( tocheck ) do
- if (v[j]) then
- params["$"..j] = 1
- name = name.."1"
- else
- name = name.."0"
- end
- end
- v.createdSprite = v.sprite
- v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
- end
- end
- end
- function SWEP:RemoveModels()
- if (self.VElements) then
- for k, v in pairs( self.VElements ) do
- if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
- end
- end
- if (self.WElements) then
- for k, v in pairs( self.WElements ) do
- if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
- end
- end
- self.VElements = nil
- self.WElements = nil
- end
- end
- //SWEP:PrimaryFire()\\
- function SWEP:PrimaryAttack()
- if ( !self:CanPrimaryAttack() ) then return end
- local bullet = {}
- bullet.Num = self.Primary.NumberofShots
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
- bullet.Tracer = 0
- bullet.Force = self.Primary.Force
- bullet.Damage = self.Primary.Damage
- bullet.AmmoType = self.Primary.Ammo
- local rnda = self.Primary.Recoil * -1
- local rndb = self.Primary.Recoil * math.random(-1, 1)
- self:ShootEffects()
- self.Owner:FireBullets( bullet )
- self.Weapon:EmitSound(Sound(self.Primary.Sound))
- self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
- self:TakePrimaryAmmo(self.Primary.TakeAmmo)
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
- end
- //SWEP:PrimaryFire()\\
- //SWEP:SecondaryFire()\\
- function SWEP:SecondaryAttack()
- if ( !self:CanSecondaryAttack() ) then return end
- local rnda = -self.Secondary.Recoil
- local rndb = self.Secondary.Recoil * math.random(-1, 1)
- self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
- local eyetrace = self.Owner:GetEyeTrace()
- self.Weapon:EmitSound ( self.Secondary.Sound )
- self:ShootEffects()
- local explode = ents.Create("env_explosion")
- explode:SetPos( eyetrace.HitPos )
- explode:SetOwner( self.Owner )
- explode:Spawn()
- explode:SetKeyValue("iMagnitude","175")
- explode:Fire("Explode", 0, 0 )
- explode:EmitSound("weapon_AWP.Single", 400, 400 )
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Secondary.Delay )
- self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
- self:TakePrimaryAmmo(self.Secondary.TakeAmmo)
- end
- //SWEP:SecondaryFire()\\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement