Hide enemy team in render.RenderView

I implemented something similar to the radar in the example on: http://wiki.garrysmod.com/?title=Render.RenderView. The only problem is that it shows the enemy team which isn’t good for a multi-team gamemode. In the CamData I can hide myself but there is no way to hide the enemy team that I saw. Does anyone have any ideas on this or possibly a different way to approach this other than using RenderView.

Set nodraw on the other team players, draw it, then set it back to draw perhaps?

returning false in PrePlayerDraw should do.

Would that hide the player altogether? They need to still be visible in the game just not in the radar.

The only issue would be that you would have to hide them in the game as it basically just draws what you would see.

That’s kinda what I assumed but I didnt know if CamData had something as I can hide the view model but there isn’t an option for enemy players. I kind of figured that if the view model can be hidden in the cam only then there might be a way to hide certain players as well.

I actually thought of a pretty brilliant solution to this. You could no-draw them when they are not on your screen at all (Which would make them invisible on your RenderView) Then when they are on your screen, you draw them again. There’d be no point in drawing them if they aren’t on your screen anyways so it shouldn’t be an issue.

Ah good idea! Now the only problem is checking to see if the entity is on the screen. If this was serverside I could use entity.visible but it isn’t so I guess a trace is my only option? Seems like it could be pretty inefficient to do a trace on multiple players every tick. The reder camdata is already inefficient and lags players with lower end computers.

No, you could do ply:GetPos():ToScreen().visible

ah I was actually thinking about using toScreen but I knew that ignores walls and such, didnt know there was a .visible! That is awesome, I’ll have to try it out when I get a chance. Thanks

My traces werent working for some reason anyways so prob best that there is something else

Glad I could help.

No, toscreen is a bad idea.

You have to set a certain variable to true when in render.RenderView and set it back once done, you check this variable in the PrePlayerDraw hook.

What variable are you talking about?

I think he just means a global variable. So something like this I assume.

[lua]

local shouldDrawPlayers = true
function Radar()
shouldDrawPlayers = true
render.RenderView( CamData )
shouldDrawPlayers = false
end

function HideNonVisPlayers(ply)
return shouldDrawPlayers
end
hook.Add(“PrePlayerDraw”, “PrePlayerDraw”, HideNonVisPlayers)
[/lua]

Oh also I have been told mixed things about prePlayerDraw. In this thread I’ve been told to return false to not draw players but on the wiki it says return true.

EDIT: setting false draws the player. Also Wizard, you solution will nodraw players on the radar but what I want to do is see if their visible or not and that is what blasphemy’s solution does. What is so bad about ToScreen()

EDIT EDIT:
[lua]
if ply:GetPos():ToScreen().visible then
return false
else
return true–showPlayers
end
[/lua]
Doesn’t work. Shows all players regardless of visibility or not which means that the ply:GetPos… bit is always returning true

EDIT ^3: Actually I see what you’re saying Wizard. You solution works for the question I posted and the solution we were trying to do with the visibility is just a workaround, but now that I visibility was brought into play, it’d be nice to draw enemy team on the radar if I can see them. Also is there any good way to hide the shadow as that is still visible even if the player isnt. Entity.DrawShadow doesn;t work on players. I guess I could change the player alpha for the rederview?

Actually, I was thinking something along the lines of:

[lua]

for k,v in pairs(player.GetAll()) do

local visible = v:GetPos():ToScreen().visible

if( visible ) then
	
	v:SetNoDraw(false)
	
else

	v:SetNoDraw(true)
	
end

end

[/lua]

Yes that is essentially what I did. The for loop isn’t needed as the prePlayerDraw fires for each player already so just seeing if they are visible should work. Or are you saying to throw out the prePlayerDraw altogether?
And does the SetNoDraw remove the shadow as well?
I’ll test this out later as I have class now.

I’m not necessarily saying you should do anything in particular, but when I did it, I just put the for loop in the hook that draws the screen.

The nodraw didn’t work for me because when I tried to reshow them then they never showed up. The became invisible correctly but I dont know why they stayed invisible. I ended up doing something else.

[lua]
if dontShowPlayers then
ply:SetModelScale(Vector(0))
else
ply:SetModelScale(Vector(1,1,1))
end
[/lua]

Hid the shadow and hid the player although it doesnt any effects which nodraw would do if I could figure out how to get it working properly. Also all the weapons seem to move to the players feet

Want to send me a steam message/PM me your steam URL? I can help you more there.