Jump to content

Setting Trigger to activate when actor is dead


Hangman4358

Recommended Posts

I actually just thought of redoing the entire script and to have it use linkedRefs. Using the .GetNthLinkedRef() and the setting it up kind of like the puzzle pillar script where I can specify how many actors are linked to the trigger and then checking them all for death.

 

Only problem is I have no clue how to go about having it set up check linked refs 1-n. I will probably look at the puzzle pillar script and try and figure it out from that when I have some time at home

Link to comment
Share on other sites

Actually I looked through the way the puzzle pillar does it and I think that way is much more ingenious actually. When the pillar is in the correct position it increases an integer count in the script for the lever. If the integer count of the number of solves pillars is the same as the defined count of pillars total in the puzzle the lever will open.

 

So I am taking that concept and having an OnDeath or OnDying increase the death count by one and then try and activate the LinkActivator. when all are dead and the counts match the gate will open. This way I can set it to use 1 actor or 50 actors

 

EDIT:

 

Ok so I went about trying to set this up but now I have a compiling problem. Here are my two scripts

 

This one is on the trigger itself

Scriptname OAQ01Valuungrann03GuardianTrigSCRIPT extends ObjectReference

int property numDead auto hidden
int property deadCount auto
{Number of Actors to Kill}

Function TryActivate()
       If numDead == deadCount
               activate(Game.GetPlayer())
               GoToState("COMPLETED")
       EndIf
EndFunction

STATE COMPLETED
;DoNothing
ENDSTATE

 

This one is on the actor

Scriptname OAQ01GuardianExplosionSCRIPT extends Actor  
{Creates explosion on the death of a Guardian and passes on a death if linked correctly}

Spell Property OAQ01GuardianExplosionSpell Auto Hidden
ObjectReference Property deathTrapLinker Auto
{trigger to use on having actor killed}

Event OnDying(Actor akKiller)
utility.Wait(0.75)
OAQ01GuardianExplosionSpell.Cast(Self)
deathTrapLinker.numDead = deathTrapLinker.numDead + 1
self.disable()
EndEvent

 

But not it is giving me this error

C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\OAQ01GuardianExplosionSCRIPT.psc(10,17): numDead is not a property on script objectreference or one of its parents

C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\OAQ01GuardianExplosionSCRIPT.psc(10,43): numDead is not a property on script objectreference or one of its parents

C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\OAQ01GuardianExplosionSCRIPT.psc(10,51): cannot add a none to a int (cast missing or types unrelated)

 

I just have no clue how to get the two scripts to talk to one another

Edited by Hangman4358
Link to comment
Share on other sites

Try something like this (untested, as being at work I don't have the CK in front of me):

 

On your trigger, add this function:

Function incrementNumDead()
 numDead = numDead + 1
EndFunction

 

Then change your onDying event on your actors to:

Event OnDying(Actor akKiller)
       utility.Wait(0.75)
       OAQ01GuardianExplosionSpell.Cast(Self)
       deathTrapLinker.incrementNumDead()
       self.disable()
EndEvent

 

This being said, though, I think the linkedRef chain is actually the better solution; this approach will break if the player kills one guardian but then has to flee, and when they eventually return the first guardian has respawned -- at that point killing one guardian will open the door, but the second guardian is still standing! You can have as many guardians as you like in the linkedRef chain, and adding and removing guardians is as easy as re-pointing those linked refs.

Link to comment
Share on other sites

Ah, yeah, that would be an issue, I hadn't thought of that.

 

I still think checking the isDead() method on each actor is better than using the dead count, but if you've set your dungeon to not respawn then there probably won't be an issue -- it's just the programmer in me thinking about race conditions and disjoint dependent states. Using the incrementing function from my previous post should fix your issue and allow you to use the counter successfully, I think -- as I said, I'm unable to test it, and I've never tried to use an approach like this before.

Link to comment
Share on other sites

But not it is giving me this error
C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\OAQ01GuardianExplosionSCRIPT.psc(10,17): numDead is not a property on script objectreference or one of its parents

C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\OAQ01GuardianExplosionSCRIPT.psc(10,43): numDead is not a property on script objectreference or one of its parents

C:\Program Files (x86)\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\OAQ01GuardianExplosionSCRIPT.psc(10,51): cannot add a none to a int (cast missing or types unrelated)

 

I just have no clue how to get the two scripts to talk to one another

 

You need to cast "deathTrapLinker" as the script that is attached to it:

 

(deathTrapLinker as OAQ01Valuungrann03GuardianTrigSCRIPT). numDead += 1

Link to comment
Share on other sites

Then change your onDying event on your actors to:

Event OnDying(Actor akKiller)
       utility.Wait(0.75)
       OAQ01GuardianExplosionSpell.Cast(Self)
       deathTrapLinker.incrementNumDead()
       self.disable()
EndEvent

 

A small correction:

 

 

Event OnDying(Actor akKiller)
       utility.Wait(0.75)
       OAQ01GuardianExplosionSpell.Cast(Self)
       (deathTrapLinker as OAQ01Valuungrann03GuardianTrigSCRIPT).incrementNumDead()
       self.disable()
EndEvent

Edited by steve40
Link to comment
Share on other sites

I actually also tried setting it up with a while loop that would go through and check each linkedRef for .isDead() but apparently you can also only set one actor to a linkedRef of something or something because I could never set more than one actor to a linkedRef.

 

Hey thanks guys for all the help again. That worked perfectly Steve. Just learned something new :)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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