GetEyeTrace help


			function btn16.DoClick()
				if eye.Entity:IsPlayer() then
					ply:ConCommand("ulx freeze "..eye.Entity:Nick())
				else
					print("error")
				end
			end

im trying to freeze player when i look at player and press button but it always returns error

any ideas?

thanks

Does it print “error” or does it actually make a Lua error?

What is eye?

print error
eye = LocalPlayer():GetEyeTrace()

i think the proplem is that it only loads it when menu is oppened so i tried fixing it with think hook lets see what happens

Try this:
[lua] function btn16.DoClick()
local trace = LocalPlayer():GetEyeTrace()
if IsValid(trace.Entity) and trace.Entity:IsPlayer() then
ply:ConCommand("ulx freeze "…eye.Entity:Nick())
else
print(“error”)
end
end[/lua]

This is different in 2 ways:

  1. It gets the trace THE MOMENT THE BUTTON WAS CLICKED. What yours does is get the trace some time before, I’m not sure exactly when since you didn’t post that part of the code.
  2. It also makes sure that the entity is valid before checking if it’s a player - this is important, as it can cause some unexpected Lua errors later on.

Thanks!