Sending Table From Serverside to Clientside

Okay So I have a table…

TeamInfo = {}

and I have a table in that…

TeamInfo.Models = {
	"models/player/group01/male_01.mdl",
}

Then I want to send it to clientside (for character creation purposes)


function TeamInfo.CivModels()
	return TeamInfo.Citizen.Models
end

function CiviModels()
	return TeamInfo.CivModels()
end
concommand.Add("LRP_RetrieveCiviModels", TeamInfo.CivModels)

I have tried setting the console command to execute CiviModels() and TeamInfo.CivModels()… But I always get the same result.

ERRORS:

Unknown Command: LRP_RetrieveCiviModels

OR



/gamemode/cl_init.lua:27: attempt to index local 'CivModels' (a nil value)


That last error is because inside the clientside I have this run…


	local CivModels = RunConsoleCommand("LRP_RetrieveCiviModels")

That’s because server->client doesn’t work like that. Use either datastream or make the table shared.

Serverside:
[lua]
function TeamInfo.SendModels(ply)
for k,v in pairs(TeamInfo.Models) do
umsg.Start(“GetTeamModels”, ply)
umsg.String(v)
umsg.End()
end
end
[/lua]

Clientside:
[lua]
function TeamInfo.GetModels(data)
TeamInfo.Models = {}
table.insert(TeamInfo.Models, tostring(data:ReadString()))
end
usermessage.Hook(“GetTeamModels”, TeamInfo.GetModels)

concommand.Add(“LRP_RetrieveCiviModels”, function()
PrintTable(TeamInfo.Models)
return TeamInfo.Models
end)
[/lua]

That will work, but it’s useless because you should just make the table shared.

okay thanks, sorry… I only usually do serverside, never done much clientside. >.>

Wouldn’t it be better to do it like this?

[lua]
function TeamInfo.SendModels(ply)
umsg.Start(“GetTeamModels”, ply)
umsg.Short(#TeamInfo.Models)
for k,v in pairs(TeamInfo.Models) do
umsg.String(v)
end
umsg.End()
end
[/lua]

[lua]function TeamInfo.GetModels(data)
TeamInfo.Models = {}
for i=1,data:ReadShort() do
table.insert(TeamInfo.Models, tostring(data:ReadString()))
end
end
usermessage.Hook(“GetTeamModels”, TeamInfo.GetModels)

concommand.Add(“LRP_RetrieveCiviModels”, function()
PrintTable(TeamInfo.Models)
return TeamInfo.Models
end)
[/lua]

Okay, but if I had made this table shared, isn’t it possible to edit it clientside? (Which is not the ideal situation)

[editline]03:46PM[/editline]

I’ll probably try something along this method possibly.

I’m not 100% sure if what I’m about to say even happens, but what if the clients loop counts faster than it receives from the server? I’ve never tested to see if it happens or not.

Can anyone confirm that it will be synced?

Sorry if that sounded dumb, I’m pretty fucked.

Yeah, might want to declare the table outside of the hook, or you’ll just be resetting it every usermessage.

I’m pretty sure that if you send 10 strings via usermessage, you can do um:ReadString() ten times and get those ten strings regardless of server/client speeds.

There is no need for it to be synced.

Yep.

snip