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 [Re-opened thread]

Post by Jouki »

ok there's a continuation. I've copied that into the real world (set up everything as before) but when I spawn classic trooper the game crashes when trooper hits the ground. Is it some limitaions of enviroment or?

Image

I've tried other elevation and it's everytime when trooper hits the 0 elevation

edit: ok I dont have any idea why it works but it does. I've just changed coordinates of spawning trooper to absolute (instead of c.bla bla bla) and it works.
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Check if spawned monster is dead [Re-opened thread]

Post by Prozail »

Think i found it.

enemySkeleton2 = spawn("skeleton_trooper_pair", c.level, c.x +1, c.y, c.facing+2 , c.elevation+2, "skeletonTroop")

facing is supposed to be 0-3 so either remove the (+2) or do it like this:

enemySkeleton2 = spawn("skeleton_trooper_pair", c.level, c.x +1, c.y, (c.facing+2)%4 , c.elevation+2, "skeletonTroop")
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead [Re-opened thread]

Post by Jouki »

Prozail wrote:Think i found it.

enemySkeleton2 = spawn("skeleton_trooper_pair", c.level, c.x +1, c.y, c.facing+2 , c.elevation+2, "skeletonTroop")

facing is supposed to be 0-3 so either remove the (+2) or do it like this:

enemySkeleton2 = spawn("skeleton_trooper_pair", c.level, c.x +1, c.y, (c.facing+2)%4 , c.elevation, "skeletonTroop")
yeah it sounds like it was that problem.
I'm almost done with scripting this puzzle finally :)
(hehe editor just crashed :lol: due to me trying spawn object on place where enemy dies :P)
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: Check if spawned monster is dead [Solved]

Post by Jouki »

ok everything is finished so I decided for others (tl;dr) show up solution:

How to solve this problem

Here's the Spawner

Code: Select all

function SpawnSkeleton(c) -- c = coordinates of script activator
	c = c.go --shortcut insted of writing absolute values
	enemySkeleton1 = spawn("skeleton_trooper", 2,c.x+1,c.y,2,0) --coordiantes are [2,2,19,2,0] (x=1;y=2)
	spawnTrooperPair(c)
	enemySkeleton1.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton")		
end
	-----------------------------------------------------------------------------------
	-- If your pressure plate is for example in the same level where you want spawn the enemy and coordinates of pressure plate is 2,1,15,2,0 [level,x,y,face,elevation,"name"] (name is not required)
	-- you can write: enemySkeleton1 = spawn("skeleton_trooper", c.level , c.x + 1 , c.y + 4 , 2 , c.elevation) result will be same
	-- c.level => c.go.level > 2
	-- c.x + 1 => c.go.x + 1 => 1 + 1 > 2
	-- c.y + 4 => c.go.y + 4 => 15 + 4 > 19
	-- 2 > 2 (facing value can reach 0 - 3 higher or lower values editor crashes
	-- c.elevation => c.go.elevation > 0 (it's same as level, if you want spawn creature 1 elevation higher than pressure plate (or w/e activator) is just put '+ 1')
	----------------------------------------------------------------------------------
Here's the spawnTrooperPair(c) method

Code: Select all

function spawnTrooperPair(c)
	enemySkeleton2 = spawn("skeleton_trooper_pair", c.level , c.x + 2, c.y+2,0,0 )   -- set enemySkeleton properties for spawn
	enemySkeleton2.monstergroup:spawnNow() -- let's spawn (someone said it has to be there actaully even Idk why, but w/e)
   for e in self.go.map:entitiesAt(c.x+2,c.y+2) do	-- for each entity at c.x+2 (c.go.x+2 = 2+2 > 4 and y is the same ; don't forget our hypothetical coords for pressure plate is now 2,1,15,2,0)
         if e.monster then
		e.monster:addConnector("onDie",self.go.id,"deadCheckerSkeleton")
	end
	-- adding a connector for every entity on this coords
	-- "onDie" - name of event connector
	-- "deadCheckerSkeleton" is name of method that launches after skeleton pair die
   end
end
And this is the method deadCheckerSkeleton()

Code: Select all

counterSkeletonDead = 0
function deadCheckerSkeleton()
	counterSkeletonDead = counterSkeletonDead + 1
	if counterSkeletonDead == 3 then
		hudPrint("Your foes are no more!!")
	else
		hudPrint("Podminka neni splnena!")
	end
end
Becareful!
Checking of skeleton pair is little bit tricky because, even when it's only one monster (as a pair) connector is added on both of them. That means when you kill the Trooper Pair the connector will be launched two times! (for each dead trooper)

Example:
Image Image Image Image

Sorry I have logs in my language :P (It means "The Condition is not met") but you can see how many time has been launched the connector.
Post Reply