• How do I hide entities from player vision?
    4 replies, posted
Say there's two players, each belong to Team A and Team B. There is a prop_physics entity in front of both players. Player of Team A can see it but Player of Team B cannot see it. How do I do this?
[IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/ENTITY/Draw"]ENTITY/Draw[/URL] [IMG]http://wiki.garrysmod.com/favicon.ico[/IMG] [URL="http://wiki.garrysmod.com/page/GM/ShouldCollide"]GM/ShouldCollide[/URL] You might aswell block the collision. Define a team in the entity is the easiest way, then it is just checking and returning booleans! In the Entity:Draw() (Which is clientside) [CODE] function ENT:Draw() if LocalPlayer():Team() == self.Team then self:DrawModel() end end [/CODE] And a hook somewhere (which is serverside) [CODE] hook.Add("ShoudCollide", "TeamEntityCollsion", function(player, entity) if isentity(player) and isentity(entity) and player:IsPlayer() then if player:Team() != entity.Team then return false end end return true end) [/CODE] Fiddle around a bit: [URL]http://darrell.nl/lualexer/11uo6[/URL]
You can do something with the PVS .. however have in mind that the entity that is blocked are useless on the client. [url]http://wiki.garrysmod.com/page/Controlling_Entity_Transmission[/url]
[QUOTE=Nak;48087387]You can do something with the PVS .. however have in mind that the entity that is blocked are useless on the client. [url]http://wiki.garrysmod.com/page/Controlling_Entity_Transmission[/url][/QUOTE] This has worked very well, thank you for directing me here. Here is my code by the way, just wanna make sure if I'm doing things right.: [lua] hook.Add("PlayerSpawn", "GhostSpawn", function( ply ) if ply:Team() == TEAM_GHOST then local grey = Color( 100, 100, 100, 0 ) ply:SetRenderMode(RENDERMODE_TRANSALPHA) ply:SetColor(grey) for _,v in pairs(ENTIG) do print("Hello") if IsValid(v) then v:SetPreventTransmit(ply, true) end end -- Not working, will get back to it eventually timer.Simple( 1, function() if (IsValid(ply) and ply:Alive() and pos) then ply:SetMoveType( MOVETYPE_NOCLIP ) end end) timer.Simple( 4, function() if (IsValid(ply) and ply:Alive() and pos) then ply:SetMoveType( MOVETYPE_WALK ) end end) elseif ply:Team() ~= TEAM_GHOST then ply:SetRenderMode(RENDERMODE_NORMAL) ply:SetColor(Color( 255, 255, 255, 255) ) ply:SetCustomCollisionCheck(false) for _,v in pairs(ENTIG) do if IsValid(v) then v:SetPreventTransmit(ply, false) end end end end) hook.Add("PostCleanupMap", "GhostHideFromView", function() for _,v in pairs(GHOST.AvoidEntities) do for _,v2 in pairs(ents.FindByClass( v )) do table.insert(ENTIG, v2) end end end) [/lua]
[QUOTE=dankiller94;48090847]This has worked very well, thank you for directing me here. Here is my code by the way, just wanna make sure if I'm doing things right.: /lua[/QUOTE] Should be fine. I haven't played much with the PVS as it couldn't block the players like I wanted to. Play around with it and smooth the corners. Just remember that you have to re-enable PVS, if you want the entity to draw, render or make the client react to it.
Sorry, you need to Log In to post a reply to this thread.