Note: This can be applied to any reference. But this tutorial only covers actors.
This is a tutorial by egocarib, the creator of mods like Enchanted Arsenal and Enchanting Awakened. Any text not in italics is either the author's words, or the author's words slightly modified by me. This tutorial assumes you have a basic knowledge of scripting, and a rudimentary knowledge of quest design.This tutorial will teach you how to use a quest and aliases to detect actors of a certain type near to the player. It can be applied in many different ways, but is very useful and pretty simple.
This is a tutorial by egocarib, the creator of mods like Enchanted Arsenal and Enchanting Awakened. Any text not in italics is either the author's words, or the author's words slightly modified by me. This tutorial assumes you have a basic knowledge of scripting, and a rudimentary knowledge of quest design.This tutorial will teach you how to use a quest and aliases to detect actors of a certain type near to the player. It can be applied in many different ways, but is very useful and pretty simple.
This will be a pretty quick tutorial. I'll use an example from something I set up recently. For a skill learning system I've implemented, I need to know whenever there are actors near the player that have the ability to spread disease (like skeevers, vampires, etc).
To do this, I first set up a quest with several aliases that can detect nearby actors that meet that description.
To do this, I first set up a quest with several aliases that can detect nearby actors that meet that description.
Setting Up the Quest
This is what the quest looks like.
These are images of the alias and quest data tabs.
A few things to notice:
These are images of the alias and quest data tabs.
A few things to notice:
- The quest is set up to NOT be Start Game Enabled. We only want to start this when we decide its time to detect actors.
- The first Alias is not optional, but all additional aliases ARE optional -- this is to ensure that the quest will start successfully as long as there is at least one actor that meets the conditions.
- Each alias has the same conditions, which check if the actor is one of a number of disease-spreading actor types, and if the actor is also within a close distance to the player (2500 units). You'll want your conditions to be specific to your actors. If I am looking for ANY bandit within a certain cell, then my conditions would be IsInFaction (BanditFaction) and IsInCell (MyCell). Likewise, if you're looking for any female Imperials within a radius of 3000 units, your conditions would be GetIsSex (Female), GetIsRace (Imperial) and GetDistance (3000 units away from Player). Hopefully you get the idea.
Using the Quest to Detect Actors
The way that I use this quest is, whenever I want to see whether there are any disease-spreading actors near the player, all I have to do is start this quest, and the aliases will fill automatically. I will name the Quest property in any script I use to check for the nearby disease-giving actors "DiseaseAntenna." So all I need is just a simple:
DiseaseAntenna.Start()
To begin detecting my actors. After starting the quest from a script (or script fragment), all aliases are automatically filled. You can then check whether the first (and any other) alias filled successfully to see if any disease-spreaders were nearby:
If (NearbyDiseaseSpreader1.GetReference() as Actor)
;you'll need to create a ReferenceAlias property if not in a script on your quest
If there were no disease-spreaders that met the necessary conditions, this will equal NONE, and nothing will happen.
Once you've detected whether your desired actors are nearby, and you've reacted appropriately to any actors in your aliases, you can simply stop the quest:
Once you've detected whether your desired actors are nearby, and you've reacted appropriately to any actors in your aliases, you can simply stop the quest:
DiseaseAntenna.Stop()
Tips
- It's super easy to duplicate Aliases in the creation kit. Just set up your first alias or two, and then all you have to do is right click and "Duplicate" to create as many as you need. This is useful if you want to detect, say, up to 50 actors (instead of just 3)
- If you DO have a lot of aliases, consider adding them all to an array to check whether they were filled using a simple while loop
- Just a reminder - make sure you fill all the necessary properties in your script before testing this (including your Quest and any ReferenceAlias properties you want to check)
Additional Info
In case you'd like a text version of the script seen in the screenshot above, I'll paste it here:
Scriptname EA_Learn_ResistDisease extends EA_Learn_TemplateAME
;effect conditioned to be active only while in combat, so this will check at the beginning of each combat
;Note to self: I should also implement a Story Manager event for player gaining a disease, then add experience as long as it lasts.
Quest property DiseaseAntenna auto
ReferenceAlias property NearbyDiseaseSpreader1 auto
ReferenceAlias property NearbyDiseaseSpreader2 auto
ReferenceAlias property NearbyDiseaseSpreader3 auto
ObjectReference diseasedCreature1
ObjectReference diseasedCreature2
ObjectReference diseasedCreature3
Event OnEffectStart(Actor target, Actor caster)
DiseaseAntenna.start()
RegisterForSingleUpdate(1.0)
EndEvent
Event OnUpdate()
if (NearbyDiseaseSpreader1.getReference() as Actor)
diseasedCreature1 = NearbyDiseaseSpreader1.getReference()
diseasedCreature2 = NearbyDiseaseSpreader2.getReference()
diseasedCreature3 = NearbyDiseaseSpreader3.getReference()
GoToState("Active")
else
GoToState("Disabled")
endif
EndEvent
State Active
Event OnHit(ObjectReference aggressor, Form source, Projectile proj, bool powAtk, bool snkAtk, bool bashAtk, bool hitBlocked)
GoToState("Paused")
if (aggressor == diseasedCreature1 || aggressor == diseasedCreature2 || aggressor == diseasedCreature3)
learnManager.LearnResistDisease()
Utility.Wait(7.0)
endif
Utility.Wait(3.0)
GoToState("Active")
EndEvent
EndState
Event OnEffectFinish(Actor target, Actor caster)
DiseaseAntenna.stop()
EndEvent
If you're interested in the complete setup I used for this disease detection example, you can also take a look at the ability I used to turn this detection script on and off for the player. The script above is actually attached to a magic effect, which is used in an ability I've added to the player.
Magic Effect Images
This is just an example of how this feature could be used. You may use it however you like.
Since the OnCombatStateChanged event doesn't work for the player, I attached this ability to the player instead, using an IsInCombat condition. What this results in, is that the script seen above will be initialized every time the player starts combat -- and thus, each time combat starts, the script will start up the DiseaseAntenna quest to check if any disease-spreaders are near the actor. If they are, I award the actor some special experience each time they are hit during this round of combat (which helps them get better at using "Resist Disease" enchantments).
And that's all there is to it! Thanks to egocarib (or on the Nexus) for the well-written tutorial.
Post what kind of tutorial you'd like to see next below.
Magic Effect Images
This is just an example of how this feature could be used. You may use it however you like.
Since the OnCombatStateChanged event doesn't work for the player, I attached this ability to the player instead, using an IsInCombat condition. What this results in, is that the script seen above will be initialized every time the player starts combat -- and thus, each time combat starts, the script will start up the DiseaseAntenna quest to check if any disease-spreaders are near the actor. If they are, I award the actor some special experience each time they are hit during this round of combat (which helps them get better at using "Resist Disease" enchantments).
And that's all there is to it! Thanks to egocarib (or on the Nexus) for the well-written tutorial.
Post what kind of tutorial you'd like to see next below.