Advertisement
Guest User

Untitled

a guest
Mar 11th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 17.09 KB | None | 0 0
  1. //Thanks to GDCW for an awesome RPG and entities, Failure for the MK6 model,
  2. //Teta_Bonita for the nuke explosion entity, and Clavus for the construction kit
  3. //if I missed anyone, sorry. This isn't going to be released to the public anyway.
  4.  
  5. // Variables that are used on both client and server
  6. SWEP.Category               = "Ultraviolence"
  7. SWEP.Author             = "Generic Default"
  8. SWEP.Contact                = ""
  9. SWEP.Purpose                = ""
  10. SWEP.Instructions               = "Hammerdown Protocol"
  11. SWEP.MuzzleAttachment           = "1"   -- Should be "1" for CSS models or "muzzle" for hl2 models
  12. SWEP.ShellEjectAttachment           = "2"   -- Should be "2" for CSS models or "1" for hl2 models
  13. SWEP.DrawCrosshair          = false
  14.  
  15. SWEP.ViewModelFOV           = 55
  16. SWEP.ViewModelFlip          = false
  17. SWEP.ViewModel              = "models/weapons/v_RL7.mdl"
  18. SWEP.WorldModel             = "models/weapons/w_GDC_RPG7.mdl"
  19.  
  20. SWEP.Spawnable              = true
  21. SWEP.AdminSpawnable         = true
  22.  
  23. SWEP.Primary.Round          = ("gdcwa_davycrockett")   
  24. SWEP.Primary.RPM            = 20                    // This is in Rounds Per Minute
  25. SWEP.Primary.ClipSize           = 1                 // Size of a clip
  26. SWEP.Primary.DefaultClip        = 1                 // Default number of bullets in a clip
  27. SWEP.Primary.Automatic          = false                 // Automatic/Semi Auto
  28. SWEP.Primary.Ammo           = "RPG_Round"
  29.  
  30. SWEP.Secondary.ClipSize         = 1                 // Size of a clip
  31. SWEP.Secondary.DefaultClip      = 1                 // Default number of bullets in a clip
  32. SWEP.Secondary.Automatic        = false                 // Automatic/Semi Auto
  33. SWEP.Secondary.Ammo         = ""
  34.  
  35. SWEP.data               = {}                    -- The starting firemode
  36. SWEP.data.ironsights            = 1
  37.  
  38. SWEP.IronSightsPos = Vector (-3.7384, -5.7481, -0.2713)
  39. SWEP.IronSightsAng = Vector (1.1426, 0.0675, 0)
  40. SWEP.SightsPos = Vector (-3.7384, -5.7481, -0.2713)
  41. SWEP.SightsAng = Vector (1.1426, 0.0675, 0)
  42. SWEP.RunSightsPos = Vector (2.4946, -1.5644, 1.699)
  43. SWEP.RunSightsAng = Vector (-20.1104, 35.1164, -12.959)
  44.  
  45.  
  46. function SWEP:Initialize()
  47.     if !self.Owner:IsNPC() then
  48.         self:SetWeaponHoldType("rpg")                           -- Hold type style ("ar2" "pistol" "shotgun" "rpg" "normal" "melee" "grenade" "smg")
  49.     end
  50.     if SERVER and self.Owner:IsNPC() then
  51.         self:SetWeaponHoldType("rpg")                           -- Hold type style ("ar2" "pistol" "shotgun" "rpg" "normal" "melee" "grenade" "smg")
  52.         self:SetNPCMinBurst(1)         
  53.         self:SetNPCMaxBurst(1)          // None of this really matters but you need it here anyway
  54.         self:SetNPCFireRate(1) 
  55.         self:SetCurrentWeaponProficiency( WEAPON_PROFICIENCY_PERFECT )
  56.     end
  57.      
  58.    
  59.    if CLIENT then
  60.        self:CreateModels(self.VElements)
  61.        self:CreateModels(self.WElements)
  62.    end
  63.  
  64. end
  65.  
  66. function SWEP:OnRemove()
  67.    
  68.    if CLIENT then
  69.        self:RemoveModels()
  70.    end
  71.    
  72. end
  73.  
  74. if CLIENT then
  75.  
  76.    SWEP.vRenderOrder = nil
  77.    function SWEP:ViewModelDrawn()
  78.        
  79.        local vm = self.Owner:GetViewModel()
  80.        if !ValidEntity(vm) then return end
  81.        if (!self.VElements) then return end
  82.        
  83.        if (!self.vRenderOrder) then
  84.            
  85.            self.vRenderOrder = {}
  86.  
  87.            for k, v in pairs( self.VElements ) do
  88.                if (v.type == "Model") then
  89.                    table.insert(self.vRenderOrder, 1, k)
  90.                elseif (v.type == "Sprite") then
  91.                    table.insert(self.vRenderOrder, k)
  92.                end
  93.            end
  94.            
  95.        end
  96.  
  97.        for k, name in ipairs( self.vRenderOrder ) do
  98.        
  99.            local v = self.VElements[name]
  100.            if (!v) then self.vRenderOrder = nil break end
  101.        
  102.            local model = v.modelEnt
  103.            local sprite = v.spriteMaterial
  104.            
  105.            if (!v.bone) then continue end
  106.            local bone = vm:LookupBone(v.bone)
  107.            if (!bone) then continue end
  108.            
  109.            local pos, ang = Vector(0,0,0), Angle(0,0,0)
  110.            local m = vm:GetBoneMatrix(bone)
  111.            if (m) then
  112.                pos, ang = m:GetTranslation(), m:GetAngle()
  113.            end
  114.            
  115.            if (self.ViewModelFlip) then
  116.                ang.r = -ang.r
  117.            end
  118.            
  119.            if (v.type == "Model" and ValidEntity(model)) then
  120.  
  121.                model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  122.                ang:RotateAroundAxis(ang:Up(), v.angle.y)
  123.                ang:RotateAroundAxis(ang:Right(), v.angle.p)
  124.                ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  125.  
  126.                model:SetAngles(ang)
  127.                model:SetModelScale(v.size)
  128.                
  129.                if (v.material == "") then
  130.                    model:SetMaterial("")
  131.                elseif (model:GetMaterial() != v.material) then
  132.                    model:SetMaterial( v.material )
  133.                end
  134.                
  135.                if (v.surpresslightning) then
  136.                    render.SuppressEngineLighting(true)
  137.                end
  138.                
  139.                render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  140.                render.SetBlend(v.color.a/255)
  141.                model:DrawModel()
  142.                render.SetBlend(1)
  143.                render.SetColorModulation(1, 1, 1)
  144.                
  145.                if (v.surpresslightning) then
  146.                    render.SuppressEngineLighting(false)
  147.                end
  148.                
  149.            elseif (v.type == "Sprite" and sprite) then
  150.                
  151.                local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  152.                render.SetMaterial(sprite)
  153.                render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  154.                
  155.            end
  156.            
  157.        end
  158.        
  159.    end
  160.    
  161.    SWEP.wRenderOrder = nil
  162.    function SWEP:DrawWorldModel()
  163.        
  164.        if (!self.WElements) then return end
  165.        
  166.        if (!self.wRenderOrder) then
  167.  
  168.            self.wRenderOrder = {}
  169.  
  170.            for k, v in pairs( self.WElements ) do
  171.                if (v.type == "Model") then
  172.                    table.insert(self.wRenderOrder, 1, k)
  173.                elseif (v.type == "Sprite") then
  174.                    table.insert(self.wRenderOrder, k)
  175.                end
  176.            end
  177.  
  178.        end
  179.  
  180.        local bone_ent
  181.        local opos, oang = self:GetPos(), self:GetAngles()
  182.        
  183.        self:DrawModel()
  184.        if (ValidEntity(self.Owner)) then
  185.            bone_ent = self.Owner
  186.        else
  187.            bone_ent = self
  188.        end
  189.        
  190.        local bone = bone_ent:LookupBone("ValveBiped.Bip01_R_Hand")
  191.        if (bone) then
  192.            local m = bone_ent:GetBoneMatrix(bone)
  193.            if (m) then
  194.                opos, oang = m:GetTranslation(), m:GetAngle()
  195.            end
  196.        end
  197.        
  198.        for k, name in pairs( self.wRenderOrder ) do
  199.        
  200.            local v = self.WElements[name]
  201.            if (!v) then self.wRenderOrder = nil break end
  202.        
  203.            local model = v.modelEnt
  204.            local sprite = v.spriteMaterial
  205.  
  206.            local pos, ang = Vector(opos.x, opos.y, opos.z), Angle(oang.p, oang.y, oang.r)
  207.  
  208.            if (v.type == "Model" and ValidEntity(model)) then
  209.  
  210.                model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
  211.                ang:RotateAroundAxis(ang:Up(), v.angle.y)
  212.                ang:RotateAroundAxis(ang:Right(), v.angle.p)
  213.                ang:RotateAroundAxis(ang:Forward(), v.angle.r)
  214.  
  215.                model:SetAngles(ang)
  216.                model:SetModelScale(v.size)
  217.                
  218.                if (v.material == "") then
  219.                    model:SetMaterial("")
  220.                elseif (model:GetMaterial() != v.material) then
  221.                    model:SetMaterial( v.material )
  222.                end
  223.                
  224.                if (v.surpresslightning) then
  225.                    render.SuppressEngineLighting(true)
  226.                end
  227.                
  228.                render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
  229.                render.SetBlend(v.color.a/255)
  230.                model:DrawModel()
  231.                render.SetBlend(1)
  232.                render.SetColorModulation(1, 1, 1)
  233.                
  234.                if (v.surpresslightning) then
  235.                    render.SuppressEngineLighting(false)
  236.                end
  237.                
  238.            elseif (v.type == "Sprite" and sprite) then
  239.                
  240.                local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
  241.                render.SetMaterial(sprite)
  242.                render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
  243.                
  244.            end
  245.            
  246.        end
  247.        
  248.    end
  249.  
  250.    function SWEP:CreateModels( tab )
  251.    
  252.        if (!tab) then return end
  253.    
  254.        for k, v in pairs( tab ) do
  255.            if (v.type == "Model" and v.model and v.model != "" and (!ValidEntity(v.modelEnt) or v.createdModel != v.model) and
  256.                    string.find(v.model, ".mdl") and file.Exists ("../"..v.model) ) then
  257.                
  258.                v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
  259.                if (ValidEntity(v.modelEnt)) then
  260.                    v.modelEnt:SetPos(self:GetPos())
  261.                    v.modelEnt:SetAngles(self:GetAngles())
  262.                    v.modelEnt:SetParent(self)
  263.                    v.modelEnt:SetNoDraw(true)
  264.                    v.createdModel = v.model
  265.                else
  266.                    v.modelEnt = nil
  267.                end
  268.                
  269.            elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
  270.                and file.Exists ("../materials/"..v.sprite..".vmt")) then
  271.                
  272.                local name = v.sprite.."-"
  273.                local params = { ["$basetexture"] = v.sprite }
  274.                local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
  275.                for i, j in pairs( tocheck ) do
  276.                    if (v[j]) then
  277.                        params["$"..j] = 1
  278.                        name = name.."1"
  279.                    else
  280.                        name = name.."0"
  281.                    end
  282.                end
  283.  
  284.                v.createdSprite = v.sprite
  285.                v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
  286.                
  287.            end
  288.        end
  289.        
  290.    end
  291.    
  292.    function SWEP:RemoveModels()
  293.        if (self.VElements) then
  294.            for k, v in pairs( self.VElements ) do
  295.                if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
  296.            end
  297.        end
  298.        if (self.WElements) then
  299.            for k, v in pairs( self.WElements ) do
  300.                if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
  301.            end
  302.        end
  303.  
  304.        self.VElements = rpgbomb
  305.        self.WElements = nuke
  306.    end
  307.  
  308. end
  309.  
  310. function SWEP:RemoveModels()
  311.    if (self.VElements) then
  312.        for k, v in pairs( self.VElements ) do
  313.            if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
  314.        end
  315.    end
  316.    if (self.WElements) then
  317.        for k, v in pairs( self.WElements ) do
  318.            if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
  319.        end
  320.    end
  321.  
  322.    self.VElements = rpgbomb
  323.    self.WElements = nuke
  324.    end
  325.  
  326. function SWEP:Deploy()
  327.     self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
  328. end
  329.  
  330. function SWEP:Precache()
  331.     util.PrecacheSound("RPGF.single")
  332. end
  333.  
  334.  
  335. function SWEP:PrimaryAttack()
  336.     if self:CanPrimaryAttack() then
  337.         self:FireRocket()
  338.         self.Weapon:EmitSound("RPGF.single")
  339.         self.Weapon:TakePrimaryAmmo(1)
  340.         self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
  341.  
  342.         self.VElements:RemoveModels()
  343.        
  344.         local fx        = EffectData()
  345.         fx:SetEntity(self.Weapon)
  346.         fx:SetOrigin(self.Owner:GetShootPos())
  347.         fx:SetNormal(self.Owner:GetAimVector())
  348.         fx:SetAttachment(self.MuzzleAttachment)
  349.         util.Effect("gdcw_backblast",fx)
  350.         self.Owner:SetAnimation( PLAYER_ATTACK1 )
  351.         self.Owner:MuzzleFlash()
  352.         self.Weapon:SetNextPrimaryFire(CurTime()+1/(self.Primary.RPM/60))
  353.  
  354.  
  355.     end
  356. end
  357.  
  358. function SWEP:FireRocket()
  359.     local aim = self.Owner:GetAimVector()
  360.     local pos = self.Owner:GetShootPos()
  361.  
  362.     if SERVER then
  363.     local rocket = ents.Create(self.Primary.Round)
  364.     if !rocket:IsValid() then return false end
  365.     rocket:SetAngles(aim:Angle()+Angle(90,0,0))
  366.     rocket:SetPos(pos)
  367.     rocket:SetOwner(self.Owner)
  368.     rocket:Spawn()
  369.     rocket.owner = self.Owner
  370.     rocket:Activate()
  371.     end
  372. end
  373.  
  374. function SWEP:SecondaryAttack()
  375.     return false
  376. end
  377.  
  378. function SWEP:Reload()
  379.  
  380.     self.Weapon:DefaultReload(ACT_VM_RELOAD)
  381.     -- Animation when you're reloading
  382.         self:SetIronsights(false, self.Owner)
  383.  
  384.     if ( self.Weapon:Clip1() < self.Primary.ClipSize ) and !self.Owner:IsNPC() then
  385.     return false
  386.     -- When the current clip < full clip and the rest of your ammo > 0, then
  387.  
  388.    
  389.  
  390. end
  391.    
  392. end
  393.  
  394.  
  395. /*---------------------------------------------------------
  396. IronSight
  397. ---------------------------------------------------------*/
  398. function SWEP:IronSight()
  399.  
  400.  
  401.     if self.Owner:KeyDown(IN_SPEED) then                    // If you run then
  402.     self.Weapon:SetNextPrimaryFire(CurTime()+0.5)               // Make it so you can't shoot for another quarter second
  403.     self:SetWeaponHoldType("passive")                                   // Hold type styles; ar2 pistol shotgun rpg normal melee grenade smg
  404.     self.IronSightsPos = self.RunSightsPos                  // Hold it down
  405.     self.IronSightsAng = self.RunSightsAng                  // Hold it down
  406.     self:SetIronsights(true, self.Owner)                    // Set the ironsight true
  407.     self.Owner:SetFOV( 0, 0.3 )                     // Reset FOV
  408.     end                            
  409.  
  410.     if self.Owner:KeyReleased(IN_SPEED) then                // If you stop running then
  411.     self:SetWeaponHoldType("rpg")                                       // Hold type styles; ar2 pistol shotgun rpg normal melee grenade smg slam fist melee2 passive knife
  412.     self:SetIronsights(false, self.Owner)                   // Set the ironsight true
  413.     self.Owner:SetFOV( 0, 0.3 )                     // Reset FOV
  414.     end
  415.  
  416.  
  417.         if self.Owner:KeyPressed(IN_ATTACK2) then
  418.         self.Owner:SetFOV( 40, 0.5 )
  419.         self.IronSightsPos = self.SightsPos                 // Bring it up
  420.         self.IronSightsAng = self.SightsAng                 // Bring it up
  421.         self:SetIronsights(true, self.Owner)
  422.         end
  423.  
  424.         if self.Owner:KeyReleased(IN_ATTACK2) and !self.Owner:KeyDown(IN_SPEED) then
  425.         self.Owner:SetFOV( 0, 0.5 )
  426.         self:SetIronsights(false, self.Owner)
  427.         end
  428. end
  429.  
  430. /*---------------------------------------------------------
  431. Think
  432. ---------------------------------------------------------*/
  433. function SWEP:Think()
  434.  
  435.     self:IronSight()
  436. end
  437.  
  438. /*---------------------------------------------------------
  439. GetViewModelPosition
  440. ---------------------------------------------------------*/
  441. local IRONSIGHT_TIME = 0.5
  442. -- Time to enter in the ironsight mod
  443.  
  444. function SWEP:GetViewModelPosition(pos, ang)
  445.  
  446.     if (not self.IronSightsPos) then return pos, ang end
  447.  
  448.     local bIron = self.Weapon:GetNWBool("Ironsights")
  449.  
  450.     if (bIron != self.bLastIron) then
  451.         self.bLastIron = bIron
  452.         self.fIronTime = CurTime()
  453.  
  454.         if (bIron) and !self.Owner:KeyDown(IN_SPEED) then   // If Ironsights and NOT RUNNING then
  455.             self.SwayScale  = 0.02
  456.             self.BobScale   = 0.02
  457.         else
  458.             self.SwayScale  = 1.0
  459.             self.BobScale   = 1.0
  460.         end
  461.     end
  462.  
  463.     local fIronTime = self.fIronTime or 0
  464.  
  465.     if (not bIron and fIronTime < CurTime() - IRONSIGHT_TIME) then
  466.         return pos, ang
  467.     end
  468.  
  469.     local Mul = 1.0
  470.  
  471.     if (fIronTime > CurTime() - IRONSIGHT_TIME) then
  472.         Mul = math.Clamp((CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1)
  473.  
  474.         if not bIron then Mul = 1 - Mul end
  475.     end
  476.  
  477.     local Offset    = self.IronSightsPos
  478.  
  479.     if (self.IronSightsAng) then
  480.         ang = ang * 1
  481.         ang:RotateAroundAxis(ang:Right(),       self.IronSightsAng.x * Mul)
  482.         ang:RotateAroundAxis(ang:Up(),      self.IronSightsAng.y * Mul)
  483.         ang:RotateAroundAxis(ang:Forward(),     self.IronSightsAng.z * Mul)
  484.     end
  485.  
  486.     local Right     = ang:Right()
  487.     local Up        = ang:Up()
  488.     local Forward   = ang:Forward()
  489.  
  490.     pos = pos + Offset.x * Right * Mul
  491.     pos = pos + Offset.y * Forward * Mul
  492.     pos = pos + Offset.z * Up * Mul
  493.  
  494.     return pos, ang
  495. end
  496.  
  497. /*---------------------------------------------------------
  498. SetIronsights
  499. ---------------------------------------------------------*/
  500. function SWEP:SetIronsights(b)
  501.  
  502.     self.Weapon:SetNetworkedBool("Ironsights", b)
  503. end
  504.  
  505. function SWEP:GetIronsights()
  506.  
  507.     return self.Weapon:GetNWBool("Ironsights")
  508. end
  509.  
  510. //the madness starts here===================================================================
  511.  
  512. // it all went here function SWEP:Initialize()
  513.  
  514. //end
  515.  
  516. SWEP.VElements = {
  517.  
  518.     ["rpgbomb"] = { type = "Model", model = "models/Failure/MK6/mk6.mdl", bone = "ValveBiped.SphereGizmo02.RPG.Rocket", pos = Vector(0, 5.057, -5.844), angle = Angle(0, -90, 0), size = Vector(0.372, 0.372, 0.372), color = Color(255, 255, 255, 255), surpresslightning = false, material = "models/Failure/MK6/Base"}
  519.  
  520. }
  521.  
  522. SWEP.WElements = {
  523.  
  524.     ["nuke"] = { type = "Model", model = "models/Failure/MK6/mk6.mdl", bone = "ValveBiped.Bip01_R_Hand", pos = Vector(30, -0.313, -17.556), angle = Angle(-9.756, 0, 0), size = Vector(0.405, 0.405, 0.405), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}
  525.  
  526. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement