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? ^^'
Kill monster when timer reaches 0
Re: Kill monster when timer reaches 0
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
Re: Kill monster when timer reaches 0
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...
I tried using a damageTile on their locations, but using it is still beyond my skills...
BASILEUS
- 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
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.
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.
Re: Kill monster when timer reaches 0
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!
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
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.
I want to try out the easy version first.
If this works, maybe I'll try the damageTile.
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
If this works, maybe I'll try the damageTile.
Re: Kill monster when timer reaches 0
That is very nearly working, but some streamlining is possible.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.
I want to try out the easy version first.Code: Select all
function killGuardians() if counter_2 == 0 then findEntity(guardian_1) guardian_1:destroy() findEntity(guardian_2) guardian_2:destroy() end end
If this works, maybe I'll try the damageTile.
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
Re: Kill monster when timer reaches 0
And it's working.
Thanks a lot.
Thanks a lot.