Targeted entity is visible. ToScreen returns integers out of bounds

I am working on an entity system in which I want to draw in information box around a specific entity once that is targeted. The code worked well, and suddenly broke. I must’ve done something wrong, but here’s the thing:

I am checking if the class of the targeted entity is the class of my own entity. If that is true, I convert the world location to the screen locaton. Here’s the deal though: The pixels go in the millions and it says that it’s not visible even though I am facing it.


	local ent = LocalPlayer():GetEyeTrace().Entity
	if( ent != nil ) then
		if( ent:GetClass() == "ground_item" ) then
			local groundpos = ent:GetPos():ToScreen()
			gix, giy = groundpos.x, groundpos.y
			print( gix, giy, groundpos.visible )

The console prints:
67962228736 -29445689344 false
67962228736 -29445689344 false
67962228736 -29445689344 false
67962228736 -29445689344 false
67962228736 -29445689344 false
67962228736 -29445689344 false
67962228736 -29445689344 false
67962228736 -29445689344 false
all the time

Thank you very much in advance.

Could be that ent is actually worldspawn (the map).
When checking if and entity is valid use IsValid(ent) not ent != nil because ent could be different than nil but could be a deleted entity and that would cause errors if you ever tried to use it’s methods (GetPos(), GetAngles(), etc).

-ninjad-

It would not declare why it would pass the if( ent:GetClass() == “ground_item”) then though. Also, moving the prop does move the location of the coördinates debugged.

[editline]3rd May 2015[/editline]

Changed the code to:


	local ent = LocalPlayer():GetEyeTrace().Entity
	if( IsValid( ent ) ) then
		if( ent:GetClass() == "ground_item" ) then
			local groundpos = ent:GetPos():ToScreen()
			gix, giy = groundpos.x, groundpos.y
			print( gix, giy, groundpos.visible )

Still the same, weird output:
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false
33879687168 -42977329152 false

Try to get the entity using something other than GetEyeTrace() (ents.GetByIndex()) so that you can move around and see where the text is actually printed on your screen (if you are even printing text).

I am not exactly sure what you are trying to say. I have just tried the same script on a different map and on different entities without all the checks, seems like the whole method is bugged to me.

If you did try using different entities/models then forget about what I said, I thought it could have been caused by a broken model with bad origins.

Restarting Garry’s Mod. After about one hour of searching on the internet I just found the cause:
http://forum.facepunch.com/showthread.php?t=1306031
In other words. Sometimes the Vector:ToScreen() gets bugged which requires the user to restart GMod.
Thank you for all your support, especially yours, _FR_Starfox64