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 = "EMSSS-12"
- SWEP.Author = "Babel Industries (Model by Defuse)"
- SWEP.Contact = "";
- SWEP.Instructions = "Electro Magnetic Shelless Slug Shotgun"
- SWEP.Category = "Babel Industries"
- SWEP.Slot = 2
- SWEP.SlotPos = 1
- SWEP.IconLetter = "k"
- SWEP.WepSelectIcon = surface.GetTextureID("vgui/entities/weapon_emsss")
- killicon.AddFont( "weapon_peashotty", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )
- SWEP.WElements = {
- ["some_unique_name"] = { type = "Model", model = "models/weapons/w_shot_mssuper90.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(1.58, 0.504, 0.3), angle = Angle(-6.588, 0.794, 176.725), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
- }
- end
- SWEP.Base = "weapon_tttbase"
- SWEP.Spawnable = true
- SWEP.AdminSpawnable = false
- SWEP.HoldType = "shotgun"
- SWEP.ViewModelFOV = 71
- SWEP.ViewModelFlip = true
- SWEP.ViewModel = "models/weapons/v_shot_mssuper90.mdl"
- SWEP.WorldModel = "models/weapons/w_shotgun.mdl"
- SWEP.ShowViewModel = true
- SWEP.ShowWorldModel = false
- SWEP.ViewModelBoneMods = {}
- SWEP.Icon = "vgui/entities/weapon_emsss"
- SWEP.Kind = WEAPON_HEAVY
- SWEP.AmmoEnt = "item_box_buckshot_ttt"
- function SWEP:Deploy()
- self.Owner:EmitSound( "weapons/barret_arm_draw.wav" ) ;
- self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
- self:SetDeploySpeed( self.Weapon:SequenceDuration(0.2) )
- return true;
- end
- SWEP.Primary.Sound = Sound( "weapons/m3/s3-1.wav" )
- SWEP.Primary.Recoil = 1
- SWEP.Primary.Damage = 5
- SWEP.Primary.NumShots = 1
- SWEP.Primary.Cone = 0.035
- SWEP.Primary.ClipSize = 12
- SWEP.Primary.Delay = 1.1
- SWEP.Primary.DefaultClip = 70
- SWEP.Primary.Automatic = true
- SWEP.Primary.Ammo = "buckshot"
- SWEP.Secondary.ClipSize = -1
- SWEP.Secondary.DefaultClip = -1
- SWEP.Secondary.Automatic = false
- SWEP.Secondary.Ammo = "none"
- SWEP.CanBuy = { ROLE_TRAITOR }
- SWEP.IronSightsPos = Vector(3.046, -4.427, 2.834)
- SWEP.IronSightsAng = Vector(0, 0, 0)
- SWEP.RunArmOffset = Vector(-0.601, -3.935, -1.461)
- SWEP.RunArmAngle = Vector(8.032, -41.885, 0)
- function SWEP:PrimaryAttack()
- // Make sure we can shoot first
- if ( !self:CanPrimaryAttack() ) then return end
- self.Weapon:EmitSound(Sound("weapons/m3/s3-1.wav"))
- self:ShootBullet( 38, 1, 0 )
- // Remove 1 bullet from our clip
- self:TakePrimaryAmmo( 1 )
- local vShootPos = self.Owner:GetShootPos()
- local vShootAng = self.Owner:GetAimVector()
- local t = {}
- t.caller = self.Owner
- t.start = vShootPos
- t.sang = vShootAng
- t.mreps = 38
- t.reps = 0
- t.damage = 40
- t.length = 70
- t.filter = self.Owner
- t.maxpens = 38
- t.pens = 0
- t.powdeg = .01
- t.skew = Vector( 0.035, 0.035, 0.035 )
- t.canbounce = true
- t.bounceang = .3
- t.bouncechance = .4
- // Punch the player's view
- self.Owner:ViewPunch( Angle( 1, 1, 1 ) )
- self.Weapon:SetNextPrimaryFire( CurTime() + 1.2 )
- return true
- --Bleh? This swep doesn't work if this isn't here.
- end
- function SWEP:ShootBullet( damage, num_bullets, aimcone )
- local bullet = {}
- bullet.Num = 1
- bullet.Src = self.Owner:GetShootPos()
- bullet.Dir = self.Owner:GetAimVector()
- bullet.Spread = Vector( 0.021, 0.021, 0.021 )
- bullet.Tracer = 5000
- bullet.Force = 5000
- bullet.Damage = damage
- bullet.AmmoType = "AR2AltFire"
- bullet.Callback = function(attacker,tr,dmginfo)
- ParticleEffect("striderbuster_attach_ring",tr.HitPos,Angle(0,0,0),nil)
- end
- self.Owner:FireBullets( bullet )
- self:ShootEffects()
- end
- /*---------------------------------------------------------
- Reload does nothing
- ---------------------------------------------------------*/
- /*---------------------------------------------------------
- Think does nothing
- ---------------------------------------------------------*/
- function SWEP:Think()
- if self.Weapon:Clip1() > self.Primary.ClipSize then
- self.Weapon:SetClip1(self.Primary.ClipSize)
- end
- if self.Weapon:GetNetworkedBool( "reloading") == true then
- if self.Weapon:GetNetworkedInt( "reloadtimer") < CurTime() then
- if self.unavailable then return end
- if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then
- self.Weapon:SetNextPrimaryFire(CurTime() + 0.8)
- self.Weapon:SetNextSecondaryFire(CurTime() + 0.8)
- self.Weapon:SetNetworkedBool( "reloading", false)
- self.Weapon:EmitSound( "weapons/m3/s3_pump.wav" )
- self.Weapon:SendWeaponAnim(ACT_SHOTGUN_RELOAD_FINISH)
- else
- self.Weapon:SetNetworkedInt( "reloadtimer", CurTime() + 12.45 )
- self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
- self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
- self.Weapon:SetClip1( self.Weapon:Clip1() + 1 )
- self.Weapon:SetNextPrimaryFire(CurTime() + 0.8)
- self.Weapon:SetNextSecondaryFire(CurTime() + 0.8)
- self.Weapon:EmitSound( "weapons/m3/s3_insertshell.wav" )
- if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0) then
- self.Weapon:SetNextPrimaryFire(CurTime() + 12.5)
- self.Weapon:SetNextSecondaryFire(CurTime() + 12.5)
- else
- self.Weapon:SetNextPrimaryFire(CurTime() + 0.5)
- self.Weapon:SetNextSecondaryFire(CurTime() + 0.5)
- end
- end
- end
- end
- end
- function SWEP:Initialize()
- // other initialize code goes here
- 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
- local vm = self.Owner:GetViewModel()
- if IsValid(vm) then
- self:ResetBonePositions(vm)
- end
- // 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
- function SWEP:Holster()
- if CLIENT then
- local vm = self.Owner:GetViewModel()
- if IsValid(vm) then
- self:ResetBonePositions(vm)
- end
- end
- return true
- 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