1. Post #1

    August 2013
    4 Posts
    Hello everyone, I am in need of some help in coding a TTT swep.
    This is my first project. Essentially, I have the code completed but for some strange reason it does not show the proper model in viewmodel.
    I am trying to build a Traitor "Golden Gun". It is purchasable and works however the proper model does not display and when shot, it does not play any sound.
    Here is what I have currently.
    Any help would be greatly appreciated.

    Code:
    ---- Example TTT custom weapon
    
    -- First some standard GMod stuff
    if SERVER then
       AddCSLuaFile( "shared.lua" )
    end
    
    if CLIENT then
       SWEP.PrintName = "Golden Gun"
       SWEP.Slot      = 6 -- add 1 to get the slot number key
    
       SWEP.ViewModelFOV  = 100
       SWEP.ViewModelFlip = true
       --[[
        resource.AddFile("materials/models/goldengun/723b4b52.vmt")
    	resource.AddFile("materials/models/goldengun/723b4b52.vtf")
    	resource.AddFile("materials/models/goldengun/1723b4b5233.vmt")
    	resource.AddFile("materials/models/goldengun/1723b4b5233.vtf")
    	resource.AddFile("materials/models/weapons/v_models/fiocchi/fiocchi-unwrap.vmt")
    	resource.AddFile("materials/models/weapons/v_models/fiocchi/fiocchi-unwrap.vtf")
    	resource.AddFile("materials/models/weapons/v_models/fiocchi/fhi0cchi-unwrap-r.vtf")
    	resource.AddFile("materials/models/weapons/w_models/fiocchi/fiocchi-unwrap.vtf")
    	resource.AddFile("materials/models/weapons/w_models/fiocchi/fiocchi-unwrap.vmt")
    	resource.AddFile("materials/models/weapons/w_models/fiocchi/fiocchi-unwrap-r.vtf")
    	resource.AddFile("materials/models/weapons/w_models/fiocchi/fiocchi-unwrap-r.vtf")
    	resource.AddFile("models/weapons/w_pist_goldgunevo1.mdl")
    	resource.AddFile("models/weapons/v_pist_goldgunevo1.mdl")
    	resource.AddFile("sound/weapons/goldengun/gg-shoot2.wav")
    	resource.AddFile("sound/weapons/goldengun/reload2.wav")
    	resource.AddFile("materials/vgui/entities/weapon_apache.vmt")	
    	resource.AddFile("materials/vgui/entities/weapon_goldengun.vmt")
    	resource.AddFile("materials/vgui/entities/weapon_goldengun.vtf") ]]--
    end
    
    -- Always derive from weapon_tttbase.
    SWEP.Base				= "weapon_tttbase"
    
    --- Standard GMod values
    
    SWEP.HoldType			= "pistol"
    
    SWEP.Primary.Delay       = 0.08
    SWEP.Primary.Recoil      = 5.9
    SWEP.Primary.Automatic   = false
    SWEP.Primary.Damage      = 100
    SWEP.Primary.Cone        = 0.025
    SWEP.Primary.Ammo        = "golden_deagle_ammo"
    SWEP.Primary.ClipSize    = 2
    SWEP.Primary.ClipMax     = 2
    SWEP.Primary.DefaultClip = 2
    SWEP.Primary.Sound       = Sound( "weapons/goldengun/gg-shoot2" )
    
    SWEP.IronSightsPos = Vector( 6.05, -5, 2.4 )
    SWEP.IronSightsAng = Vector( 2.2, -0.1, 0 )
    
    SWEP.ViewModel  = "models/goldengun.mdl"
    SWEP.WorldModel = "models/weapons/w_pist_goldgunevo1.mdl"
    
    function SWEP:Reload()
    	if !( ( self.Weapon:Clip1() ) < ( self.Primary.ClipSize ) ) then return end
    	self.Weapon:DefaultReload( ACT_VM_RELOAD )
    	self:SetIronsights( false )
        self:SetZoom(false)
    	self:EmitSound( "weapons/goldengun/reload2.wav" )
    	
    end
    
    function SWEP:PreDrop()
        self:SetZoom(false)
        self:SetIronsights(false)
        return self.BaseClass.PreDrop(self)
    end
    
    function SWEP:Holster()
        self:SetIronsights(false)
        self:SetZoom(false)
        return true
    end
    
    
    --- TTT config values
    
    -- Kind specifies the category this weapon is in. Players can only carry one of
    -- each. Can be: WEAPON_... MELEE, PISTOL, HEAVY, NADE, CARRY, EQUIP1, EQUIP2 or ROLE.
    -- Matching SWEP.Slot values: 0      1       2     3      4      6       7        8
    SWEP.Kind = WEAPON_EQUIP1
    
    -- If AutoSpawnable is true and SWEP.Kind is not WEAPON_EQUIP1/2, then this gun can
    -- be spawned as a random weapon. Of course this AK is special equipment so it won't,
    -- but for the sake of example this is explicitly set to false anyway.
    SWEP.AutoSpawnable = false
    
    -- The AmmoEnt is the ammo entity that can be picked up when carrying this gun.
    -- SWEP.AmmoEnt = "item_ammo_357_ttt"
    
    -- CanBuy is a table of ROLE_* entries like ROLE_TRAITOR and ROLE_DETECTIVE. If
    -- a role is in this table, those players can buy this.
    SWEP.CanBuy = { ROLE_TRAITOR }
    
    -- InLoadoutFor is a table of ROLE_* entries that specifies which roles should
    -- receive this weapon as soon as the round starts. In this case, none.
    SWEP.InLoadoutFor = nil
    
    -- If LimitedStock is true, you can only buy one per round.
    SWEP.LimitedStock = true
    
    -- If AllowDrop is false, players can't manually drop the gun with Q
    SWEP.AllowDrop = true
    
    -- If IsSilent is true, victims will not scream upon death.
    SWEP.IsSilent = false
    
    -- If NoSights is true, the weapon won't have ironsights
    SWEP.NoSights = false
    
    -- Equipment menu information is only needed on the client
    if CLIENT then
       -- Path to the icon material
       SWEP.Icon = "VGUI/ttt/icon_myserver_goldengun"
    
       -- Text shown in the equip menu
       SWEP.EquipMenuData = {
          type = "Weapon",
          desc = "Goldeneye's Legendary Golden Gun!"
       };
    end
    
    -- Tell the server that it should download our icon to clients.
    if SERVER then
       -- It's important to give your icon a unique name. GMod does NOT check for
       -- file differences, it only looks at the name. This means that if you have
       -- an icon_ak47, and another server also has one, then players might see the
       -- other server's dumb icon. Avoid this by using a unique name.
       resource.AddFile("materials/VGUI/ttt/icon_myserver_goldengun.vtf")
    end

  2. Post #2
    Nobody shall ever know I am actually, Batman c:
    smithy285's Avatar
    August 2012
    874 Posts
    Code:
    SWEP.ViewModel  = "models/goldengun.mdl"
    Are you sure that is the correct model path for the view model? Looking the the world model I would expect it to be something like this;

    Code:
    SWEP.WorldModel = "models/weapons/v_pist_goldgunevo1.mdl"

  3. Post #3

    August 2013
    4 Posts
    Thank you for the swift response.
    Code:
    SWEP.ViewModel  = "models/goldengun.mdl"
    Are you sure that is the correct model path for the view model? Looking the the world model I would expect it to be something like this;

    Code:
    SWEP.WorldModel = "models/weapons/v_pist_goldgunevo1.mdl"
    Yes, I have tried that and it came out looking like this:
    http://steamcommunity.com/sharedfile.../?id=170037264

  4. Post #4
    Gold Member
    mitterdoo's Avatar
    June 2009
    593 Posts
    Yes, I have tried that and it came out looking like this:
    http://steamcommunity.com/sharedfile.../?id=170037264
    i don't get it, what is wrong about the picture

    are you talking about another player holding it or yourself?

  5. Post #5

    August 2013
    4 Posts
    i don't get it, what is wrong about the picture
    that's not the proper view model.
    it's supposed to be the 007 "goldeneye" Golden Gun. :/

  6. Post #6
    Gold Member
    mitterdoo's Avatar
    June 2009
    593 Posts
    that's not the proper view model.
    it's supposed to be the 007 "goldeneye" Golden Gun. :/
    sorry i haven't really seen any 007 stuff so i don't know what it's supposed to look like

       don't kill me please   
    Reply With Quote Edit / Delete Reply Windows Vista United States Show Events Dumb Dumb x 1 (list)

  7. Post #7

    August 2013
    4 Posts
    Sorry, here is what the workshop of it is. It is Sandbox that I am trying to make usable for TTT.
    http://steamcommunity.com/sharedfile.../?id=118999822

  8. Post #8

    February 2008
    322 Posts
    Well, this sort of works. There's funny bug with this though, the next round after you had it on, you will get tiny crowbar/messed up weps for the rest of the map. Guns and stuff still work.
    also plays a james bond themed song when deployed.
    Code:
    // Variables that are used on both client and server
    if SERVER then
    resource.AddSingleFile( "sound/007_original.mp3" )
    resource.AddSingleFile( "models/goldengun.dx80.vtx" )
    resource.AddSingleFile( "models/goldengun.dx90.vtx" )
    resource.AddSingleFile( "models/goldengun.mdl" )
    resource.AddSingleFile( "models/goldengun.phy" )
    resource.AddSingleFile( "models/goldengun.sw.vtx" )
    resource.AddSingleFile( "models/goldengun.vvd" )
    resource.AddSingleFile( "models/weapons/v_pist_xiveseven.dx80.vtx" )
    resource.AddSingleFile( "models/weapons/v_pist_xiveseven.dx90.vtx" )
    resource.AddSingleFile( "models/weapons/v_pist_xiveseven.mdl" )
    resource.AddSingleFile( "models/weapons/v_pist_xiveseven.sw.vtx" )
    resource.AddSingleFile( "models/weapons/v_pist_xiveseven.vvd" )
    resource.AddSingleFile( "models/weapons/v_pist_xiveseven.xbox.vtx" )
    resource.AddSingleFile( "models/weapons/w_pist_xiveseven.dx80.vtx" )
    resource.AddSingleFile( "models/weapons/w_pist_xiveseven.dx90.vtx" )
    resource.AddSingleFile( "models/weapons/w_pist_xiveseven.mdl" )
    resource.AddSingleFile( "models/weapons/w_pist_xiveseven.phy" )
    resource.AddSingleFile( "models/weapons/w_pist_xiveseven.sw.vtx" )
    resource.AddSingleFile( "models/weapons/w_pist_xiveseven.vvd" )
    resource.AddSingleFile( "models/weapons/w_pist_xiveseven.xbox.vtx" )
    resource.AddSingleFile( "materials/models/goldengun/1723b4b5233.vmt" )
    resource.AddSingleFile( "materials/models/goldengun/1723b4b5233.vtf" )
    resource.AddSingleFile( "materials/models/goldengun/723b4b52.vmt" )
    resource.AddSingleFile( "materials/models/goldengun/723b4b52.vtf" )
    resource.AddSingleFile( "materials/models/weapons/v_models/fiocchi/fiocchi-unwrap-r.vtf" )
    resource.AddSingleFile( "materials/models/weapons/v_models/fiocchi/fiocchi-unwrap.vmt" )
    resource.AddSingleFile( "materials/models/weapons/v_models/fiocchi/fiocchi-unwrap.vtf" )
    resource.AddSingleFile( "sound/weapons/goldengun/gg-shoot2.wav" )
    resource.AddSingleFile( "sound/weapons/goldengun/reload2.wav" )
    end
    
    if CLIENT then
       SWEP.PrintName = "Golden Gun"			
       SWEP.ViewModelFlip = false
       SWEP.Slot = 6
       SWEP.Icon = ""
       SWEP.EquipMenuData = {
       type = "item_weapon",
       desc = "The mighty golden gun"
    };
    end
     
    SWEP.VElements = {
    	["element_name"] = { type = "Model", model = "models/goldengun.mdl", bone = "Object03", rel = "", pos = Vector(15.454, 0.057, 0.521), angle = Angle(-1.065, -180, -90.282), size = Vector(0.834, 0.834, 0.834), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
    }
    SWEP.WElements = {
    	["element_name"] = { type = "Model", model = "models/goldengun.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(-12.855, 1.567, 0.054), angle = Angle(-3.962, 0, 173.091), size = Vector(0.935, 0.935, 0.935), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
    }
     
     
    SWEP.RunArmOffset 		= Vector (0, -4.919, -2.623)
    SWEP.RunArmAngle 			= Vector (33.852, 0, 0)
    SWEP.NextReloadTime = 0;
    SWEP.IronSightsPos = Vector(0, 0, 0)
    SWEP.IronSightsAng = Vector(0, 0, 0)
    SWEP.Category				= "Babel Industries"
    
    SWEP.Author = "Babel Ind. (model ripped by Asteroidrules)";
    SWEP.Contact = "Babel Industries";
    SWEP.Purpose = "";
    SWEP.Instructions = "If you've ever played Goldeneye 64's multiplayer into the morning hours with friends, you know what this does.";
    SWEP.IconLetter = "m"
    
    
    SWEP.Base = "weapon_tttbase"
    
    SWEP.Kind = WEAPON_EQUIP1
    SWEP.WeaponID = AMMO_STUN
    SWEP.CanBuy = {ROLE_DETECTIVE}
    SWEP.LimitedStock = true
    
    SWEP.HoldType = "pistol"
    SWEP.ViewModelFOV = 70
    SWEP.ViewModelFlip = true
    SWEP.ViewModel = "models/weapons/v_pist_xiveseven.mdl"
    SWEP.WorldModel = "models/weapons/w_pistol.mdl"
    SWEP.ShowViewModel = true
    SWEP.ShowWorldModel = false
    SWEP.ViewModelBoneMods = {
    	["R 09"] = { scale = Vector(1, 1, 1), pos = Vector(0.901, 0.603, -0.12), angle = Angle(0, 0, 0) },
    	["Object03"] = { scale = Vector(0.128, 0.128, 0.128), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) }
    }
    
    SWEP.IronSightsPos = Vector(4, 1.84, 1.519)
    SWEP.IronSightsAng = Vector(0.28, 1, 0.068)
    
    function SWEP:Reload()
    	if !( ( self.Weapon:Clip1() ) < ( self.Primary.ClipSize ) ) then return end
    	self.Weapon:DefaultReload( ACT_VM_RELOAD )
    	if self.NextReloadTime <= CurTime() then
    		self:EmitSound( "weapons/goldengun/reload2.wav" )
    		self.NextReloadTime = CurTime() + 2  -- Can only play sound once every 2 seconds.
    	end
    	
    	
    end
     local mysound = Sound("007_original.mp3")
    
    function SWEP:Deploy()
    if self.NextReloadTime <= CurTime() then
    		self:EmitSound("007_original.mp3", 100, 100)
    		self.NextReloadTime = CurTime() + 28  -- Can only play sound once every 2 seconds.
    	end
    
    
    	  
    
        self.Weapon:SendWeaponAnim( ACT_VM_DRAW )
    
    
    	return true;
    end
    
    
    
    
    SWEP.Spawnable			= true
    SWEP.AdminSpawnable		= false
    
    SWEP.Primary.Sound 		= Sound("weapons/goldengun/gg-shoot2.wav")  
    SWEP.Primary.Recoil		= .35
    SWEP.Primary.Damage		= 11
    SWEP.Primary.NumShots   = 7
    SWEP.Primary.Cone	    = 0
    SWEP.Primary.Delay 		= .1
    SWEP.Primary.Force      = 5000;
    
    SWEP.Primary.ClipSize		= 1				// Size of a clip
    SWEP.Primary.DefaultClip	= 6					// Default number of bullets in a clip
    SWEP.Primary.Automatic		= false				// Automatic/Semi Auto
    SWEP.Primary.Ammo			= "357"
    
    SWEP.Secondary.ClipSize		= -1					// Size of a clip
    SWEP.Secondary.DefaultClip	= -1					// Default number of bullets in a clip
    SWEP.Secondary.Automatic	= false				// Automatic/Semi Auto
    SWEP.Secondary.Ammo		= "none"
    
    
    
    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
    	
    		end
    		
    	end
    
    
    
    function SWEP:Holster()
    
    	--self:StopSound("007_original.mp3", 100, 100)
    	
    	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

  9. Post #9
    Roag15's Avatar
    July 2013
    178 Posts
    This isn't a problem with the lua, it's your perseption of what you thought the model looks like, that is the correct model. Try this. http://www.garrysmod.org/downloads/?a=view&id=113975
    Reply With Quote Edit / Delete Reply Mac United Kingdom Show Events Dumb Dumb x 2 (list)