Nutulator Posted September 4, 2016 Share Posted September 4, 2016 Hello, how can I end a quest when a number of NPCs die? I have 12 NPCs which spawn through a quest and I want that quest to end when all the 12 NPCs die. What type of script do I need and what would it exactly look like? Thanks. Link to comment Share on other sites More sharing options...
TummaSuklaa Posted September 4, 2016 Share Posted September 4, 2016 (edited) You can put a script on all of them(just make one script and just add it to all of them) and use a count that increments after each death. Scriptname myNPCAliasScript extends ReferenceAlias Int property iDeathCount auto Event OnDeath(Actor akKiller) if iDeathCount == 12 GetOwningQuest().Stop() ; or SetCurrentStageID(stage you want the quest to complete on), etc else iDeathCount += 1 Endif EndEvent Edited September 4, 2016 by TummaSuklaa Link to comment Share on other sites More sharing options...
Nutulator Posted September 4, 2016 Author Share Posted September 4, 2016 (edited) Ah okay, thanks! I've put in the script on all the NPCs but I'm missing something--it's not exactly working. You mentioned a count that increments after each death, is that iDeathCount += 1, or would I have to set that up separately? Edited September 4, 2016 by Nutulator Link to comment Share on other sites More sharing options...
TummaSuklaa Posted September 4, 2016 Share Posted September 4, 2016 (edited) Yes, the thing the event will check is if iDeathCount is already 12, and if not, iDeathCount will add 1 to itself every time an alias dies with that script attached, until it reaches 12. All you have to do is copy the script or at least include the lines if you have other things you want to happen when they die. Post if you have problems, there's more than one way to do what you want - that way however is easier for me. Edited September 4, 2016 by TummaSuklaa Link to comment Share on other sites More sharing options...
Nutulator Posted September 4, 2016 Author Share Posted September 4, 2016 Unfortunately it's not working. I've messed around with it but the stage just doesn't change nor does the quest stop. That would be great if you could tell another way to do this. Link to comment Share on other sites More sharing options...
TummaSuklaa Posted September 4, 2016 Share Posted September 4, 2016 (edited) Alright, this one is a little more complicating. You need to add a ReferenceAlias array property to a quest script. If your quest doesn't have one, create it. Make sure it's not "const". Once you set up the property make sure to fill the array with your 12 aliases, and be sure to remove the last element after the 12th. You'll need a way to call a quest stage that calls one function I've made(out of three). You can use the script above for that but put it on ONE alias. Otherwise all 12 could potentially be calling OnDeath/SetCurrentStageID/Stop() unnecessarily. So with that said.. put this in your quest script. ReferenceAlias[] property myAliases auto Int Function CheckForDeadAliases() int iCount int i = 0 int iIndex = myAliases.Length While i < iIndex if myAliases[i].isDead() iCount += 1 i += 1 else i += 1 endif EndWhile return iCount EndFunction Function RunTimer() if CheckForDeadAliases() == 12 Stop() ; again or just SetCurrentStageID(stagehere) else StartTimer(10) endif EndFunction Event OnTimer(Int aiTimerID) if CheckForDeadAliases() == 12 Stop() else StartTimer(10) endif EndEventThe function "RunTimer" needs to go in a stage fragment that your alias with the OnDeath script will set upon death. In the stage fragment is a drop down to select your quest script(not sure how much you know, so I'm explaining everything).Then put this in the field: kmyQuest.RunTimer()This should in theory check every 10 seconds if all of them are dead. RunTimer is only called once. The event will keep calling itself until CheckForDeadAliases reaches 12. Edited September 4, 2016 by TummaSuklaa Link to comment Share on other sites More sharing options...
Nutulator Posted September 5, 2016 Author Share Posted September 5, 2016 (edited) I've got everything setup but when I try to compile it says, "isDead is not a function or does not exist." I'm guessing this is happening because isDead is a actor function instead of a quest one? Edited September 5, 2016 by Nutulator Link to comment Share on other sites More sharing options...
TummaSuklaa Posted September 5, 2016 Share Posted September 5, 2016 Ohhh sorry about that. Common error on my part. Change myAliases.isDead() to(myAliases[i].GetReference() as Actor).isDead() Link to comment Share on other sites More sharing options...
Nutulator Posted September 5, 2016 Author Share Posted September 5, 2016 (edited) Ahh, okay. It compiles now but the quest still isn't ending--there's something very simple which I'm screwing up on. I'll keep at it and I'll figure it out eventually; thanks for all the help, I really appreciate it. Edited September 5, 2016 by Nutulator Link to comment Share on other sites More sharing options...
Recommended Posts