92
« on: December 01, 2013, 04:30:57 AM »
It's getting late and I'm tired now. But I have been tormented by this issue for a few hours now, and I still have gotten nowhere. I ran a trace, basically my bricks start deleting themselves once 177 of them are created. This can work perfectly fine up until then, and then suddenly the bricks stop spawning and I'm flooded with 'cannot find object' errors (Primarily occurring from the onAdd). A slightly separate issue is that when I call createDungeon("0 0"); %room ends up being 1 instead of "0 0", I can't fathom why.
If you can figure out what I've done wrong, I'm glad to hear it. I'm really tired, so you probably won't hear from me tonight unless you answer in the next 20 minutes lol.
function startDungeon(%clear)
{
if(%clear)
brickGroup.deleteall();
deleteVariables("$dungeonMaster*"); //Clean up the array
%clients = clientGroup.getCount(); //GET IN HERE
for(%i=0;%i<%clients;%i++)
{
%client = clientGroup.getObject(%i);
if(%client.minigame.isTheDungeonOfDoomyDoom && isObject(%client.player))
%client.player.setTransform("0 0 1");
}
$dungeonMaster[0, 0] = 0 SPC 0;
createDungeon("0 0");
}
function createDungeon(%room)
{
%x = firstWord(%room);
%y = getword(%room, 1);
//Baseplate
makeDungeonBrick("0 0 0.5", brick32x32fdata, 8, %room, 0);
//Doors
makeDungeonBrick("7.75 0 2", brick1x6x5data, 6, %room, 0, 2);
makeDungeonBrick("0 7.75 2", brick1x6x5data, 6, %room, 1, 1);
makeDungeonBrick("-7.75 0 2", brick1x6x5data, 6, %room, 0, 4);
makeDungeonBrick("0 -7.75 2", brick1x6x5data, 6, %room, 1, 3);
//Walls
makeDungeonBrick("7.75 4.5 2", brick1x12x5data, 7, %room, 0);
makeDungeonBrick("7.75 -4.5 2", brick1x12x5data, 7, %room, 0);
makeDungeonBrick("-7.75 4.5 2", brick1x12x5data, 7, %room, 0);
makeDungeonBrick("-7.75 -4.5 2", brick1x12x5data, 7, %room, 0);
makeDungeonBrick("4.5 7.75 2", brick1x12x5data, 7, %room, 1);
makeDungeonBrick("4.5 -7.75 2", brick1x12x5data, 7, %room, 1);
makeDungeonBrick("-4.5 7.75 2", brick1x12x5data, 7, %room, 1);
makeDungeonBrick("-4.5 -7.75 2", brick1x12x5data, 7, %room, 1);
//Corners
makeDungeonBrick("7.75 7.75 2", brick1x1x5data, 7, %room, 0);
makeDungeonBrick("7.75 -7.75 2", brick1x1x5data, 7, %room, 0);
makeDungeonBrick("-7.75 7.75 2", brick1x1x5data, 7, %room, 0);
makeDungeonBrick("-7.75 -7.75 2", brick1x1x5data, 7, %room, 0);
}
function makeDungeonBrick(%position, %data, %color, %room, %rot, %door)
{
%rot=eulerToMatrix("0 0 "@(%rot % 4)*90);
%brick = new fxDTSBrick()
{
client = findClientByBL_ID(getNumKeyID());
dataBlock = %data;
position = vectorAdd(%position,vectorScale(%room,16));
rotation = %rot;
colorID = %color;
scale = "1 1 1";
angleID = 0;
colorfxID = 0;
shapefxID = 0;
isPlanted = 1;
stackBL_ID = getNumKeyID();
dungeonRoom = %room;
};
%brick.plant();
%brick.setTrusted(1);
nameToID("brickGroup_"@getNumKeyID()).add(%brick);
if(%door)
{
%brick.addEvent(1, 0, "onActivate", "self", "openDungeonDoor", %door);
}
}
function fxDtsBrick::openDungeonDoor(%this, %direction)
{
%room = %this.dungeonRoom;
%x = firstword(%room);
%y = getWord(%room, 1);
switch(%direction)
{
case 1:
%y++;
case 2:
%x++;
case 3:
%y--;
case 4:
%x--;
}
if($dungeonMaster[%x, %y] $= "")
{
echo("Created the" SPC %x SPC %y SPC "dungeon room");
$dungeonMaster[%x, %y] = %x SPC %y;
createDungeon(%x SPC %y);
}
else
echo("Sorry, room taken :/" SPC %x SPC %y);
%this.disappear(-1);
}
registerOutputEvent(fxDtsBrick, openDungeonDoor, "INT 0 4 0", 0);