Last active
December 13, 2018 20:32
-
-
Save QuadStorm/3d49d5b58a5938508b184ffd346e7903 to your computer and use it in GitHub Desktop.
Terrain to Bricks, direct to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//BrickifyTerrain | |
//Turns map terrain into a 4x4 cubescape (I couldn't think of a better name) | |
%cubes = forceRequiredAddOn("Brick_Large_Cubes"); | |
if(%cubes == $Error::AddOn_NotFound) | |
return; | |
$dbSelect = brick4xCubeData; // For use in Brickadia, Replace the UI name in resulting BLS files with with 4x4x200f | |
$dbSp = 2; | |
$factor = 3; | |
$factor2 = 2; | |
function ServerCmdBrickifyTerrainAvgFile(%client,%bound,%color,%filename) | |
{ | |
$nExtra = 0; | |
%topCt = 0; | |
%dbSp = $dbSp; | |
%curPos = %client.player.getPosition(); | |
echo("Current Position - (" @ %curPos @ ")"); | |
%hbound = %bound * %dbSp / 2; | |
%rPos = mRound(getWord(%curPos,0),2) SPC mRound(getWord(%curPos,1),2) SPC getWord(%curPos,2); | |
%start = vectorAdd(%rPos,%hbound SPC %hbound @ " 0"); | |
for(%x=0;%x<%bound;%x++) | |
{ | |
for(%y=0;%y<%bound;%y++) | |
{ | |
%xPos = getWord(%start,0) - %dbSp * %x; | |
%yPos = getWord(%start,1) - %dbSp * %y; | |
$t = 0; | |
%avgHeight = 0; | |
%xPosB = 0; | |
%yPosB = 0; | |
if ($factor) | |
{ | |
for (%xa = -$factor; %xa <= $factor; %xa++) | |
{ | |
for (%ya = -$factor; %ya <= $factor; %ya++) | |
{ | |
%xPosB = %xPos + %xa * $dbSp * $factor2; | |
%yPosB = %yPos + %ya * $dbSp * $factor2; | |
%avgHeight += mRound(getTerrainHeight(%xPosB SPC %yPosB) - 16, 5); | |
//echo($t++ SPC getTerrainHeight(%xPosB SPC %yPosB)); | |
} | |
} | |
} | |
%avgHeight = %avgHeight / mPow($factor * 2 + 1, 2); | |
//echo(%avgHeight); | |
%zPos = mRound(%avgHeight, 5); | |
//%zPos = mRound(getTerrainHeight(%xPos SPC %yPos),5); | |
%place = %xPos SPC %yPos SPC %zPos; | |
%file = new FileObject(); | |
if (%file.openForAppend("config/server/terrain" @ %filename @ ".blsf")) | |
{ | |
%file.writeLine("4x Cube\"" SPC %place SPC "r"); // https://forum.blockland.us/index.php?topic=290622.0 replace "r" with "0 1 15 0 0 1 1 1" | |
} | |
%file.close(); | |
%file.delete(); | |
%topCt++; | |
} | |
} | |
TerraFinish(%topCt); | |
} | |
function TerraFinish(%topCt) | |
{ | |
messageAll('',"Brickifying completed \c6(" @ getDateTime() @ ")"); | |
messageAll('',"\c6" @ %topCt @ "\c0 grid bricks created"); | |
messageAll('',"\c6" @ $nExtra @ "\c0 added layer bricks created"); | |
%total = %topCt + $nExtra; | |
messageAll('',"\c6" @ %total @ "\c0 bricks created total"); | |
if(%total != $Server::brickcount) | |
echo("Error TerraFinish(); - Brickcount does not match number of bricks created (" @ $Server::brickcount @ ")"); | |
} | |
function mRound(%float,%index) | |
{ | |
%float *= %index; | |
if(mAbs(%float - mFloor(%float)) >= 0.5) | |
return mCeil(%float) / %index; | |
else | |
return mFloor(%float) / %index; | |
} | |
function isTerrBrick(%pos) | |
{ | |
%brick = containerFindFirst($TypeMasks::fxBrickObjectType,%pos,0.1,0.1,0.1); | |
if(%brick == 0) | |
return -1; | |
if(%pos $= %brick.position) | |
return 1; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment