Page 1 of 1
Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 2:20 pm
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? ^^'
Re: Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 2:42 pm
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!
Re: Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 2:50 pm
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...
Re: Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 3:03 pm
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.
Re: Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 3:05 pm
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!
Re: Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 7:46 pm
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.
Re: Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 8:32 pm
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.
Re: Kill monster when timer reaches 0
Posted: Thu Oct 11, 2012 10:35 pm
by Tyrion
And it's working.
Thanks a lot.