Jump to content

[SCRIPT] Follower Magic AI: Directed Heals&Buffs


Ayporos

Recommended Posts

I decided I want to play skyrim with a party of 6 followers, each of them filling custom roles.
Melee/Ranged combat roles seemed easily enough to set up but I had some trouble with the mages..
Firstly the (custom/mod) followers I enlisted seemed to know spells I could not remove with Advanced Follower Tweaks such as SparksLeftHand and SparksRightHand.. I had to -manually- remove them from their respective follower mods in the creationkit and then re-run ASIS patcher with said follower names in the exclusions list.

After all of this and equipping one of my mages whom I've decided would be our dedicated healer I found out Follower AI leaves much to be desired.. more specifically, they don't actually use directed healing/buff spells on friendly characters such as the player or other followers.
AFT has the option to apply TweakSpells but it seems its implementation is severely sketchy, not exactly clear and overall leaves things to be desired (I.E. my healermage would DUMP all of her heals onto me until manage depletion immediately and I'd continue getting healed for up to 30 seconds even after moving far away from her)

I looked at possible mods/scripts for what I want to achieve but all I could find were a few (2 major) follower mods but those employ custom healer AI with custom healing spells which I'd rather not employ as it requires use of said followers (I like choice) and use of said custom healing spells (what's wrong with the default ones??)

I will thus endeavour to -learn- Papyrus scripting from scratch and write an AI script for my needs.

An outline of what it should do and how I want it set up will be as follows:

- script automatically runs on any Actor designated as a follower (not sure yet as to how to implement this, will hopefully figure out after having learned Papyrus)
- script will check for available healing/buffing spells known to Actor
- buffing script will get activated and deactivated on combat start/end and will poll periodically for useful buffs (I'm thinking 1-5 second loop?)
- healing script will poll periodically (out of combat 5 seconds in combat 1 second?) // 5 second poll out of combat to identify possible fall damage or other non-combat inflicted damage
- script will have to keep track of player party (game.getplayer() is easy enough, should be able to fetch a list of active followers easily enough too.. not sure if updating can be set through game event triggers or if I'll have to poll this too)
- during healingscript poll it will check health of all tracked party members and identify who's in need of heals and apply applicable heals depending on available known spells, actual health damage and available magicka
- it will require certain tweaks like preserving magicka for heals if magicka runs low and thus actor needs to refrain from using buff spells; disable polling/script if no directed healing/buffing spells are known to the follower npc; move within spellrange of hurt/to be buffed actor upon identifying damage/combat and before trying to cast said spells

Any things I might have overlooked or tweaks/improvements upon my outline are welcome and highly appreciated!
I will update this thread with progress reports as soon and when it makes sense to do so (milestones or progress-hampering issues that could benefit from outside opinion/help).

possible enhancement/added features:
- check available spells on runtime (if this is possible?) for healing/buffing spells and add them to the scripts known/applyable spells (basically this is supposed to implement compatibility with mods that add new spells by checking all of skyrim's spells at run time for any that are directed and cause a positive (+) attribute modifier on the target)
I would really like to be able to do this as it'd make it compatible with -any- spell adding/altering mod without having to manually make compatibility patches.



That's about it for now, wish me luck!

Edited by Ayporos
Link to comment
Share on other sites

Hi Ayporos,

 

Sounds like a worthy endeavor. To my knowledge only Vilja has the smarts to heal the PC... Your approach to add this ability to all NPCs certainly makes sense. Also will make group enemies more realistic and challenging.

 

Here's a first pass at pointers to your bullets above:

  • script automatically runs on any Actor designated as a follower (not sure yet as to how to implement this, will hopefully figure out after having learned Papyrus)
    • ​I think that would be NPCs belonging to the Followers faction
    • You might consider applying to a broader scope such that enemies could also heal each other
  • script will check for available healing/buffing spells known to Actor
    • ​You can use GetSpellCount() and GetNthSpell() to iterate through known spells of an NPC
    • might also be easier to test for as conditional in AI or Quest
  • buffing script will get activated and deactivated on combat start/end and will poll periodically for useful buffs (I'm thinking 1-5 second loop?)
    • ​RegisterForSingleUpdate(5.0)
    • OnCombatStateChanged
  • healing script will poll periodically (out of combat 5 seconds in combat 1 second?) // 5 second poll out of combat to identify possible fall damage or other non-combat inflicted damage
    • same as above
    • ​maybe put a check for Magicka levels here so as not to deplete
  • script will have to keep track of player party (game.getplayer() is easy enough, should be able to fetch a list of active followers easily enough too.. not sure if updating can be set through game event triggers or if I'll have to poll this too)
    • ​Probably do this with faction membership and line-of-sight (LOS) functions. FindRandomActorFromRef is also useful for locating NPCs within a certain range.
  • during healingscript poll it will check health of all tracked party members and identify who's in need of heals and apply applicable heals depending on available known spells, actual health damage and available magicka
    • ​GetActorValue is your friend for both Health and Magicka levels
  • it will require certain tweaks like preserving magicka for heals if magicka runs low and thus actor needs to refrain from using buff spells; disable polling/script if no directed healing/buffing spells are known to the follower npc; move within spellrange of hurt/to be buffed actor upon identifying damage/combat and before trying to cast said spells
    • ​I think that much of this could happen as a result of the other conditionals you set up... sometimes it is best to set up simple rules and see what complex behaviors emerge naturally
Link to comment
Share on other sites

jaxonz thanks for the pointers!

Regarding non-follower NPC's:
I'm afraid they won't benefit from this script as I doubt any of them even -know- healing/buffing spells and I am not inclined to start actually modding NPC's. The goal is to provide a simple mod that only attaches this script to NPC's in the Player Follower faction, not to actually modify NPC's by adding spells to them.

I.E. for this script to run on an NPC it'd have to be your follower and it'd have to know a directed healing/buffing spell (either as default or by you teaching it to them through AFT or otherwise).

While I agree it would make sense / be more immersive if groups of hostile mages also healed each other I don't think it is necessary. Most hostile mages already have self-healing spells and they use those (in my opinion) properly when fighting them. The goal of this mod/script is more to provide myself and my non-mage party members with a way of being healed aside from using potions (I despise potions).

I agree that keeping the script lightweight should be priority and I will thus endeavour to keep it as bare-minimum as possible.
I mostly just added the "move to target before healing" because I am not sure yet whether the natural AI will do this on its own before casting the spell or if the cast will fail due to being out of range when ordered to cast it, I will test and script as applicable once I've reached that bridge and the script is ready to cross it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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