Author Topic: Dedicated and in-game servers are doing different things when loading bricks  (Read 2114 times)

Code: [Select]
if(!$Platforms::HasInit) {
new SimGroup(BrickGroup_Platforms : BrickGroup_888888);
mainBrickGroup.add(BrickGroup_Platforms);
}

function loadLayout(%which) {
// blockland pls
// let me set commands to simsets
// pls
%this = PlatformLayouts;

PlatformAI.loadingLayout = 1;
%group = BrickGroup_Platforms;
%group.deleteAll();
messageAll('',"\c4AI: \c6Loading a new layout...");

if(!%which) {
if(%this.currentLayout $= "") {
%this.currentLayout = 0;
} else {
%this.currentLayout++;
}
if(%this.currentLayout > %this.getCount()) {
%this.currentLayout = 0;
}
%which = %this.currentLayout;
}
$LoadingBricks_BrickGroup = BrickGroup_Platforms;
$LoadingBricks_Client = -1;
$LoadingBricks_ColorMethod = 3; //should always be 3
$LoadingBricks_FileName = %this.getObject(%which).file;
$LoadingBricks_Silent = true;
$LoadingBricks_StartTime = getSimTime();
ServerLoadSaveFile_Start(%this.getObject(%which).file);
}

package FallingPlatformsLayoutPackage {
function fxDTSBrick::onLoadPlant(%this) {
parent::onLoadPlant(%this);

if(PlatformAI.loadingLayout) {
BrickGroup_Platforms.add(%this);
}
}

function ServerLoadSaveFile_End() {
parent::ServerLoadSaveFile_End();

if(!$Platforms::HasInit) {
gatherLayouts();
loadLayout(getRandom(0,PlatformLayouts.getCount()-1));
if(isFile("config/server/Platforms/leaderboard.cs")) {
exec("config/server/Platforms/leaderboard.cs");
}
$Platforms::HasInit = 1;
return;
}
if(PlatformAI.loadingLayout) {
PlatformAI.loadingLayout = 0;
PlatformAI.schedule(200,reset);
}

echo("GETTING PLATFORM BRICKS");
gatherPlatformBricks();
echo("GETTING PROJECTILE BRICKS");
schedule(500,0,gatherProjectileBricks);
}
};
activatePackage(FallingPlatformsLayoutPackage);

With in-game hosting, this works fine.
Dedicated servers however, bricks loaded through this on the first time it's called are put into BrickGroup_888888, even though I explicitly said to put them into BrickGroup_Platforms (the game reacts fine to this, again it works perfectly fine if it's not dedicated).

PlatformAI.loadingLayout during this time is 1, I've made sure.
BrickGroup_Platforms does exist the first time it's called.
Layouts are loaded after the initial loading of save.bls.

EDIT 1: BrickGroup_Platforms isn't added to mainBrickGroup, delaying it to the next frame also does nothing.
EDIT 2: Making sure BrickGroup_Platforms is added to mainBrickGroup before loading does nothing to help, but it's now in mainBrickGroup.
« Last Edit: March 01, 2015, 03:54:54 AM by TheBlackParrot »

Code: [Select]
if(!$Platforms::HasInit) {
new SimGroup(BrickGroup_Platforms : BrickGroup_888888);
mainBrickGroup.add(BrickGroup_Platforms);
}

function loadLayout(%which) {
// blockland pls
// let me set commands to simsets
// pls
%this = PlatformLayouts;

PlatformAI.loadingLayout = 1;
%group = BrickGroup_Platforms;
%group.deleteAll();
messageAll('',"\c4AI: \c6Loading a new layout...");

if(!%which) {
if(%this.currentLayout $= "") {
%this.currentLayout = 0;
} else {
%this.currentLayout++;
}
if(%this.currentLayout > %this.getCount()) {
%this.currentLayout = 0;
}
%which = %this.currentLayout;
}
if(BrickGroup_Platforms.getGroup() $= "") {
mainBrickGroup.add(BrickGroup_Platforms);
}
$LoadingBricks_BrickGroup = BrickGroup_Platforms;
$LoadingBricks_Client = -1;
$LoadingBricks_ColorMethod = 3; //should always be 3
$LoadingBricks_FileName = %this.getObject(%which).file;
$LoadingBricks_Silent = true;
$LoadingBricks_StartTime = getSimTime();
ServerLoadSaveFile_Start(%this.getObject(%which).file);
}

package FallingPlatformsLayoutPackage {
function fxDTSBrick::onLoadPlant(%this) {
parent::onLoadPlant(%this);

if(PlatformAI.loadingLayout) {
BrickGroup_Platforms.schedule(1,add,%this);
}
}

function ServerLoadSaveFile_End() {
parent::ServerLoadSaveFile_End();

if(!$Platforms::HasInit) {
gatherLayouts();
loadLayout(getRandom(0,PlatformLayouts.getCount()-1));
if(isFile("config/server/Platforms/leaderboard.cs")) {
exec("config/server/Platforms/leaderboard.cs");
}
$Platforms::HasInit = 1;
return;
}
if(PlatformAI.loadingLayout) {
PlatformAI.loadingLayout = 0;
PlatformAI.schedule(200,reset);
}

echo("GETTING PLATFORM BRICKS");
gatherPlatformBricks();
echo("GETTING PROJECTILE BRICKS");
schedule(500,0,gatherProjectileBricks);
}
};
activatePackage(FallingPlatformsLayoutPackage);

Delaying adding the brick to the group to the next frame seems to have fixed it, but I feel like there's something better I could do.

Two things. One, there's already a function for loading a save file and you don't need to hack up the literal load save file function.

serverDirectSaveFileLoad(%fileName, 3, "", %ownership)

So, this makes your life easier, but %ownership can only have three values: 0 loads as host, 1 loads as default ownership, and 2 loads as public. So, since you want to use a weird name like BrickGroup_Platforms instead of following the nomenclature the game uses, none of these will do what you want automatically.

So, secondly, there's a solution to this, but it's a little roundabout. Load the bricks into public and then instantly transfer them into the correct brickgroup:

while(brickGroup_888888.getCount() > 0)
    BrickGroup_Platforms.add(brickGroup_888888.getObject(0));

Trinick is right, but instead of transferring all the bricks you could simply rename BrickGroup_888888 to BrickGroup_Platforms and then recreate the public brickgroup.

Trinick is right, but instead of transferring all the bricks you could simply rename BrickGroup_888888 to BrickGroup_Platforms and then recreate the public brickgroup.
This is true. You could run the following code to place all the bricks into a group called BrickGroup_Platforms, but then the group would have all the traits of the public brick group aside from its name. I assumed the reason you wanted a brick group other than BrickGroup_888888 was because you had attributes on the object that you wanted different from the public brick group, in which case moving all the bricks over is probably still the best way.

Code: [Select]
%newBG = new ScriptObject(:BrickGroup_888888);
serverDirectSaveFileLoad(%fileName, 3, "", 2);
BrickGroup_888888.setName("BrickGroup_Platforms");
%newBG.setName("BrickGroup_888888");

I guess you could simply reset the attributes to what you need. It's much less processor-intensive than moving thousands of bricks.

I'm not looking to load everything in 888888 over to Platforms though.
What I'm doing is loading a game board/layout/etc. after I load the shell/area that surrounds it, and that one specific group (Platforms, not 888888) is cleared every 5 games.

I don't need that outer shell in Platforms. Looping through that many bricks would be a nightmare.

I guess you could simply reset the attributes to what you need. It's much less processor-intensive than moving thousands of bricks.
Brick amounts range from ~300 - ~1200 so far.

Load them into whatever brickgroup (Public, yours, etc.) and just add them all to a SimSet.

would it be possible and efficient to set some sort of temporary flag and intercept onLoadPlant to add the bricks to the appropriate brickgroup?

would it be possible and efficient to set some sort of temporary flag and intercept onLoadPlant to add the bricks to the appropriate brickgroup?
That's what I'm doing
Code: [Select]

function fxDTSBrick::onLoadPlant(%this) {
parent::onLoadPlant(%this);

if(PlatformAI.loadingLayout) {
BrickGroup_Platforms.schedule(1,add,%this);
}
}

The best option for you is honestly to use the function I provided with the ownership value 0 for save-defined ownership. Go through your saves and attribute each part that needs to be in a specific brick group to that brickgroup, then when you load it with save-defined ownership the bricks will all be in their proper brickgroups. The group won't be named BrickGroup_Platforms but BrickGroup_888889 works just as well.