How to remove crosshair while looking at an entity, then re enabling afterwards.
6 replies, posted
How would I make it so if I'm looking at an entity it removes the crosshair, then when I look away it re-enables it? I'm editing inside of a clientside file, I know about CrosshairDisable() but it's serverside only. How would I do it in clientside? I gave it a try, when they look away though, it does not re-enable it.
Example Code:
[lua]isLooking = false
hook.Add("HUDShouldDraw", "HideThings", function( name )
if name == "CHudCrosshair" and isLooking == true then
return false
end
end)
hook.Add("HUDPaint", "ExampleRemoveCrosshair", function()
if not IsValid(LocalPlayer()) then return end
local eye = LocalPlayer():GetEyeTrace()
if not IsValid(eye.Entity) then return end
if LocalPlayer():EyePos():Distance(eye.HitPos) <= 150 then
isLooking = true
draw.SimpleTextOutlined("You're looking at something", "Default", ScrW() / 2, ScrH() / 2 + 40, Color(39,186,17), 1, 1, .7, Color(0,0,0,255))
end
end)[/lua]
:snip: snippity snoppity snoop
It doesn't reenable it because you never set isLooking to false anywhere in your code.
You also should localize your isLooking variable.
[QUOTE=Robotboy655;50687409]It doesn't reenable it because you never set isLooking to false anywhere in your code.
You also should localize your isLooking variable.[/QUOTE]
How would I set it to false when the player looks away?
isLooking = false, obviously.
If you can't figure out where to copy paste it, the lazy solution would be either on the very first like of HUDPaint or on the very last line on HUDShouldDraw hook.
[QUOTE=Robotboy655;50687785]isLooking = false, obviously.
If you can't figure out where to copy paste it, the lazy solution would be either on the very first like of HUDPaint or on the very last line on HUDShouldDraw hook.[/QUOTE]
Sorry, I'm tired, I should be more specific, how would I check if the player looks away from the entity, should have specified it more clearly.
Go get some sleep and comeback tomorrow and realize how inappropriate your question is.
You already have detection of when a player looks at something, all you have to do is set the variable to false when you are not setting it to true. Just logically think the problem.
Sorry, you need to Log In to post a reply to this thread.