Page 2 of 2

Re: how to spawn a monster only if a certain square is empty

Posted: Sat Sep 15, 2012 3:03 pm
by Komag
I'm trying to make the spawn be a few seconds delay, so I use a timer which then triggers a spawner. I don't think I can use a blob because I don't want the party being hit by a blob. I could possible use a combination of a hidden pressure plate to detect the party, and a separate room faraway with a spawner, teleport, and blob, and if the blob hits the receptor the teleport turns on, but that's sorta crazy.

Anyway, here is my code that has a problem, enemies keep getting spawned on top of themselves, but I don't see why?

Code: Select all

function testmonst()
    for i in entitiesAt(2, 17, 8) do
        if i.name == "wyvern" then
            testgate:open()
        else
            testtimer:activate()
        end
    end
end
The testtimer waits a couple seconds then activates the spawner. When I trigger this test script, the gate does NOT immediately open, which is correct, and then two seconds later a wyvern is spawned there, good. Then when I trigger the script again the gate opens, which is correct, so it's correctly reading "wyvern" with the entitiesAt, but then another wyvern gets spawned in there two seconds later! what gives? It's firing the testtimer again, why?

Re: how to spawn a monster only if a certain square is empty

Posted: Sat Sep 15, 2012 3:05 pm
by Scorcher24
Deactivate the timer.

Code: Select all

function testmonst()
    for i in entitiesAt(2, 17, 8) do
        if i.name == "wyvern" then
            testgate:open()
            testtimer:deactivate()
        else
            testtimer:activate()
        end
    end
end

Re: how to spawn a monster only if a certain square is empty

Posted: Sat Sep 15, 2012 3:09 pm
by petri
Use a spawner. It wont spawn unless the cell is unoccupied.

Re: how to spawn a monster only if a certain square is empty

Posted: Sat Sep 15, 2012 3:11 pm
by Komag
hmm, that works, thanks! But I don't understand why, since I already have the timer set up to deactivate itself.

I thought the logic was "if there is a wyvern, open the door, but if there is not a wyvern, activate the timer". Before adding testtimer:deactivate() why does it open the door AND activate the timer?

Re: how to spawn a monster only if a certain square is empty

Posted: Sat Sep 15, 2012 3:30 pm
by Komag
Ah, so that's a bug! I WISH they wouldn't spawn if the cell is occupied, but they DO! That's the whole problem I've been trying to avoid, but if it's just a straight up bug, then that explains it.

Re: how to spawn a monster only if a certain square is empty

Posted: Sun Sep 16, 2012 4:08 pm
by petri
Komag wrote:Ah, so that's a bug! I WISH they wouldn't spawn if the cell is occupied, but they DO! That's the whole problem I've been trying to avoid, but if it's just a straight up bug, then that explains it.
I checked the code and there is indeed a bug. I'll fix it for the next build. Thank you for the report!