Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is for ZCOM.
- //Good luck with your vaginal discharge.
- //<3 Annoyed Tree
- /////////////////////////////////////////////
- // SAVING TO TEXT //
- /////////////////////////////////////////////
- local PS = {};
- PS.Save = {};
- PS.Load = {};
- PS.Props = {};
- function PS.Save.File( dir )
- 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
- local map = game.GetMap();
- if ( file.Exists( "prop_saver/" .. map .. "/" .. dir .. ".txt" ) ) then
- file.Delete( "prop_saver/" .. map .. "/" .. dir .. ".txt" );
- print( "File '" .. dir .. ".txt' removed" );
- end
- local num = 0
- for k, v in pairs( ents.GetAll() ) do
- if ( v:GetClass() == "prop_physics" ) then
- local tempTbl = {
- Model = v:GetModel(),
- Vector = v:GetPos(),
- Angles = v:GetAngles()
- };
- table.insert( PS.Props, tempTbl );
- num = num + 1;
- end
- end
- file.Write( "prop_saver/" .. map .. "/" .. dir .. ".txt", glon.encode( PS.Props ) );
- print( num .. " props saved" );
- end
- function PS.Load.File( dir )
- 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
- local map = game.GetMap();
- if ( !file.Exists( "prop_saver/" .. map .. "/" .. dir .. ".txt" ) ) then
- print( dir .. ".txt was not found" );
- return;
- end
- /*for k, v in pairs( ents.GetAll() ) do
- if ( v:GetClass() == "prop_physics" ) then
- v:Remove();
- end
- end*/ //Uncomment those lines in order to remove all props when a new file loads
- local props = glon.decode( file.Read( "prop_saver/" .. map .. "/" .. dir .. ".txt" ) );
- for k, v in pairs( props ) do
- local prop = ents.Create( "prop_physics" );
- prop:SetModel( v:GetModel() );
- prop:SetPos( v:GetPos() );
- prop:SetAngles( v:GetAngles() );
- prop:Spawn();
- prop:Activate();
- end
- end
- function PS.Save.ConCmd( pl, cmd, args )
- local dir = args[ 1 ];
- PS.Save.File( dir );
- end
- function PS.Load.ConCmd( pl, cmd, args )
- local dir = args[ 1 ];
- PS.Load.File( dir );
- end
- concommand.Add( "ps_save", PS.Save.ConCmd );
- concommand.Add( "ps_load", PS.Load.ConCmd );
Add Comment
Please, Sign In to add comment