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.
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.
Do you know about the http://www.creationkit.com/index.php?title=OnTriggerEnter_-_ObjectReference?
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?
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.
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.
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.
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.
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
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
Find a mod that has a shower in it and duplicate the activator and script. Use it as a template.
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!
Blackjack....there are no mods where npcs shower.....the ones that have them, it is the player who can shower.
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.
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?
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!
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.
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.
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
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.
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?
That's the objective--to devise a script that npc will trigger. I don't want a player interaction, just npc.
nvm then, I thought you are using two different activations for player and npc
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?
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.