lua code hats for deathrun

who can lua code hats for me for in a deathrun server?

This is not a request section

Try the request section this section is for people who actually try and do it not ask others to do it for them

Although this was shot down, could you guys explain anyways? I Would like to know how. My first guess is that it’s just vectors? Do you spawn it as a prop through lua then make it go to a certain vector?

You attach it to the bone named “head” and then offset it with a vector, and parent it to the Player.

Makes sense, also how do you go a bout spawning it? Or is it kind of like E2 where you use “holograms” essentially?

ents.Create

Make an entity for it called “hat” or something.

“holograms” pretty much.
**[G.ClientsideModel

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=G.ClientsideModel)**

Or you can just use ENT:Draw().

Why register a new entity class just for a hat?:confused:

[editline]18th October 2010[/editline]

You could draw every hat on the server using 1 ClientsideModel.

Because it’s easier I guess.

You can do different things in the ENT:Draw() function that make it appear differently depending on settings, you could scale it, or not draw it while you’re in a vehicle, or when you’re dead make it not render.

All while doing it clientside.

And what’s stopping you from doing the same with ClientsideModel?

Well I guess you could hook it to think, I just think an entity is easier. You can also control it serverside too, and just draw it clientside.

Meh, I just think that anything that is just a model without physics should use ClientsideModel.
But I guess it could be a SENT if there’s gonna be particles or glow or some shit coming from the hat.

[lua]
local Hats = {}

Hats[“models/myhat.mdl”] = ClientsideModel(“models/myhat.mdl”)
Hats[“models/anotherhat.mdl”] = ClientsideModel(“models/anotherhat.mdl”)

for _, hat in pairs(Hats) do
hat:SetNoDraw(true)
end

hook.Add(“PostPlayerDraw”, “”, function(ply)
if ply._Hat then
local _Hat = Hats[ply._Hat.Model]
_Hat:SetPos(ply:GetPos()) – and of course offsets
_Hat:SetColor(ply._Hat.Color) – do all sorts…
_Hat:DrawModel()
end
end)
[/lua]

As Ralle said, that’s a much more effective method, you can still do particles if needed.

Actually you only need one (you can change the model right before drawing)

Even better :L

Will this code also make the hat draw for other players? (expecting dumb ratings)

Of course, PostPlayerDraw loops through all players individually.

This is pseudo-code so don’t expect it to work, is just a theory :L

Using 1 ClientsideModel:

[lua]
_PlayerHat = ClientsideModel(“models/error.mdl”)
_PlayerHat:SetNoDraw(true)

hook.Add(“PostPlayerDraw”, “”, function(ply)
if ply._Hat then
local _Hat = _PlayerHat
_Hat:SetModel(ply.__Hat.Model)
_Hat:SetPos(ply:GetPos()) – and of course offsets
_Hat:SetColor(ply._Hat.Color) – do all sorts…
_Hat:DrawModel()
end
end)
[/lua]

I’m having problem with this:

[lua]
if SERVER then

AddCSLuaFile(“autorun/hats.lua”)

else

_PlayerHat = ClientsideModel(“models/props_2fort/metalbucket001.mdl”)
_PlayerHat:SetNoDraw(true)

hook.Add(“PostPlayerDraw”, “hatsss”, function(ply)
local Bone = ply:LookupBone(“ValveBiped.Bip01_Head1”)
local BonePos , BoneAng = ply:GetBonePosition( Bone )
local _Hat = _PlayerHat
_Hat:SetModel(“models/props_2fort/metalbucket001.mdl”)
_Hat:SetPos(BonePos + Vector(0, 0, 10))
_Hat:SetAngles(ply:EyeAngles() + Angle(0, 0, 180))
_Hat:SetColor(255, 255, 255, 255)
_Hat:DrawModel()
end)

end
[/lua]

The bucket angles are strange and it won’t draw for every player (I can only see one at time)