Guest User

Untitled

a guest
Feb 21st, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. //This is for ZCOM.
  2. //Good luck with your vaginal discharge.
  3. //<3 Annoyed Tree
  4.  
  5. /////////////////////////////////////////////
  6. // SAVING TO TEXT //
  7. /////////////////////////////////////////////
  8.  
  9. local PS = {};
  10. PS.Save = {};
  11. PS.Load = {};
  12. PS.Props = {};
  13.  
  14. function PS.Save.File( dir )
  15. if ( !dir ) then Error( "Directory does not exist or no file name was given." ); end //We do not need return because Error does that for us
  16.  
  17. local map = game.GetMap();
  18. if ( file.Exists( "prop_saver/" .. map .. "/" .. dir .. ".txt" ) ) then
  19. file.Delete( "prop_saver/" .. map .. "/" .. dir .. ".txt" );
  20. print( "File '" .. dir .. ".txt' removed" );
  21. end
  22.  
  23. local num = 0
  24. for k, v in pairs( ents.GetAll() ) do
  25. if ( v:GetClass() == "prop_physics" ) then
  26. local tempTbl = {
  27. Model = v:GetModel(),
  28. Vector = v:GetPos(),
  29. Angles = v:GetAngles()
  30. };
  31.  
  32. table.insert( PS.Props, tempTbl );
  33.  
  34. num = num + 1;
  35. end
  36. end
  37.  
  38. file.Write( "prop_saver/" .. map .. "/" .. dir .. ".txt", glon.encode( PS.Props ) );
  39. print( num .. " props saved" );
  40.  
  41. end
  42.  
  43. function PS.Load.File( dir )
  44. if ( !dir ) then Error( "Directory does not exist or no file name was given." ); end //We do not need return because Error does that for us
  45.  
  46. local map = game.GetMap();
  47. if ( !file.Exists( "prop_saver/" .. map .. "/" .. dir .. ".txt" ) ) then
  48. print( dir .. ".txt was not found" );
  49. return;
  50. end
  51.  
  52. /*for k, v in pairs( ents.GetAll() ) do
  53. if ( v:GetClass() == "prop_physics" ) then
  54. v:Remove();
  55. end
  56. end*/ //Uncomment those lines in order to remove all props when a new file loads
  57.  
  58. local props = glon.decode( file.Read( "prop_saver/" .. map .. "/" .. dir .. ".txt" ) );
  59.  
  60. for k, v in pairs( props ) do
  61. local prop = ents.Create( "prop_physics" );
  62.  
  63. prop:SetModel( v:GetModel() );
  64. prop:SetPos( v:GetPos() );
  65. prop:SetAngles( v:GetAngles() );
  66. prop:Spawn();
  67. prop:Activate();
  68. end
  69.  
  70. end
  71.  
  72.  
  73. function PS.Save.ConCmd( pl, cmd, args )
  74. local dir = args[ 1 ];
  75.  
  76. PS.Save.File( dir );
  77. end
  78.  
  79. function PS.Load.ConCmd( pl, cmd, args )
  80. local dir = args[ 1 ];
  81.  
  82. PS.Load.File( dir );
  83. end
  84.  
  85. concommand.Add( "ps_save", PS.Save.ConCmd );
  86. concommand.Add( "ps_load", PS.Load.ConCmd );
Add Comment
Please, Sign In to add comment