Anyone got any ideas on how to share a table across an enity, I have tried using net messages, but cant seem to get it to work.
What errors do you get, also need more information, is the data going from one entity to another, or just within the same entity but going from server/client to client/server?
Right, I am trying to get the table to go from server to client, when attempting to use a net message and do it, on the client, I set the RecievedEntity.InfoTable = net.ReadTable() and when attempting to print that table elsewhere in the client of the entity it fails to find it
Can you show us code?
Init.lua
util.AddNetworkString( "CS_SendTableInfo" ) function ENT
cl_init.lua
net.Receive( "CS_SendTableInfo", function() local RecievedEnt ..
**These are not the entire files, just an example that I quickly made.**
Change
RecievedEnt.HoldingTable = tableVal
to
self.HoldingTable = tableVal
and your code should work
You're getting confused thinking that if you send a server entity through a netmessage it'll magically convert into the client entity or something and then you can assign values to it.
You don't need to send the entity, just send the value you want to share from the server and then assign it in the client.
But then where is self going to come from?
Yeah sorry my bad, that won't work.
You need some way to identify the entity but you don't have to send all the entity data.
Someone else might have a better solution but what I would try next is:
1) Get the ID of the entity serverside using
Entity:EntIndex()
2) Send both the index (as a 16 bit int) and the table in the netmessage
3) For the receive netmessage do something like:
net.Receive( "CS_SendTableInfo", function()
local entID = net.ReadInt(16)
local tableVal = net.ReadTable()
Entity(entID).HoldingTable = tableval
end)
Why don't you use Entity/NetworkVar
Right thanks for the help, not entirely sure it will work though, will test it later.
Why don't you use Entity/NetworkVar
The reason why is that I am trying to network a whole table, not a couple of variables.
It could be because when the entity is initialized and the SetHoldingTable function is called, the player is not yet initialized so its broadcasting to no one.
Try call it inside a GM/InitPostEntity hook instead.
You're only networking the table once when the entity is created so it won't be networked to players that joined after it was created.
NetworkVar's cant do tables
From the looks of the code we were given the table looks like it's going to have static values so he might as well use NetworkVars for the individual values instead of networking the entire table.
True, however those could just be example values.
It's obvious they are but the table is being defined inside the ENTITY:Initialize function.
Do you HAVE to use a table? (are you planning to add/remove values later in the code)
Or will you have a known amount of values?
If you know the amount of values you are going to use then use NetworkVars like Chewgum and beaner suggested.
The entity is going to be placed by the player, so surely the player would have already been initialised?
Also, I was trying to just get this working first and then I was going to add something similar to a PlayerInitialSpawn hook.
This is just an example as I said, later on I will be defining the table elsewhere.
I do not know the amount of values that will be used, plus the values will be tables themselves.
e.g.
local tables = {}
tables[1] = {
name = "fsad",
type = "fassd",
}
Found a fix, I was pretty stupid. Instead of broadcasting each time the table was updated, I decided to just send the table along with the entity when the player pressed "use" on the entity.
No point in writing the entity's index. Just use net.WriteEntity(), it uses the index internally anyway.
Sorry, you need to Log In to post a reply to this thread.