Scripting AddItem Holotape Using OnMenuOpenCloseEvent
This will add a persistent quest item, in this case a holotape, to the player inventory when the player opens the PipboyMenu.
There are several ways to do this. This is but one example.
Quest Set up
The quest will need to be enabled at start, will have two stages, and will contain a reference alias with a Specific Reference Fill Type.
- Create a quest that is Start Enabled, Run Once. For easy reference later, fill in Object Window Filter with your NameSpace. You'll be able to easily go to Character > Quests > YourNameSpace to find your new quest.
- Create a Reference Alias under the Quests tab. For purposes of this example, the name of the alias is
SettingsHolotape
. Fill type: Specific Reference (none). Optional, Quest Object, Reserves Reference, Allow Reuse in Quest, Allow Disabled - Create two stages - 10 and 20.
Quest Stages
Stage 10:
- Check Run on Start.
- New Entry
- Add designer notes, such as "Start Up".
- Add the following papyrus fragment:
Stage 10 Papyrus Fragment
debug.trace(self + "stage 10 - start up")
This is just a simple trace. It isn't necessary but it's useful if something goes south.
Stage 20:
- New Entry
- Add designer notes, such as shut down.
- Check complete quest
- Add the following papyrus fragment:
Stage 20 Papyrus Fragment
debug.trace(self + "stage 20 - shutting down")
;stop quest
Stop()
This will complete the quest once the Quest script has run its functions.
Quest Script
On the Scripts tab, attach a new script:
Scriptname YourNameSpace:AddHolotapeOnMenuOpenCloseScript extends Quest
Group Required_Properties
Holotape Property HolotapeRef auto const
{the holotape we're forcing into the player inventory}
ReferenceAlias Property Alias_SettingsHolotape auto const mandatory
{autofill}
Actor Property PlayerRef auto const mandatory
{autofill}
int Property StageToSet = 20 auto const
{default stage = 20 - only change this number if using a different shutdown stage number}
EndGroup
;holotapes in the inventory
int maxHolotapeCount = 1 const
Event OnQuestInit()
; Register for the pipboy opening
RegisterForMenuOpenCloseEvent("PipboyMenu")
; wait for player input
while utility.IsInMenuMode()
utility.wait(0.2)
endwhile
EndEvent
Event OnMenuOpenCloseEvent(string asMenuName, bool abOpening)
if (asMenuName == "PipboyMenu")
if abOpening
Debug.Trace(self + " PlayerRef has opened " + asMenuName)
;Add the holotape
TryToAddSettingsHolotape()
; we done
SetStage(StageToSet)
endif
endif
endEvent
Function TryToAddSettingsHolotape()
ObjectReference TapeRef = PlayerRef.PlaceAtMe(HolotapeRef)
Alias_SettingsHolotape.ForceRefTo(TapeRef)
;count the amount of actual tapes instead of the ref
int currentCount = PlayerRef.GetItemCount(HolotapeRef)
if currentCount < maxHolotapeCount
PlayerRef.AddItem(TapeRef, maxHolotapeCount, false)
debug.trace(self + "Holotape has been added to player inventory")
endif
EndFunction
If you do not want a pop-up indicating the player has received the holotape, change PlayerRef.AddItem(TapeRef, maxHolotapeCount, false)
to PlayerRef.AddItem(TapeRef, maxHolotapeCount, true)
. See AddItem_-_ObjectReference.
Usage
- This is specifically for compatibility with mods that skip the prologue but should also work during debug if coc'ing directly from main menu with default character.