Jump to content

I wrote a script to monitor actors' detection state. Am I doing anything wrong?


Recommended Posts

Posted (edited)

I am once again hoping someone can point me in the right direction to learn how to make something happen.

 

I want to create a script that attaches to the player and all humanoids around them, that checks if the actor is being detected by anyone so I can use the result to create a DAR condition for modesty mods in order to only play modesty animations if a character is actually being noticed by anyone. As I understand it, cloak spells were typically used to apply magic effects to NPCs to monitor them, but this tended to add a lot of script load. Since SPID came out, I've seen a number of previously cloaking mods get changed to use SPID instead, so is that the best route to take now?

 

At any rate, Papyrus Extender adds the following function:

Bool Function IsDetectedByAnyone(Actor akActor) global native

which sounds like what I need to use. I need to distribute a script onto all humanoid actors that checks for whether IsDetectedByAnyone returns true or false, then does something to the actor that DAR can detect in order to make them play the animations I want. Apply a magic effect, add to a faction, I think the specifics on that step don't matter as long as it can be seen by DAR. I have no clue how to add a function from SKSE/Papyrus Extender to my scripts though, so I'm hoping for help on that too.

 

So what is the proper way to accomplish this? Am I supposed to use SPID to apply a perk to all actors, and put the detector script on that perk? Or is such a perk supposed to give an ability with a magic effect that has the detector script? Do I need to make quests with quest aliases? Should I just use a cloak spell since there are more tutorials on how to use those?

Edited by Mud
Posted (edited)
16 hours ago, Dawndrake said:

You should ask in the modding discord for faster response: https://discord.gg/EHRvjCEP

I have, in the development channel since it seemed likely it would quickly get washed away by users trying to troubleshoot their mod profiles in the modding help channels. Basically trying to put out feelers looking for any aid I can get here.

 

What I have currently done is the following:

 

I have created an ESP called DAR Actor Detection.esp. I've created two magic effects, and an Ability record for each: a dummy effect called CoverSelfDetected attached to the ability CoverSelfFlag that does nothing, to serve as the DAR condition, and a monitoring effect called CoverSelfDetectEffect whose ability, CoverSelfDetector, will be distributed via SPID, containing the script that will check the actor's detection state.

 

The script looks like this:

Spoiler
Scriptname DARdetectionstatescript extends ActiveMagicEffect  

import PO3_SKSEFunctions
Actor character
Spell Property CoverSelfFlag Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
	character = akTarget
	RegisterForSingleUpdate(2.0)
endEvent

Event OnUpdate()
	if IsDetectedByAnyone(character)
		character.AddSpell(CoverSelfFlag, false)
	else
		character.RemoveSpell(CoverSelfFlag)
	endif
	RegisterForSingleUpdate(4.0)
endEvent

 

 

This script does compile successfully, after I spent some time reading a bunch of things and weeding out the mistakes I was making, but I don't know if it works yet.

 

I'll keep experimenting later and try to set up SPID and DAR, but if I'm making any missteps here I'd love to learn what they are.

Edited by Mud
Posted (edited)

Update: The script and effects work! As a novice to scripting though, my thoughts now turn to whether or not I'm committing any scripting sins with this thing. Are there optimizations I should make? Is there a better way to do this?

Edited by Mud

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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