Kill monster when timer reaches 0

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Tyrion
Posts: 5
Joined: Tue Oct 09, 2012 11:27 pm

Kill monster when timer reaches 0

Post by Tyrion »

Hey. I need a little help again with my programming.
I want to make a room containing two monsters.
When the player enters the room, the timer starts ticking.
After 30 seconds or so, when the timer reaches 0, it should kill the two monsters in that room automatically.

I'm not so sure how to do that.
I connected a timer with a script entity, but now what?
Does anybode have a clue? ^^'
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Kill monster when timer reaches 0

Post by Komag »

you could teleport them or destroy them, but I'm not sure how that appears on the screen. Maybe also spawn a kill effect where they last stood. sorry, that's probably not much help!
Finished Dungeons - complete mods to play
User avatar
Kuningas
Posts: 268
Joined: Wed Apr 11, 2012 10:29 pm
Location: Northern Finland

Re: Kill monster when timer reaches 0

Post by Kuningas »

Hm, destroy just makes them disappear, hardly satisfactory. setHealth is unusable -- putting a zero or a negative value actually makes them invincible.

I tried using a damageTile on their locations, but using it is still beyond my skills...
BASILEUS
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Kill monster when timer reaches 0

Post by cromcrom »

You could cycle through all the monsters in the level (allEntities) and for each monster with the proper id, destroy it when the counter reaches 0, or check if the proper one (findEntity) is not nil, and if not, destroy it when the counter reaches 0 (Monster:destroy() )
Check the scripts in the modding section of the site.
Last edited by cromcrom on Thu Oct 11, 2012 3:07 pm, edited 2 times in total.
A trip of a thousand leagues starts with a step.
User avatar
Shroom
Posts: 98
Joined: Tue Mar 27, 2012 6:37 pm
Location: UK

Re: Kill monster when timer reaches 0

Post by Shroom »

If you name your creatures specifically. ie room_mob_1 & room_mob_2

you can use
findEntity(id)
to find them and then kill them with
damageTile(level, x, y, direction, flags, damageType, power)

so you have the counter, which connects to the script. The script then looks for the entities and if found, destroys them.

You get the level, x + y from the found entity.

ie

local mob = findEntity("room_mob_1")

check it exists and then use the damageTile to kill it if you want a visual effect, or destoy if you want it to go poof!
Tyrion
Posts: 5
Joined: Tue Oct 09, 2012 11:27 pm

Re: Kill monster when timer reaches 0

Post by Tyrion »

Thank you so far, I think, I'm almost there.

So the setup looks like this.
Once the player enters the room, there's a hidden pressure plate.
The pressure plate connects to the timer and activates it.
The timer then connects to a counter, which gets decremented every second.
The counter finally connects to the script, which should kill the monsters, when the counter reaches 0.

So far, it looks like this, but it's not working yet.

Code: Select all

function killGuardians()

if counter_2 == 0 then

	findEntity(guardian_1) 
	guardian_1:destroy()
	
	findEntity(guardian_2)
	guardian_2:destroy()
	
end
end
I want to try out the easy version first.
If this works, maybe I'll try the damageTile.
User avatar
Kuningas
Posts: 268
Joined: Wed Apr 11, 2012 10:29 pm
Location: Northern Finland

Re: Kill monster when timer reaches 0

Post by Kuningas »

Tyrion wrote:Thank you so far, I think, I'm almost there.

So the setup looks like this.
Once the player enters the room, there's a hidden pressure plate.
The pressure plate connects to the timer and activates it.
The timer then connects to a counter, which gets decremented every second.
The counter finally connects to the script, which should kill the monsters, when the counter reaches 0.

So far, it looks like this, but it's not working yet.

Code: Select all

function killGuardians()

if counter_2 == 0 then

	findEntity(guardian_1) 
	guardian_1:destroy()
	
	findEntity(guardian_2)
	guardian_2:destroy()
	
end
end
I want to try out the easy version first.
If this works, maybe I'll try the damageTile.
That is very nearly working, but some streamlining is possible.

First, you shouldn't need the counter: give the timer a 30 second interval, and connect it to your function, it should fire succesfully. If you do this, make sure you connect it to itself and select "deactivate" as well so it won't try to destroy the guardians a second time -- it won't find them and it will crash the game. (it might have a fire only once tickbox too). You can use it, though, if you want.

Second, you shouldn't need the findEntities either (I think). If you'll try the damageTile, you might have use for them, though. Referencing to their id's should work alone as well.

If you want to use the counter (I don't see a reason why it wouldn't work as well), just connect it to the script entity in the editor -- counters fire automatically when they reach zero, another handy feature. If you have the script entity ready, just point the counter to it and select killGuardians from the action menu.
BASILEUS
Tyrion
Posts: 5
Joined: Tue Oct 09, 2012 11:27 pm

Re: Kill monster when timer reaches 0

Post by Tyrion »

And it's working.
Thanks a lot. :)
Post Reply