Author Topic: Auto Saver  (Read 6183 times)

Does anyone know why this will not save brick ownership?
Quote
if(isFile("Add-Ons/System_ReturnToBlockland/server.cs"))
{
   if(!$RTB::RTBR_ServerControl_Hook)
   {
      exec("Add-Ons/System_ReturnToBlockland/RTBR_ServerControl_Hook.cs");
   }
   RTB_registerPref("File name","Auto Saver","$AutoSaver::SaveFile","string 255","Server_AutoSaver","autosave",0,0);
   RTB_registerPref("Loop time","Auto Saver","$AutoSaver::SaveTime","int 1 1440","Server_AutoSaver",30,0,0);
   RTB_registerPref("Save ownership","Auto Saver","$AutoSaver::SaveOwnership","bool","Server_AutoSaver",1,0,0);
   RTB_registerPref("Save events","Auto Saver","$AutoSaver::SaveEvents","bool","Server_AutoSaver",1,0,0);
}
else
{
   $AutoSaver::SaveFile = "autosave";
   $AutoSaver::SaveTime = 30;
   $AutoSaver::SaveOwnership = 1;
   $AutoSaver::SaveEvents = 1;
}
function AutoSaver_saveLoop()
{
   cancel($AutoSaver::SaveLoop);
   if($AutoSaver::SaveTime < 1)
   {
      $AutoSaver::SaveTime = 1;
   }
   if($AutoSaver::SaveFile $= "")
   {
      $AutoSaver::SaveFile = "autosave";
   }
   dediSave(fileBase($AutoSaver::SaveFile),$AutoSaver::SaveEvents,$AutoSaver::SaveOwnership);
   $AutoSaver::SaveLoop = schedule($AutoSaver::SaveTime * 60000,0,"AutoSaver_saveLoop");
}
//Modified version of Randy's saveBricks function
function dediSave(%name, %desc, %events, %ownership)
{
   %path = "saves/" @ MissionInfo.saveName @ "/" @ %name @ ".bls";
   if(!isWriteableFileName(%path))
   {
      error("Cannot save to file: ", %path);
      return;
   }
   %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"); // What does this mean?
   %file.writeLine(%desc);
   for(%i=0;%i<64;%i++)
      %file.writeLine(getColorIDTable(%i));
   %bricks = 0;
   for(%i=0;%i<mainBrickGroup.getCount();%i++)
      %bricks += mainBrickGroup.getObject(%i).getCount();
   %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;
            if(%brick.getDataBlock().hasPrint)
            {
               %texture = getPrintTexture(%brick.getPrintId());
               %path = filePath(%texture);
               %underscorePos = strPos(%path, "_");
               %name = getSubStr(%path, %underscorePos + 1, strPos(%path, "_", 14) - 14) @ "/" @ fileBase(%texture);
               if($printNameTable[%name] !$= "")
               {
                  %print = %name;
               }
            }
            %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());
               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" && isObject(%brick.eventOutputParameter[%b, %c + 1]))
                        %params = %params TAB %brick.eventOutputParameter[%b, %c + 1];
                     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 @ "\" "); // Not sure if something else comes after the name
            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 @ "\" "); // Not sure if something else comes after the name
            if(isObject(%brick.vehicleSpawnMarker))
               %file.writeLine("+-VEHICLE " @ %brick.vehicleSpawnMarker.uiName @ "\" " @ %brick.reColorVehicle);
         }
      }
   }
   %file.close();
   %file.delete();
   messageAll('',"Auto Saver: "@%bricks@" bricks have been successfully saved.");
}
function serverCmdStartAutoSaver(%client)
{
   if(%client.isSuperAdmin)
   {
      cancel($AutoSaver::SaveLoop);
      $AutoSaver::SaveLoop = schedule($AutoSaver::SaveTime * 60000,0,"AutoSaver_saveLoop");
      messageAll('',%client.getPlayerName() @ "\c6 has started the auto saver.");
   }
   else
   {
      messageClient(%client,'',"\c6Only \c0Super Admins\c6 may start the auto saver.");
   }
}
function serverCmdStopAutoSaver(%client)
{
   if(%client.isSuperAdmin)
   {
      cancel($AutoSaver::SaveLoop);
      messageAll('',%client.getPlayerName() @ "\c6 has stopped the auto saver.");
   }
   else
   {
      messageClient(%client,'',"\c6Only \c0Super Admins\c6 may stop the auto saver.");
   }
}
Quote
Yes, I do have the save ownership box checked in server control.
« Last Edit: December 22, 2009, 10:25:57 PM by Wicked »

It appears to only save ownership for bricks that are baseplates (because all bricks on a baseplate's owners are automatically set to owner of their baseplate). I can make an update to this soon.

Ok any help is appreciated.

It appears to only save ownership for bricks that are baseplates (because all bricks on a baseplate's owners are automatically set to owner of their baseplate). I can make an update to this soon.

This is correct behavior to avoid huge filesizes. In this case, a brick being a baseplate only means that it isn't being supported by another brick.

Wow, thanks for warning me, the fact that it would have to write the owner's id for each brick totally flew over my head.

This is correct behavior to avoid huge filesizes. In this case, a brick being a baseplate only means that it isn't being supported by another brick.
How would I get this to save everybrick's ownership without creating a huge filesize like normal saving? If it is not possible then how can you make it so it saves the brick's ownership that is touching the ground and the bricks ontop are the same ownership?

If it is not possible then how can you make it so it saves the brick's ownership that is touching the ground and the bricks ontop are the same ownership?

This is how it works currently.

Well for some reason it does not save bricks from my PeopleMods section of the brick selector ( such as lots ) for my City RPG.

Try it on an unmodded server without CityRP and see if it works then. Chances are CityRP is breaking it, or you don't know what it's meant to do when it does actually work normally.

Ok I tested it without the mod and when I reloaded the save the ownership didn't save still. I'm guessing the script has a problem in it.
« Last Edit: December 23, 2009, 04:18:04 PM by Wicked »

What was the owner being set to? From a logical point of view, this looks to work fine. I have also used this script on a bunch of occasions and it's worked fine for me.

The ownership is set to my own.

Yeah there definately must be something wrong in the script because I tried redownloading Blockland with only default addons and this one and it did the same thing.

What are you typing in the console to save it?

Oh I just use the command /startautosaver and I have the box checked in server control to save ownership.