NW int save after cleanup

Hello when i do a server cleanup the nw ints i set on doors reset and i have to reload the gamemode init.lua file

function updateDoors()
for i=1,table.Count(ents.GetAll()) do
local allEnts = ents.GetAll()
local ent = allEnts*

	ent:SetNWInt("DoorID", ent:CreatedByMap() and ent:MapCreationID() or nil)

this is the code to set the nw ints its near the top of the init.lua

How are you doing a server cleanup? In any case, just call the function again once you’ve cleaned up.

how do i do that the only way i can find is opening and saving the file.

in console: lua_run updateDoors()

That script is terrible. You are setting the map creation id as a network var to every entity on the map. Don’t do that.

whats the best way of getting a map creation id from the client then

That’s “nice” O(n²) right there:

for i=1,table.Count(ents.GetAll()) do -- for each entity...
    local allEnts = ents.GetAll()  -- get all entities again
    local ent = allEnts*

It should be this:

for _, ent in ipairs(ents.GetAll()) do


That’s not an n², but is still badly made, if he would loop through the seconds time then it would be :stuck_out_tongue:

It is O(n²), ents.GetAll() internally loops over entity list and fills Lua table which is then returned.

It could be an O(n²), but can’t really know for sure, still it isn’t in any way efficient to do how he did it, even if it doesn’t take much for it to get it every time.