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]