Setting up a table on a player as soon as they spawn in the client.

I’ve run into a wall here. I’m trying to network a bunch of variables in a table for the client using usermessages and it needs to be set up as soon as the player spawns. I figured it’d be easy enough, send a usermessage to the current clients to setup the joining client. Problem being, PlayerInitialSpawn, PlayerSpawn, etc are all fired when only the server knows about the joining client. If I send a usermessage to the active clients about the joining client, it returns NULL.

[lua]if SERVER then
hook.Add( “PlayerInitialSpawn”, “SetupTable”, function( pl )
pl.ATable = {}

	local filter = RecipientFilter()
	filter:AddAllPlayers()
	filter:RemovePlayer( pl ) -- Player is currently joining, don't include them. They'll setup their own table in InitPostEntity.
	
	umsg.Start( "SetupPlayer", filter )
	umsg.Entity( pl )
	umsg.End()
end )

else
usermessage.Hook( “SetupPlayer”, function( um )
um:ReadEntity().ATable = {}
end )
end[/lua]

That’s pretty much what I’m doing in a nutshell. Is there any hook that is safe to send a usermessage with the new client in?

I don’t know if this will work or not, but could you use **[Gamemode.OnEntityCreated

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.OnEntityCreated)**?

It’s also a shared hook, so you might be able to skip out the networking.

Something like:
[lua]
hook.Add( “OnEntityCreated”, “SetupTable”, function( ent )

if not ent:IsPlayer() or ent == LocalPlayer() then return end

ent.ATable = {}

end )[/lua]

Damn, how did I miss that? Thanks, I’ll try it now.

[editline]27th November 2011[/editline]

It worked, thanks!