• NWVars exist on Server but not Client
    6 replies, posted
Allright, So After about 3 years of not touching Garry's Mod, I may simply need a refresher... For some reason, the code below has a problem. The NW variables that are being set on these doors are Nil clientside, but exist serverside (However, system works fine in Singleplayer) For some reason they are not syncing with the clients when they join it seems. Now the whole point of NWVars was that it automatically synced up the inital state and sent an update to the clients when the value changes. If I remember correctly, the inital value is sent to the player when they join, so I would not have to force the NWVar to change to the same value for the player to get the update. So... Whats up? How do I fix this? Has something changed in the systems since the 3 years that I have been gone? Snippet from Database.lua which is serverside only. [CODE]function DB.LoadProperties() print("Loading all properties:") --Unlock all doors. for _, ent in pairs( ents.GetAll() ) do if ( ent:IsDoor()) then --ent.Ownable = false ent:Fire("unlock", "", 0) ent:SetNWBool( "ownable", false) end end DB.Query("SELECT * FROM hs_properties NATURAL JOIN hs_doors WHERE mapname = " .. sql.SQLStr(game.GetMap()) .. ";", function(Data) if not Data then print("-No Properties found... Error?") print("-Loaded Properties Successfully") return end --[[ local property = Data[1] if property.owner != "None" then ---- DB.QueryValue("SELECT playername FROM hs_players WHERE playerid = " .. sql.SQLStr(property.owner) .. ";", ---- function(namedata) print("--Character name \"" .. namedata .. "\" loaded for property " .. property.propertyid) ---- GameMode.PlayerNames[v.owner] = namedata end) end --]] local v for k, v in pairs (Data) do -- Does the property exist already? if not GameMode.Properties[v.propertyid] then local Property = {} Property.propertytype = tonumber(v.propertytype) Property.propertyname = v.propertyname Property.value = v.value Property.owner = v.owner Property.sector = v.sector Property.masterdoor = v.entityid Property.doors = {} GameMode.Properties[v.propertyid] = Property end local masterDoor = GameMode.Properties[v.propertyid].masterdoor --table.insert(v.entityid, GameMode.Properties[v.propertyid].doors) local Door = ents.GetByIndex(v.entityid) Door.propertyid = v.propertyid Door:SetNWString("name", v.doortitle) Door:SetNWEntity("masterdoor", masterDoor) -- Update one, update the rest! print("Set master door of " .. tostring(Door) .. "to " .. tostring(masterDoor)) Door:SetColor(Color(0,255,255)) if masterDoor == Door then -- 0 Do nothing. Non-ownable -- Non-Rentable if v.propertytype >= 1 then Door:SetNWString( "owner", v.owner) Door:Fire("lock", "", 0) end -- 2 is a buisness -- Rentable if v.propertytype >= 2 then Door:SetNWBool( "rentable", true) Door:SetNWString("keyowner", nil) -- Does nothing. Reminder for which Key to use. end end end print("-Loaded Properties Successfully") end) end[/CODE] Snippet from Shared.lua code [CODE]properties.Add("PurchaseProperty", { MenuLabel = "Purchase Property", Order = 500, Filter = function(self, ent, ply) if ent:IsDoor() and ent:GetNWEntity("masterDoor") then local masterDoor = ent:GetNWEntity("masterdoor") if masterDoor and masterDoor:GetNWString("owner") == "" then return true end end return false end, Action = function(self, ent) self:MsgStart() net.WriteEntity(ent:GetNWEntity("masterdoor")) self:MsgEnd() end, Receive = function(self, length, ply) local ent = net.ReadEntity() -- manipulate the selected entity ent:GetNWInt("propertyid") ent:SetNWString("owner", ply:SteamID()) print("Bought property!") end }); properties.Add("SellProperty", { MenuLabel = "Sell Property", Order = 500, Filter = function(self, ent, ply) if ent:IsDoor() and ent:GetNWEntity("masterDoor") then local masterDoor = ent:GetNWEntity("masterdoor") if masterDoor and masterDoor:GetNWString("owner") == ply:SteamID() then return true end end return false end, Action = function(self, ent) self:MsgStart() net.WriteEntity(ent:GetNWEntity("masterdoor")) self:MsgEnd() end, Receive = function(self, length, ply) local ent = net.ReadEntity() -- manipulate the selected entity ent:SetNWString("owner",nil) print("Sold property!") end }); properties.Add("RentProperty", { MenuLabel = "Rent Property", Order = 500, Filter = function(self, ent, ply) if ent:IsDoor() and ent:GetNWEntity("masterDoor") then local masterDoor = ent:GetNWEntity("masterdoor") if masterDoor and masterDoor:GetNWString("keyowner") == "" and masterDoor:GetNWBool("rentable") then return true end end return false end, Action = function(self, ent) self:MsgStart() net.WriteEntity(ent:GetNWEntity("masterdoor")) self:MsgEnd() end, Receive = function(self, length, ply) local ent = net.ReadEntity() -- manipulate the selected entity ent:GetNWInt("propertyid") ent:SetNWString("keyowner", ply:SteamID()) end }); [/CODE] Any help would be appreciated.
[url]http://facepunch.com/showthread.php?t=1383088[/url] you can use this you cant set a nwvar clientside though (you can, but it wont network to the server), but on the server it'll network to both realms
[QUOTE=Sm63;46726094][URL]http://facepunch.com/showthread.php?t=1383088[/URL] you can use this you cant set a nwvar clientside though (you can, but it wont network to the server), but on the server it'll network to both realms[/QUOTE] Thank you, but I am already aware of that fact. The NWVars are being set serverside under the InitPostEntity hook - so they SHOULD be set on the client as well, like you stated. However what is happening is not what is expected. My only real question right now is whether or not the inital values are sent to the player when a new player joins. If that is not the case, then the system is different than it was a while back. I'll take a look at the library you listed, but I am perfectly capable of writing my own syncing system using the net.* functions (Especially since this masterdoor value will NOT change once initialized.) - I just did not want to put forth the effort when a NWVar system by definition SHOULD already do this - atleast it did 3+ years ago.
The [URL="http://wiki.garrysmod.com/page/Dev_Branch"]dev branch[/URL] has a full rewrite of the NWVars system to improve the networking and reliability, try it out. It still has some bugs which will be fixed soon, and you can report issues [URL="https://github.com/Facepunch/garrysmod-issues/issues"]here[/URL].
[QUOTE=Jvs;46726366]The [URL="http://wiki.garrysmod.com/page/Dev_Branch"]dev branch[/URL] has a full rewrite of the NWVars system to improve the networking and reliability, try it out. It still has some bugs which will be fixed soon, and you can report issues [URL="https://github.com/Facepunch/garrysmod-issues/issues"]here[/URL].[/QUOTE] Sweet. Any ETA/estimate on how often this will be pushed to the stable branches? I don't really want to exclude the majority of the Gmod userbase by hosting a server under the new development branch if it isnt going to be pushed in quite some time... (Even if I dont use it, it is still pretty awesome to keep in mind. Thank you)
I honestly don't know, there's still quite a few bugs that _Kilburn/Robotboy have to fix, but don't get your hopes high before Christmas.
So... As it turns out: When I made the switch from playing the game locally, to moving it to a dedicated server, the entity ID's changed and completely invalidated my database. Code is working perfectly fine now. Was apparently never broken - just adding NWVars onto completely meaningless entities instead of the ones I had targeted in Single player. Lesson learned.
Sorry, you need to Log In to post a reply to this thread.