zombiesurvival-evolved/gamemodes/zombiesurvival/entities/entities/zs_hands.lua
2014-11-10 00:26:49 -05:00

70 lines
1.4 KiB
Lua

AddCSLuaFile()
ENT.Type = "anim"
ENT.RenderGroup = RENDERGROUP_OTHER
function ENT:Initialize()
hook.Add( "OnViewModelChanged", self, self.ViewModelChanged )
self:SetNotSolid( true )
self:DrawShadow( false )
self:SetTransmitWithParent( true ) -- Transmit only when the viewmodel does!
end
function ENT:DoSetup( ply )
-- Set these hands to the player
ply:SetHands( self )
self:SetOwner( ply )
-- Which hands should we use?
local info = GAMEMODE:GetHandsModel( ply )
if ( info ) then
self:SetModel( info.model )
self:SetSkin( info.skin )
self:SetBodyGroups( info.body )
end
-- Attach them to the viewmodel
local vm = ply:GetViewModel( 0 )
self:AttachToViewmodel( vm )
vm:DeleteOnRemove( self )
ply:DeleteOnRemove( self )
end
local defaultcolor = Vector( 62.0/255.0, 88.0/255.0, 106.0/255.0 )
function ENT:GetPlayerColor()
local owner = self:GetOwner()
if owner and owner:IsValid() and owner.GetPlayerColor then
return owner:GetPlayerColor()
end
return defaultcolor
end
function ENT:ViewModelChanged( vm, old, new )
if not IsValid(self) then return end
-- Ignore other peoples viewmodel changes!
if ( vm:GetOwner() != self:GetOwner() ) then return end
self:AttachToViewmodel( vm )
end
function ENT:AttachToViewmodel( vm )
self:AddEffects( EF_BONEMERGE )
self:SetParent( vm )
self:SetMoveType( MOVETYPE_NONE )
self:SetPos( Vector( 0, 0, 0 ) )
self:SetAngles( Angle( 0, 0, 0 ) )
end