Blockland Forums > Modification Help
Brick Creation: CreateBrick
(1/1)
Xalos:
I posted this in another thread but I feel it deserves its own thread. After all, I use this code a lot and I feel that many others would find it useful as well.


--- Code: ("Create Brick") ---function createBrick(%cl, %data, %pos, %color, %angleID)
{

   //This function was made by Xalos.
   //Its purpose is to create a brick owned by a player on which they are able to build.

   if(!isObject(%data) || %data.getClassName() !$= "fxDTSBrickData")
      return -1;
   if(getWordCount(%pos) != 3)
      return -1;
   if(%angleID $= "")
      %angleID = 0;
   if(isObject(%cl) && (%cl.getClassName() $= "GameConnection" | %cl.getClassName() $= "AIConnection"))
   {
      %blid = %cl.bl_id;
      if(%blid $= "")
         %blid = -1;
      %flag = 1;
   }
   else if(isObject(%cl) && %cl.getClassName() $= "SimGroup" && MainBrickgroup.isMember(%cl))
      %group = %cl;
   else
      %cl = 0;
   switch(%angleID)
   {
      case 0:
         %rot = "1 0 0 0";
      case 1:
         %rot = "0 0 1 90";
      case 2:
         %rot = "0 0 1 180";
      case 3:
         %rot = "0 0 -1 90";
   }
   (%brick = new fxDtsBrick()
   {
      client = %cl;
      colorFxID = 0;
      colorID = %color;
      datablock = %data;
      isPlanted = 1;
      position = getWord(%pos, 0) SPC getWord(%pos, 1) SPC getWord(%pos, 2);
      rotation = %rot;
      shapeFxID = 0;
      stackBL_ID = %blid;
   }).angleID = %angleID;
   %err = %brick.plant();
   %brick.setTrusted(1);
   missionCleanup.add(%brick);
   if(%flag)
      %cl.brickgroup.add(%brick);
   else if(isObject(%group))
      %group.add(%brick);
   return %brick TAB %err;
}

--- End code ---

createBrick(findClientByName(Xal), brick2x4Data, "0 0 4", 5, 1);
infiniteLoop:
Cool.  :cookieMonster:
Destiny/Zack0Wack0:
1. You're supposed to call setTrusted before planting the brick.
2. You shouldn't include shortened code in a sample, even more considering the shortened code you have is pointless (why not just include the angleID in the constructor?)
Xalos:

--- Quote from: Destiny/Zack0Wack0 on August 03, 2011, 02:13:56 AM ---1. You're supposed to call setTrusted before planting the brick.
2. You shouldn't include shortened code in a sample, even more considering the shortened code you have is pointless (why not just include the angleID in the constructor?)

--- End quote ---

1. I've tested this and I'm able to plant bricks on the bricks I make with this. What do you think the errors of calling setTrusted after planting the brick are?
2. I was having problems with the bricks being rotated wrongly, so I was trying different things to fix the problem. One of them was to try moving the angleID definition out of the brick.
Navigation
Message Index

Go to full version