Author Topic: Dedicated saver  (Read 579 times)

A function for saving all bricks on a dedicated server would be nice.
Quote
This is a Blockland save file.  You probably shouldn't modify it cause you'll screw it up.
If it shouldn't be messed with, it should actually be supported fully. A function like saveallbricks("Filepath","Filename"); would be cool. I am currently trying to save bricks automatically on a dedicated server, but there are just so many things that have to be covered for it to actually work.
This would easily allow for build backup on dedicated servers that can sometimes prove to go down at the worst times, or support for more spread apart town builds or adventures without having to teleport all over the map.

This doesn't seem like something extremely difficult for badspot to do, and it could really be helpful to so many people if it existed.


too bad it sucks and ownership is broken

too bad it sucks and ownership is broken
What do you mean it sucks?
Let me find something I have had for a while, that should help you :)

it doesn't save ownership correctly and I'm a noob so I cant fix it

Code: [Select]
function saveBricks(%name,%events,%ownership)
{
   if(%name $= "" || %events $= "" || %ownership $= "" || (%events !$= 1 && %events !$= 0) || (%ownership !$= 1 && %ownership !$= 0))
   {
      echo("Usage: saveBricks(\"savename\",save events,save ownership);");
      return;
   }
   
%path = "saves/" @ MissionInfo.saveName @ "/" @ %name @ ".bls";
if(!isWriteableFileName(%path))
{
echo("Error: Cannot save to file: "@%path);
return;
}

%bricks = 0;
for(%i=0;%i<mainBrickGroup.getCount();%i++)
%bricks += mainBrickGroup.getObject(%i).getCount();

   if(%bricks <= 0)
   {
      echo("Error: There are no bricks to save.");
      return;
   }
echo("Saving to "@%path@" ...");

%file = new FileObject();
%file.openForWrite(%path);
%file.writeLine("This is a Blockland save file.  You probably shouldn't modify it cause you'll screw it up.");
%file.writeLine("1");
%file.writeLine(%desc);
for(%i=0;%i<64;%i++)
%file.writeLine(getColorIDTable(%i));
%file.writeLine("Linecount " @ %bricks);
for(%d=0;%d<2;%d++)
{
for(%i=0;%i<mainBrickGroup.getCount();%i++)
{
%group = mainBrickGroup.getObject(%i);
for(%a=0;%a<%group.getCount();%a++)
{
%brick = %group.getObject(%a);
if(!(%d ^ %brick.isBasePlate()))
continue;
%print = (%brick.getDataBlock().subCategory $= "Prints") ? getPrintTexture(%brick.getPrintID()) : "";
%file.writeLine(%brick.getDataBlock().uiName @ "\" " @ %brick.getPosition() SPC %brick.getAngleID() SPC %brick.isBasePlate() SPC %brick.getColorID() SPC %print SPC %brick.getColorFXID() SPC %brick.getShapeFXID() SPC %brick.isRayCasting() SPC %brick.isColliding() SPC %brick.isRendering());
if(%ownership && %brick.isBasePlate() && !$Server::LAN)
%file.writeLine("+-OWNER " @ getBrickGroupFromObject(%brick).bl_id);
if(%events)
{
if(%brick.getName() !$= "")
%file.writeLine("+-NTOBJECTNAME " @ %brick.getName());
if(%brick.numEvents > 0)
{
for(%b=0;%b<%brick.numEvents;%b++)
{
%targetClass = %brick.eventTargetIdx[%b] >= 0 ? getWord(getField($InputEvent_TargetListfxDTSBrick_[%brick.eventInputIdx[%b]], %brick.eventTargetIdx[%b]), 1) : "fxDtsBrick";
%paramList = $OutputEvent_parameterList[%targetClass, %brick.eventOutputIdx[%b]];
%params = "";
for(%c=0;%c<4;%c++)
{
if(firstWord(getField(%paramList, %c)) $= "dataBlock" && %brick.eventOutputParameter[%b, %c + 1] >= 0)
%params = %params TAB %brick.eventOutputParameter[%b, %c + 1].uiName;
else
%params = %params TAB %brick.eventOutputParameter[%b, %c + 1];
}
%file.writeLine("+-EVENT" TAB %b TAB %brick.eventEnabled[%b] TAB %brick.eventInput[%b] TAB %brick.eventDelay[%b] TAB %brick.eventTarget[%b] TAB %brick.eventNT[%b] TAB %brick.eventOutput[%b] @ %params);
}
}
}
if(isObject(%brick.emitter))
%file.writeLine("+-EMITTER " @ %brick.emitter.emitter.uiName @ "\" " @ %brick.emitterDirection);
if(%brick.getLightID() >= 0)
%file.writeLine("+-LIGHT " @ %brick.getLightID().getDataBlock().uiName @ "\" ");
if(isObject(%brick.item))
%file.writeLine("+-ITEM " @ %brick.item.getDataBlock().uiName @ "\" " @ %brick.itemPosition SPC %brick.itemDirection SPC %brick.itemRespawnTime);
if(isObject(%brick.audioEmitter))
%file.writeLine("+-AUDIOEMITTER " @ %brick.audioEmitter.getProfileID().uiName @ "\" ");
if(isObject(%brick.vehicleSpawnMarker))
%file.writeLine("+-VEHICLE " @ %brick.vehicleSpawnMarker.uiName @ "\" " @ %brick.reColorVehicle);
}
}
}
%file.close();
%file.delete();

echo(%bricks@" bricks saved to "@%path@" successfully.");
}
Remember this?