Page 3 of 5
Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 9:08 am
by Blichew
I found out how I did onDie function on my squishy version of skeleton warrior with 10 HP:
I require the player to kill 4 of them before the door opens.
I made a counter KillCount_1 with a value of 4
I made a script KillCount_lua with a function that plays a sound after each kill and opens the door when it reaches 0 (Of course this part can be done by only linking the counter to the door)
Code: Select all
cloneObject{
name = "squishy_skeleton_warr",
baseObject = "skeleton_warrior",
health = 10,
onDie = function(self)
local kc = KillCount_1
local kcl = KillCount_lua
kc:decrement()
kcl:checkNumber()
end
}
Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 4:05 pm
by SpacialKatana
Have you tested this by using the 'k' method to kill monsters? I had no luck before doing this, but was using 'k' to quick kill. The counter never fired it's triggers for me.
Re: how to "action" when monster dies.
Posted: Mon Oct 01, 2012 1:27 am
by HaunterV
this is still beyond me... i'll try to understand it again in a few more months.
For now...I'll just use practical nuts & bolts methods.
Re: how to "action" when monster dies.
Posted: Mon Oct 01, 2012 4:30 am
by davehca
I was able to get a monster's death to open a door using the following:
Code: Select all
cloneObject {
name = "snail2",
baseObject = "snail",
onDie = function(self)
dungeon_door_iron_1:open()
end,
}
If it returns "false" then when the monster "dies" it doesn't really, but the door still opens. What's funny is if I set to toggle() and return false, after the initial "death" the door will toggle with each whack made against the creature.
Re: how to "action" when monster dies.
Posted: Mon Oct 08, 2012 6:53 pm
by Kuningas
I am battling with this problem as well, and I suppose many will be doing likewise in the future, so I humbly suggest adding this topic to the modding superthread.
I am trying to do a room with 3 slimes, so that when you kill them, the last one you kill always has a green gem item. I've simplified by isolating one of the slimes for testing purposes (the one to be killed last), and I've managed to build a functioning counter that will run a lua script entity on the map when you kill a slime. The script is then supposed to check if the counter equals 2 (in other words, 2 of the three slimes killed), and if it is so, it will place the green_gem item on the remaining slime. The thing is, the last part doesn't work, apparently. I don't know the reason. My codes are as follows.
The onDie function with the slime:
Code: Select all
onDie = function(self)
local s = slimekillcounter
local sl = givegemscript
s:increment()
sl:givegem()
end,
"slimekillcounter" is the counter on the map
"givegemscript" is the script entity.
This part seems to work correctly, but I am not entirely sure.
This is the script entity (simplified for testing, the final product would be threefold)
Code: Select all
function givegem()
if slimekillcounter == 2 then
if not findEntity("sewer_slime_1") and not findEntity("sewer_slime_2") then
sewer_slime_3:addItem("green_gem") else
nothing()
end
end
end
I killed the slimes using conventional means and I have verified the counter works as intended. The problem is probably in the latter part.
Re: how to "action" when monster dies.
Posted: Mon Oct 08, 2012 8:14 pm
by Komag
I've never tried "if not" stuff. Maybe put in some print messages to test where it's breaking down. Try one right after the test to find the two slimes.
Re: how to "action" when monster dies.
Posted: Mon Oct 08, 2012 9:20 pm
by Kuningas
Weird -- as a matter of fact it seems it is the addItem function that isn't working -- I can't add anything to the slimes even through console. It always gives the same error: "(Item expected, got ???)".
This is... perplexing. All the other lines work fine alone.
EDIT: Wait, you don't suppose it wants the UI name? Gotta check... EDIT2: aaand no...
Re: how to "action" when monster dies.
Posted: Mon Oct 08, 2012 10:07 pm
by Komag
you could try nesting in a spawn command in place of "green_gem", sometimes it works with those but not with direct items
Re: how to "action" when monster dies.
Posted: Tue Oct 09, 2012 7:38 am
by petri
addItem() expects an Item and "green_gem" is not an Item, it's a string. An Item is an object returned by e.g. spawn("green_gem"). Hope this helps!
Re: how to "action" when monster dies.
Posted: Tue Oct 09, 2012 8:15 am
by Trollmann
hello there everybody, I've been doing my dungeon for several days now, and I've come to point where I need to add snail farm, but I don't know where to start.
I've tried some scripting and at this point I can get 3 snails spawned at random intervals, but I don't know how to make them do a decrement as they die.
I'm still kinda noob with LUA, so even the basics can be hard
Some help would be appreciated.