Facepunch / garrysmod-issues

Garry's Mod issue tracker
147 stars 56 forks source link

sbox_persist doesn't persist through server restarts #2180

Closed Fuzzik closed 9 years ago

Fuzzik commented 9 years ago

sbox_persist "1" is in my server.cfg, thus being set before the map loads. Making an entity persistent and using changelevel to see if it is still there works fine, but even after using changelevel to load the same map, persistent entities are gone after a server restart.

The persist file for the map "data/persist/mapname_1.txt" is still there, but it's as if it's being ignored by the game.

mcd1992 commented 9 years ago

If I'm not mistaken persisting entities only works in single player or on listen servers.

robotboy655 commented 9 years ago

I am pretty sure your convar is being reset to 0.

Fuzzik commented 9 years ago

After a restart the server console says its set to 1.

robotboy655 commented 9 years ago

https://github.com/garrynewman/garrysmod/blob/ead2b4d7f05681e577935fef657d4a4d962091e6/garrysmod/gamemodes/sandbox/gamemode/persistence.lua#L51-L54

Add print(PersistPage) and see what it prints ( BEFORE the if then return end bit )

Fuzzik commented 9 years ago

Alright, one moment.

Fuzzik commented 9 years ago

A bit confused, should that print something to the server console on startup or do I execute it in game, or something else?

robotboy655 commented 9 years ago

Add it to the file, restart your server and look for server console output.

hook.Add( "InitPostEntity", "PersistenceInit", function()

    local PersistPage = GetConVarString( "sbox_persist" )
    print("DONT MISS ME: ------------------------------------- ", PersistPage)
    if ( PersistPage == "0" ) then return end

    hook.Run( "PersistenceLoad", PersistPage );

end )
Fuzzik commented 9 years ago

DONT MISS ME: ------------------------------------- 1

robotboy655 commented 9 years ago

Dedicated server?

Fuzzik commented 9 years ago

Yes

robotboy655 commented 9 years ago

server.cfg is executed AFTER or WHILE InitPostEntity, so it is too late.

image

You can see PersistPage in console before the sbox_persist prints in red from the server.cfg, which is for me:

sbox_persist
sbox_persist "1"
sbox_persist
Fuzzik commented 9 years ago

Would you recommend setting it in the batch file that opens the server or somewhere else so it is set to 1 before InitPostEntity?