Script to have npc extinguish torch if sneaking

Post » Thu Jun 21, 2012 1:31 am

Ok.. I think I got what you were saying and I'm about to go see if it's working.. thanks.
User avatar
Alyce Argabright
 
Posts: 3403
Joined: Mon Aug 20, 2007 8:11 pm

Post » Thu Jun 21, 2012 1:25 am

Well, it seems to be working but let me ask you, once the NPC has the torch out and I go into sneak mode, reading your code it looks like she should remove the torch within 3 seconds? Usually it's around that long, but I have counted as high as 7 once. Just not sure why that is.

I can say she put the torch down every single time I went into sneak and she would not equip the torch while I was sneaking so it seems to be working well enough. I guess I could fiddle with that (3) to see if it effects how quickly she unequips.

*UPDATE yeah I changed it to (1) and I counted to 8 the first 2 times and realized that it hadn't done anything. I guess I'm just confused as to why the npc isn't removing the torch quicker.
User avatar
Bryanna Vacchiano
 
Posts: 3425
Joined: Wed Jan 31, 2007 9:54 pm

Post » Thu Jun 21, 2012 1:48 am

I've used the old code in my mod as well for the next update. Can you confirm that the new code doesn't put a torch into follower inventory if there previously wasn't any torch in their inventory? Because that's what the old code did.

On another question, how do I need to change the script so that followers would also put lenterns away if in their inventory?
User avatar
Anna Watts
 
Posts: 3476
Joined: Sat Jun 17, 2006 8:31 pm

Post » Thu Jun 21, 2012 5:17 am

]*UPDATE yeah I changed it to (1) and I counted to 8 the first 2 times and realized that it hadn't done anything. I guess I'm just confused as to why the npc isn't removing the torch quicker.
Hmm... The 0.01 update should be the one that determines how quickly the torch is unequipped while the 3 would be for re-equipping when !Sneaking.
I've used the old code in my mod as well for the next update. Can you confirm that the new code doesn't put a torch into follower inventory if there previously wasn't any torch in their inventory? Because that's what the old code did.

On another question, how do I need to change the script so that followers would also put lenterns away if in their inventory?
It shouldn't give any free torches as the iTorchCount ought to keep track whereas the old code just blindly gave one when they stopped sneaking.

Lanterns: Just dragondrop the lanterns into the FormList. As long as only one follower is utilizing the container, it should be that simple. If filling multiple aliases with more followers, I'd make a *"Create Reference" container alias for each slot that torches and lanterns won't end up where they didn't come from.

*or just place more containers

Edited above code: Removed errant properties.
User avatar
Amiee Kent
 
Posts: 3447
Joined: Thu Jun 15, 2006 2:25 pm

Post » Thu Jun 21, 2012 12:50 pm

Hmm... The 0.01 update should be the one that determines how quickly the torch is unequipped while the 3 would be for re-equipping when !Sneaking.It shouldn't give any free torches as the iTorchCount ought to keep track whereas the old code just blindly gave one when they stopped sneaking.

Lanterns: Just dragondrop the lanterns into the FormList. As long as only one follower is utilizing the container, it should be that simple. If filling multiple aliases with more followers, I'd make a *"Create Reference" container alias for each slot that torches and lanterns won't end up where they didn't come from.

*or just place more containers

Edited above code: Removed errant properties.

Thanks a bunch friend. You shall be mentioned in my ReadMes credit section. Life without you would be so much harder...:D
User avatar
gemma
 
Posts: 3441
Joined: Tue Jul 25, 2006 7:10 am

Post » Thu Jun 21, 2012 11:37 am

Glad to be able to help when able :) Scripting riddles are fun! Also, answered *your questions on the Workshop.

*assuming you're Mofakin on Steam
User avatar
teeny
 
Posts: 3423
Joined: Sun Feb 25, 2007 1:51 am

Post » Thu Jun 21, 2012 12:58 pm

Well, it seems to be working but let me ask you, once the NPC has the torch out and I go into sneak mode, reading your code it looks like she should remove the torch within 3 seconds? Usually it's around that long, but I have counted as high as 7 once. Just not sure why that is.

I can say she put the torch down every single time I went into sneak and she would not equip the torch while I was sneaking so it seems to be working well enough. I guess I could fiddle with that (3) to see if it effects how quickly she unequips.

*UPDATE yeah I changed it to (1) and I counted to 8 the first 2 times and realized that it hadn't done anything. I guess I'm just confused as to why the npc isn't removing the torch quicker.
That line uses a registerforupdate. if it didn't have enough time to finish the onupdate function before a new update happens, two update functions will exist. This can happen with 3, 4, 5... onupdate functions and the greater the number, the slower it will work. This way, reducing the number could make it last longer instead.

I really would suggest to use a registerforsingleupdate instead, as that way no new update will be registered before the onupdate function finishes.
User avatar
tannis
 
Posts: 3446
Joined: Sat Dec 09, 2006 11:21 pm

Post » Thu Jun 21, 2012 6:55 am

Could be wrong, but I really doubt 'If bDisallowTorch != GetActorReference().IsSneaking()' takes that long to process or is staggering. Swapping RegisterForUpdate() with RegisterForSingleUpdate() would necessitate each OnUpdate() iteration also checking 'ElseIf bDisallowTorch'.

Just the same:
Event OnUpdate()	If bDisallowTorch != GetActorReference().IsSneaking()		bDisallowTorch = !bDisallowTorch		If bDisallowTorch			iTorchCount = GetActorReference().GetItemCount(TorchFLST)			GetActorReference().RemoveItem(TorchFLST, iTorchCount, True, TorchContainerREF)		Else			TorchContainerREF.RemoveItem(TorchFLST, iTorchCount, True, GetActorReference())		EndIf		RegisterForSingleUpdate(3)	ElseIf bDisallowTorch		RegisterForSingleUpdate(3)	EndIfEndEvent
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Thu Jun 21, 2012 11:25 am

It has two if blocks and up to 4 functions (2 getactorreference, getitemcount and a removeitem if bdisallowtorch exist but the reference is not sneaking). It's a light script but it needs to be processed. Keep in mind that nbtc971 was reducing the update time from 3 seconds to 1 second and that other scripts, or the engine failing to give control to the scripting part in time could make it last way longer than it should.

Some of the functions, could also be slower than one could suppose, and could be delayed under certain circumstances (removeitem is a good candidate for both).

Registerforupdate can be used safelly, but it's much easier to use registerforsingleupdate rather than ensuring that the onupdate won't bloat with a registerforupdate instruction. There isn't speed lost either for using registerforsingleupdate. You only need to give a lower update time to compensate the addition of the execution to the time and if the execution time is too long for that, the bloating is ensured if you use a registerforupdate. In other words, in short update times, a registerforupdate won't be quicker than a registerforsingleupdate ever.

Besides, using that instruction even with quick enough functions and long enough update times have two additional disadvantages: you get used to use it, and will end up using when you shouldn't and it makes more dificult to convince everibody not to use it (something that is really needed).

It's like using plutonium for constructing weighing scales. It's a heavy material, which allow to make the pieces small, but it's dangerous and there are other alternatives.
User avatar
Hannah Barnard
 
Posts: 3421
Joined: Fri Feb 09, 2007 9:42 am

Post » Thu Jun 21, 2012 9:29 am

Just for confirmation. This script has to be attached to the 'Follower' alias in 'DialogueFollower' quest? If so, it doesn't seem to work. Do I need to specify a signle follower to make it work?

Another question. Would it be possible to modifie this script so that followers only equip torch when you do? OnEquip/OnUnequip doesn't seem to do anything. Probably theese are only supposed to work on object script?

Edit: This doesn't seem to work for me. Created a Formlist, put the torches and lanterns into it, created a container and referenced it inside the script. The script:

Spoiler
Scriptname TestNoTorchScript extends ReferenceAlias  Bool bDisallowTorchInt iTorchCountFormList Property TestFollowerFL AutoObjectReference Property TestNoFollowerCONREF AutoEvent OnObjectEquipped(Form akBaseObject, ObjectReference akReference)	    If TestFollowerFL.HasForm(akBaseObject)			    RegisterForSingleUpdate(0.01)	    EndIfEndEventEvent OnUpdate()	    If bDisallowTorch != GetActorReference().IsSneaking()			    bDisallowTorch = !bDisallowTorch			    If bDisallowTorch					    iTorchCount = GetActorReference().GetItemCount(TestFollowerFL)					    GetActorReference().RemoveItem(TestFollowerFL, iTorchCount, True, TestNoFollowerCONREF)					    RegisterForUpdate(3)			    Else					    TestNoFollowerCONREF.RemoveItem(TestFollowerFL, iTorchCount, True, GetActorReference())					    UnregisterForUpdate()			    EndIf	    EndIfEndEventEvent OnItemAdded(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	    If bDisallowTorch			    If TestFollowerFL.HasForm(akBaseItem As Form)					    GetActorReference().RemoveItem(akBaseItem, aiItemCount, True, TestNoFollowerCONREF)					    iTorchCount += aiItemCount			    EndIf	    EndIfEndEvent

The script is attached to the unique actor alias 'Sven'.
User avatar
Sabrina garzotto
 
Posts: 3384
Joined: Fri Dec 29, 2006 4:58 pm

Post » Thu Jun 21, 2012 9:10 am

Another question. Would it be possible to modifie this script so that followers only equip torch when you do? OnEquip/OnUnequip doesn't seem to do anything. Probably theese are only supposed to work on object script?

It's certainly possible--my Aela follower mod does it. There are various ways it can be accomplished: you could poll the player in the follower script every few seconds to see if they have a torch equipped or not, which would be quick but inefficient; you could also create a separate alias for the player, with a script on it to monitor what the player equips and take action accordingly.
User avatar
James Shaw
 
Posts: 3399
Joined: Sun Jul 08, 2007 11:23 pm

Post » Thu Jun 21, 2012 12:24 am

Just for confirmation. This script has to be attached to the 'Follower' alias in 'DialogueFollower' quest?
No. You'd attach it to your own quest's alias(es).
Do I need to specify a signle follower to make it work?
You could, or you could use http://www.creationkit.com/ForceRefIfEmpty_-_ReferenceAlias to fill it with a follower's reference.
Another question. Would it be possible to modifie this script so that followers only equip torch when you do? OnEquip/OnUnequip doesn't seem to do anything. Probably theese are only supposed to work on object script?
http://www.creationkit.com/OnObjectEquipped_-_Actor works for actors and actor aliases alike.

Also, just noticed the code won't work as is if the follower equips the torch while not sneaking. I'm making a plugin which I'll link when the kinks are ironed out which has multiple alias slots. *I've still yet to figure out how, but it should be possible to attach the script to as many followers as desired.

*handing a follower a note should work well enough.
User avatar
Jah Allen
 
Posts: 3444
Joined: Wed Jan 24, 2007 2:09 am

Post » Thu Jun 21, 2012 12:51 am

I'm making a plugin which I'll link when the kinks are ironed out which has multiple alias slots. I've still yet to figure out how, but it should be possible to attach the script to as many followers as desired.

What if you http://www.creationkit.com/Dynamically_Attaching_Scripts instead? You could give the player a constant cloak effect that applies scripts to anyone with a rank in the CurrentFollowerFaction.
User avatar
Andrea P
 
Posts: 3400
Joined: Mon Feb 12, 2007 7:45 am

Post » Thu Jun 21, 2012 1:08 am

No. You'd attach it to your own quest's alias(es).You could, or you could use http://www.creationkit.com/ForceRefIfEmpty_-_ReferenceAlias to fill it with a follower's reference.http://www.creationkit.com/OnObjectEquipped_-_Actor works for actors and actor aliases alike.

Also, just noticed the code won't work as is if the follower equips the torch while not sneaking. I'm making a plugin which I'll link when the kinks are ironed out which has multiple alias slots. I've still yet to figure out how, but it should be possible to attach the script to as many followers as desired.

Well, I give up. I exactly did what you told me. I've made a new quest priority 10. Made a new alias named Sven with fill type unique actor = sven. Made a container and put it into a cell, made the Formlist and put the torch inside. But this just does not seem to work at all. Follower Sven does not put his torch away. I think I'd rather stay with the old script as this new script seems to be way over my head.

Problem is I don't even remotely understand what I'm doing wrong since I've did anything like described. Here's the final script:

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

And a picture of the quest alias screen:

http://imageshack.us/photo/my-images/803/aliasscreen.jpg/

About the whole http://www.creationkit.com/ForceRefIfEmpty_-_ReferenceAlias thing. I'm a basic scripter that can do basic scripts, but I don't even have a a clue where to anchor this. Please someone help. I just wanna get this script working, or I'm going back to the old one.
User avatar
gandalf
 
Posts: 3400
Joined: Wed Feb 21, 2007 6:57 pm

Post » Thu Jun 21, 2012 3:32 am

He said he noticed his script is flawed in that it won't work if the NPC equips the torch while not sneaking. That would probably be my problem.
User avatar
Adam
 
Posts: 3446
Joined: Sat Jun 02, 2007 2:56 pm

Post » Thu Jun 21, 2012 12:04 pm

Guess we're all in wait mode for JustinOther... hah
User avatar
Amanda Leis
 
Posts: 3518
Joined: Sun Dec 24, 2006 1:57 am

Post » Thu Jun 21, 2012 1:55 am

Guess we're all in wait mode for JustinOther... hah

True. I've tried to change the .IsSneaking function with a .OnEquipped function, but then the script doesn't compile.
User avatar
katie TWAVA
 
Posts: 3452
Joined: Tue Jul 04, 2006 3:32 am

Post » Thu Jun 21, 2012 9:18 am

Guess we're all in wait mode for JustinOther... hah
Sorry for the delay. Spent a few hours on this yesterday and got swept up by other stuff.

Anyhow, I've set it all up with a note which can be handed to a follower which explains how carrying a lit torch while sneaking makes no sense and to not do so while under 's employ. When the note is handed off, it's scripted to fill the first unfilled alias slot with the actor bearing the note right before it's given back to the player and each alias who has 'read' the note gets the script attached to 'em. Each alias has its own torch container which is also an alias, an invisible container placed at the player at the time of its creation. It should leave no footprint if uninstalled and not ever conflict with anything even if the base forms are overridden. The part I'm still working on is addition of dummy torches which will look just like the normal ones from within the inventory, but will not be equipable such that the CarryWeight of a follower will not be altered.


http://www.gamesas.com/user/794056-mofakin/: OnEquipped is an event and events aren't interchangeable with functions. You can't have an event in another event, only within a state.



What if you http://www.creationkit.com/Dynamically_Attaching_Scripts instead? You could give the player a constant cloak effect that applies scripts to anyone with a rank in the CurrentFollowerFaction.
Might have to try that if I encounter any brick walls with the alias setup. So far, all is working well though.
User avatar
R.I.P
 
Posts: 3370
Joined: Sat Dec 01, 2007 8:11 pm

Post » Thu Jun 21, 2012 12:45 am

http://www.gamesas.com/user/794056-mofakin/: OnEquipped is an event and events aren't interchangeable with functions. You can't have an event in another event, only within a state.

Yeah. Well, most of the scripts I've created are simple copy and paste scripts from the creation kit wiki. I basically just try to figure out different variants and see if they work. Sometimes they do, sometimes they don't.

I think I'm staying with the old script and try to perfectionate it. It's beter to work with scripts that you have complete understanding of. I think I need more experience in understanding bigger scripts.

But thanks for your input and help... :biggrin:
User avatar
Alina loves Alexandra
 
Posts: 3456
Joined: Mon Jan 01, 2007 7:55 pm

Post » Thu Jun 21, 2012 7:49 am

Yeah this does seem to of grown, but I'm sticking with it to see what JustinOther comes up with. :smile:

The invisible container, it is something the player will never see or run into correct?
User avatar
Tammie Flint
 
Posts: 3336
Joined: Mon Aug 14, 2006 12:12 am

Post » Thu Jun 21, 2012 3:20 am

Yeah this does seem to of grown, but I'm sticking with it to see what JustinOther comes up with. :smile:

The invisible container, it is something the player will never see or run into correct?

Correct, unless you've put it somehwere in the vanilla world. I'm using a custom made cell for ~15 dummy containers that serve as temporary deposit for most of my scripded mod features, such as a craftable containers/satchels, portable tools and other gimmicks.
User avatar
Meghan Terry
 
Posts: 3414
Joined: Sun Aug 12, 2007 11:53 am

Post » Thu Jun 21, 2012 11:00 am

The invisible container, it is something the player will never see or run into correct?
Correct. The containers are completely innocuous.
User avatar
Mistress trades Melissa
 
Posts: 3464
Joined: Mon Jun 19, 2006 9:28 pm

Post » Thu Jun 21, 2012 2:32 am

Any update on this? I had removed the older script in anticipation of this.
User avatar
Natasha Callaghan
 
Posts: 3523
Joined: Sat Dec 09, 2006 7:44 pm

Post » Thu Jun 21, 2012 11:00 am

Oh and I don't know if you were planning on releasing the mod you are working on, but originally I was going to share what came out of this thread with the guy creating this mod..

http://skyrim.nexusmods.com/downloads/file.php?id=16531

I already gave him the first script, with proper credits, and he is happy with that, but I told him that at this point another script was being worked on and that maybe you'd be willing to merge it with his mod. Either way, I understand and he does have a script that will deliver what I promised so I'm sure he is happy either way.
User avatar
jennie xhx
 
Posts: 3429
Joined: Wed Jun 21, 2006 10:28 am

Post » Thu Jun 21, 2012 5:25 am

Oh and I don't know if you were planning on releasing the mod you are working on, but originally I was going to share what came out of this thread with the guy creating this mod..

http://skyrim.nexusmods.com/downloads/file.php?id=16531

I already gave him the first script, with proper credits, and he is happy with that, but I told him that at this point another script was being worked on and that maybe you'd be willing to merge it with his mod. Either way, I understand and he does have a script that will deliver what I promised so I'm sure he is happy either way.
I was just gonna post the result here for ...whatever to be done with it. It currently has ten slots, but could have more added easily enough. I'll try to wrap it up ASAP and just need to finish the note's script and addition/removal of the dummy torches.
User avatar
Chloe Botham
 
Posts: 3537
Joined: Wed Aug 30, 2006 12:11 am

PreviousNext

Return to V - Skyrim