Author Topic: function to spawn bricks?  (Read 998 times)

blockland modding documentation is so spotty that i cant reliably find anything on it.

Is there a function somewhere that'll spawn blocks in a certain location or something?

This is something that's lying in my pastebin. Important things to note are as follow:

%color is an ID (integer), to get it manually, count on the paint menu starting on the top left, moving down and then going to the right, it would look smth like this:
036
147
258

So color ID for green would be 1.

EDIT: Corrected colorID to start from 0

%client field in that example is going to represent the host, since getNumKeyID() returns the host's BL_ID.

stackBL_ID in that example is %client.bl_id, but in retrospect, you probably want to use whatever you used for findClientByBL_ID. For host, this would then be
Code: [Select]
stackBL_ID = getNumKeyID();
This is in case the server is dedicated and the host isn't in the server, or the player you want to own the bricks isn't on the server -> the %client wouldn't exist.

Code: [Select]
position = VectorAdd(%x/2 SPC %y/2 SPC "50", $Temple::Position);
...
$Temple::Map::chunk[%x, %y] = %brick;
These are snippets that are specific to the project I was working on. The position is a string of three numbers (x y z coordinates) separated by spaces (i.e. 12 5 3) and the second part can be deleted alltogether.

Code: [Select]
BrickGroup_17003.add(%brick);
This is mentioned in the paste as well, but BrickGroup_### is a simset for all of a client's bricks. The ### is the BL_ID of the client.
« Last Edit: October 26, 2017, 07:06:29 AM by Dannu »

%color is an ID (integer), to get it manually, count on the paint menu starting on the top left, moving down and then going to the right, it would look smth like this:
147
258
369

So color ID for green would be 2.
Nooooooo.
It starts from 0.


Code: [Select]
function nothereisntafunctionlikethat()
{
%brick = new fxdtsbrick()
{
datablock = "brick1x1Data";
position = "0.25 0.25 0.3";
rotation = "0 0 1 90";
isplanted = 1;
};
%brick.setColor(10);
brickgroup_31546.add(%brick);
%brick.setTrusted(1);
%err = %brick.plant();
if(%err!=0||%err!=2)
{
%brick.schedule(1,"delete");
}
}

%brick will be the object id of the newly created brick.

you can replace brick1x1Data with the name of the datablock of whatever brick you're trying to create
position is the center of the brick and will snap to the grid automatically.
rotation is an axis angle formula [x y z][angle]  in this case we rotate around the z axis, and we pick an angle divisible by 90, negatives are accepted I think?
isplanted defines whether its a ghost brick or not.  Like some variables, this should only do it's job at the initial creation of the brick.  Changing isPlanted after the brick is created may not have the desired effect.

afaik brick color has to be set after the brick is created, but i may be wrong
add the brick to a brickgroup so it will be autodeleted on server shutdown, and so it interacts with the wrench properly

if we want to plant the brick, we can either do a trust check or cut through that bullstuff and just set it as trusted.
bricks will generate an error number when planted, 0 means OK, 2 means its floating, I forget the rest.
aside from "too far", the rest of the errors mean the brick probably wont work right, so we just delete the brick if it didn't plant correctly.


changing isPlanted after the brick is created will NOT have the desired effect - must call %brick.plant(); if you want it to change

brick.setTrusted(1) is required for any created bricks that stick around as not calling it will create a 1 stud/brick zone around the brick that you cannot plant/build in. havent experimented enough with it to figure out the details, but basically if you create a brick you have to call that if you're not going to delete the brick immediately due to some other reason (ex, trust check failing).

%brick.plant should be called AFTER adding it to the brickgroup i believe since a number of special bricks (like the spawn brick) interact with the brickgroup the brick is part of - namely, calling certain functions to make sure the brickgroup knows the spawn brick exists. same goes for named bricks: however, the format for named bricks is "_name" so if you're creating named bricks make sure to include an _ prefixing the name.

a brick's position is the center of the brick bounds. the brick grid works on the dimensions of 0.5 x 0.5 x 0.2 (the dimensions of a plate), and the global position 0 0 0 is in the center of a 2x2 stud area (eg not in the middle of a stud). putting invalid positions into a brick when creating it wont cause problems - the brick will just snap to the closest valid location from that position.
« Last Edit: October 26, 2017, 12:01:25 PM by Conan »