Serverside entity visibility at client

Dear All,
I am trying to create an entity that is server sided, yet it is only visible to one random client upon creation. I would like to have assistance with it since I am failing at this task.
Thank you very much in advance!

What kind of entity is this??? You know you can block the draw on serverside and clientside too.

Entity:SetPreventTransmit

Server:
[lua]
local ent = ents.Create(“sent_ball”)
ent:Spawn()

local pls = player.GetAll()
local randPlayer = pls[math.random(#pls)]

for i, pl in pairs(pls) do
if pl ~= randPlayer then
ent:SetPreventTransmit(pl, true)
end
end
[/lua]

This completely stops networking to those players though, so if they bump into said entity, it will feel jittery.

Thank you very much for your assistance, I will try your solution. My issue was that I had no clue how to handle nodraw on client side. Thankfully the entity is passable, so no bumping or jittering will happen. Thank you again!

[editline]26th January 2017[/editline]

I tried to do:


if CLIENT then self:SetNoDraw(true) end

in shared.lua but to no avail.

The ent:SetPreventTransmit(pl, true) code did not work sadly. I put it after spawning the entity into init.lua.

In that case try this:

Put this in a server only lua file outside a function:
[lua]util.AddNetworkString(“ent.hide”)[/lua]

Spawn entity like this:
[lua]local ent = ents.Create(“sent_ball”)
ent:Spawn()

local pls = player.GetAll()
local randPlayer = pls[math.random(#pls)]

net.Start(“ent.hide”)
net.WriteEntity(ent)
net.SendOmit(randPlayer)[/lua]

And put this in a client only lua file:
[lua]net.Receive(“ent.hide”, function()
local ent = net.ReadEntity()
ent:SetNoDraw(true)
end)[/lua]

If this is a scripted ent (made via ENT in an entities folder:) you can do something like this.



--Serverside, set what player can see this entitiy via:
ent:SetNWEntity("myPlayer", ply); 

--Use this only when the server needs to set what player can see this entity. When the entity is created.
--be sure to also set ent:DrawShadow(false); to disable the shadow too.


then in shared.lua or cl_init.lua of the entity.



function ENT:Draw()
	if (self:GetNWEntity("myPlayer") != LocalPlayer()) then
		return;
	end
	self:DrawModel();
end
function ENT:DrawTranslucent()
	if (self:GetNWEntity("myPlayer") != LocalPlayer()) then
		return;
	end
	self:DrawModel();
	
end


Yes

I will try your solution today, thank you very much!