Permalink
Browse files

"live" persitence cvar change effects

  • Loading branch information...
robotboy655 committed Feb 24, 2017
1 parent 1ff829d commit f7a2bb0b2c3a5bc700bbf68df221deab22cd2c1e
@@ -3,9 +3,9 @@ if ( CLIENT ) then return end
hook.Add( "ShutDown", "SavePersistenceOnShutdown", function() hook.Run( "PersistenceSave" ) end )
hook.Add( "PersistenceSave", "PersistenceSave", function()
hook.Add( "PersistenceSave", "PersistenceSave", function( name )
local PersistPage = GetConVarString( "sbox_persist" )
local PersistPage = name or GetConVarString( "sbox_persist" )

This comment has been minimized.

@mcNuggets1

mcNuggets1 Feb 24, 2017

Contributor

Shouldn't we use GetConVar("sbox_persist" ):GetString() ?

This comment has been minimized.

@robotboy655

robotboy655 Feb 24, 2017

Collaborator

That's exactly what GetConVarString does.

This comment has been minimized.

@mcNuggets1

mcNuggets1 Feb 24, 2017

Contributor

Yeah, but it is marked as deprecated.

if ( PersistPage == "" ) then return end
local Ents = ents.GetAll()
@@ -25,7 +25,7 @@ hook.Add( "PersistenceSave", "PersistenceSave", function()
file.CreateDir( "persist" )
file.Write( "persist/" .. game.GetMap() .. "_" .. PersistPage .. ".txt", out )
end )
hook.Add( "PersistenceLoad", "PersistenceLoad", function( name )
@@ -46,11 +46,26 @@ hook.Add( "PersistenceLoad", "PersistenceLoad", function( name )
end )
cvars.AddChangeCallback( "sbox_persist", function( name, old, new )
-- A timer in case someone tries to rapily change the convar, such as addons with "live typing" or whatever
timer.Create( "sbox_persist_change_timer", 1, 1, function()
hook.Run( "PersistenceSave", old )
game.CleanUpMap() -- Maybe this should be moved to PersistenceLoad?
if ( new == "" ) then return end
hook.Run( "PersistenceLoad", new )
end )
end, "sbox_persist_load" )
hook.Add( "InitPostEntity", "PersistenceInit", function()
local PersistPage = GetConVarString( "sbox_persist" )
if ( PersistPage == "" ) then return end
hook.Run( "PersistenceLoad", PersistPage );
hook.Run( "PersistenceLoad", PersistPage )
end )
@@ -28,3 +28,6 @@ AddCSLuaFile( "sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/game
AddCSLuaFile( "sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/npcs.lua" )
AddCSLuaFile( "sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/postprocess.lua" )
AddCSLuaFile( "sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/weapons.lua" )
AddCSLuaFile( "sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/vehicles.lua" )
AddCSLuaFile( "sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/saves.lua" )
AddCSLuaFile( "sandbox/gamemode/spawnmenu/creationmenu/content/contenttypes/dupes.lua" )

0 comments on commit f7a2bb0

Please sign in to comment.