how to spawn a monster only if a certain square is empty?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post 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?
Finished Dungeons - complete mods to play
User avatar
Scorcher24
Posts: 34
Joined: Thu Apr 12, 2012 8:32 am

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

Post 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
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

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

Post by petri »

Use a spawner. It wont spawn unless the cell is unoccupied.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post 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?
Finished Dungeons - complete mods to play
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

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

Post 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.
Finished Dungeons - complete mods to play
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

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

Post 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!
Post Reply