Jump to content

scripts on furniture / event onsit


Recommended Posts

Okay, I have made a church lectern as a furniture and used the confessor speech animation for a quick test. The pastor will come to the lectern and load into the animation. I then created a simple script to launch his dialogue quest (pastor sermons) and placed the script onto the lectern (furniture item). Tested it again, like before the pastor comes to the lector when summoned and loads into the animation as before; however, the event on sit doesn’t seem to fire. Any suggestions.

Scriptname ActivateSermonScript extends ObjectReference

Scene property PastorAllenSermon01 Auto Const Mandatory
ReferenceAlias Property Alias_PastorAllen Auto
Furniture Property FO4_ChurchPulpit01 Auto

;Auto State WaitingState
	Event Actor.OnSit(Actor akSender, ObjectReference akFurniture)
		Debug.MessageBox("The event has fired")
		If akSender == Alias_PastorAllen.GetActorRef()
			Debug.MessageBox("Pastor Allen passed the test")
			If (akFurniture.GetBaseObject() as Furniture) == FO4_ChurchPulpit01
				;gotoState("doneState")
				Debug.MessageBox("The pulpit psssed the test")
				utility.Wait(0.1)
				PastorAllenSermon01.Start()
			EndIf
		EndIf
	endEvent
;EndState
Link to comment
Share on other sites

OnSit is an actor event, but you're listening for it from the furniture, so you're using the remote event Actor.OnSit, but you didn't registered for it.

At this point I could tell you to use RegsiterForRemoteEvent from some other event like OnInit, but it might unregister unexpectedly later, on the object unload probably, so I would suggest moving this code to the pastor alias, the script of a reference alias filled with an actor will listen for all actor events, and you don't need to worry about unload event unregistering for the remote event.

Scriptname PastorAliasScript extends ReferenceAlias

Scene property PastorAllenSermon01 Auto Const Mandatory
Furniture Property FO4_ChurchPulpit01 Auto

Event OnSit(ObjectReference akFurniture)
	Debug.MessageBox("The event has fired")
	If (akFurniture.GetBaseObject() as Furniture) == FO4_ChurchPulpit01
		Debug.MessageBox("The pulpit passed the test")
		Utility.Wait(0.1)
		PastorAllenSermon01.Start()
	EndIf
EndEvent
Link to comment
Share on other sites

DieFeM, thank you for the input and rudder steer. This padawan has much to learn in the ways of Papyrus so I truly appreciate the advice.

 

[update]. Worked beautifully. Thanks again mate, much appreciated. Now to flesh it out a but more (i.e., randomize the sermon selected) and develop the sermons.

Edited by pepperman35
Link to comment
Share on other sites

DieFeM, thank you for the input and rudder steer. This padawan has much to learn in the ways of Papyrus so I truly appreciate the advice.

 

[update]. Worked beautifully. Thanks again mate, much appreciated. Now to flesh it out a but more (i.e., randomize the sermon selected) and develop the sermons.

If you want to attache the script to the furniture then OnActivate() event will do the trick.

if akActionRef == PastorAllen...

Link to comment
Share on other sites

DieFeM, thank you for the input and rudder steer. This padawan has much to learn in the ways of Papyrus so I truly appreciate the advice.

 

[update]. Worked beautifully. Thanks again mate, much appreciated. Now to flesh it out a but more (i.e., randomize the sermon selected) and develop the sermons.

 

No problem. I'm glad to help.

Link to comment
Share on other sites

Here what I ended up with and up until today it worked fine. Today, however, is a different story. For some strange reason the OnSit Event doesn't seem to be firing.

Scriptname PastorAliasScript extends ReferenceAlias
;/Script designed to automatically play a random scene(sermon) once the NPC (pastor) loads into the  
furniture (church lectern).  Script resides on the pastor alias.
Special thanks to DieFeM for the assist.
https://forums.nexusmods.com/index.php?/topic/12724311-scripts-on-furniture-event-onsit/
/;

; ╔═════════════════════════════════════════════════╗
; ║                   Properties                    ║
; ╚═════════════════════════════════════════════════╝

Scene property PastorAllenSermon01 Auto Const Mandatory
ObjectReference Property FO4_LecternLightsEnable Auto Const Mandatory
Furniture Property FO4_ChurchLectern02 Auto Const Mandatory

Event OnSit(ObjectReference akFurniture)
	;Debug.Trace(self + "PastorAliasScript OnSit " + akFurniture)
	If (akFurniture.GetBaseObject() as Furniture) == FO4_ChurchLectern02
		;Debug.Trace("PastorAliasScript: the pastored has enter the pulpit")
		; Add addition code to randomly select a scene to play
		Utility.Wait(0.1)
		;
		; Turn the lectern lights on
		;
		FO4_LecternLightsEnable.enable()
		PastorAllenSermon01.Start()
	EndIf
EndEvent

Event OnGetUp(ObjectReference akFurniture)
  If (akFurniture.GetBaseObject() as Furniture) == FO4_ChurchLectern02
		; Debug.Trace("PastorAliasScript: the pastored has left the pulpit")
		; 
		Utility.Wait(1.0)
		;
		; Turn off the lectern lights
		;
		FO4_LecternLightsEnable.disable()
	EndIf
endEvent
Link to comment
Share on other sites

You can use this sequence from ScriptObject.psc, F4SE contributions:

; Filter can be one or none of the following:
; ObjectReference
; Var[] (containing ObjectReferece Vars)
; FormList (containing ObjectReference)
; Filtering by Furniture object will receive events from any Actor who sits in it
; Filtering by Actor will receive events from whenever the specified Actor sits on any furniture
; Registering again with a different filter will result in merging of the filters
Function RegisterForFurnitureEvent(Var filter = None) native

; Filter works similarly to Register
; None filter will remove all active filters and unregister the event
Function UnregisterForFurnitureEvent(Var filter = None) native

Event OnFurnitureEvent(Actor akActor, ObjectReference akFurniture, bool isGettingUp)
EndEvent

Just use it directly in your ObjectReference script attached to the furniture. No need for remote event sniffing.

Link to comment
Share on other sites

lee3310,

 

apologies for not acknowledging your approach. onactivate works as well so now I have to troubleshoot why the quest refuses to start.

Scriptname Bart:ActivateSermonScript01 extends ObjectReference Const
;/Script designed to automatically play a random scene(sermon) once the NPC (pastor) loads into the  
furniture (church lectern).  Script resides on the church lectern.
Special thanks to DieFeM and lee3310 for the assist.
https://forums.nexusmods.com/index.php?/topic/12724311-scripts-on-furniture-event-onsit/
/;

Scene property PastorAllenSermon01 Auto Const Mandatory
ObjectReference Property FO4_LecternLightsEnable Auto Const Mandatory
ObjectReference Property FO4_PastorAllen Auto Const


Event OnActivate(ObjectReference akActionRef)
	if akActionRef == FO4_PastorAllen
      	; Add addition code to randomly select a scene to play
		Utility.Wait(0.1)
		;
		; Turn the lectern lights on
		;
		FO4_LecternLightsEnable.enable()
		;
		; Start up the scene
		PastorAllenSermon01.Start()
	endif
EndEvent
Link to comment
Share on other sites

OnActivate is good alternative to the non-existing vanilla OnFurnitureEnter (developers added OnFurnitureExit to the ObjectReference script for the first main quest but OnFurnitureEnter is missing) and the F4SE added OnFurnitureEvent events but if the akActionRef fails to sit in the furniture (pathing failure, bad furniture interaction marker, etc.) the event is sent regardless so you should register for OnSit of akActionRef upon receiving OnActivate to make sure you start the scene only if and when the actor is actually sitting.

Edited by LarannKiar
Link to comment
Share on other sites

  • Recently Browsing   0 members

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