• Need help using the SCK base on an already existing SWEP.
    6 replies, posted
Short and to the point, I suck at Lua but have been trying to learn. Basically I took a SWEP off the workshop and wanted to add entities to their bodies via worldmodels but I cant seem to get the SCK base to work properly on this SWEP. Somethings to note before I show it: -I merged the initializations before hand and nothing different happened. -The original functionality still works on this swep, but nothing I wanted to add. -There are no script errors. [CODE]AddCSLuaFile() SWEP.PrintName = "Blah Blah Blah" SWEP.Category = "Blah Blah Blah" SWEP.Author = "Blah Blah Blah" SWEP.Purpose = "Blah Blah Blah." SWEP.Spawnable = true SWEP.UseHands = true SWEP.DrawAmmo = false SWEP.Base = "weapon_base" SWEP.ViewModel = "models/weapons/v_slam.mdl" SWEP.WorldModel = "" SWEP.TraceLength = 500 SWEP.ViewModelFOV = 52 SWEP.Slot = 0 SWEP.SlotPos = 5 SWEP.Effect = "c4_explosion" SWEP.EffectAir = "c4_explosion_air" SWEP.WElements = { ["Detonator"] = { type = "Model", model = "models/Items/battery.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.675, 3.635, -3.636), angle = Angle(0, 0, 0), size = Vector(0.56, 0.56, 0.56), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }, ["Bomb1"] = { type = "Model", model = "models/dav0r/tnt/tnttimed.mdl", bone = "ValveBiped.Bip01_Spine4", rel = "", pos = Vector(-7.792, -9.87, -1.558), angle = Angle(-94.676, 171.817, 180), size = Vector(0.367, 0.367, 0.367), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }, ["Bomb3"] = { type = "Model", model = "models/dav0r/tnt/tnt.mdl", bone = "ValveBiped.Bip01_Spine4", rel = "", pos = Vector(-7.792, -9.87, -4.676), angle = Angle(-3.507, -101.689, -85.325), size = Vector(0.367, 0.367, 0.367), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }, ["Bomb2"] = { type = "Model", model = "models/dav0r/tnt/tnt.mdl", bone = "ValveBiped.Bip01_Spine4", rel = "", pos = Vector(-7.792, -9.87, 1.557), angle = Angle(-10.52, -104.027, -85.325), size = Vector(0.367, 0.367, 0.367), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } util.PrecacheModel( SWEP.ViewModel ) SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" local Explosion = { "ambient/explosions/explode_1.wav" , "ambient/explosions/explode_2.wav" , "ambient/explosions/explode_3.wav" , "ambient/explosions/explode_4.wav" } local MuselScream = { "allakbar1.mp3", "allakbar2.mp3" , "allakbar3.mp3" } SWEP.DamageDistance = 1000 function SWEP:Initialize() self:SetHoldType( "slam" ) self.CanPerformAttack = true timer.Simple(0.05,function() self:SendWeaponAnim(ACT_SLAM_DETONATOR_IDLE) end) end function SWEP:Initialize() self:SetHoldType( "slam" ) self.CanPerformAttack = true timer.Simple(0.05,function() self:SendWeaponAnim(ACT_SLAM_DETONATOR_IDLE) end) 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
So I tried even more methods of taking out old pieces and trying to rework them to the point where I actually re-created the desired function, but it still didn't connect the SCK base. :L
do you still have duplicates of functions SWEP:Initialize(), SWEP:OnRemove(), and SWEP:Holster()?
Merge the duplicates together or else stuff is going to not work.
[QUOTE=cynaraos;48633979]do you still have duplicates of functions SWEP:Initialize(), SWEP:OnRemove(), and SWEP:Holster()?[/QUOTE] I merged the Initialize and OnRemove. To be honest, I feel stupid i didn't see a duplicate Holster. Ill try that now and see what happens.
Alright, I tampered alot with it and merged the Functions to their respective places, and now it will not even appear under the Guns tab. Anyone have any idea?
-snip- didn't read op code
Sorry, you need to Log In to post a reply to this thread.