• Noob SWEP Construction Kit Question
    5 replies, posted
Noob question, I feel stupid asking this. I've tried looking through SWEP Construction Kit tutorials for this, but I can't seem to find the issue. I'm trying to make a custom weapon in Garry's Mod, and the placement in the model is off and needs to be flipped. [B]My test model in SWEP Construction Kit:[/B] [IMG]http://i.imgur.com/tyPTB88.jpg[/IMG] [B]My test model corrected with SWEP Construction Kit:[/B] [IMG]http://i.imgur.com/tokY9mp.jpg[/IMG] [B] My test model after inserting the weapon code (Lua) into the weapon script:[/B] [IMG]http://i.imgur.com/4tQBXpd.jpg[/IMG] Here's the weapon lua code that needs to be inserted, but doesn't quite work when it is [CODE]SWEP.HoldType = "crossbow" SWEP.ViewModelFOV = 70 SWEP.ViewModelFlip = false SWEP.ViewModel = "models/matt/phaserrifleexporttest.mdl" SWEP.WorldModel = "models/weapons/w_crossbow.mdl" SWEP.ShowViewModel = true SWEP.ShowWorldModel = true SWEP.ViewModelBoneMods = { ["Box041"] = { scale = Vector(1, 1, 1), pos = Vector(-13.969, -18.095, -10.476), angle = Angle(0, -1.905, -91.43) } }[/CODE] The trouble is, where do I insert this code to make the model orient correctly? Before, after, or in the base code? Here's a snippet of the base and orientation code as of now: [CODE]/******************************************************** 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() // 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 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:Set
Bumpity.
SWEP Kit goes at the bottom, define the SWEP variables like WElements etc. in a client side if statement. The weapon/ironsights code, if used, can go in the general SWEP. Also, use [t] tags for images, then they don't get too big. [t]http://dl.dropbox.com/u/11217331/Screens/gmod/swep_construction_kit/tut16.jpg[/t]
Thank you, I'll be sure to use the tag feature for images when I post from now on. Now then, I still can't get the View Model to orient correctly. Here's a snippet of my code: [CODE]SWEP.Spawnable = true SWEP.AdminOnly = false SWEP.PrintName = "Type 3 Phaser" SWEP.Author = "Eishen" SWEP.Instructions = "Star Trek" if CLIENT then SWEP.HoldType = "crossbow" SWEP.ViewModelFOV = 70 SWEP.ViewsModelFlip = false SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Slot = 3 SWEP.SlotPos = 2 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true SWEP.ViewModelBoneMods = {["Box041"] = { scale = Vector(1, 1, 1), pos = Vector(-13.969, -18.095, -10.476), angle = Angle(0, -1.905, -91.43) } } end SWEP.ViewModel = "models/matt/phaserrifleexporttest.mdl" SWEP.WorldModel = "models/weapons/w_crossbow.mdl" SWEP.ShowViewModel = true SWEP.ShowWorldModel = true 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"[/CODE] The rest of the code is my firing functions, and then the base code from SWEP Construction Kit goes at the end. Help?
Bumpy!
Bump again
Sorry, you need to Log In to post a reply to this thread.