Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ( SERVER ) then
- AddCSLuaFile( "shared.lua" )
- end
- if ( CLIENT ) then
- SWEP.PrintName = "DC-19 Stealth"
- SWEP.Author = "Doctor Jew"
- SWEP.ViewModelFOV = 50
- SWEP.Slot = 2
- SWEP.SlotPos = 3
- SWEP.WepSelectIcon = surface.GetTextureID("HUD/killicons/DC15S")
- killicon.Add( "weapon_jew_dc19", "HUD/killicons/DC15S", Color( 255, 80, 0, 255 ) )
- SWEP.ViewModelBoneMods = {
- ["v_e11_reference001"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
- }
- SWEP.VElements = {
- ["dc15s"] = { type = "Model", model = "models/weapons/blaster.mdl", bone = "v_e11_reference001", rel = "", pos = Vector(-0.719, 6.392, -3.484), angle = Angle(0, -90, 0), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
- }
- SWEP.WElements = {
- ["dc15_s"] = { type = "Model", model = "models/weapons/blaster.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(10.159, 1.044, 0.764), angle = Angle(-16, 1.636, 180), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
- }
- end
- SWEP.HoldType = "ar2"
- SWEP.Base = "weapon_jew_base"
- SWEP.Category = "Star Wars (Updated)"
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = true
- SWEP.ViewModel = "models/weapons/synbf3/c_e11.mdl"
- SWEP.WorldModel = "models/weapons/synbf3/w_a280.mdl"
- SWEP.ViewModelFOV = 47
- SWEP.ViewModelFlip = false
- SWEP.UseHands = true
- SWEP.Weight = 10
- SWEP.AutoSwitchTo = false
- SWEP.AutoSwitchFrom = false
- local FireSound = Sound ("weapons/DC15S_fire.wav");
- local ReloadSound = Sound ("weapons/synbf3/e11_reload.wav")
- local EmptySound = Sound ("weapons/sw_noammo.wav")
- local FireModeSound = Sound ("weapons/sw_detonator/sw_detonator_select.wav")
- SWEP.Primary.Recoil = 0.5
- SWEP.Primary.Damage = 45
- SWEP.Primary.NumShots = 1
- SWEP.Primary.Cone = 0.0125
- SWEP.Primary.ClipSize = 50
- SWEP.Primary.Delay = 0.3
- SWEP.Primary.DefaultClip = 150
- SWEP.Primary.Automatic = true
- SWEP.Primary.Ammo = "ar2"
- SWEP.Primary.Tracer = "effect_sw_laser_blue"
- SWEP.Secondary.Automatic = true
- SWEP.Secondary.Ammo = "none"
- SWEP.IronSightsPos = Vector(-2.655, -9.554, 3.038)
- SWEP.IronSightsAng = Vector(0.787, 0.035, 0)
- // Custom values for fire switching
- SWEP.SelectiveFire = true
- SWEP.NextFireSelect = CurTime()
- SWEP.SMode = 1
- function SWEP:Precache()
- util.PrecacheSound("weapons/DC15S_fire.wav")
- util.PrecacheSound("weapons/synbf3/e11_reload.wav")
- util.PrecacheSound("weapons/sw_noammo.wav")
- util.PrecacheSound("weapons/sw_detonator/sw_detonator_select.wav")
- end
- function SWEP:Think()
- if self.SelectiveFire and self.NextFireSelect < CurTime() then
- if self.Owner:KeyDown(IN_SPEED) and self.Owner:KeyDown(IN_USE) then
- self:SelectFireMode()
- elseif self.Owner:KeyDown(IN_WALK) then
- self:PrintMode()
- end
- end
- end
- local FireModeMessage = {"Stealth mode selected.","Stun mode selected.","Vaporize mode selected.","Normal mode selected."}
- function SWEP:SelectFireMode()
- if CLIENT then
- self.Owner:PrintMessage(HUD_PRINTTALK,FireModeMessage[self.SMode])
- --self.Owner:PrintMessage(HUD_PRINTTALK,"OLD MODE: " .. self.SMode)
- end
- self.NextFireSelect = CurTime() + 3
- self.Weapon:EmitSound(FireModeSound)
- self.SMode = math.fmod((self.SMode + 1), 5)
- if self.SMode < 1 then
- self.SMode = 1
- end
- --if CLIENT then
- -- self.Owner:PrintMessage(HUD_PRINTTALK,"NEW MODE: " .. self.SMode)
- --end
- end
- local PrintModeMessage = {"Normal mode selected.","Stealth mode selected.","Stun mode selected.","Vaporize mode selected."}
- function SWEP:PrintMode()
- if CLIENT then
- self.Owner:PrintMessage(HUD_PRINTTALK,PrintModeMessage[self.SMode])
- --self.Owner:PrintMessage(HUD_PRINTTALK,self.SMode)
- self.NextFireSelect = CurTime() + 1.5
- end
- end
- function SWEP:PrimaryAttack()
- if self.SMode == 1 then
- self:NormalFire()
- elseif self.SMode == 2 then
- self:StealthFire()
- elseif self.SMode == 3 then
- self:Stun()
- elseif self.SMode == 4 then
- self:Vaporize()
- end
- end
- function SWEP:NormalFire()
- self.Primary.Recoil = 0.01
- self.Primary.Damage = 18.75
- self.Primary.NumShots = 1
- self.Primary.Cone = 0.0125
- self.Primary.ClipSize = 50
- self.Primary.Delay = 0.18
- self.Primary.DefaultClip = 50
- self.Primary.Automatic = true
- self.Primary.Ammo = "ar2"
- self.Primary.Tracer = "effect_sw_laser_blue"
- self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
- self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
- if ( !self:CanPrimaryAttack() ) then return end
- if self:Clip1() < 1 then
- self.Weapon:EmitSound( EmptyAmmo )
- return
- end
- self.Weapon:EmitSound( FireSound )
- self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.Primary.Cone )
- self:TakePrimaryAmmo( 1 )
- if ( self.Owner:IsNPC() ) then return end
- self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
- // In singleplayer this function doesn't get called on the client, so we use a networked float
- // to send the last shoot time. In multiplayer this is predicted clientside so we don't need to
- // send the float.
- if ( (game.SinglePlayer() && SERVER) || CLIENT ) then
- self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
- end
- end
- function SWEP:CSShootBullet( dmg, recoil, numbul, cone )
- numbul = numbul or 1
- cone = cone or 0.01
- local bullet = {}
- bullet.Num = numbul
- bullet.Src = self.Owner:GetShootPos() // Source
- bullet.Dir = self.Owner:GetAimVector() // Dir of bullet
- bullet.Spread = Vector( cone, cone, 0 ) // Aim Cone
- bullet.Tracer = 1 // Show a tracer on every x bullets
- bullet.TracerName = self.Primary.Tracer
- bullet.Force = 5 // Amount of force to give to phys objects
- bullet.Damage = dmg
- self.Owner:FireBullets( bullet )
- self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) // View model animation
- self.Owner:MuzzleFlash() // Crappy muzzle light
- self.Owner:SetAnimation( PLAYER_ATTACK1 ) // 3rd Person Animation
- if ( self.Owner:IsNPC() ) then return end
- // CUSTOM RECOIL !
- if ( (game.SinglePlayer() && SERVER) || ( !game.SinglePlayer() && CLIENT && IsFirstTimePredicted() ) ) then
- local eyeang = self.Owner:EyeAngles()
- eyeang.pitch = eyeang.pitch - recoil
- self.Owner:SetEyeAngles( eyeang )
- end
- end
- function SWEP:Reload()
- if self.SMode == 1 or self.SMode == 2 or self.SMode == 3 or self.SMode == 4 then
- if (self.Weapon:Clip1() < self.Primary.ClipSize) then
- if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 then
- self.Weapon:EmitSound( ReloadSound )
- end
- self.Weapon:DefaultReload( ACT_VM_RELOAD );
- self:SetIronsights( false )
- end
- end
- end
- /********************************************************
- SWEP Construction Kit base code
- Created by Clavus
- Available for public use, thread at:
- facepunch.com/threads/1032378
- DESCRIPTION:
- This script is meant for experienced scripters
- that KNOW WHAT THEY ARE DOING. Don't come to me
- with basic Lua questions.
- Just copy into your SWEP or SWEP base of choice
- and merge with your own code.
- The SWEP.VElements, SWEP.WElements and
- SWEP.ViewModelBoneMods tables are all optional
- and only have to be visible to the client.
- ********************************************************/
- function SWEP:Initialize()
- self:SetWeaponHoldType( self.HoldType )
- if CLIENT then
- // Create a new table for every weapon instance
- self.VElements = table.FullCopy( self.VElements )
- self.WElements = table.FullCopy( self.WElements )
- self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
- self:CreateModels(self.VElements) // create viewmodels
- self:CreateModels(self.WElements) // create worldmodels
- // init view model bone build function
- if IsValid(self.Owner) then
- local vm = self.Owner:GetViewModel()
- if IsValid(vm) then
- self:ResetBonePositions(vm)
- // Init viewmodel visibility
- if (self.ShowViewModel == nil or self.ShowViewModel) then
- vm:SetColor(Color(255,255,255,255))
- else
- // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
- vm:SetColor(Color(255,255,255,1))
- // ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
- // 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
- vm:SetMaterial("Debug/hsv")
- end
- end
- end
- end
- end
- function SWEP:Holster()
- if CLIENT and IsValid(self.Owner) then
- local vm = self.Owner:GetViewModel()
- if IsValid(vm) then
- self:ResetBonePositions(vm)
- end
- end
- return true
- end
- function SWEP:OnRemove()
- self:Holster()
- end
- if CLIENT then
- SWEP.vRenderOrder = nil
- function SWEP:ViewModelDrawn()
- local vm = self.Owner:GetViewModel()
- if !IsValid(vm) then return end
- if (!self.VElements) then return end
- self:UpdateBonePositions(vm)
- 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
- if (v.hide) then continue end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- if (!v.bone) then continue end
- local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
- if (!pos) then continue end
- if (v.type == "Model" and IsValid(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)
- local matrix = Matrix()
- matrix:Scale(v.size)
- model:EnableMatrix( "RenderMultiply", matrix )
- 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
- if (IsValid(self.Owner)) then
- bone_ent = self.Owner
- else
- // when the weapon is dropped
- bone_ent = self
- end
- for k, name in pairs( self.wRenderOrder ) do
- local v = self.WElements[name]
- if (!v) then self.wRenderOrder = nil break end
- if (v.hide) then continue end
- local pos, ang
- if (v.bone) then
- pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
- else
- pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
- end
- if (!pos) then continue end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- if (v.type == "Model" and IsValid(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)
- local matrix = Matrix()
- matrix:Scale(v.size)
- model:EnableMatrix( "RenderMultiply", matrix )
- 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:GetBoneOrientation( basetab, tab, ent, bone_override )
- local bone, pos, ang
- if (tab.rel and tab.rel != "") then
- local v = basetab[tab.rel]
- if (!v) then return end
- // Technically, if there exists an element with the same name as a bone
- // you can get in an infinite loop. Let's just hope nobody's that stupid.
- pos, ang = self:GetBoneOrientation( basetab, v, ent )
- if (!pos) then return end
- pos = 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)
- else
- bone = ent:LookupBone(bone_override or tab.bone)
- if (!bone) then return end
- pos, ang = Vector(0,0,0), Angle(0,0,0)
- local m = ent:GetBoneMatrix(bone)
- if (m) then
- pos, ang = m:GetTranslation(), m:GetAngles()
- end
- if (IsValid(self.Owner) and self.Owner:IsPlayer() and
- ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
- ang.r = -ang.r // Fixes mirrored models
- end
- end
- return pos, ang
- 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 (!IsValid(v.modelEnt) or v.createdModel != v.model) and
- string.find(v.model, ".mdl") and file.Exists (v.model, "GAME") ) then
- v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
- if (IsValid(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", "GAME")) 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
- local allbones
- local hasGarryFixedBoneScalingYet = false
- function SWEP:UpdateBonePositions(vm)
- if self.ViewModelBoneMods then
- if (!vm:GetBoneCount()) then return end
- // !! WORKAROUND !! //
- // We need to check all model names :/
- local loopthrough = self.ViewModelBoneMods
- if (!hasGarryFixedBoneScalingYet) then
- allbones = {}
- for i=0, vm:GetBoneCount() do
- local bonename = vm:GetBoneName(i)
- if (self.ViewModelBoneMods[bonename]) then
- allbones[bonename] = self.ViewModelBoneMods[bonename]
- else
- allbones[bonename] = {
- scale = Vector(1,1,1),
- pos = Vector(0,0,0),
- angle = Angle(0,0,0)
- }
- end
- end
- loopthrough = allbones
- end
- // !! ----------- !! //
- for k, v in pairs( loopthrough ) do
- local bone = vm:LookupBone(k)
- if (!bone) then continue end
- // !! WORKAROUND !! //
- local s = Vector(v.scale.x,v.scale.y,v.scale.z)
- local p = Vector(v.pos.x,v.pos.y,v.pos.z)
- local ms = Vector(1,1,1)
- if (!hasGarryFixedBoneScalingYet) then
- local cur = vm:GetBoneParent(bone)
- while(cur >= 0) do
- local pscale = loopthrough[vm:GetBoneName(cur)].scale
- ms = ms * pscale
- cur = vm:GetBoneParent(cur)
- end
- end
- s = s * ms
- // !! ----------- !! //
- if vm:GetManipulateBoneScale(bone) != s then
- vm:ManipulateBoneScale( bone, s )
- end
- if vm:GetManipulateBoneAngles(bone) != v.angle then
- vm:ManipulateBoneAngles( bone, v.angle )
- end
- if vm:GetManipulateBonePosition(bone) != p then
- vm:ManipulateBonePosition( bone, p )
- end
- end
- else
- self:ResetBonePositions(vm)
- end
- end
- function SWEP:ResetBonePositions(vm)
- if (!vm:GetBoneCount()) then return end
- for i=0, vm:GetBoneCount() do
- vm:ManipulateBoneScale( i, Vector(1, 1, 1) )
- vm:ManipulateBoneAngles( i, Angle(0, 0, 0) )
- vm:ManipulateBonePosition( i, Vector(0, 0, 0) )
- end
- end
- /**************************
- Global utility code
- **************************/
- // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
- // Does not copy entities of course, only copies their reference.
- // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
- function table.FullCopy( tab )
- if (!tab) then return nil end
- local res = {}
- for k, v in pairs( tab ) do
- if (type(v) == "table") then
- res[k] = table.FullCopy(v) // recursion ho!
- elseif (type(v) == "Vector") then
- res[k] = Vector(v.x, v.y, v.z)
- elseif (type(v) == "Angle") then
- res[k] = Angle(v.p, v.y, v.r)
- else
- res[k] = v
- end
- end
- return res
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement