• Hats System
    4 replies, posted
Hello im making a hat system for my gamemode and I'm stuck the hat in this case Santa hat is allays on the left of the head and i cannot get it to go to the top of the head Screenshot: [IMG]http://cloud-4.steamusercontent.com/ugc/45375528347392907/7E9EDFCE923CD97F319FBF08B99D155E68237F2A/1024x576.resizedimage[/IMG] [LUA] local hats = { } local function CreateHat( pl, model ) SafeRemoveEntity( pl.Hat ) local hat hat = ClientsideModel( model, RENDERGROUP_OPAQUE ) hat:SetNoDraw( true ) pl.Hat = hat hat.Owner = pl table.insert( hats, hat ) end local function CleanHats( ) local k, v for k, v in pairs( hats ) do if not ValidEntity( v ) then hats[ k ] = nil elseif not ValidEntity( 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 v == nil then continue end if v == LocalPlayer() then continue end if not v:Alive( ) and ValidEntity( v.Hat ) then SafeRemoveEntity( v.Hat ) v = v:GetRagdollEntity( ) end if not ValidEntity( v.Hat ) then CreateHat( v, table.Random(EMSRP.hats).model ) end pos, ang = v:GetBonePosition( 6 ) v.Hat:SetPos( pos ) v.Hat:SetAngles( ang ) v.Hat:FollowBone( v, 6 ) v.Hat:DrawModel( ) end end hook.Add( "PostDrawOpaqueRenderables", "Draw Hats.PostDrawOpaqueRenderables", DrawHats ) [/LUA] I take no credit for this code i just edited [URL="http://facepunch.com/showthread.php?t=940319&p=22060923&viewfull=1#post22060923"]this[/URL].
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Angle/RotateAroundAxis]Angle:RotateAroundAxis[/url]
[QUOTE=Tomelyr;47475224][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Angle/RotateAroundAxis]Angle:RotateAroundAxis[/url][/QUOTE] I tried doing [LUA] v.Hat:SetAngles( ang:RotateAroundAxis( ang:Up(), 90 ) ) [/LUA] but it just creates an error sorry never used that func before and im not great at lua Error: [CODE] Error in hook PostDrawOpaqueRenderables: gamemodes/emsrp/gamemode/modules/hats/cl_hats.lua:49: bad argument #1 to 'SetAngles' (Angle expected, got no value) stack traceback: [C]: in function 'SetAngles' gamemodes/emsrp/gamemode/modules/hats/cl_hats.lua:49: in function 'fn' addons/ulib/lua/ulib/shared/hook.lua:179: in function <addons/ulib/lua/ulib/shared/hook.lua:162> [C]: in function '•&#8236;•&#8300;•&#8206;&#8303;&#8302;&#8301;' [ERROR] 1. unknown - [C]:-1 [/CODE]
ang:RotateAroundAxis( ang:Up(), 90 ) v.Hat:SetAngles( ang )
Thanks that worked [editline]7th April 2015[/editline] Randomly i get this error [CODE] Error in hook PostDrawOpaqueRenderables: gamemodes/emsrp/gamemode/modules/hats/cl_hats.lua:42: attempt to index local 'v' (a nil value) stack traceback: gamemodes/emsrp/gamemode/modules/hats/cl_hats.lua:42: in function 'fn' addons/ulib/lua/ulib/shared/hook.lua:179: in function <addons/ulib/lua/ulib/shared/hook.lua:162> [C]: in function '•&#8236;•&#8300;•&#8206;&#8303;&#8302;&#8301;' [ERROR] 1. unknown - [C]:-1 [/CODE] and also the hats occasionally spaz out and glitch in front/behind the player models (ill get a screenshot hopefully)
Sorry, you need to Log In to post a reply to this thread.