Advertisement
Guest User

Untitled

a guest
Mar 5th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.43 KB | None | 0 0
  1. -- Swep Creator - Bullets N Explosions
  2. // Made By BummieHead
  3. -- Have Fun !
  4. -- Ver 1.0.0
  5.  
  6.  
  7. //General Settings \\
  8. SWEP.AdminSpawnable = true                          // Is the swep spawnable for admin
  9. SWEP.HoldType = "pistol"
  10. SWEP.ViewModelFOV = 78
  11. SWEP.ViewModelFlip = true
  12. SWEP.ViewModel = "models/weapons/v_smg_mac10.mdl"
  13. SWEP.WorldModel = "models/weapons/w_smg_mac10.mdl"
  14. SWEP.ShowViewModel = true
  15. SWEP.ShowWorldModel = true
  16. SWEP.ViewModelBonescales = {}
  17. SWEP.AutoSwitchTo = false                           // when someone walks over the swep, chould i automatectly change to your swep ?
  18. SWEP.Slot = 0                                       // Deside wich slot you want your swep do be in 1 2 3 4 5 6
  19. SWEP.PrintName = "Mac 10 Scope"                         // your sweps name
  20. SWEP.Author = "DoubleElite"                            // Your name
  21. SWEP.Spawnable = true                               //  Can everybody spawn this swep ? - If you want only admin keep this false and adminsapwnable true.
  22. SWEP.AutoSwitchFrom = false                         // Does the weapon get changed by other sweps if you pick them up ?
  23. SWEP.FiresUnderwater = false                        // Does your swep fire under water ?
  24. SWEP.Weight = 5                                     // Chose the weight of the Swep
  25. SWEP.DrawCrosshair = true                           // Do you want it to have a crosshair ?
  26. SWEP.Category = "Sweps"                      // Make your own catogory for the swep
  27. SWEP.SlotPos = 0                                    // Deside wich slot you want your swep do be in 1 2 3 4 5 6
  28. SWEP.DrawAmmo = true                                // Does the ammo show up when you are using it ? True / False
  29. SWEP.ReloadSound = "Weapon_Pistol.Reload"           // Reload sound, you can use the default ones, or you can use your one; Example; "sound/myswepreload.waw"
  30. SWEP.Instructions = "Point and shoot."              // How do pepole use your swep ?
  31. SWEP.Contact = ""                     // How Pepole chould contact you if they find bugs, errors, etc
  32. SWEP.Purpose = "To have fun"          // What is the purpose with this swep ?
  33. SWEP.Base = "weapon_cs_base"
  34.  
  35. SWEP.VElements = {
  36.     ["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 = {} }
  37. }
  38. SWEP.WElements = {
  39.     ["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 = {} }
  40. }
  41. //General settings\\
  42.  
  43. //PrimaryFire Settings\\
  44. SWEP.Primary.Sound = "Weapon_Pistol.Single"        // The sound that plays when you shoot :]
  45. SWEP.Primary.Damage = 10                           // How much damage the swep is doing
  46. SWEP.Primary.TakeAmmo = 1                          // How much ammo does it take for each shot ?
  47. SWEP.Primary.ClipSize = 35                         // The clipsize
  48. SWEP.Primary.Ammo = "Pistol"                       // ammmo type pistol/ smg1
  49. SWEP.Primary.DefaultClip = 150                      // How much ammo does the swep come with `?
  50. 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
  51. SWEP.Primary.NumberofShots = 1                     // How many bullets you are firing each shot.
  52. SWEP.Primary.Automatic = true                     // Is the swep automatic ?
  53. SWEP.Primary.Recoil = 2                            //  How much we should punch the view
  54. SWEP.Primary.Delay = 0.1                           // How long time before you can fire again
  55. SWEP.Primary.Force = 10                            // The force of the shot
  56. //PrimaryFire settings\\
  57.  
  58. //Secondary Fire Variables\\
  59. SWEP.Secondary.ClipSize             = -1
  60. SWEP.Secondary.DefaultClip          = -1
  61. SWEP.Secondary.Automatic            = false
  62. SWEP.Secondary.Ammo             = ""
  63.  
  64. SWEP.IronSightsPos = Vector (-5.757, -13.0875, 4.0363)
  65. SWEP.IronSightsAng = Vector (1.5691, 0.3562, -87.6971)
  66. //Secondary Fire Variables\\
  67.  
  68. /**************************************************
  69.     SWEP Construction Kit base code
  70.         Created by Clavus
  71.     Available for public use, thread at:
  72.        facepunch.com/threads/1032378
  73. **************************************************/
  74.  
  75. function SWEP:Initialize()
  76.  
  77.     // other initialize code goes here
  78.     util.PrecacheSound(self.Primary.Sound)
  79.     util.PrecacheSound(self.Secondary.Sound)
  80.     if ( SERVER ) then
  81.         self:SetWeaponHoldType( self.HoldType )
  82.     end
  83.  
  84.     if CLIENT then
  85.      
  86.         self:CreateModels(self.VElements) // create viewmodels
  87.         self:CreateModels(self.WElements) // create worldmodels
  88.          
  89.         // init view model bone build function
  90.         self.BuildViewModelBones = function( s )
  91.             if LocalPlayer():GetActiveWeapon() == self and self.ViewModelBonescales then
  92.                 for k, v in pairs( self.ViewModelBonescales ) do
  93.                     local bone = s:LookupBone(k)
  94.                     if (!bone) then continue end
  95.                     local m = s:GetBoneMatrix(bone)
  96.                     if (!m) then continue end
  97.                     m:Scale(v)
  98.                     s:SetBoneMatrix(bone, m)
  99.                 end
  100.             end
  101.         end
  102.          
  103.     end
  104.  
  105. end
  106.  
  107.  
  108. function SWEP:OnRemove()
  109.      
  110.     // other onremove code goes here
  111.      
  112.     if CLIENT then
  113.         self:RemoveModels()
  114.     end
  115.      
  116. end
  117.      
  118.  
  119. if CLIENT then
  120.  
  121.     SWEP.vRenderOrder = nil
  122.     function SWEP:ViewModelDrawn()
  123.          
  124.         local vm = self.Owner:GetViewModel()
  125.         if !ValidEntity(vm) then return end
  126.          
  127.         if (!self.VElements) then return end
  128.          
  129.         if vm.BuildBonePositions ~= self.BuildViewModelBones then
  130.             vm.BuildBonePositions = self.BuildViewModelBones
  131.         end
  132.  
  133.         if (self.ShowViewModel == nil or self.ShowViewModel) then
  134.             vm:SetColor(255,255,255,255)
  135.         else
  136.             // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
  137.             vm:SetColor(255,255,255,1)
  138.         end
  139.          
  140.         if (!self.vRenderOrder) then
  141.              
  142.             // we build a render order because sprites need to be drawn after models
  143.             self.vRenderOrder = {}
  144.  
  145.             for k, v in pairs( self.VElements ) do
  146.                 if (v.type == "Model") then
  147.                     table.insert(self.vRenderOrder, 1, k)
  148.                 elseif (v.type == "Sprite" or v.type == "Quad") then
  149.                     table.insert(self.vRenderOrder, k)
  150.                 end
  151.             end
  152.              
  153.         end
  154.  
  155.         for k, name in ipairs( self.vRenderOrder ) do
  156.          
  157.             local v = self.VElements[name]
  158.             if (!v) then self.vRenderOrder = nil break end
  159.          
  160.             local model = v.modelEnt
  161.             local sprite = v.spriteMaterial
  162.              
  163.             if (!v.bone) then continue end
  164.             local bone = vm:LookupBone(v.bone)
  165.             if (!bone) then continue end
  166.              
  167.             local pos, ang = Vector(0,0,0), Angle(0,0,0)
  168.             local m = vm:GetBoneMatrix(bone)
  169.             if (m) then
  170.                 pos, ang = m:GetTranslation(), m:GetAngle()
  171.             end
  172.              
  173.             if (self.ViewModelFlip) then
  174.                 ang.r = -ang.r // Fixes mirrored models
  175.             end
  176.              
  177.             if (v.type == "Model" and ValidEntity(model)) then
  178.  
  179.                 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  180.                 ang:RotateAroundAxis(ang:Up(), v.angle.y)
  181.                 ang:RotateAroundAxis(ang:Right(), v.angle.p)
  182.                 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  183.  
  184.                 model:SetAngles(ang)
  185.                 model:SetModelScale(v.size)
  186.                  
  187.                 if (v.material == "") then
  188.                     model:SetMaterial("")
  189.                 elseif (model:GetMaterial() != v.material) then
  190.                     model:SetMaterial( v.material )
  191.                 end
  192.                  
  193.                 if (v.skin and v.skin != model:GetSkin()) then
  194.                     model:SetSkin(v.skin)
  195.                 end
  196.                  
  197.                 if (v.bodygroup) then
  198.                     for k, v in pairs( v.bodygroup ) do
  199.                         if (model:GetBodygroup(k) != v) then
  200.                             model:SetBodygroup(k, v)
  201.                         end
  202.                     end
  203.                 end
  204.                  
  205.                 if (v.surpresslightning) then
  206.                     render.SuppressEngineLighting(true)
  207.                 end
  208.                  
  209.                 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  210.                 render.SetBlend(v.color.a/255)
  211.                 model:DrawModel()
  212.                 render.SetBlend(1)
  213.                 render.SetColorModulation(1, 1, 1)
  214.                  
  215.                 if (v.surpresslightning) then
  216.                     render.SuppressEngineLighting(false)
  217.                 end
  218.                  
  219.             elseif (v.type == "Sprite" and sprite) then
  220.                  
  221.                 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  222.                 render.SetMaterial(sprite)
  223.                 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  224.                  
  225.             elseif (v.type == "Quad" and v.draw_func) then
  226.                  
  227.                 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  228.                 ang:RotateAroundAxis(ang:Up(), v.angle.y)
  229.                 ang:RotateAroundAxis(ang:Right(), v.angle.p)
  230.                 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  231.                  
  232.                 cam.Start3D2D(drawpos, ang, v.size)
  233.                     v.draw_func( self )
  234.                 cam.End3D2D()
  235.  
  236.             end
  237.              
  238.         end
  239.          
  240.     end
  241.  
  242.     SWEP.wRenderOrder = nil
  243.     function SWEP:DrawWorldModel()
  244.          
  245.         if (self.ShowWorldModel == nil or self.ShowWorldModel) then
  246.             self:DrawModel()
  247.         end
  248.          
  249.         if (!self.WElements) then return end
  250.          
  251.         if (!self.wRenderOrder) then
  252.  
  253.             self.wRenderOrder = {}
  254.  
  255.             for k, v in pairs( self.WElements ) do
  256.                 if (v.type == "Model") then
  257.                     table.insert(self.wRenderOrder, 1, k)
  258.                 elseif (v.type == "Sprite" or v.type == "Quad") then
  259.                     table.insert(self.wRenderOrder, k)
  260.                 end
  261.             end
  262.  
  263.         end
  264.          
  265.         local opos, oang = self:GetPos(), self:GetAngles()
  266.         local bone_ent
  267.  
  268.         if (ValidEntity(self.Owner)) then
  269.             bone_ent = self.Owner
  270.         else
  271.             // when the weapon is dropped
  272.             bone_ent = self
  273.         end
  274.          
  275.         local bone = bone_ent:LookupBone("ValveBiped.Bip01_R_Hand")
  276.         if (bone) then
  277.             local m = bone_ent:GetBoneMatrix(bone)
  278.             if (m) then
  279.                 opos, oang = m:GetTranslation(), m:GetAngle()
  280.             end
  281.         end
  282.          
  283.         for k, name in pairs( self.wRenderOrder ) do
  284.          
  285.             local v = self.WElements[name]
  286.             if (!v) then self.wRenderOrder = nil break end
  287.          
  288.             local model = v.modelEnt
  289.             local sprite = v.spriteMaterial
  290.  
  291.             local pos, ang = Vector(opos.x, opos.y, opos.z), Angle(oang.p, oang.y, oang.r)
  292.  
  293.             if (v.type == "Model" and ValidEntity(model)) then
  294.  
  295.                 model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  296.                 ang:RotateAroundAxis(ang:Up(), v.angle.y)
  297.                 ang:RotateAroundAxis(ang:Right(), v.angle.p)
  298.                 ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  299.  
  300.                 model:SetAngles(ang)
  301.                 model:SetModelScale(v.size)
  302.                  
  303.                 if (v.material == "") then
  304.                     model:SetMaterial("")
  305.                 elseif (model:GetMaterial() != v.material) then
  306.                     model:SetMaterial( v.material )
  307.                 end
  308.                  
  309.                 if (v.skin and v.skin != model:GetSkin()) then
  310.                     model:SetSkin(v.skin)
  311.                 end
  312.                  
  313.                 if (v.bodygroup) then
  314.                     for k, v in pairs( v.bodygroup ) do
  315.                         if (model:GetBodygroup(k) != v) then
  316.                             model:SetBodygroup(k, v)
  317.                         end
  318.                     end
  319.                 end
  320.                  
  321.                 if (v.surpresslightning) then
  322.                     render.SuppressEngineLighting(true)
  323.                 end
  324.                  
  325.                 render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  326.                 render.SetBlend(v.color.a/255)
  327.                 model:DrawModel()
  328.                 render.SetBlend(1)
  329.                 render.SetColorModulation(1, 1, 1)
  330.                  
  331.                 if (v.surpresslightning) then
  332.                     render.SuppressEngineLighting(false)
  333.                 end
  334.                  
  335.             elseif (v.type == "Sprite" and sprite) then
  336.                  
  337.                 local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  338.                 render.SetMaterial(sprite)
  339.                 render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  340.                  
  341.             elseif (v.type == "Quad" and v.draw_func) then
  342.                  
  343.                 local drawpos = 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.                 cam.Start3D2D(drawpos, ang, v.size)
  349.                     v.draw_func( self )
  350.                 cam.End3D2D()
  351.  
  352.             end
  353.              
  354.         end
  355.          
  356.     end
  357.  
  358.     function SWEP:CreateModels( tab )
  359.  
  360.         if (!tab) then return end
  361.  
  362.         // Create the clientside models here because Garry says we can't do it in the render hook
  363.        for k, v in pairs( tab ) do
  364.            if (v.type == "Model" and v.model and v.model != "" and (!ValidEntity(v.modelEnt) or v.createdModel != v.model) and
  365.                    string.find(v.model, ".mdl") and file.Exists ("../"..v.model) ) then
  366.                
  367.                v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  368.                if (ValidEntity(v.modelEnt)) then
  369.                    v.modelEnt:SetPos(self:GetPos())
  370.                    v.modelEnt:SetAngles(self:GetAngles())
  371.                    v.modelEnt:SetParent(self)
  372.                    v.modelEnt:SetNoDraw(true)
  373.                    v.createdModel = v.model
  374.                else
  375.                    v.modelEnt = nil
  376.                end
  377.                
  378.            elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  379.                and file.Exists ("../materials/"..v.sprite..".vmt")) then
  380.                
  381.                local name = v.sprite.."-"
  382.                local params = { ["$basetexture"] = v.sprite }
  383.                // make sure we create a unique name based on the selected options
  384.                local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  385.                for i, j in pairs( tocheck ) do
  386.                    if (v[j]) then
  387.                        params["$"..j] = 1
  388.                        name = name.."1"
  389.                    else
  390.                        name = name.."0"
  391.                    end
  392.                end
  393.  
  394.                v.createdSprite = v.sprite
  395.                v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  396.                
  397.            end
  398.        end
  399.        
  400.    end
  401.  
  402.    function SWEP:RemoveModels()
  403.        if (self.VElements) then
  404.            for k, v in pairs( self.VElements ) do
  405.                if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
  406.            end
  407.        end
  408.        if (self.WElements) then
  409.            for k, v in pairs( self.WElements ) do
  410.                if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
  411.            end
  412.        end
  413.        self.VElements = nil
  414.        self.WElements = nil
  415.    end
  416.  
  417. end
  418.  
  419. //SWEP:PrimaryFire()\\
  420. function SWEP:PrimaryAttack()
  421.     if ( !self:CanPrimaryAttack() ) then return end
  422.     local bullet = {}
  423.         bullet.Num = self.Primary.NumberofShots
  424.         bullet.Src = self.Owner:GetShootPos()
  425.         bullet.Dir = self.Owner:GetAimVector()
  426.         bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
  427.         bullet.Tracer = 0
  428.         bullet.Force = self.Primary.Force
  429.         bullet.Damage = self.Primary.Damage
  430.         bullet.AmmoType = self.Primary.Ammo
  431.     local rnda = self.Primary.Recoil * -1
  432.     local rndb = self.Primary.Recoil * math.random(-1, 1)
  433.     self:ShootEffects()
  434.     self.Owner:FireBullets( bullet )
  435.     self.Weapon:EmitSound(Sound(self.Primary.Sound))
  436.     self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
  437.     self:TakePrimaryAmmo(self.Primary.TakeAmmo)
  438.     self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
  439.     self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
  440. end
  441. //SWEP:PrimaryFire()\\
  442.  
  443. //SWEP:SecondaryFire()\\
  444. function SWEP:SecondaryAttack()
  445.     if ( !self:CanSecondaryAttack() ) then return end
  446.     local rnda = -self.Secondary.Recoil
  447.     local rndb = self.Secondary.Recoil * math.random(-1, 1)
  448.     self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
  449.     local eyetrace = self.Owner:GetEyeTrace()
  450.     self.Weapon:EmitSound ( self.Secondary.Sound )
  451.     self:ShootEffects()
  452.     local explode = ents.Create("env_explosion")
  453.     explode:SetPos( eyetrace.HitPos )
  454.     explode:SetOwner( self.Owner )
  455.     explode:Spawn()
  456.     explode:SetKeyValue("iMagnitude","175")
  457.     explode:Fire("Explode", 0, 0 )
  458.     explode:EmitSound("weapon_AWP.Single", 400, 400 )
  459.     self.Weapon:SetNextPrimaryFire( CurTime() + self.Secondary.Delay )
  460.     self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
  461.     self:TakePrimaryAmmo(self.Secondary.TakeAmmo)
  462. end
  463. //SWEP:SecondaryFire()\\
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement