Entities clientside returning the same name as it has serverside.

In my gamemode the players are spectating an entity.

I want to show the players name over an entity in 3D2D if the player is looking at another player’s entity.

So that means the name of the entity on clientside has to be the same as on serverside.

I am doing

[lua]
ent.user = ply
ent.name = ent.user:Nick()
[/lua]

while I am spawning the Scripted Entity in GM:PlayerSpawn(ply)

Therefore, I can’t go shared to give server and client those informations at the same time.

I made a hook.
[LUA]
hook.Add(“PostDrawOpaqueRenderables”, “DrawNames”, function()
blah
end)[/LUA]
with cam.3D2D()
but I can’t show the name of the entity, because it’s not defined clientside.

Do I really need to do a net.Start()?
Somebody got a workaround for this?

Your best option is to send a usermessage to the client with the needed info.

Almost the same as I do net.Start()

Datatable.

In shared:



function ENT:SetupDatatables( )
  self:DTVar( "Entity", 0, "Player" )
end

Server:



function ENT:SetPlayer( pl )
  self.dt.Player = pl
  --other code
end

Clientside:



if v.dt.Player:IsValid( ) then
  drawtext( v.dt.Player:Nick( ) )
end


Thank you sooo much.

I found a bug
[lua]
usermessage.Hook(“Blah”, function( um )
ent = um:ReadEntity()
ent.name = um:ReadString() – returns nil
end
usermessage.Hook(“Blah”, function( um )
ent = um:ReadEntity()
print(um:ReadString()) – returns true
end[/lua]
the same with net.ReadString()
The String gets sent but it returns nil if you do “ent.string =” or something.

bump, I am now getting “line blah errored ‘dt’ a nil value” can you explain me why?
I am using self.dt.blah = blah on ENT:Initialize in clientside.
Sry never used it before.

User messages are received in the order you send them. If you send them in a different order, you must receive them in that same order.

Just use the net library. Send a table, if you don’t want to fuck with the order and stuff.

An alternative would be:


ent:SetNetworkedString(ply:Nick())

Yeah, I got the same idea, but that make my code messy. :smiley:

@MulledDK
Why didn’t I think of that before?
lol I was so busy to find a way with net library, umsg or DTVar that I forgot about Networked Strings.
But Networked Strings are laggy, aren’t they? Too many of them I mean.

Not only that, but they don’t update correctly while the player cannot see the entity. The changes in the default mode only allow the server to send data to the client when the player can SEE the entity, so if the player no longer within those boundaries when it changes, then your network variables will come out of sync. You can explicitly tell it to always update, but it becomes ever so expensive as it sends the information even when it doesn’t necessarily change.

Post your SetupDataTables section, or simply provide the types of DTVars that you are using… reason being is the “String” type does not exist for DTVars, Therefore, if you are using “String” as your type, this would be why you were getting initialization errors trying to set self.dt.blah to something.