[Client] A specified map position on screen

Started by Sebastian, Feb 26, 2017, 07:43 PM

Previous topic - Next topic

Sebastian

Is there any way to detect if a player has a specified position in his view ?

I've created a GUI Label on map position, like in this video:

https://www.youtube.com/watch?v=p_vkR7oH7g8#

But it comes with an adverse effect.
This means the text will appear even when not looking at that position, in some cases.

To avoid that, I need to know when the player is looking at it or not ... to hide the label or not.

Maybe extracting player.Angle from Server to Client would do the job, but how can that be done ?
I just started to script in client-side ... so I don't really know much.

DizzasTeR

The only other way I can think of is making that label 3d because you don't have any angle function or other something. The problem is 3d entity is a bit messed up and doesn't work with labels.

vito

Well I've faced with this problem few months ago, I even created player.Angle in client side (without any data from server) with tons of dirty tricks xD
But you don't need it.

Actually this thing is inbuild here already... just not documented by vc-mp devs.
GUI.WorldPosToScreen will return Vector. X and Y for your screen and Z is for thing you needed.
If Z is < 1 - that position is on your screen, if Z above 1 - it hidden, so you need to hide that label...
I've created custom player's nametags to make them looks same as nametags of npc and I used this code there:
local tag_pos = GUI.WorldPosToScreen(Vector(plr_pos.X, plr_pos.Y, (plr_pos.Z + 1.5)));
if(tag_pos.Z < 1){
//...
::nametags[i].Position = VectorScreen((tag_pos.X - 250), (tag_pos.Y - 25));
::nametagsh[i].Position = VectorScreen((tag_pos.X - 250), (tag_pos.Y - 10));
} else {
::nametags[i].Position = VectorScreen(0,-50);
::nametagsh[i].Position = VectorScreen(0,-50);
}
}
It also useful to put text above pickup and so on. But to be clear... Native tags looks better due some reasons.

Sebastian

Awesome job @vito ! It works just perfect !
Thank you very much ! :D

DizzasTeR