Author Topic: Sensing when people leave an area, dedi save/load  (Read 5258 times)

So apparently the Trigger class has been completely deleted from Blockland as far as I can tell. At least, I can't seem to make them anymore. It won't even let me define a datablock for one.

What are some options for doing a method call when a player leaves a cuboid area? Ideally,
  • It wouldn't involve big walls of bricks in any way
  • It wouldn't use an update tick to check all the god-damn time if a player has left the area.

I know triggers use ticks but they tended to be a lot faster.

EDIT: I don't want to spam the forum with topics so: What's the current state of how to save/load via console on  a dedi? Are there still shenanigans involved, and if so what are they?
« Last Edit: July 31, 2013, 09:56:21 PM by Mr. Wallet »

Triggers still work for me..

Code: [Select]
datablock TriggerData(MyTrigger) {
    tickPeriodMS=100;
};

function MyTrigger::onEnterTrigger(%this, %trigger, %obj)  {
    announce(%obj);
}

function MyTrigger::onLeaveTrigger(%this, %trigger, %obj) {
    announce("!" @ %obj);
}

new Trigger(MyTriggerInst) { datablock = MyTrigger; };

loading:
Code: [Select]
serverDirectSaveFileLoad("path", 3, "", %ownership);more information in this topic

saving is still difficult, heres the best way to do it
https://dl.dropboxusercontent.com/u/50959273/Blockland%20Private/saving.txt

Thanks guys!

I would be less nervous about using the save thing if it were an RTB add-on that people had been giving bug reports for already, but whatever I'm sure I'll fix any problems if they come up.

As for triggers, I thought it was very peculiar that I didn't seem to be able to make a trigger in the mission editor, which used to work... but if you say they work, when you do the code above, even though that's what I was doing, I'm inclined to believe you. Blockland has a habit of not working until the third time you restart it trying to do the exact same thing.

Code: [Select]
//***************************************************
//* Save Bricks
//***************************************************
function RTB_Hosting::saveBricks(%this,%filename)
{
    if(%this.saving)
        return;

    %bricks = getBrickCount();
    if(%bricks <= 0)
        return;

    if($RTBHosting::AnnounceSave)
        messageAll('', 'Saving bricks. Please wait.');
   
    %this.saveBricks = 0;
    %this.saveStart = $Sim::Time;
    %this.saveFilename = %filename;
    %this.saving = true;

    %this.savePath = "saves/" @ %filename;
     
    %file = %this.saveFile = new FileObject();
    %file.openForWrite(%this.savePath);
    %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("RTB Hosting Automated Save File - Taken at " @ getDateTime());
   
    for(%i=0;%i<64;%i++)
        %file.writeLine(getColorIDTable(%i));
   
    %file.writeLine("Linecount TBD");

    %this._brickGroupDig(0);
}

//- RTB_Hosting::_saveEnd (called when saving is complete)
function RTB_Hosting::_saveEnd(%this)
{
    %this.saveFile.close();
    %this.saveFile.delete();

    %this.saving = false;
   
    %diff = mFloatLength($Sim::Time - %this.saveStart,2);
    if(getSubStr(%diff,0,1) $= "-")
        %diff = "0.00";
   
    if($RTBHosting::AnnounceSave)
        messageAll('', '%1 bricks saved in %2', %this.saveBricks, getTimeString(%diff));

    %this.commClient.send("packSave\t" @ %this.saveFilename @ "\r\n");
}

//- RTB_Hosting::_writeBrick (writes data for a single brick to file)
function RTB_Hosting::_writeBrick(%this,%brick)
{
    RTB_Hosting.saveBricks++;
   
    %print = (%brick.getDataBlock().hasPrint) ? getPrintTexture(%brick.getPrintID()) : "";
   
    %file = %this.saveFile;
    %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(%brick.isBasePlate())
        %file.writeLine("+-OWNER " @ getBrickGroupFromObject(%brick).bl_id);
    if(%brick.getName() !$= "")
        %file.writeLine("+-NTOBJECTNAME " @ %brick.getName());
    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);
     
    for(%i=0;%i<%brick.numEvents;%i++)
    {
        %targetClass = %brick.eventTargetIdx[%i] >= 0 ? getWord(getField($InputEvent_TargetListfxDTSBrick_[%brick.eventInputIdx[%i]], %brick.eventTargetIdx[%i]), 1) : "fxDtsBrick";
        %paramList = $OutputEvent_parameterList[%targetClass, %brick.eventOutputIdx[%i]];
        %params = "";
        for(%j=0;%j<getFieldCount(%paramList);%j++)
        {
            if(firstWord(getField(%paramList,%j)) $= "dataBlock" && %brick.eventOutputParameter[%i,%j+1] >= 0)
                %params = %params TAB %brick.eventOutputParameter[%i, %j+1].getName();
            else
                %params = %params TAB %brick.eventOutputParameter[%i, %j+1];
        }
        %file.writeLine("+-EVENT" TAB %i TAB %brick.eventEnabled[%i] TAB %brick.eventInput[%i] TAB %brick.eventDelay[%i] TAB %brick.eventTarget[%i] TAB %brick.eventNT[%i] TAB %brick.eventOutput[%i] @ %params);
    }
}

//- RTB_Hosting::_brickGroupDig (digs through brick groups)
function RTB_Hosting::_brickGroupDig(%this,%index)
{
    if(%index >= mainBrickGroup.getCount())
    {
        %this._saveEnd();
        return;
    }
    %this._brickDig(mainBrickGroup.getObject(%index),0,%index,%count);
}

//- RTB_Hosting::_brickDig (recurses through a brick group in a semi-non-blocking way)
function RTB_Hosting::_brickDig(%this,%group,%index,%childIndex,%count)
{
    if(%index >= %group.getCount())
    {
        %this._brickGroupDig(%childIndex++);
        return;
    }

    if(!isObject(%this.saveFile))
    {
        %this.saveFile = new FileObject();
        %this.saveFile.openForAppend(%this.savePath);
    }
    %this._writeBrick(%group.getObject(%index));
   
    if(%count >= 500)
    {
        %this.saveFile.close();
        %this.saveFile.delete();

        %this.schedule(100,"_brickDig",%group,%index++,%childIndex,0);
    }
    else
        %this._brickDig(%group,%index++,%childIndex,%count++);
}
alternatively here is the code from the rtb hosting auto saver



Is that open source? Because otherwise how would that be helpful at all.

Is that open source? Because otherwise how would that be helpful at all.
Well it seems that swollow just posted the script.

Well it seems that swollow just posted the script.
This lol
Seems pretty open-source to me

I've incorporated the rtb saving method into my Save Auto Loader
it's by far the most reliable saving method we have

Soz I didn't know swollow had anything to do with RTB

I know basically nothing about this community because I hide away in my own little server forever,  :panda: fortunately it also shields me from "drama" which is apparently happening all the time to hear tell of it but I wouldn't know  :cookieMonster:

Soz I didn't know swollow had anything to do with RTB
No, I think he rents an RTB server and has FTP access.

I want to call a function which loads a brick file and starts a schedule. After the schedule expires, another function runs, unless the bricks are still loading, in which case it will postpone until loading is complete. I have a few options and I was wondering what you guys thought would be good:
  • I could detect that bricks are still loading and just have it schedule itself for 1 second over and over until I notice bricks aren't loading anymore. For this approach, I need to detect if bricks are loading. Is there a built-in way to check, or would I need to package something?
  • I could just not do it and give up if bricks are loading, and package the brick loading process to check at the end if that schedule is pending, and if not call the function itself. As IIRC there's no unique function that runs at the end of brick loading, packaging this would be a little... messy.
  • I could set the schedule to call a "listener" that listens for a flag, and package the brick load function to set the flag, so if the flag is set between the listener's schedules of itself, it postpones until the flag stops being set. This is a tiny bit clunkier than option one, but would probably be a tiny bit easier and less bug-prone if there's no built-in "bricks are loading" detection.

You're taking a far more complicated approach than you need to.

Just load the bricks and then package ServerLoadSaveFile_End(), which will call your post-loading function.