Author Topic: [SCRIPT] Finding Adjacent Bricks  (Read 1750 times)

I don't think there is a built-in way to do this, so i wrote a function that returns all of the bricks that are adjacent (touching) a certain brick. I made it so that my fire mod can spread fire to bricks more accurately. Basically what you do is put something like this in your script:
Code: [Select]
%adjacentBricks=findAdjacentBricks(%obj); where %obj is the id of a brick, and then %adjacentBricks will store a string where each word will be an ID of a brick that is touching the brick %obj. You could cycle through the string like this:
Code: [Select]
for(%i=0;%i<getwordcount(%adjacentBricks);%i++){
%brick=getword(%adjacentBricks,%i);
//%brick is now a brick adjacent to the original brick.
//do what you want to it here.
}

The attached file includes the function findAdjacentBricks(). I haven't found any issues with it, but if you find any please post them here! I hope this is helpful!
« Last Edit: September 08, 2007, 07:00:13 PM by Zor »

Someone please make wiremod thing with this. Like Gmod but simpler.

Badspot

  • Administrator
This is completely terrible for many reasons. 

First, you're putting things together into a string, sending a copy of that string back from a function, then taking the string apart to get the objects again.  That is a lot of useless string operations that are slow.

Second, you're doing like a billion ray casts but you STILL aren't going to find bricks that are catty-corner to the one you're searching from.

Third, there IS a built in function for this sort of thing. 

Code: [Select]
initContainerBoxSearch(%position, %boxSize, %mask);
while (%searchObj= containerSearchNext())
{
   //do stuff to %searchObj
}