Jump to content

On death script after all enemies are cleared


Ex0rdium

Recommended Posts

Just seeing if anyone knows how to run a script for something after a group of specific enemies have been killed.

I know how to run an Ondeath script on one enemy.

I just need something to run after I kill like 4 or 5.

Any help would be appreciated.

Link to comment
Share on other sites

Adding for example say your 5 enemy npcs to a blank quest is really quite easy.

You don't have to set up quest stages, objectives, dialogues or anything like that if you don't need it.

 

I know the Quest window looks daunting with all it's options and tabs, but you only need to focus on what you need to use.

Before long it becomes 2nd nature to say "I'll add a quest for this" with different things you add in the game.

 

Other ways you could do it without a quest would be attach your ondeath script to each enemy and each time one of those enemies dies add a count to a Global variable or even another property in a script.

When the count hit's 5 then do your required action.

Link to comment
Share on other sites

Would you be able to give me an example of how to write a global variable? Basically what Im wanting to do is simply enable an object that is disabled when they all die.
Link to comment
Share on other sites

Add a global variable in CK select in the Object Window -> Miscellaneous -> Global -> Right click the right hand side of the object window and select New from the context menu.

In the Global window that pops up enter a name in the ID field for your new global variable. example name: KilledEnemies

Click OK and you now have your global variable ready to use in your Actor Script.

 

In your Actor Script add a property for the newly created global variable.

Along with that maybe add a property for your ObjectReference you want to enable when they are all dead.

I gave the name for an Object as SecretChest.

Attach the script to each enemy actor in CK.

After you attach the script to an actor, do a properties on the script and set the Properties to point to your global variable and your SecretChest that you want to enable.

(Do this for each actor, the script below is based on 5 actors)

ScriptName EnemyActorScript Extends Actor

GlobalVariable Property KilledEnemies Auto
ObjectReference Property SecretChest Auto

Event OnDeath(Actor akKiller)
    KilledEnemies.Mod(1)
    If KilledEnemies.GetValueInt() >= 5
        SecretChest.Enable()
    EndIf
EndEvent

I haven't tested this, but it does compile error free.

In theory it should work, but in practice there might be timing issues depending on how quick the actors are killed and OnDeath() of one actor may not be registered as another dies at the same time (mutithreaded scripts sometimes don't sync as expected in some situations)

Edited by sLoPpYdOtBiGhOlE
Link to comment
Share on other sites

  • Recently Browsing   0 members

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