Several Questions

Hi,

How can I detect which entity a player is looking at and perform commands on it?

Thanks,
jSherz

you would use traces

Example for you.

[lua]
function SWEP:PrimaryAttack()

local tr = self.Owner:GetEyeTrace()

if tr.Entity:IsValid() then

-- Prints the model in console
print(tr.Entity:GetModel())

end

end
[/lua]

Thanks!

EDIT: How would I apply it so it is always on (the script is always checking what you are looking at).

Here.
When you are pointing at a prop, then it shows the model.
(I hope, that this is what you mean by checking all the time)

[lua]
function Test()

local tr = LocalPlayer():GetEyeTrace() 

if tr.Entity:IsValid() then

	draw.SimpleText("" .. tr.Entity:GetModel(), "ScoreboardText", ScrW() / 2, ScrH() / 2, Color(255,255,255,255), TEXT_ALIGN_CENTER)
	
end

end
hook.Add(“HUDPaint”, “Test”, Test)
[/lua]

Thank you!