Page 1 of 2

Killing spawned monsters

Posted: Sun Oct 07, 2012 3:43 am
by Lemonz
I'm having a bit of trouble with killing (not destroying) a spawned monster. In my case a cube. I have it so the player steps on a hidden pressure plate spawning a cube around the corner. In the same block that contains the hidden pressure plate I have one more that's connected to a script_entity. I want the cube to be killed once it touches the second hidden pressure plate. I've tried Monster:setHealth(0), however, I can't seem to find the cube's ID.

This was posted before, but it assigns a random ID on every run. I tried running the second script Grimwold posted that I've edited to suit my needs, but that just crashed the editor.

Code: Select all

function killCube()
  for i in entitiesAt(1,6,14) do
    if i.name == "cube"
    then
      i:destroy()
    end
  end
end
If I use i:setHealth(0) instead of i:destroy() it doesn't do anything.

This is the error it gives when it crashes.
SpoilerShow
[string "Cube.lua"]:0: attempt to index field 'map' (a nil value)
stack traceback:
[string "Cube.lua"]: in function 'crushEntities'
[string "Cube.lua"]: in function 'update'
[string "Monster.lua"]: in function 'update'
[string "Map.lua"]: in function 'updateEntities'
[string "Dungeon.lua"]: in function 'updateLevels'
[string "GameMode.lua"]: in function 'update'
[string "DungeonEditor.lua"]: in main chunk
[C]: in function 'xpcall'
[string "DungeonEditor.lua"]: in function 'preview'
[string "DungeonEditor.lua"]: in function 'update'
[string "Grimrock.lua"]: in main chunk
stack traceback:
[C]: in function 'error'
[string "DungeonEditor.lua"]: in function 'handleError'
[string "DungeonEditor.lua"]: in function 'preview'
[string "DungeonEditor.lua"]: in function 'update'
Any and all help would be greatly appreciated. Thanks in advance :D

Re: Killing spawned monsters

Posted: Sun Oct 07, 2012 4:47 am
by Komag
have you tested with other monsters? I've read that the cube is very different and causes problems a lot with trying to do stuff like this

Re: Killing spawned monsters

Posted: Sun Oct 07, 2012 5:26 am
by Lemonz
I guess it's just the cube. I tried it on a snail and it removed it just fine. Interestingly enough I set it's HP to 0 as well and I was unable to hit it, but it was still able to move and attack me. It's the same for negative numbers. I'd still like to figure out how to kill a cube (or any enemy) once they step on a certain area much like when you press K on an enemy in debug mode.

Re: Killing spawned monsters

Posted: Sun Oct 07, 2012 10:16 am
by Montis
setting the health to zero is a bit strange since that causes the monster to be dead and alive at the same time = invulnerable. same with the party btw.
you could try to set up a killsquare. I don't know if that would work on the cube though, so many things hardcoded with that...

Re: Killing spawned monsters

Posted: Sun Oct 07, 2012 1:17 pm
by Lemonz
It doesn't work on a cube.

Code: Select all

function killCube()
  for i in entitiesAt(1,6,14) do
    if i.name == "cube"
    then
      damageTile(1,6,14,1,128,"physical",9001)
    end
  end
end
Perhaps these things are impossible to kill, though you can kill them when you press K on them. I'd like to know what command that does. I've searched quite a bit, but maybe not enough.

Re: Killing spawned monsters

Posted: Thu Oct 18, 2012 10:42 am
by Drachir
Just wondering if you got a response from the devs on the error

[string "Cube.lua"]:0: attempt to index field 'map' (a nil value)
stack traceback:

I had the same thing with a teleporter... a pure guess says the problem is the game losing track of where something actually is when you attempt to destroy it.

Re: Killing spawned monsters

Posted: Sun Oct 21, 2012 7:48 pm
by SpiderFighter
Drachir wrote:Just wondering if you got a response from the devs on the error

[string "Cube.lua"]:0: attempt to index field 'map' (a nil value)
stack traceback:

I had the same thing with a teleporter... a pure guess says the problem is the game losing track of where something actually is when you attempt to destroy it.
I also had a teleported Big Herder become invincible as I was hitting it, so that explanation makes sense.

(edited for clarity)

Re: Killing spawned monsters

Posted: Sun Oct 21, 2012 7:55 pm
by msyblade
is it possible that cube doesnt trigger plate, like a crowern?

Re: Killing spawned monsters

Posted: Sun Oct 21, 2012 8:14 pm
by Billick
The cube is weird, and you can't do a lot of things with it that you can do with other monsters. I'm trying to figure out how to "kill" a cube in the game. The only thing I can think of is to destroy it and then spawn an fx object on top of it at the same time to simulate a death animation, and assign xp to the party through a script call. I haven't tried this yet though. A Monster:kill() command would be useful, but I don't think it exists as of yet.
msyblade wrote:is it possible that cube doesnt trigger plate, like a crowern?
I've gotten a cube to trigger plates. The issue seems to be that there's no way to do any damage to it.

Re: Killing spawned monsters

Posted: Mon Oct 22, 2012 5:20 am
by Edsploration
You could always just... spawn a pit under it, and then destroy that pit! "Sending it to hell", if you like. :lol: If you spawn another cube on top of it immediately before you could probably get one to leave a corpse behind. (Cubes crush other cubes, and that's the only way to do it I know of.) You'd probably have to time this with the cube's onMove hook in order to know exactly which space the cube was moving onto, and be able to time this sort of slight of hand.