How to know if player is not looking throught his eyes?

I dont know how to describe it other wise. For example… Being in a third person. So far i used something like


if PLAYER:GetViewEntity():GetClass() == "gmod_cameraprop"
or PLAYER:GetViewEntity():GetClass() == "ent1".. or ent2.. or ent3 and so on.

But its not exactly a perfect solution… So any way to know if a player has left his models view site? – I really suck at describing.

I think this should work
[lua]if PLAYER:GetViewEntity() ~= PLAYER then --[[ Third person ]] end[/lua]

Well that makes it compatible with every other view entity. But when you switch to third person (or crouch in a car) it doesn’t exactly create a new entity. You’re just not looking through your eyepos. So third person problem still remain.

This is a hacky way, and I don’t recommend using this, but it should work.

[lua]local function _R.Player:IsFirstPerson()
local view = gamemode.Call( “CalcView”, self, self:GetShootPos(), self:GetAimVector():Angle(), self:GetFOV() )

return self:GetViewEntity() == self and view.origin == self:GetShootPos()

end[/lua]

On clientside, you can do that for the local player using LocalPlayer():ShouldDrawLocalPlayer(). Returns true if you can see yourself, false if you are in first person.

I really don’t see why you would need this otherwise. Especially serverside.

The reason basically is im attaching entities to players and i dont want them to see the entities attached to them, to not interfere.


local eyepos = EyePos()  
local eyepos2 = ply:EyePos() 
		
if  eyepos:Distance(eyepos2) > 5 or LocalPlayer() != ent:GetOwner() then 
      self.Entity:DrawModel()
end

That should work, just adjust the distance to whatever you need it, right above. Adjust to fit your code.

Hm ill test it

Yeah, Doesn’t seem to work. Damn Automerge…

Or just usermessage the index of the entity and make it invisible on the client…

How exactly would that solve my problem?.. I can already make it invisible on client. With your idea i’d still have the same problem.

So what more do you need…

If they are scripted entities, you can use SetOwner serverside to mark the entity as belonging to the player it is attached to, and then do this clientside:

[lua]function ENT:Draw()
if self:GetOwner() ~= LocalPlayer() or LocalPlayer():ShouldDrawLocalPlayer() then
self:DrawModel()
end
end[/lua]

[editline]11:38AM[/editline]

self.Entity is deprecated and this is an awful way to do it anyway.

Thanks, just what i needed :slight_smile: