• Serverside entity visibility at client
    8 replies, posted
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.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetPreventTransmit]Entity:SetPreventTransmit[/url] 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.
[QUOTE=SFArial;51728791][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetPreventTransmit]Entity:SetPreventTransmit[/url] 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.[/QUOTE] 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] [QUOTE=kem008;51725707]What kind of entity is this??? You know you can block the draw on serverside and clientside too.[/QUOTE] I tried to do: [CODE]if CLIENT then self:SetNoDraw(true) end[/CODE] 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. [code] --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. [/code] then in shared.lua or cl_init.lua of the entity. [code] 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 [/code]
Yes
[QUOTE=Brassx;51738038]If this is a scripted ent (made via ENT in an entities folder:) you can do something like this. [code] --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. [/code] then in shared.lua or cl_init.lua of the entity. [code] 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 [/code][/QUOTE] I will try your solution today, thank you very much!
Sorry, you need to Log In to post a reply to this thread.