Check if spawned monster is dead [Solved]

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

I guess I have another problem the monstergroup doesn't have a connectors so I can't add "onDie" connector. any suggestions?
Last edited by Jouki on Thu Nov 06, 2014 10:40 pm, edited 1 time in total.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Check if spawned monster is dead

Post by Prozail »

still havn't figured out how to work with monster Groups...

this is as far as i've come.

Code: Select all

function spawner(c)
	enemySkeleton2 = c.go:spawn("skeleton_trooper_pair")
	enemySkeleton2.monstergroup:spawnNow()
	-- print(enemySkeleton2.id) 	-- this gives "Bad object error"
	for e in self.go.map:entitiesAt(c.go.x, c.go.y) do
			if e.monster then e.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton") end
	end
end

function deadCheckerSkeleton()
	print ("moo")
	hudPrint("Moo!")
end

It seems that, the monstergroup doesn't spawn the actual monsters until the next frame, so, if you don't call "spawnNow" there are no monsters to add events to.

And... if you call "spawnNow" the monstergroup destroys itself after creating the monster pair.

so.. i Think the above code is the way to do it.
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

Prozail wrote:still havn't figured out how to work with monster Groups...

this is as far as i've come.

Code: Select all

function spawner(c)
	enemySkeleton2 = c.go:spawn("skeleton_trooper_pair")
	enemySkeleton2.monstergroup:spawnNow()
	-- print(enemySkeleton2.id) 	-- this gives "Bad object error"
	for e in self.go.map:entitiesAt(c.go.x, c.go.y) do
			if e.monster then e.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton") end
	end
end

function deadCheckerSkeleton()
	print ("moo")
	hudPrint("Moo!")
end

It seems that, the monstergroup doesn't spawn the actual monsters until the next frame, so, if you don't call "spawnNow" there are no monsters to add events to.

And... if you call "spawnNow" the monstergroup destroys itself after creating the monster pair.

so.. i Think the above code is the way to do it.
how can I set coords of spawning position?
User avatar
SnowyOwl47
Posts: 148
Joined: Fri Sep 12, 2014 10:41 pm

Re: Check if spawned monster is dead

Post by SnowyOwl47 »

I use this in my dungeons.

What I used was on die trigger yes but if you want to do more I had a loop that would check to see if the monsters health == 0 and if not it would restart the function.
I don't remember why I used this instead of onDie...

Code: Select all

function dead()
     while monster.monster:getHealth() == not 0 do
     else
           --something...
     end
end
Something like that...
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

actaully the problem with 'onDie' is solved, only and I'm almost sure LAST problem is how can I set coords on skeleton_trooper_pair. it's working what prozail sent but last thing is how to set position. I've been trying combinations but no success :cry: :cry: I feel I'm almost on the end this whole tunnel of problems :evil:
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Check if spawned monster is dead

Post by Prozail »

You don't HAVE to use the caller-references, you can go with the hardcoded approach, since i don't really know how you've set tings up.

Code: Select all

function spawner(c)
	enemySkeleton2 = spawn("skeleton_trooper_pair", 1 , 10,10,0,0 )		
	enemySkeleton2.monstergroup:spawnNow()
	for e in self.go.map:entitiesAt(10,10) do
			if e.monster then e.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton") end
	end
end

function deadCheckerSkeleton()
	hudPrint("Moo!")
end
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

Prozail wrote:You don't HAVE to use the caller-references, you can go with the hardcoded approach, since i don't really know how you've set tings up.

Code: Select all

function spawner(c)
	enemySkeleton2 = spawn("skeleton_trooper_pair", 1 , 10,10,0,0 )		
	enemySkeleton2.monstergroup:spawnNow()
	for e in self.go.map:entitiesAt(10,10) do
			if e.monster then e.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton") end
	end
end

function deadCheckerSkeleton()
	hudPrint("Moo!")
end

I've tried this (even something similar), it doesn't crash the game but the troopers still spawning on the pressure plate (same location) :cry:
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Check if spawned monster is dead

Post by NutJob »

disableSelf
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead

Post by Jouki »

NutJob wrote:disableSelf
I dont mean troopers are spawning again and again (I can handle that :P) what I mean is that these coordinates doesnt working, I have absolutely no idea why it doesnt :shock:
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Check if spawned monster is dead

Post by Prozail »

Are you sure you're connected to the right script?

I just ran that one.. differnet hardcoded coords, but still, and that worked fine. (and it was a kinda small room and i got overrun by skeletons pretty quickly :lol: )
Post Reply