Page 1 of 1
Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 10:24 pm
by Ixnatifual
I have a monster where I've changed the onDie hook so it spawns a different monster on top of where it died. There's a problem with this approach, namely that the player, if spamming the forward key, can walk in and occupy the square where the monster is spawned as the previous one dies!
Anyone know of a way to prevent this?
Re: Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 10:38 pm
by Ixnatifual
OK I figured I'd use the onDamage hook instead. Unfortunately the game crashes when I attempt to call the destroy() command.
Can anyone see what I'm doing wrong?
Code: Select all
onDamage = function(self, amount, type)
hudPrint("What?! I'm a snail?!!")
spawn("snail", self.level, self.x, self.y, self.facing)
self:destroy() -- If I remove this line it works.
end
Re: Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 10:45 pm
by Ixnatifual
Meh, I don't think that would work anyway. Even if I spawn the second monster on top of the current monster and then teleport the first monster away as it takes damage, the player can still move into the square.
Re: Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 10:50 pm
by Ixnatifual
I discovered when you spawn a monster on top of another, it stops blocking for a bit. That's why you can enter the square. When I teleported the original monster away before spawning the new one, it worked.
I can then call self:setHealth(0) to kill it off. However this awards the player experience, which I'd prefer it didn't. But then again I can just set the first monster's XP value to 0.
Re: Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 10:56 pm
by Ixnatifual
Ixnatifual wrote:But then again I can just set the first monster's XP value to 0.
Damn, a scrolling text saying "+0 XP" pops up when you kill it. Not what I want.
Re: Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 10:57 pm
by msyblade
Interesting stuff, thanx for the feed.

Re: Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 10:59 pm
by Ixnatifual
msyblade wrote:Interesting stuff, thanx for the feed.

Glad to be of service

Re: Spawning a new monster on top of a dying one?
Posted: Sat Jan 19, 2013 11:19 pm
by Komag
you could teleport it away, then set a very short 0.05s timer which THEN does destroy() on it, and I don't think you get XP from that.
Re: Spawning a new monster on top of a dying one?
Posted: Sun Jan 20, 2013 10:20 am
by Ixnatifual
I was hoping to avoid that. But it works - thanks! My guess is it's a problem to delete an entity from within a script attached to said entity.