Jump to content

Setting Trigger to activate when actor is dead


Hangman4358

Recommended Posts

Ok, so i have an activator that activates a "door" made from the spears that go up and down. I want this activator to open the door when two actors guarding the door are both dead. So do this I have come up with this script but it just does not work. It compiles fine and I can set the two guardians in the properties but when I kill them, nothing happens

 

 

Scriptname OAQ01TriggerTwoDeadSCRIPT extends ObjectReference  
import Debug

Actor Property guardian01 Auto
Actor Property guardian02 Auto

Function StartChain()
RegisterForSingleUpdate(1.0) ; Give us a single update in one second
EndFunction

Event OnUpdate()
Bool bKeepUpdating = True
If guardian01.isDead() == True && guardian02.isDead() == True
	self.activate(Game.GetPlayer())
	debug.trace("TrapLink with two dead activated")
	Bool bKeepUpadating = False
EndIf
If bKeepUpdating
	RegisterForSingleUpdate(1.0)
EndIf
EndEvent

 

Edited by Hangman4358
Link to comment
Share on other sites

Well, for starters, you've declared a function which is fine (but rather useless if you're not going to reuse it and it contains only one statement) but you never call on it. So the update loop never gets started, I think.

 

Instead of

Function StartChain()
       RegisterForSingleUpdate(1.0) ; Give us a single update in one second
EndFunction

 

try

 

Event OnCellAttach()
RegisterForSingleUpdate(1.0)
EndEvent

 

Also note this extra "a":

Bool bKeepUpadating = False

 

Generally, if a script doesn't work as expected I add lots of debug.notification("we're in stage X now") statements to see what is happening.

(on that note, you don't need to import debug if you then go on to call debug.somedebugstatement <- the debug. part calls on the debug script)

 

Finally, I'm not sure if this script will act as you expect even with proper event calls, but get that sorted first :)

Link to comment
Share on other sites

you could try redoing the door made from spears in a different way. Have one part of the door come down when one actor dies, then the last part when the second actor dies. This could be done in one script with 2 events.

 

In the end making one event recognize the two deaths at once would probably be more efficient but its not the only way.

Edited by Vandrath
Link to comment
Share on other sites

@acidzebra: he's probably calling that function from another script. The function is redundant however, he could simply call OnUpdate directly to start the ball rolling.

 

 

Scriptname OAQ01TriggerTwoDeadSCRIPT extends ObjectReference  
import Debug

Actor Property guardian01 Auto
Actor Property guardian02 Auto

Function StartChain()
RegisterForSingleUpdate(1.0) ; Give us a single update in one second
EndFunction

AUTO STATE LISTENING
Event OnUpdate()
If guardian01.isDead() && guardian02.isDead()
	GoToState("COMPLETED")
	activate(Game.GetPlayer())
	debug.trace("TrapLink with two dead activated")
EndIf
RegisterForSingleUpdate(1.0)
EndEvent
ENDSTATE

STATE COMPLETED
ENDSTATE

 

 

Here's an alternative method that doesn't need to use updates:

 

 

Scriptname OAQ01TriggerTwoDeadSCRIPT extends ObjectReference  
import Debug

Actor Property guardian01 Auto
Actor Property guardian02 Auto

bool G1IsDead
bool G2IsDead

Function Guardian1Died()
debug.trace("Guardian 1 registered his death")
G1IsDead = true
TryActivate()
EndFunction

Function Guardian2Died()
debug.trace("Guardian 2 registered his death")
G2IsDead = true
TryActivate()
EndFunction

Function TryActivate()
If G1IsDead && G2IsDead
	activate(Game.GetPlayer())
	debug.trace("TrapLink with two dead activated")
EndIf
EndFunction

 

 

Put a small script on each guardian with an OnDeath() event that calls Guardian1Died() or Guardian2Died() on the above script.

Edited by steve40
Link to comment
Share on other sites

I'm guessing that last part should be "function TryActivate()" and you were hitting the eggnog last night ;) (I know I was)

 

What is preferable in terms of speed/efficiency, one script using registerforsingleupdate() or three scripts but without updates? Because I would tend to go for the single script option, so I was wondering.

Link to comment
Share on other sites

I was drinking Baileys actually :thumbsup: but yes, it should be a function, BUT it will probably still work as is (events are functions after all - it compiled without errors) :tongue:

The second method is more efficient and safer - it doesn't run any update calls.

Edited by steve40
Link to comment
Share on other sites

Just to chime in with another option (that's what I love about programming, always so many ways to approach any given problem, each with their own pros and cons!), I would use Steve40's second approach but simplified:

Scriptname OAQ01TriggerTwoDeadSCRIPT extends ObjectReference  
import Debug

Actor Property guardian01 Auto
Actor Property guardian02 Auto

Function TryActivate()
       If guardian01.isDead() && guardian02.isDead()
               activate(Game.GetPlayer())
               debug.trace("TrapLink with two dead activated")
       EndIf
EndFunction

Then just put an onDeath() (or onDying() -- dunno if Beth's fixed it yet, but onDeath() has been problematic, and for my mod Dovahheim I had to switch to onDying() to get things to work reliably...) event on your two guardians that calls TryActivate(). [Note that I'm trusting Steve40's syntax, I have not tried to compile or test this myself, but if his compiled and worked this one will as well.]

Link to comment
Share on other sites

@kromey: D'oh, I definitely had too much Baileys when I wrote that! :tongue:

Absolutely nothing wrong with that, I myself had had too much of that same poison yesterday -- although I was sober again before I posted, I still managed to make an utter fool of myself in front of my parents and my wife! :tongue:

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...