Jump to content

Quick papyrus fragment question


antstubell

Recommended Posts

Ok, I'll detail what I want. When player picks up a light source, in my case either a torch, a lantern or a candle I want a message to appear that says "It is always advisable to keep a source of with you." Appear once only. I thought that having a quest run as start game enabled and adding a script to the quest would manage this. The bare bones of the script...

 

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
if !akSourceContainer
Debug.Notification("I picked up something")

EndIf
EndEvent

 

I put this script in the scripts of the quest. My original question was how do I make the quest address this script? Is the script already running because the quest is running? I don't see the message. Do I need a papyrus fragment to run the script?

Link to comment
Share on other sites

Technically the script is already available to run because the quest is running. However, quests do not receive the OnItemAdded event. ObjectReferences receive the OnItemAdded event. You can create an alias on the quest that points to the player and apply the script there instead.

 

I would create a custom formlist that contains all the equip able light sources that you want to provide this warning with. Then create a player alias on a quest and add a script that would be similar to the following. Of course I might use different names and such as this is only an example:

 

 

 

Scriptname PlayerAliasLightWarningScript Extends ReferenceAlias

Formlist Property myListOfLights Auto
String Property myWarning Auto
Bool doOnce = false

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  If myListOfLights.HasForm(akBaseItem) && doOnce == false
    doOnce = true
    Debug.MessageBox(myWarning)
  EndIf
EndEvent

States could alternatively be used instead of a bool and may be preferable in the long run depending upon how many mods might add the OnItemAdded event. Even though it does nothing after the initial run, it will contribute to potential stack dumps since each item passed in to the player will trigger the event.

Scriptname PlayerAliasLightWarningScript Extends ReferenceAlias

Formlist Property myListOfLights Auto
String Property myWarning Auto

Auto State Waiting
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  If myListOfLights.HasForm(akBaseItem)
    Debug.MessageBox(myWarning)
    GoToState("Completed")
  EndIf
EndEvent
EndState

State Completed
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
EndEvent
EndState

 

 

In both examples, if the item picked up is on the list of lights the message is displayed and then the script is told to no longer display that message even if other valid lights are picked up.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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