Saving a Networked String for Server Restart

So currently on this map I have been playing I have been findling around with this idea of networked strings by setting them on an object like a door, so like


door:SetNetworkString("Level", 2)

What I was wondering is how/can you save the information of the networked string so that when the server is restarted the door still retains that value anyway, in this case “2”. If the answer is quite in depth and would take to long, a nudge in the right direction would also be helpful.

Txt file/database.

you have to save it somewhere I assume?

That’s what I was thinking. Saving it to a database wouldn’t be a problem for me, and I imagine it would be more reliable and easier to pull the information from than a text file.

I don’t know if entity ID’s and such persist through restarts or they’re random, but if they’re random I suppose you could just like have a table in an SQLite db with 4 fields (level, x, y, z) so you just store the position of the door and then when you need to retrieve them you just do some ents.FindInSphere :v:

I was unaware of ents.FindInSphere, I suppose that would be such a way of doing it.

ent:GetCreationID()
ents.GetMapCreatedEntity(creationID)

Seems like a better way for sure

That’s weird. The creation ID is changed on each restart for doors I am looking at on gm_underground_iv.

One time the ID is 26570 then after the restart it becomes 31676.

EvacX’s way would work. Save the position of the door. Load the file on restart. Find the door by reading the coordinates. Set the info of the door.

If you wanted to save it to a .txt file, util.TableToKeyValues or util.TableToJSON and vice versa would be the easiest way of doing it.

SQL is way more efficient though

[editline]11th July 2013[/editline]

I can help OP with it if he wants

I will certainly keep that offer in mind. I’m trying to do it myself though, as what this is related to is a project where I’m honing my LUA skills for an actual project to see if I can complete it. Thanks for all the help guys, I’ll see how it goes.

Well I did it. Not the best method by any stretch of the imagination but it will do for now until I can make it more efficient, I just made it so that the game writes a file with the doors positioning and level. When the map starts up it cycles through all the entities on the map to see if it matches the positioning with the file and if it does, sets the networkedstring value to that of what’s recorded in the file.

So yeah guys, thanks for all the help. :smile:

Oh well, guess that works too :v: