Page 2 of 5
Re: how to "action" when monster dies.
Posted: Sat Sep 29, 2012 9:13 pm
by Komag
I tried cloning a snail into a "sick_snail", and I added the line
but that doesn't work, so I tried:
Code: Select all
onDie = function()
diecounter:decrement
print("you got 'em")
end
but that doesn't work either. both ways give an error and won't load the dungeon
Re: how to "action" when monster dies.
Posted: Sat Sep 29, 2012 9:23 pm
by Shloogorgh
I would try putting diecounter:decrement in a script entity within the game and change the onDie function to reference that so you can load and debug it:
Code: Select all
onDie = function()
return sicksnail.diecounter()
print("you got 'em")
end
then in game a script entity called sicksnail:
Code: Select all
function diecounter()
diecounter:decrement
end
Re: how to "action" when monster dies.
Posted: Sat Sep 29, 2012 9:57 pm
by SpacialKatana
Komag wrote:I tried cloning a snail into a "sick_snail", and I added the line
but that doesn't work, so I tried:
Code: Select all
onDie = function()
diecounter:decrement
print("you got 'em")
end
but that doesn't work either. both ways give an error and won't load the dungeon
Had a similar problem a while back, a script with a counter:decrement() command in would not for love or money decrement the counter. Perhaps the problem is related, and the decrement() command is broken for scripts(ie only works from connecters) ???
Re: how to "action" when monster dies.
Posted: Sat Sep 29, 2012 11:03 pm
by Blichew
Komag wrote:I tried cloning a snail into a "sick_snail", and I added the line
but that doesn't work, so I tried:
Code: Select all
onDie = function()
diecounter:decrement
print("you got 'em")
end
but that doesn't work either. both ways give an error and won't load the dungeon
my guess would be your
onDie = function() line instead of
onDie = function(monster)
according to reference:
onDie: a hook which is called when the monster dies. The function gets one parameter, the monster itself. If the function returns false, the monster is resurrected to life.
so, while overriding a hook you have to remember to use exact number of parameters (according to asset reference).
I hope this will work for you

Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 1:19 am
by Komag
hmm, I tried some of that but it didn't work (got crashes of different types, now I can't quite remember exactly what I did or what crashes, should have keep better track!)
But I ended up with it working now. Part of the problem I had was that I have a counter named "diecounter" and that script was also named "diecounter", and it didn't like that, something about calling a global script name or something when I tried to decrement the counter. So I renamed the script, both in the cloneObject and in the script in the editor.
Here is my monsters.lua clone:
Code: Select all
cloneObject{
model = "mod_assets/models/monsters/snail_ben.fbx",
name = "sick_snail",
baseObject = "snail",
health = 2,
sight = 1,
attackPower = 1,
onDie = function(monster)
return sickscript.snaildie()
end
}
and here is my script (named "sickscript") in the editor:
Code: Select all
function snaildie()
diecounter:decrement()
print("you got 'em")
end
I still don't understand how parameters work or quite how the monsters.lua affects this sicksnail script, but it works just how I want now - the counter decrements and in turn triggers the actions I want to happen when the snail dies.
Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 2:31 am
by Komag
small note, if I press K to kill the monster, the "you got 'em" prints to the console, but the counter doesn't get decremented. But if I actually attack and kill the snail, the "you got 'em works AND the counter decrements. Why on earth would the print work but not the decrement when pressing K?
Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 2:33 am
by Neikun
Probably something related to how you don't get exp when you use k to kill
Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 2:36 am
by SpacialKatana
Hmmm.....that could've been my problem before Komag, I was fast killing bosses to check stuff and using the 'k' method. Now, if I'd actually killed them properly maybe my counter would've worked via the decrement command in the script they fired from the death hook. Sheesh and I did a workaround for it....
Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 2:39 am
by Komag
so really this is a bug, or maybe a feature request, but K to kill needs to act like real kills, so we don't always have to fully battle tough monsters we place just to test things fully
Re: how to "action" when monster dies.
Posted: Sun Sep 30, 2012 2:42 am
by SpacialKatana
Not so much a bug...but an oversight I suppose
