• Problem with WElements...
    2 replies, posted
Hi everyone! I always work on my CakeScript changed and I create weapons, NOHD this is my first weapon is a deck. So as there is no model in W hl2, I left the line like this: SWEP.WorldModel = "" So, to still have a model pick in hand, I create this code snippet: SWEP.WElements = { ["pickaxe"] = { type = "Model", model = "models/props_mining/pickaxe01.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(2.825, 1.361, 4.693), angle = Angle(-177.907, 0, 0), size = Vector(0.722, 0.722, 0.722), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } So what is in the hands of the pick (model HL2: EP2). But I can not put this paragraph in my code of my weapon as follows: if (SERVER) then AddCSLuaFile( "shared.lua" ) SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end if ( CLIENT ) then SWEP.PrintName = "Pickaxe" SWEP.Author = "Lyc@n" SWEP.Contact = "" SWEP.DrawAmmo = false SWEP.DrawCrosshair = false SWEP.ViewModelFOV = 70 SWEP.ViewModelFlip = false SWEP.CSMuzzleFlashes = false end SWEP.Category = "RP Weapons" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModel = "models/props_mining/pickaxe01.mdl" SWEP.WorldModel = "" SWEP.Primary.Sound = Sound("Weapon_Crowbar.Single") SWEP.Primary.Damage = 75 SWEP.Primary.NumShots = 0 SWEP.Primary.Recoil = 0.8 SWEP.Primary.Cone = 0.1 SWEP.Primary.Delay = 0.5 SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Tracer = 0 SWEP.Primary.Force = 15 SWEP.Primary.TakeAmmoPerBullet = false SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = 0 SWEP.Secondary.DefaultClip = 0 SWEP.IronSightsPos = Vector(-51.28, -5.12, -6.231) SWEP.IronSightsAng = Vector(37.349, -133.801, 650.599) function SWEP:Reload() end function SWEP:PrimaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self.Weapon:EmitSound( self.Primary.Sound ) self:Slash() self.Owner:SetAnimation( PLAYER_ATTACK1 ) end end end function SWEP:SecondaryAttack() end function SWEP:Think() end function SWEP:Initialize() self.HoldType = "melee2" //Sets their holdtype to that of the AR2 self:SetWeaponHoldType( self.HoldType ) end Where I have to put this paragraph in the code for my weapon? Thank you!
First of all, always put your code in lua tags. Secondly, You can just shove that code snippet anywhere in your code. However, you need to include the base weapon creator code there too. [lua] /************************************************** SWEP Construction Kit base code Created by Clavus Available for public use, thread at: facepunch.com/threads/1032378 **************************************************/ function SWEP:Initialize() // other initialize code goes here if CLIENT then self:CreateModels(self.VElements) // create viewmodels self:CreateModels(self.WElements) // create worldmodels // init view model bone build function self.BuildViewModelBones = function( s ) if LocalPlayer():GetActiveWeapon() == self and self.ViewModelBonescales then for k, v in pairs( self.ViewModelBonescales ) do local bone = s:LookupBone(k) if (!bone) then continue end local m = s:GetBoneMatrix(bone) if (!m) then continue end m:Scale(v) s:SetBoneMatrix(bone, m) end end end end end function SWEP:OnRemove() // other onremove code goes here if CLIENT then self:RemoveModels() end end if CLIENT then SWEP.vRenderOrder = nil function SWEP:ViewModelDrawn() local vm = self.Owner:GetViewModel() if !ValidEntity(vm) then return end if (!self.VElements) then return end if vm.BuildBonePositions ~= self.BuildViewModelBones then vm.BuildBonePositions = self.BuildViewModelBones end if (self.ShowViewModel == nil or self.ShowViewModel) then vm:SetColor(255,255,255,255) else // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called vm:SetColor(255,255,255,1) end 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 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 ValidEntity(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) 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 (ValidEntity(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 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 ValidEntity(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) 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
And don't forget to merge your current SWEP:Initialize function with that of the base code.
Sorry, you need to Log In to post a reply to this thread.