Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. if ( CLIENT ) then return end
  2.  
  3. hook.Add( "ShutDown", "SavePersistenceOnShutdown", function() hook.Run( "PersistenceSave" ) end )
  4.  
  5. hook.Add( "PersistenceSave", "PersistenceSave", function()
  6. local Ents = ents.GetAll()
  7.  
  8. for k, v in pairs( Ents ) do
  9.  
  10. if ( !v:GetPersistent() ) then
  11. Ents[ k ] = nil
  12. end
  13.  
  14. end
  15.  
  16. local tab = duplicator.CopyEnts( Ents )
  17. if ( !tab ) then return end
  18.  
  19. local out = util.TableToJSON( tab )
  20.  
  21. file.CreateDir( "persist" )
  22. file.Write( "persist/" .. game.GetMap() .. "_" .. "bhopmaps" .. ".txt", out )
  23. end )
  24.  
  25. hook.Add( "PersistenceLoad", "PersistenceLoad", function( name )
  26. local file = file.Read( "persist/" .. game.GetMap() .. "_" .. "bhopmaps" .. ".txt" )
  27. if ( !file ) then return end
  28.  
  29. local tab = util.JSONToTable( file )
  30. if ( !tab ) then return end
  31. if ( !tab.Entities ) then return end
  32. if ( !tab.Constraints ) then return end
  33.  
  34. local Ents, Constraints = duplicator.Paste( nil, tab.Entities, tab.Constraints )
  35.  
  36. for k, v in pairs( Ents ) do
  37. v:SetPersistent( true )
  38. end
  39. end )
  40.  
  41. hook.Add( "InitPostEntity", "PersistenceInit", function()
  42. hook.Run( "PersistenceLoad", "bhopmaps" );
  43. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement