Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SERVER--
- if SERVER then
- function SendTableToClient(tab, name, ply, containing_table, ...)
- for f, v in pairs(tab) do
- local t=type(f)
- local t2=type(v)
- if !ValidEntity(ply) then
- if !type(ply)=="table" then
- ply=RecipientFilter():AddAllPlayers()
- else
- ply=RecipientFilter()
- for k, pl in pairs(ply) do
- if ValidEntity(pl) then
- ply:AddPlayer(pl)
- end
- end
- end
- end
- if !containing_table then -- If it wasn't already part of a table --
- if t2=="table" then
- SendTableToClient(v, name, ply, true, {[1]=f}) -- if the value IS a table --
- else
- umsg.Start("_ServersideTable", ply)
- umsg.String(name)
- umsg.String(t) -- Send key type --
- -- Below sends key --
- if ( t == "string" ) then
- umsg.String( v )
- elseif ( IsEntity( v ) ) then
- umsg.Entity( v )
- elseif ( t == "number" ) then
- umsg.Long( v )
- elseif ( t == "Vector" ) then
- umsg.Vector( v )
- elseif ( t == "Angle" ) then
- umsg.Angle( v )
- elseif ( t == "boolean" ) then
- umsg.Bool( v )
- end
- umsg.String(t2) -- Send value type --
- -- Below sends value --
- if ( t2 == "string" ) then
- umsg.String( v )
- elseif ( IsEntity( v ) ) then
- umsg.Entity( v )
- elseif ( t2 == "number" ) then
- umsg.Long( v )
- elseif ( t2 == "Vector" ) then
- umsg.Vector( v )
- elseif ( t2 == "Angle" ) then
- umsg.Angle( v )
- elseif ( t2 == "boolean" ) then
- umsg.Bool( v )
- end
- umsg.End()
- else -- otherwise --
- if type(v)=="table" then
- local hierarchy={...}
- hierarchy[#hierarchy+1]=f
- SendTableToClient(v, name, ply, true, hierarchy)
- else
- umsg.Start("_ServersideTableCont", ply)
- umsg.String(name)
- umsg.String(glon.encode({...}))
- umsg.String(t) -- Send key type
- -- Below sends key --
- if ( t == "string" ) then
- umsg.String( f )
- elseif ( IsEntity( f ) ) then
- umsg.Entity( f )
- elseif ( t == "number" ) then
- umsg.Long( f )
- elseif ( t == "Vector" ) then
- umsg.Vector( f )
- elseif ( t == "Angle" ) then
- umsg.Angle( f )
- elseif ( t == "boolean" ) then
- umsg.Bool( f )
- end
- umsg.String(t2) -- Send value type
- -- Below sends value --
- if ( t2 == "string" ) then
- umsg.String( v )
- elseif ( IsEntity( v ) ) then
- umsg.Entity( v )
- elseif ( t2 == "number" ) then
- umsg.Long( v )
- elseif ( t2 == "Vector" ) then
- umsg.Vector( v )
- elseif ( t2 == "Angle" ) then
- umsg.Angle( v )
- elseif ( t2 == "boolean" ) then
- umsg.Bool( v )
- end
- umsg.End()
- end
- end
- end
- end
- end
- local tab={}
- tab["Twenty"]=20
- tab["TwentyOne"]=21
- tab["TwentyTwo"]=22
- tab["MoreNumbers"]={23, 24}
- tab["MoreNumbers"].Wha="Testing"
- SendTableToClient(tab, "Numbers")
- end
- --CLIENT--
- if !CLIENT then return end
- ServerData={}
- usermessage.Hook("_ServersideTable", function(data)
- local tabname=data:ReadString()
- local t=data:ReadString()
- local f
- local v
- if ( t == "string" ) then
- f=data:ReadString()
- elseif ( t=="Entity" ) then
- f=data:ReadEntity()
- elseif ( t == "number" ) then
- f=data:ReadLong()
- elseif ( t == "Vector" ) then
- f=data:ReadVector()
- elseif ( t == "Angle" ) then
- f=data:ReadAngle()
- elseif ( t == "boolean" ) then
- f=data:ReadBool()
- end
- local t2=data:ReadString()
- if ( t2 == "string" ) then
- v=data:ReadString()
- elseif ( t2=="Entity" ) then
- v=data:ReadEntity()
- elseif ( t2 == "number" ) then
- v=data:ReadLong()
- elseif ( t2 == "Vector" ) then
- v=data:ReadVector()
- elseif ( t2 == "Angle" ) then
- v=data:ReadAngle()
- elseif ( t2 == "boolean" ) then
- v=data:ReadBool()
- end
- if ( !(tabname) || !(f) || !(v) ) then return end
- ServerData.tabname=ServerData.tabname or {}
- ServerData.tabname[f]=v
- end)
- usermessage.Hook("_ServersideTableCont", function(data)
- local tabname=data:ReadString()
- local cont=glon.decode(data:ReadString())
- local t=data:ReadString()
- local f
- local v
- if ( t == "string" ) then
- f=data:ReadString()
- elseif ( t=="Entity" ) then
- f=data:ReadEntity()
- elseif ( t == "number" ) then
- f=data:ReadLong()
- elseif ( t == "Vector" ) then
- f=data:ReadVector()
- elseif ( t == "Angle" ) then
- f=data:ReadAngle()
- elseif ( t == "boolean" ) then
- f=data:ReadBool()
- end
- local t2=data:ReadString()
- if ( t2 == "string" ) then
- v=data:ReadString()
- elseif ( t2=="Entity" ) then
- v=data:ReadEntity()
- elseif ( t2 == "number" ) then
- v=data:ReadLong()
- elseif ( t2 == "Vector" ) then
- v=data:ReadVector()
- elseif ( t2 == "Angle" ) then
- v=data:ReadAngle()
- elseif ( t2 == "boolean" ) then
- v=data:ReadBool()
- end
- if ( !(tabname) || !(f) || !(v) || !(cont) ) then return end
- ServerData.tabname=ServerData.tabname or {}
- ServerData.tabname[cont]=ServerData.tabname[cont] or {}
- ServerData.tabname[cont][f]=v
- end)
- function GetServerTable(name)
- return ServerData[name] or nil
- end
Advertisement
Add Comment
Please, Sign In to add comment