Alternative Networked Vars

Over 1 day of work included!
This is my amazing version of networked variables that has some cool features. The default system for networked vars is lacking and often causes net overflows because of the obnoxious spam. This offers an alternative system that is reliable and doesn’t overflow everything.

Part of it is written in C++ (for insane server fps), so it requires a module, but only for the server.

Typical usage:
[lua]
RegisterNWTableGlobal({ {“PVPRoundTime”, 0, NWTYPE_FLOAT, REPL_EVERYONE},
{“PVPRoundOver”, false, NWTYPE_BOOLEAN, REPL_EVERYONE},
{“PVPRoundCount”, 0, NWTYPE_CHAR, REPL_EVERYONE } })

GetWorldEntity().PVPRoundTime = 555;
print(GetWorldEntity().PVPRoundTime)
[/lua]

[lua]
RegisterNWTablePlayer({
{“BAL”, 0, NWTYPE_CHAR, REPL_PLAYERONLY},
})
[/lua]

[lua]
function ENT:SharedInit()
RegisterNWTable(self, { {“Active”, false, NWTYPE_BOOLEAN, REPL_EVERYONE, self.CreateBeam} })
end
[/lua]

As you can see, you register a table shared and each variable has certain attributes and even a proxy function. You access variables by doing entity.x, you simply set and get the variable. For “Global” vars you have to use GetWorldEntity().x.

The table to register is fairly simple,
[lua]
{
{“variable a”, default value, nwtype, repltype, optional callback},
}
[/lua]

You can call RegisterNWTablePlayer and RegisterNWTableGlobal multiple times.

The callbacks work like regular callbacks:
[lua]
function Callback(entity, name, old, new)
[/lua]

There are different types obviously. I didn’t implement vector and angle yet. There are two repls REPL_EVERYONE (goes to everyone) and REPL_PLAYERONLY (goes to that player)

Thanks goes to:
Conna for testing it.

check out the latest from the svn
http://gmodmodules.googlecode.com/svn/trunk/gm_transmittools/

This code needs PlayerThink, which is simply this:
[lua]
timer.Create( “GTowerPlayerThink”, 1.0, 0, function()

for _, v in ipairs( player.GetAll() ) do
	hook.Call("PlayerThink", GAMEMODE, v)
end

end)
[/lua]

Let’s see. This might come extremely useful. Thanks!

At least thanks for the player crash test code. I read somewhere a function called IsTimingOut, but apparently I read something that doesn’t exist, not at least in GMod.

EDIT: http://svn.alliedmods.net/viewvc.cgi/trunk/core/smn_player.cpp?annotate=688&root=sourcemod&pathrev=2149#l679

Oops I fixed some serious crashes. Here’s the updated version.

If you set values to nil it would crash.

http://gmodmodules.googlecode.com/svn/trunk/gm_transmittools/

Looks cool but what’s it do?

Here’s what it doesn’t do:
http://azu.pastebin.com/m2a6209ef

This is something for Lua developers. Normal Garry’s mod player won’t be able to understand this.

Conna, thanked?? Not downloading.

Can it fix the “Host_Error: Overflow error writing string table baseline LuaStringTable” overflows?

Oh wow he put it on his computer and tried it, now it’s a bad product.

This looks extremly interesting, maybe it’s worth it to ask garry to implement it :wink:

I bet Conna has sandbox on it computer. It must be horrid!

This doesn’t support tables?

Why would you send a table to the client? Is it really necessary to synchronize a table?

I can’t get this to work… I must not be doing something right.

I do this in shared:

[lua]
RegisterNWTablePlayer({
{“Mana”, 0, NWTYPE_SHORT, REPL_EVERYONE},
})
[/lua]

Then I set someplayer.Mana serverside. Nothing happens clientside. Is there something I missed?

Did you include nwvar.lua?

Yeah, clientside and serverside… And print(RegisterNWTablePlayer) returns a valid function.

Oh right, you have to make sure it’s included before datastream, dumpstringtables_new LuaUserStrings or whatever needs to have N as the first. I’ll see if I can’t fix that.

Ah ok.

I’ve been doing this:
[lua]
ALBION_MSG_Center(“Datastream…”)
require(“datastream”)

ALBION_MSG_Center(“Gatekeper…”)
require(“gatekeeper”)

ALBION_MSG_Spacer()
ALBION_Include( “nwvars/nwvars.lua” )
[/lua]

So if I do,
[lua]
RegisterNWTablePlayer({
{“Test”, 0, NWTYPE_CHAR, REPL_PLAYERONLY},
})
[/lua]

It exists as:

Server:
ply.Test

Client:
LocalPlayer().Test
?

When using RegisterNWTablePlayer, what determines which player you are talking about?