So I am trying to add hats to my shop that someone made, and I cant figure out how he did it, i know how to code models,trails,and weapons, but for some reason hats dont work so if someone could help me that would be great, and it wouldnt take very long i just need to know how to code one line of it
You need to attatch the "Prop" (Hat in your case) to a bone on the player. I've never done it before, but I am pretty sure it's done with
[B][URL="http://wiki.garrysmod.com/?title=Entity.SetParent"]Entity.SetParent[IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [/URL][/B]
Well. It ccould be
[b][url=http://wiki.garrysmod.com/?title=Entity.SetAttachment]Entity.SetAttachment [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
as well.
Attach hats to the eyes and modify the cords. That's what i did
[QUOTE=gameguysz;32193094]Attach hats to the eyes and modify the cords. That's what i did[/QUOTE]
- how?
[QUOTE=Busymonkey;32218370]- how?[/QUOTE]
[lua]local attachment = player:LookupAttachment("eyes")[/lua]
then basically set the position to the attachment position and the attachment angle, you might have to add or take away from the position depending on the size or where you want the model to be position to the player
I was having a similar problem, I solved it with that but the prop appears in the player's view, obstructing it.
Anyone know a fix?
[QUOTE=Ylsid;32220542]I was having a similar problem, I solved it with that but the prop appears in the player's view, obstructing it.
Anyone know a fix?[/QUOTE]
Are you displaying only the world model?
[U]Serverside:[/U]
[lua]
function SendHat(p)
if !ValidEntity(p) or !p.hat or !ValidEntity(p.hat) then return end
umsg.Start("get_hat",p)
umsg.Entity(p.hat)
umsg.End()
end
[/lua]
[U]Clientside:[/U]
[lua]
usermessage.Hook("get_hat", function (um)
local hat = um:ReadEntity()
function hat:Draw()
//Don't draw anything
end
end)
[/lua]
When you assign a player a hat, index the hat into the player and call the SendHat function. This will make the person wearing it not see it.
[lua]
...
Player.hat = hat
SendHat(Player)
...
[/lua]
It would probably be better to just network the position of a ClientSideModel.
Make a clientside model and set it to rotate the angle about ValveBiped.Bip01_Head1 using the Angle.RotateAroundAxis method.
[QUOTE=zzaacckk;32266162]Make a clientside model and set it to rotate the angle about ValveBiped.Bip01_Head1 using the Angle.RotateAroundAxis method.[/QUOTE]
You still have to network what the hat's model, material, size, and all that other bull shit as well.
Serverside entities already do this. Just spawn a hat serverside and make it not draw on the 1 player that doesn't want to see it. You people are turning this into a networking nightmare.
[QUOTE=Gryphian;32270894]You still have to network what the hat's model, material, size, and all that other bull shit as well.
Serverside entities already do this. Just spawn a hat serverside and make it not draw on the 1 player that doesn't want to see it. You people are turning this into a networking nightmare.[/QUOTE]
You usermessage the players the model and material then ..
[quote]Make a clientside model and set it to rotate the angle about ValveBiped.Bip01_Head1 using the Angle.RotateAroundAxis method.[/quote]
Doing it on the server wouldn't be suggested.
[QUOTE=zzaacckk;32266162]Make a clientside model and set it to rotate the angle about ValveBiped.Bip01_Head1 using the Angle.RotateAroundAxis method.[/QUOTE]
Then don't do it on server. Place it in positions with the correct offset, then angle it properly, then just parent it. Send the owner of the hat the usermsg(only 1, and only to 1 player mind you) that makes the owner not draw it. Made a proof of concept in E2. Works perfect
*Updated clientside to draw the hat if the player is looking at themself.
[U]Serverside:[/U]
[lua]
function SendHat(p)
if !ValidEntity(p) or !p.hat or !ValidEntity(p.hat) then return end
umsg.Start("get_hat",p)
umsg.Entity(p.hat)
umsg.End()
end
[/lua]
[U]Clientside:[/U]
[lua]
usermessage.Hook("get_hat", function (um)
local hat = um:ReadEntity()
function hat:Draw()
if LocalPlayer():ShouldDrawLocalPlayer() then
self:DrawModel()
end
end
end)
[/lua]
Sorry, you need to Log In to post a reply to this thread.