Skip to content

Commit

Permalink
Completely move skins painting code into draw hooks
Browse files Browse the repository at this point in the history
And let's hope it completely fixes skins not painting
  • Loading branch information
xDShot committed Dec 31, 2016
1 parent 7efbc61 commit 2f71dcc
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lua/weapons/csgo_baseknife.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ end


function SWEP:Initialize()
self:SetSkin( self.SkinIndex or 0 ) -- Sets worldmodel skin
self:SetHoldType( self.AreDaggers and "fist" or "knife" ) -- Avoid using SetWeaponHoldType! Otherwise the players could hold it wrong!
end

Expand All @@ -128,25 +127,45 @@ end
-- PaintMaterial
function SWEP:DrawWorldModel()
if self.PaintMaterial then
self:SetMaterial( self.PaintMaterial or "" )
self:SetMaterial( self.PaintMaterial or nil )
else
self:SetSkin( self.SkinIndex or self:GetSkin() or 0 )
end
self:DrawModel()
end



local function FuncPaintMaterial( vm, ply, weapon )
if not ( IsValid( vm ) and IsValid( weapon ) ) then return end

vm:SetMaterial( weapon.PaintMaterial or "" )
if not ( IsValid( vm ) and IsValid( weapon ) ) then
-- print( "HookPaintMaterial FAIL" )
return
end

-- print( "HookPaintMaterial", "vm", vm, vm:GetModel(), "\n",
-- "ply", ply, ply:GetModel(), "\n",
-- "weapon", weapon, weapon:GetModel(), "\n",
-- "weapon.PaintMaterial", weapon.PaintMaterial, "\n",
-- "weapon.SkinIndex", weapon.SkinIndex )

if weapon.PaintMaterial then
vm:SetMaterial( weapon.PaintMaterial or nil )
vm:SetSkin( 0 )
elseif weapon.SkinIndex then
vm:SetMaterial( nil )
vm:SetSkin( weapon.SkinIndex or vm:GetSkin() or 0 )
else
vm:SetMaterial( vm:GetMaterial() or nil )
vm:SetSkin( vm:GetSkin() or 0 )
end
end

hook.Add( "PreDrawViewModel", "HookPaintMaterial", FuncPaintMaterial )



function SWEP:Think()
self.ViewModelFlip = cvars.Bool("cl_csgo_knives_lefthanded", false)
self.Owner:GetViewModel():SetSkin( self.SkinIndex or 0 )
if CurTime()>=self:GetIdleTime() then
self.Weapon:SendWeaponAnim( ACT_VM_IDLE )
self:SetIdleTime( CurTime() + self.Owner:GetViewModel():SequenceDuration() )
Expand Down

0 comments on commit 2f71dcc

Please sign in to comment.