// Private NW vars. // By RabidToaster // Usage: // Serverside: // name: Entity:SetPrivateNW* or Entity:SetPrivateNetworked* // arguments: recipient (player/filter), string key, value // Clientside, use standard GetNW* functions. // Normal NW vars will overwrite private ones when set. local Entity = FindMetaTable("Entity") if !Entity then return end local CreateFunction if SERVER then AddCSLuaFile("privNWvars.lua") // Keep this updated if you change the filename! // Entity to set on, player/RF to send to, umsg.Func name, key, value local function Send(ent, ply, sendName, key, var) local sendFunc = umsg[sendName] if !sendFunc then return end umsg.Start("PrivNW" .. sendName, ply) umsg.Entity(ent) umsg.String(key) sendFunc(var) umsg.End() end function CreateFunction(funcName, sendName) local func = function(ent, ply, key, var) Send(ent, ply, sendName, key, var) end Entity["SetPrivateNW" .. funcName] = func Entity["SetPrivateNetworked" .. funcName] = func end end if CLIENT then local function Receive(funcName, readName, msg) local ent = msg:ReadEntity() if !ValidEntity(ent) then return end local key = msg:ReadString() local meta = getmetatable(msg) if !meta then return end local readFunc = meta["Read" .. readName] if !readFunc then return end local setFunc = Entity["SetNW" .. funcName] if !setFunc then return end setFunc(ent, key, readFunc(msg)) end function CreateFunction(funcName, readName) usermessage.Hook("PrivNW" .. readName, function(msg) Receive(funcName, readName, msg) end) end end // SetNW/GetNW name, umsg name CreateFunction("Angle", "Angle") CreateFunction("Bool", "Bool") CreateFunction("Entity", "Entity") CreateFunction("Float", "Float") CreateFunction("Int", "Long") CreateFunction("Number", "Long") CreateFunction("String", "String") CreateFunction("Vector", "Vector")