Author Topic: [Solved] Brick Generation Problems  (Read 1268 times)

When I generate the desired bricks via script, some of them you can see, but I don't think they technically exists(it's usually every other one).

Also, you get the overlap error whenever you try planting a brick next to one of them. But you don't get it if you manually plant one of the bricks.

Code: [Select]
function BlockMiner_createRandomMineable(%pos)
{
if(getRandom(1, 100) <= 85)
{
%mineable = BlockMiner_getCurrLayer(%pos);
%layer = true;
}

else
{
%mineable = BlockMiner_getRandomOre(%pos);

if(%mineable == -1)
{
%mineable = BlockMiner_getCurrLayer(%pos);
%layer = true;
}
}

if(%mineable == -1)
{
echo("\c2BlockMiner_createRandomMineable - Something went very wrong!");

return;
}

if(%layer)
{
%color = $BlockMiner::LayerData[%mineable, "colorID"];
%fx = $BlockMiner::LayerData[%mineable, "colorFX"] == -1 ? 0 : $BlockMiner::LayerData[%mineable, "colorFX"];
%shapeFX = $BlockMiner::LayerData[%mineable, "shapeFX"] == -1 ? 0 : $BlockMiner::LayerData[%mineable, "shapeFX"];
}

else
{
%color = $BlockMiner::OreData[%mineable, "colorID"];
%fx = $BlockMiner::OreData[%mineable, "colorFX"] == -1 ? 0 : $BlockMiner::OreData[%mineable, "colorFX"];
%shapeFX = $BlockMiner::OreData[%mineable, "shapeFX"] == -1 ? 0 : $BlockMiner::OreData[%mineable, "shapeFX"];
}

%brick = new fxDTSBrick()
{
datablock = brickBlockMinerOreData;
position = %pos;
rotation = "0 0 0 0";
colorID = %color;
scale = "1 1 1";
angleID = 0;
colorFxID = %fx;
shapeFxID = %shapeFX;
isPlanted = 1;
isBaseplate = 1;
client = -1;
stackBL_ID = -1;

isMineable = true;
mineable = %mineable;
};

if(%layer)
{
%brick.mineableName = $BlockMiner::LayerData[%mineable, "uiName"];
%brick.health = $BlockMiner::LayerData[%mineable, "health"];
%brick.minLevel = $BlockMiner::LayerData[%mineable, "minLevel"];
%brick.dirtAmount = $BlockMiner::LayerData[%mineable, "dirtAmt"];
}

else
{
%brick.mineableName = $BlockMiner::OreData[%mineable, "uiName"];
%brick.health = $BlockMiner::OreData[%mineable, "health"];
%brick.minLevel = $BlockMiner::OreData[%mineable, "minLevel"];
%brick.value = $BlockMiner::OreData[%mineable, "value"];
%brick.maxVein = $BlockMiner::OreData[%mineable, "maxVein"];
}

%brick.setTrusted(0);
%error = %brick.plant();

echo("ERROR:" SPC %error);

//Brick ERRORS.
//0 = None.
//1 = Overlap.
//2 = Float.
//3 = Stuck.
//5 = Buried.

//Too far doesn't give an error number. Dunno why.
//No idea what error numbers Flood, Limit, Too Loud, or Unstable had.

if(%error != 0 && %error != 2 && %error != 3 && %error != 5)
{
echo("\c2DELETE");
//%brick.schedule(0, delete);
//return -1;
}

if(%layer)
{
%brick.setPrintByName($BlockMiner::LayerData[%mineable, "printUI"]);
%brick.setEmitter($BlockMiner::LayerData[%mineable, "emitter"]);
%brick.setLight($BlockMiner::LayerData[%mineable, "light"]);
}

else
{
%brick.setPrintByName($BlockMiner::OreData[%mineable, "printUI"]);
%brick.setEmitter($BlockMiner::OreData[%mineable, "emitter"]);
%brick.setLight($BlockMiner::OreData[%mineable, "light"]);
}

BrickGroup_888888.add(%brick);
$Server::BrickCount++;

return %brick;
}
« Last Edit: August 15, 2015, 06:32:52 AM by jes00 »

I don't know why you're doing setTrusted(0); but try setTrusted(1); , that's what I use. I also had a problem where I couldn't place bricks adjacent to another, and it was because I was forgetting to call setTrusted.

Ninja: I also call plant() after setTrusted(1) so you could try that.

I don't know why you're doing setTrusted(0); but try setTrusted(1); , that's what I use. I also had a problem where I couldn't place bricks adjacent to another, and it was because I was forgetting to call setTrusted.

Ninja: I also call plant() after setTrusted(1) so you could try that.

This will solve your problem. setTrusted(1) and plant().

Also Unstable has error #4, and the default case being "forbidden"

Sweet. It works now.
What's the exact purpose of setTrusted though?
I set it to 0 because I didn't want anyone doing anything to the bricks.

the default case being "forbidden"
What do you mean by this? 0 means there is no error.

What do you mean by this? 0 means there is no error.
Switch case 0 and case default are different.

Default case is executed when no other case above worked. Forbidden isn't a plant error, that just means something messed up and it's not one of the known error numbers.

On a somewhat related note.
Does anyone know why this function is messing up?
Code: [Select]
function generateMineablesAround(%pos, %size)
{
//Generates mineable materials(dirt, ores, etc.) in a rectangle of %size(vector3F).

%x = firstWord(%pos);
%y = getWord(%pos, 1);
%z = getWord(%pos, 2);

%sizeX = firstWord(%size);
%sizeY = getWord(%size, 1);
%sizeZ = getWord(%size, 2);
%sizeZ /= 2;

for(%h = %z; %h < %z + (%sizeZ) - 2; %h += 2)
{
for(%i = %x - (%sizeX / 2); %i < %x + (%sizeX / 2) + 2; %i += 2)
{
BlockMiner_createRandomMineable(%i SPC %y + (%y / 2) - 2 SPC %h);
BlockMiner_createRandomMineable(%i SPC %y - (%y / 2) + 3 SPC %h);
}

for(%i = %y + (%sizeY / 2) + 0.5; %i > %y - (%sizeY / 2); %i -= 2)
{
BlockMiner_createRandomMineable(%x + (%x / 2) - 2.5 SPC %i SPC %h);
BlockMiner_createRandomMineable(%x - (%x / 2) + 2.5 SPC %i SPC %h);
}
}
}
I works fine at position x -25 y 50 but the farther I move the position away from that, the farther apart the generated walls of bricks go away from each other.


I feel like it might be because of the %y + (%y / 2) etc. parts.
You're effectively doing (3/2)*%y which I don't think is what you want?

so one is .5 * %y, while the other brick is 1.5 * %y, so it's a %y gap each time
so as your Y value gets larger, the bricks should spread

I feel like it might be because of the %y + (%y / 2) etc. parts.
You're effectively doing (3/2)*%y which I don't think is what you want?
Huzzah! Don't see how I didn't see that.