Script to have npc extinguish torch if sneaking

Post » Thu Jun 21, 2012 8:00 am

I was just going through a cave with Aela in sneak mode when all of a sudden she whipped out a torch. I don't remember her doing that before and I was wondering if anyone had a script to stop that behavior. If not is it even possible? I know you can test if a npc is sneaking, just not sure how to do the rest. Thanks

FYI The title should of been "follower" not "npc" but same difference I guess.
User avatar
Jennie Skeletons
 
Posts: 3452
Joined: Wed Jun 21, 2006 8:21 am

Post » Thu Jun 21, 2012 3:25 am

i would go for http://www.creationkit.com/IsSneaking_-_Actor
remove all torches, or use http://www.creationkit.com/UnequipItem_-_Actor

not sure how to put the script on all followers automatically tough...
User avatar
Adam Porter
 
Posts: 3532
Joined: Sat Jun 02, 2007 10:47 am

Post » Wed Jun 20, 2012 9:56 pm

Something like...
Bool bDisallowTorchLight Property Torch01 AutoLight Property Torch01Shadow AutoEvent OnUpdate()	If bDisallowTorch != IsSneaking()		bDisallowTorch = !bDisallowTorch		If bDisallowTorch			UnequipItem(Torch01, True)			UnequipItem(Torch01Shadow, True)		Else			UnequipItem(Torch01, False)			UnequipItem(Torch01Shadow, False)		EndIf	EndIfEndEvent
...should work.
User avatar
adame
 
Posts: 3454
Joined: Wed Aug 29, 2007 2:57 am

Post » Thu Jun 21, 2012 1:01 pm

Something like...
Bool bDisallowTorchLight Property Torch01 AutoLight Property Torch01Shadow AutoEvent OnUpdate()	If bDisallowTorch != IsSneaking()		bDisallowTorch = !bDisallowTorch		If bDisallowTorch			UnequipItem(Torch01, True)			UnequipItem(Torch01Shadow, True)		Else			UnequipItem(Torch01, False)			UnequipItem(Torch01Shadow, False)		EndIf	EndIfEndEvent
...should work.

Thank you, I'll stick it in there and let you know if I notice the behavior any more.

*UPDATE* Won't compile.
*UPDATE* Never mind, I added the scriptname at the top and now it's compiling. I'm a newb.
User avatar
Latino HeaT
 
Posts: 3402
Joined: Thu Nov 08, 2007 6:21 pm

Post » Thu Jun 21, 2012 4:45 am

I hope you make this a standalone addition. I would love my follower to do this.
User avatar
Bryanna Vacchiano
 
Posts: 3425
Joined: Wed Jan 31, 2007 9:54 pm

Post » Thu Jun 21, 2012 3:17 am

I happened to be saved at a part where she was holding a torch. I went into sneak and she continued to hold the torch. I attached the script to aela was that not correct? I went through a door to trigger a transition but it didn't change anything.

I'm trying to figure out what could be wrong but have extremely limited knowledge with papyrus. Looking at all the available events however, I wonder if OnUpdate is correct as it appears that OnUpdate is really for magic items? "Received at periodic intervals, if the magic effect is registered."
User avatar
Jessie Butterfield
 
Posts: 3453
Joined: Wed Jun 21, 2006 5:59 pm

Post » Wed Jun 20, 2012 9:39 pm

Well going over this thing OnLoad would be the best event to use but since it's tied to magical items I just don't know. The only other thing I see is OnObjectEquipped but that would just trigger after the npc whipped out the torch.

After looking at all available events, I no longer believe this is possible. If there was an OnSneak event or they added sneak to the OnCombatStateChange event, then it would be possible. Please someone prove me wrong.
User avatar
Myles
 
Posts: 3341
Joined: Sun Oct 21, 2007 12:52 pm

Post » Thu Jun 21, 2012 4:00 am

Is there maybe a way to do this with SKSE? I'm trying to find a list of functions/events that SKSE adds but all they have on their website is a link to the install files.

I have since found the list in their threads and have requested a new event since I don't think there is a built in event that will help us here.
User avatar
Nathan Maughan
 
Posts: 3405
Joined: Sun Jun 10, 2007 11:24 pm

Post » Wed Jun 20, 2012 10:56 pm

I imagine that Justin's example script was designed to be used in conjunction with a http://www.creationkit.com/RegisterForUpdate_-_Form call--because there is no OnBeginSneak-type of event, the basic method would be to check every 20 seconds or so if the actor is sneaking, and if they are then unequip any torch they might have equipped.

You could also use http://www.gamesas.com/topic/1354316-conditions-in-papyrus/ to simulate OnBeginSneak/OnEndSneak events.
User avatar
Claire Mclaughlin
 
Posts: 3361
Joined: Mon Jul 31, 2006 6:55 am

Post » Thu Jun 21, 2012 12:44 am

I imagine that Justin's example script was designed to be used in conjunction with a http://www.creationkit.com/RegisterForUpdate_-_Form call--because there is no OnBeginSneak-type of event, the basic method would be to check every 20 seconds or so if the actor is sneaking, and if they are then unequip any torch they might have equipped.

You could also use http://www.gamesas.com/topic/1354316-conditions-in-papyrus/ to simulate OnBeginSneak/OnEndSneak events.

I had found RegisterForUpdate but that didn't seem to be the best of ideas because it would have to run constantly wouldn't it? Having it run every, say 10 seconds, wouldn't that drain memory or not so much?
User avatar
k a t e
 
Posts: 3378
Joined: Fri Jan 19, 2007 9:00 am

Post » Thu Jun 21, 2012 5:10 am

I just tried it using RegisterForUpdate and it was running every 10 seconds because I put a notification in there, but she wasn't unequipping the torch...

What is happening is, she unequips then instantly re-equips.. i'm trying to figure it out.
User avatar
Sheeva
 
Posts: 3353
Joined: Sat Nov 11, 2006 2:46 am

Post » Wed Jun 20, 2012 11:34 pm

I have had to actually remove torches from an actor's inventory when I wanted to prevent them being equipped--as http://www.creationkit.com/UnequipItem_-_Actor notes, the "prevent re-equipping" flag doesn't seem to work.

Registering for updates every 10 seconds, for a quick script like this, wouldn't cause any problems. People working on combat mods are registering for updates every 0.1 second, or less.
User avatar
Laura Richards
 
Posts: 3468
Joined: Mon Aug 28, 2006 4:42 am

Post » Thu Jun 21, 2012 1:12 pm

Well, the script works to a point. It will unequip and reequip as it should, however there is some overriding behavior that causes the npc to instantly reequip the torch. If I knew anything about papyrus scripting i'd probably know what the issue is, but I don't. Here is the script as it stands now for testing.

Scriptname ActorDisallowTorchWhileSneaking extends ActorBool bDisallowTorchLight Property Torch01 AutoLight Property Torch01Shadow AutoEvent OnInit()    RegisterForUpdate(10)EndEventEvent OnUpdate()	    If bDisallowTorch != IsSneaking()			    bDisallowTorch = !bDisallowTorch			    If bDisallowTorch					    UnequipItem(Torch01, True)					    UnequipItem(Torch01Shadow, True)					    Debug.Notification("Unequip")			    Else					    UnequipItem(Torch01, False)					    UnequipItem(Torch01Shadow, False)					    Debug.Notification("Equip")			    EndIf	    EndIfEndEvent
User avatar
X(S.a.R.a.H)X
 
Posts: 3413
Joined: Tue Feb 20, 2007 2:38 pm

Post » Thu Jun 21, 2012 11:35 am

I have had to actually remove torches from an actor's inventory when I wanted to prevent them being equipped--as http://www.creationkit.com/UnequipItem_-_Actor notes, the "prevent re-equipping" flag doesn't seem to work.

Registering for updates every 10 seconds, for a quick script like this, wouldn't cause any problems. People working on combat mods are registering for updates every 0.1 second, or less.

Then I would have to remove the item from their inventory then give it back when I wasn't sneaking?
User avatar
Christine Pane
 
Posts: 3306
Joined: Mon Apr 23, 2007 2:14 am

Post » Thu Jun 21, 2012 2:51 am

Exactly.
User avatar
QuinDINGDONGcey
 
Posts: 3369
Joined: Mon Jul 23, 2007 4:11 pm

Post » Thu Jun 21, 2012 3:43 am

Ok thanks guys. It appears to be working now but I will post if I run into any bugs.

Working script below:

Scriptname ActorDisallowTorchWhileSneaking extends ActorBool bDisallowTorchLight Property Torch01 AutoLight Property Torch01Shadow AutoEvent OnInit()	RegisterForUpdate(10)EndEventEvent OnUpdate()		If bDisallowTorch != IsSneaking()				bDisallowTorch = !bDisallowTorch				If bDisallowTorch						UnequipItem(Torch01, True)						UnequipItem(Torch01Shadow, True)						RemoveItem(Torch01)				Else						UnequipItem(Torch01, False)						UnequipItem(Torch01Shadow, False)						AddItem(Torch01)				EndIf		EndIfEndEvent

Don't really know if I still need to unequips in there?
User avatar
Penny Wills
 
Posts: 3474
Joined: Wed Sep 27, 2006 6:16 pm

Post » Thu Jun 21, 2012 1:44 am

You should upload that to the steam workshop and/or nexus, I'm sure loads of people would download this tweak.

- Hypno
User avatar
Kat Ives
 
Posts: 3408
Joined: Tue Aug 28, 2007 2:11 pm

Post » Thu Jun 21, 2012 1:05 pm

Don't really know if I still need to unequips in there?
Probably not. Would be 'cheaper' and less conflict proned to do it all with a follower alias.
ScriptName FollowerAliasDisallowTorchWhileSneaking extends ReferenceAliasBool bDisallowTorchInt iTorchCountFormList Property TorchFLST Auto ; Torch01Shadow & Torch01ObjectReference Property TorchContainerREF AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	If TorchFLST.HasForm(akBaseObject)		RegisterForSingleUpdate(0.01)	EndIfEndEventEvent OnUpdate()	If bDisallowTorch != GetActorReference().IsSneaking()		bDisallowTorch = !bDisallowTorch		If bDisallowTorch			iTorchCount = GetActorReference().GetItemCount(TorchFLST)			GetActorReference().RemoveItem(TorchFLST, iTorchCount, True, TorchContainerREF)			RegisterForUpdate(3)		Else			TorchContainerREF.RemoveItem(TorchFLST, iTorchCount, True, GetActorReference())			UnregisterForUpdate()		EndIf	EndIfEndEventEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If bDisallowTorch		If TorchFLST.HasForm(akBaseObject)			GetActorReference().RemoveItem(akBaseObject, aiItemCount, True, TorchContainerREF)			iTorchCount += aiItemCount		EndIf	EndIfEndEvent
That could be glued to multiple aliases all using the same TorchContainerREF and leave the base forms untouched.
User avatar
My blood
 
Posts: 3455
Joined: Fri Jun 16, 2006 8:09 am

Post » Wed Jun 20, 2012 11:02 pm

@JustinOther I will try your script as well. I had just come back to get the names of those who helped because I believe this script is going to be released in a Follower AI mod that is in beta right now. If your script works, I will add you to the list of those getting credit. :)
User avatar
Robyn Howlett
 
Posts: 3332
Joined: Wed Aug 23, 2006 9:01 pm

Post » Thu Jun 21, 2012 6:33 am

I haven't messed with aliases before so I'm trying to take a crash course so I can test your script but I am confused. What I am reading makes me think that aliases are used in association to quests, but this is a behavior I always want the follower to exhibit. I'm assuming that is very possible and I am just not understanding how to apply the script. I figured there was a way to assign an alias to, for instance, the follower faction, but I don't see how. Any help is appreciated.
User avatar
Tai Scott
 
Posts: 3446
Joined: Sat Jan 20, 2007 6:58 pm

Post » Thu Jun 21, 2012 12:15 pm

Followers are controlled through aliases in a quest. The vanilla follower system uses the Follower alias in the DialogueFollower quest. Simply attach the script provided by JustinOther to that alias and it will work.

The problem is if someone uses a custom follower or uses a custom follower system provided by a mod. Then you would have to edit those mods and apply the script to the aliases used in those mods.
User avatar
sw1ss
 
Posts: 3461
Joined: Wed Nov 28, 2007 8:02 pm

Post » Wed Jun 20, 2012 11:14 pm

I had found DialogueFollower quest and wondering if that was where it needed to go.

As for compatibility, I'm just going to pass the script on and let the mod author worry about that stuff. ;)

Thanks, I will try to get the new version working....
User avatar
Cash n Class
 
Posts: 3430
Joined: Wed Jun 28, 2006 10:01 am

Post » Thu Jun 21, 2012 7:42 am

Haven't been able to get it to compile yet...

ScriptName FollowerAliasDisallowTorchWhileSneaking extends ReferenceAliasBool bDisallowTorchInt iTorchCountFormList Property TorchFLST AutoFormList Property Torch01Shadow AutoFormList Property Torch01 AutoObjectReference Property TorchContainerREF AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)		If TorchFLST.HasForm(akBaseObject)				RegisterForSingleUpdate(0.01)		EndIfEndEventEvent OnUpdate()		If bDisallowTorch != GetActorReference().IsSneaking()				bDisallowTorch = !bDisallowTorch				If bDisallowTorch						iTorchCount = GetActorReference().GetItemCount(TorchFLST)						GetActorReference().RemoveItem(TorchFLST, iTorchCount, True, TorchContainerREF)						RegisterForUpdate(3)				Else						TorchContainerREF.RemoveItem(TorchFLST, iTorchCount, True, GetActorReference())						UnregisterForUpdate()				EndIf		EndIfEndEventEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)		If bDisallowTorch				If TorchFLST.HasForm(akBaseObject)						GetActorReference().RemoveItem(akBaseObject, aiItemCount, True, TorchContainerREF)						iTorchCount += aiItemCount				EndIf		EndIfEndEvent

Anyone see a problem? I'm a noob.

It says akBaseObject is undefined, but it looks defined to me. :tongue:

Never mind, I found it myself. The problem was he had used "akBaseObject" instead of "akItemObject" in the OnItemAdded event. Thanks.
User avatar
kyle pinchen
 
Posts: 3475
Joined: Thu May 17, 2007 9:01 pm

Post » Thu Jun 21, 2012 1:05 am

What value do you give to TorchContainerREF and TorchFLST? Do I have to create something to assign to those pointers?
User avatar
Penny Wills
 
Posts: 3474
Joined: Wed Sep 27, 2006 6:16 pm

Post » Wed Jun 20, 2012 9:01 pm

What value do you give to TorchContainerREF and TorchFLST? Do I have to create something to assign to those pointers?
akBaseObject: Wups, it's supposed to be akBaseItem. Yeah, the properties are gonna need to be pointed at what they represent, so you'd place a container somewhere and assign it the EditorID 'TorchContainerREF' and make a FormList named TorchFLST. Then, when you hit the autofill button, the properties will automatically be pointed at the appropriate REFR/FLST.

Fixed code with indentation restored:
Spoiler
ScriptName FollowerAliasDisallowTorchWhileSneaking extends ReferenceAliasBool bDisallowTorchInt iTorchCountFormList Property TorchFLST AutoObjectReference Property TorchContainerREF AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	If TorchFLST.HasForm(akBaseObject)		RegisterForSingleUpdate(0.01)	EndIfEndEventEvent OnUpdate()	If bDisallowTorch != GetActorReference().IsSneaking()		bDisallowTorch = !bDisallowTorch		If bDisallowTorch			iTorchCount = GetActorReference().GetItemCount(TorchFLST)			GetActorReference().RemoveItem(TorchFLST, iTorchCount, True, TorchContainerREF)			RegisterForUpdate(3)		Else			TorchContainerREF.RemoveItem(TorchFLST, iTorchCount, True, GetActorReference())			UnregisterForUpdate()		EndIf	EndIfEndEventEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If bDisallowTorch		If TorchFLST.HasForm(akBaseItem As Form)			GetActorReference().RemoveItem(akBaseItem, aiItemCount, True, TorchContainerREF)			iTorchCount += aiItemCount		EndIf	EndIfEndEvent
^That compiles


Aliases: Your quest could have a bunch of ReferenceAlias slots with that script to be filled dynamically with http://www.creationkit.com/ForceRefIfEmpty_-_ReferenceAlias, I believe. Haven't yet messed with on-the-fly alias filling, but I'd imagine it works as advertized.
User avatar
jeremey wisor
 
Posts: 3458
Joined: Mon Oct 22, 2007 5:30 pm

Next

Return to V - Skyrim