Shower Script

Post » Wed May 11, 2016 5:28 pm

Does anybody know how to set up a shower script for an NPC to use? I actually have a script to use for the player upon activation, but I need a self-activating script that will result in a shower coming on when an npc enters the trigger zone.

User avatar
Laura Mclean
 
Posts: 3471
Joined: Mon Oct 30, 2006 12:15 pm

Post » Wed May 11, 2016 8:46 pm

Do you know about the http://www.creationkit.com/index.php?title=OnTriggerEnter_-_ObjectReference?

User avatar
marina
 
Posts: 3401
Joined: Tue Mar 13, 2007 10:02 pm

Post » Wed May 11, 2016 1:30 pm

I do not know how to write scripts but I do know I need a script that will activate on a trigger. Would I copy what you linked to a created script?

User avatar
BRIANNA
 
Posts: 3438
Joined: Thu Jan 11, 2007 7:51 pm

Post » Wed May 11, 2016 1:18 pm

Not exactly...



You'd want to create an Activator and give it a Papyrus script with code like the following. No need to give it a name or 3D model (in fact, don't give it either!).



Scriptname YouShouldPickAUniqueNameForThisScript extends ObjectReference

Int iCount = 0

Event OnTriggerEnter(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount += 1
;
; ... do shower stuff here ...
;
EndIf
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount -= 1
If iCount == 0
;
; ... stop shower stuff here ...
;
EndIf
EndIf
EndEvent

Next, you'd create a trigger box in your shower. I believe you can do that by selecting the shower, pressing the Create Trigger button in the CK toolbar (the icon is a cube with a T on it), and selecting the activator type you just created.



Now, as for making the script actually trigger your shower... I have no idea how your shower is set up, so I can't write that for you. The above script is really just a template.

User avatar
Smokey
 
Posts: 3378
Joined: Mon May 07, 2007 11:35 pm

Post » Wed May 11, 2016 4:14 pm

Well, there would be a triggerbox that should trigger the shower to go on once the npc steps within. I'm assuming the script would be attached to this triggerbox. I am going to use one of the rain animations in the game for the actual shower; I believe you then link the shower/rain to the triggerbox that has the script attached so that it will go on and off as npcs enter and leave. Would I be able to use the script you wrote out for this?



Thanks you very much.

User avatar
Charlotte Lloyd-Jones
 
Posts: 3345
Joined: Fri Jun 30, 2006 4:53 pm

Post » Wed May 11, 2016 8:45 pm

The script goes on the trigger box, yes. However, it'll need to be modified to actually start and stop the shower effect (the code comments indicate where to make these changes).



As I said earlier, that'll depend on precisely how the shower is already set up. You said you already had a script that runs on activation. The way that script is written will determine exactly how you get the trigger box to do what you want to do: you may be able to actually communicate with the existing script and say, "start the shower;" or you may have to copy and paste its code into the trigger box script.

User avatar
Laura Wilson
 
Posts: 3445
Joined: Thu Oct 05, 2006 3:57 pm

Post » Wed May 11, 2016 1:08 pm

Appreciate your help with this, but I know next to null about scripting. In the script you kindly wrote up, where you say "do shower stuff here" what exactly would I need? I just need the shower to turn on when npc enters the triggerbox, and turn off when the npc leaves the triggerbox. Basically shower comes on when entered, and shower turns off when leave. The script I currently have which is available with consent from mod, requires the player to interact with an activator to turn the shower on (it is not designed for NPC use). So, it's set up differently than what I'm trying to achieve with an npc who basically just enters a trigger box and the shower water turns on.



I could use my existing script if I knew how to get the npc to interact with activator to turn on the shower....but I'm assuming that requires a quest....which I also know little about to do.

User avatar
carrie roche
 
Posts: 3527
Joined: Mon Jul 17, 2006 7:18 pm

Post » Wed May 11, 2016 5:02 pm

If you're just trying to activate water and nothing else, MyWater.Enable() for the on part and MyWater.Disable() for the off part. You'll also need to add a property for the water.


Something like



Scriptname MyShowerScript extends ObjectReference

TypeOfProperty Property MyWater Auto ;You need to find the type for property and then fill the property with your water object

Event OnTriggerEnter(ObjectReference akActionRef) ;never used this, just stole it from the above code.
MyWater.Enable()
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
MyWater.Disable()
EndEvent
User avatar
GRAEME
 
Posts: 3363
Joined: Sat May 19, 2007 2:48 am

Post » Wed May 11, 2016 3:23 pm

What do you mean by find type of property?

User avatar
An Lor
 
Posts: 3439
Joined: Sun Feb 18, 2007 8:46 pm

Post » Thu May 12, 2016 12:14 am

Could you get that modder's permission to post the script for us to see?



In the meantime, something like the following could turn the shower on, but I wouldn't know how to turn it back off. You'll need to make your shower object the linked ref of your trigger box. If that's not something you're familiar with, Bethesda has a tutorial on how to set up linked refs (they use it to create NPC patrols); http://www.creationkit.com/index.php?title=Bethesda_Tutorial_Encounters#Linked-Refs_and_Patrols.



Scriptname YouShouldPickAUniqueNameForThisScript extends ObjectReference

Int iCount = 0 ; number of objects in the trigger box; we use this because sometimes our code runs out of order

Event OnTriggerEnter(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount += 1
If iCount == 1 ; if the shower isn't already running (there may be better ways to check but I'd need to see your script)
GetLinkedRef().Activate(akActionRef) ; have akActionRef activate the trigger box's Linked Ref
EndIf
EndIf
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount -= 1
If iCount == 0
;
; ... stop shower stuff here ...
;
EndIf
EndIf
EndEvent
User avatar
Ludivine Dupuy
 
Posts: 3418
Joined: Tue Mar 27, 2007 6:51 pm

Post » Wed May 11, 2016 2:38 pm

Find a mod that has a shower in it and duplicate the activator and script. Use it as a template.

User avatar
Alexandra Ryan
 
Posts: 3438
Joined: Mon Jul 31, 2006 9:01 am

Post » Wed May 11, 2016 11:35 pm

I have to ask...what is the secret formula to learning to script? I have looked at it a good bit but its like a foreign language to me.



Again, thanks for all the help!

User avatar
Wane Peters
 
Posts: 3359
Joined: Tue Jul 31, 2007 9:34 pm

Post » Wed May 11, 2016 2:13 pm

Blackjack....there are no mods where npcs shower.....the ones that have them, it is the player who can shower.

User avatar
Shae Munro
 
Posts: 3443
Joined: Fri Feb 23, 2007 11:32 am

Post » Wed May 11, 2016 7:51 am

SkyBeth.... I guess what you need to do is look at tesalliance maybe - they have a lot of tuts etc. You just have to ignore some of the more.... obnoxious.... people there.

User avatar
Nany Smith
 
Posts: 3419
Joined: Sat Mar 17, 2007 5:36 pm

Post » Wed May 11, 2016 9:19 am

There's also a scripting tutorial on http://www.creationkit.com/index.php?title=Category:Bethesda_Scripting_Tutorial_Series. See if that works for you?

User avatar
joannARRGH
 
Posts: 3431
Joined: Mon Mar 05, 2007 6:09 am

Post » Wed May 11, 2016 1:55 pm

Here is the shower script I have which is for player use. It has two other scripts attached to a valve but those relate to the player turning on the valve so I don't think they are needed here. This one is attached to an activator.



scriptName defaultToggleSelfOnActivate extends objectReference


{This script toggles it's own enable state onActivate


this is mainly used on objects that are enable parents}



;State containment used in case other states are needed later


auto state waiting


event onActivate(objectReference triggerRef)


;if this object is enabled, disable it


if self.isEnabled()


self.Disable()



;if it is disabled, enable it


else


self.Enable()


endif


endEvent


endState




I'm setting up test cell to try to work this out...thanks!

User avatar
Adrian Powers
 
Posts: 3368
Joined: Fri Oct 26, 2007 4:44 pm

Post » Wed May 11, 2016 4:04 pm

Ah, a default Bethesda script -- something they made when they needed generic behaviors. What object, exactly, is the script attached to?



This script isn't (directly) meant for something that the player can just walk up to and activate. If the player manually activates this object, it will disable (i.e. become hidden). If it's activated while it's disabled, it will enable, but only another script can do that; the player can't activate disabled objects because they're not visible or solid.



The script can still be useful if it's attached to an object with an activate parent. If A is the activate parent of B, then activating A will also activate B, even if B is disabled. So this is definitely something that depends on how the objects themselves are set up in your cell.

User avatar
Darlene DIllow
 
Posts: 3403
Joined: Fri Oct 26, 2007 5:34 am

Post » Wed May 11, 2016 10:04 am

I didn't know it was a default script....It is attached to a sphere shaped trigger which is not directly linked to the player doing anything...meaning its not a triggerbox that activates when player comes in contact with it. Yes, there are two other scripts attached to a valve itself. The player must interact with the valve/activator in order to turn shower on and then again to turn off.



I was thinking to just have a trigger that is only activated when npc enters the trigger, and then deactivated when the npc leaves the trigger. I have an undress script that actually works that way. In my limited way of understanding this stuff, what I'm hoping to do is a lot simpler requiring only one script and no action from npc except an AI package.

User avatar
gemma
 
Posts: 3441
Joined: Tue Jul 25, 2006 7:10 am

Post » Wed May 11, 2016 6:27 pm

If you select the trigger sphere in the Creation Kit, do any lines appear and connect it to other objects?



If I had to make a blind guess at your setup, I'd say that some object (or more than one) is the activate parent of the sphere, and the sphere is the enable parent of something else. That latter term means that if the sphere enables or disables, other objects will follow suit automatically (or depending on how they're set up, they'll automatically do the opposite of what the sphere does). It's a bit of a roundabout setup, but it would allow the shower to work using only default scripts -- at least, for the player. For NPCs, we'll need to write a custom script.



If you create a trigger box and set the trigger sphere as the box's linked ref, then a script like the following may work. For now I'm assuming that the shower runs when the sphere is enabled, and stops when it's disabled. If that assumption is wrong, it won't be hard to fix the script.



Scriptname YouShouldPickAUniqueNameForThisScript extends ObjectReference

Int iCount = 0 ; number of objects in the trigger box; we use this because sometimes our code runs out of order

Event OnTriggerEnter(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount += 1
ObjectReference kTemporary = GetLinkedRef() ; store in a temporary variable -- faster than calling the function repeatedly
If iCount == 1 && kTemporary && kTemporary.IsDisabled() ; if the shower isn't already running
kTemporary.Enable()
EndIf
EndIf
EndEvent

Event OnTriggerLeave(ObjectReference akActionRef)
If (akActionRef as Actor) && akActionRef != Game.GetPlayer()
iCount -= 1
ObjectReference kTemporary = GetLinkedRef() ; store in a temporary variable -- faster than calling the function repeatedly
If iCount == 0 && kTemporary && !kTemporary.IsDisabled() ; if the shower is running but is now empty
kTemporary.Disable()
EndIf
EndIf
EndEvent
User avatar
Katie Pollard
 
Posts: 3460
Joined: Thu Nov 09, 2006 11:23 pm

Post » Wed May 11, 2016 11:07 am

The sphere's Activate Parent tab list the valve/activator (item which player interacts with to turn on/off water).



The water's Enable Parent Tab references the Sphere



The three items definitely are linked together to make it work.

User avatar
Ludivine Poussineau
 
Posts: 3353
Joined: Fri Mar 30, 2007 2:49 pm

Post » Wed May 11, 2016 1:45 pm

I wonder, if you do it via trigger, then is there any reason to keep the OnActivate method separate for player? instead of doing it OnTriggerEnter for everyone?

User avatar
Emmie Cate
 
Posts: 3372
Joined: Sun Mar 11, 2007 12:01 am

Post » Wed May 11, 2016 9:57 am

That's the objective--to devise a script that npc will trigger. I don't want a player interaction, just npc.

User avatar
ashleigh bryden
 
Posts: 3446
Joined: Thu Jun 29, 2006 5:43 am

Post » Wed May 11, 2016 6:29 pm

nvm then, I thought you are using two different activations for player and npc

User avatar
Annick Charron
 
Posts: 3367
Joined: Fri Dec 29, 2006 3:03 pm

Post » Wed May 11, 2016 10:52 am

Are you saying here to make a separate trigger box AND use the sphere activator I already have which operates the Player shower? If so, keep the existing script on the sphere AND then add the script you created to the new triggerbox?

User avatar
Carolyne Bolt
 
Posts: 3401
Joined: Mon Jul 10, 2006 4:56 am

Post » Wed May 11, 2016 7:36 pm

Yes, precisely. Add my script to a new trigger box. Modify the box to use the sphere as its "linked ref." Do not modify the sphere.

User avatar
Jade MacSpade
 
Posts: 3432
Joined: Thu Jul 20, 2006 9:53 pm

Next

Return to V - Skyrim