Hello,
Im new to Lua Development and i currently work on a little thing that makes a Icon appear when a Player looks at a Door
hitFuncs = {
["func_button"] = true,
["func_door"] = true,
["func_door_rotating"] = true,
["prop_door_rotating"] = true,
}
hook.Add( "HUDPaint", "handIconOnDoor", function()
if IsValid( LocalPlayer():GetEyeTrace().Entity ) and hitFuncs[LocalPlayer():GetEyeTrace().Entity:GetClass()] then
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( Material("scp/handsymbol.png"))
surface.DrawTexturedRect( ScrW()/2-32, ScrH()/2-32, 64, 64 )
end end )
Now i have run into the Issue that the Icon renders at any Distance and that is bad can anyone help me set it so it only draws for example at a distance of 200
This should work, alternatively try to swap tr.HitPos and EyePos(), i always forget which one should come first so you don't get a negative result from Vector:Length()
hitFuncs = {
["func_button"] = true,
["func_door"] = true,
["func_door_rotating"] = true,
["prop_door_rotating"] = true,
}
hook.Add( "HUDPaint", "handIconOnDoor", function()
local tr = LocalPlayer():GetEyeTrace()
if IsValid( tr ) and hitFuncs[ tr.Entity:GetClass() ] and ((tr.HitPos - EyePos()):Length()) < 200 then
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial( Material("scp/handsymbol.png") )
surface.DrawTexturedRect( ScrW()/2-32, ScrH()/2-32, 64, 64 )
end
end)
Not sure what happend but with your Code the Icon wont appear at all
You're running IsValid on the trace result itself, this is always going to return false. You need to check it on the entity hit.
oops, i should have probably just tested the script ingame, i ment to type "tr.Entity" there probably - i'll fix it, thanks!
Can you send me the "fixed" Code?
you donut
Sorry, you need to Log In to post a reply to this thread.