[lua]
local hats = { }
local function CreateHat( ply, model )
SafeRemoveEntity( ply.Hat )
local hat
hat = ClientsideModel( model, RENDERGROUP_OPAQUE )
hat:SetNoDraw( true )
ply.Hat = hat
hat.Owner = ply
table.insert( hats, hat )
end
local function CleanHats( )
local k, v
for k, v in pairs( hats ) do
if not IsValid( v ) then
hats[ k ] = nil
elseif not IsValid( v.Owner ) then
SafeRemoveEntity( v )
hats[ k ] = nil
end
end
end
local function DrawHats( )
local k, v, pos, ang
CleanHats( )
for k, v in ipairs( player.GetAll( ) ) do
if not v:Alive( ) and IsValid( v.Hat ) then
SafeRemoveEntity( v.Hat )
v = v:GetRagdollEntity( )
end
if not IsValid( v.Hat ) then
CreateHat( v, "models/player/items/humans/top_hat.mdl" )
end
pos, ang = v:GetBonePosition( 6 )
v.Hat:SetPos( pos )
v.Hat:SetAngles( ang )
v.Hat:DrawModel( )
end
end
hook.Add( "PostDrawOpaqueRenderables", "Draw Hats.PostDrawOpaqueRenderables", DrawHats )
[/lua]
How do I change the angle, size and position of the entity/hat?
[QUOTE=Netheous;40941458][lua]Entity:SetScale(Integer)
Entity:SetAngle(Angle)
Entity:SetPos(Vector)[/lua][/QUOTE]
[url]http://i.imgur.com/z65NTgr.jpg[/url]
The hat is is in the wrong position how do I edit the rotation and pos? I've tried * but it just spins.
Never mind, figured it out now.
Fix:
[lua]
v.Hat:SetAngles( v:GetAngles() )
[/lua]
(About Sixth line from bottom)
And heres full working code with comments.
[lua]
// this is a table/array
local hats = { }
// function that is passed players(ply) and models
local function CreateHat( ply, model )
SafeRemoveEntity( ply.Hat ) // i assume this removes the hat before a new one can be drawn (dunno)
local hat // hat variable. starts blank
hat = ClientsideModel( model, RENDERGROUP_OPAQUE ) // [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7401.html[/url]
hat:SetNoDraw( true ) //http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexcf29.html
ply.Hat = hat // set the hat entity to your hat variable
hat.Owner = ply // set the hats owner to player
table.insert( hats, hat ) // insert the hat into the hats table
end
local function CleanHats( )
local k, v // key(k) and value(v)
for k, v in pairs( hats ) do // for each key(12345) and value(its name)
if not IsValid( v ) then // if not a valid hat
hats[ k ] = nil // set it to blank
elseif not IsValid( v.Owner ) then // otherwise
SafeRemoveEntity( v ) // remove the hat
hats[ k ] = nil // then set it to nil
end
end
end
local function DrawHats( )
local k, v, pos, ang, model // key, value, position, angle
CleanHats( ) // call the clean hats function
for k, v in ipairs( player.GetAll( ) ) do // for each player
if not v:Alive( ) and IsValid( v.Hat ) then // if the player is alive and there is a valid hat selected
SafeRemoveEntity( v.Hat ) // remove the hat
v = v:GetRagdollEntity( ) // [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1230.html[/url]
end
if not IsValid( v.Hat ) then // if there's a legit hat
CreateHat( v, "models/dav0r/hoverball.mdl" ) // create the hat
end
pos, ang, model = v:GetBonePosition( 6 ) // get the position and angle. [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index22b6.html[/url]
v.Hat:SetModelScale( 2, 0 )
v.Hat:SetPos( pos ) // set the hats position aka on players head
v.Hat:SetAngles( v:GetAngles() ) // set the angle of the hat
v.Hat:DrawModel( ) // create the hat
end
end
hook.Add( "PostDrawOpaqueRenderables", "Draw Hats.PostDrawOpaqueRenderables", DrawHats ) // [url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index7e79.html[/url]
[/lua]
Sorry, you need to Log In to post a reply to this thread.