Page 99 of 396
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 11:11 am
by Zo Kath Ra
Isaac wrote:**Is there a simpler way to send a delayed kill than to spawn a timer connected to a function that calls .monster:die() ?
There is
delayedCall(receiver, delay, msg, parameters)
receiver = ID of a script entity with a killMonster function
delay = can be zero
msg = function name, e.g. killMonster
parameter = the monster's ID
Example:
viewtopic.php?f=22&t=8182&start=10#p83174
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 11:18 am
by THOM
I think the repeated killing is coming from the fact that a monster isn't dead until the die-particles are gone...
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 12:01 pm
by petri
THOM wrote:I think the repeated killing is coming from the fact that a monster isn't dead until the die-particles are gone...
Yes, the monster's soul lingers for a few seconds in the level before it's cleaned up, so you should always check isAlive() before calling die().
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 5:47 pm
by Isaac
Zo Kath Ra wrote:Isaac wrote:**Is there a simpler way to send a delayed kill than to spawn a timer connected to a function that calls .monster:die() ?
There is
delayedCall(receiver, delay, msg, parameters)
receiver = ID of a script entity with a killMonster function
delay = can be zero
msg = function name, e.g. killMonster
parameter = the monster's ID
Example:
viewtopic.php?f=22&t=8182&start=10#p83174
Delayed Call has never worked for me in that, or any situation that requires a component. It does seem that a controller (or other) component does handle some calls/redirects to scripts, but
delayedCall(id, .01 , "die") to a monster object, always fails silently for me; it's the reason I asked.
petri wrote:...so you should always check isAlive() before calling die().
This is good to know. In my case, it is alive. It seems that any use of the variable (in this case named 'monster') causes the the [false?] detection for using a non-existant 'go' field. I have an onDie hook that if I checked/used monster.id in, it would halt at the previous damageTile function (that killed the monster), and give the [seemingly erroneous] error.
It's working with the work-around, but I don't know the reason for the error.
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 6:28 pm
by minmay
Isaac wrote:Zo Kath Ra wrote:Isaac wrote:**Is there a simpler way to send a delayed kill than to spawn a timer connected to a function that calls .monster:die() ?
There is
delayedCall(receiver, delay, msg, parameters)
receiver = ID of a script entity with a killMonster function
delay = can be zero
msg = function name, e.g. killMonster
parameter = the monster's ID
Example:
viewtopic.php?f=22&t=8182&start=10#p83174
Delayed Call has never worked for me in that, or any situation that requires a component. It does seem that a controller (or other) component does handle some calls/redirects to scripts, but
delayedCall(id, .01 , "die") to a monster object, always fails silently for me; it's the reason I asked.
delayedCall is like a connector, it tries to call the corresponding method on the object's "controller" component. If the object doesn't have a component named "controller" with a "die" method - and it doesn't - then that delayedCall isn't going to help you.
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 8:09 pm
by Isaac
minmay wrote:delayedCall is like a connector, it tries to call the corresponding method on the object's "controller" component. If the object doesn't have a component named "controller" with a "die" method - and it doesn't - then that delayedCall isn't going to help you.
I understand that. I had written a delayedAction() function (a few weeks ago) that simulates delayedCall, but allows for [sub] components to be given. DelayedAction("object.monster", 1, "die") works with it; but when I noticed that delayedCall seemed to [albeit inconsistently] succeed with some components, I began to wonder if I was missing something about how it worked. If delayedCall(worked for it, then I would not have to define/link to delayedAction() in every mod/or script).
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 8:19 pm
by petri
btw. I'm not sure if this has been mentioned anywhere, but if I remember correctly (it has been a long time since I touched this code!), you should be able to pass extra arguments after the regular args to delayedCall(). Those extra args will be passed to the receiver function. Useful when a function needs to be called with diferent parameters. Just something to keep in mind.
Re: Ask a simple question, get a simple answer
Posted: Fri Oct 30, 2015 9:46 pm
by Isaac
petri wrote:btw. I'm not sure if this has been mentioned anywhere, but if I remember correctly (it has been a long time since I touched this code!), you should be able to pass extra arguments after the regular args to delayedCall(). Those extra args will be passed to the receiver function. Useful when a function needs to be called with diferent parameters. Just something to keep in mind.
It is the case; since the patch. It's been a boon.
Re: Ask a simple question, get a simple answer
Posted: Sun Nov 01, 2015 1:55 pm
by Zo Kath Ra
Isaac wrote:Delayed Call has never worked for me in that, or any situation that requires a component. It does seem that a controller (or other) component does handle some calls/redirects to scripts, but
delayedCall(id, .01 , "die") to a monster object, always fails silently for me; it's the reason I asked.
What I meant was:
You put a script entity called "script_entity_1" with this function in your mod:
Code: Select all
function killMonster(id)
local entity = findEntity(id)
if (entity) and (entity.monster) and (entity.monster:isAlive()) then
entity.monster:die()
end
end
And call it like this:
Code: Select all
delayedCall("script_entity_1", 0, "killMonster", "forest_ogre_1")
It not exactly what you were asking for, but it's simpler than spawning a new timer.
Re: Ask a simple question, get a simple answer
Posted: Mon Nov 02, 2015 5:49 am
by Drakkan
I have to say this thread is quite a mess, but it is probably one of the most helpful thread around. RIP NutJob.