I have decided to make a /warpbrick cmd that works like /warp, but works with bricks. Here is what I have so far:
function serverCmdWarpBrick(%client)
{
if(%client.isAdmin)
{
%raycast = containerRayCast(%client.player.getEyePoint(),vectorAdd(%client.player.getEyePoint(),vectorScale(%client.player.getEyeVector(),200)),$TypeMasks::FxBrickObjectType);
if(isObject(%raycast))
{
%pos = posFromRaycast(%raycast);
%pos2 = %pos;
while(containerBoxEmpty($TypeMasks::FxBrickObjectType,%pos2,%client.player.getWorldBox) == 1)
{
%pos2 = %pos;
%pos2 = vectorAdd(%pos,getRandom(-3,3) SPC getRandom(-3,3) SPC getRandom(-3,3));
}
%client.player.position = %pos2;
}
}
}
I want it to send the player to the position of the raycast, but not halfway inside of the brick. Thats where the while statement comes in. If a brick is within the size of the world box of the player, then it generates a random position around the raycast position until a brick is no longer within the box. I have tried this in-game, but I either end up within the brick, or my game crashes. What am I doing wrong?