Difference between revisions of "Scripting AddItem Holotape Using OnMenuOpenCloseEvent"

From the Fallout4 CreationKit Wiki
Jump to navigation Jump to search
imported>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
(scripting guide/tutorial for adding a holotape to the player inventory using OnMenuOpenCloseEvent)
 
imported>0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
m (minor corrections and formatting)
Line 8: Line 8:
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.
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.


[[File:Ck_4.PNG|thumb|Fig. 1: Reference Alias]]
'''Creation:'''
* 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 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.
[[File:Ck_1.PNG]]
[[File:Ck_1.PNG]]
* Create a Reference Alias under the Quests tab. For purposes of this example, the name of the alias is <code>SettingsHolotape</code>. Fill type: Specific Reference (none). Optional, Quest Object, Reserves Reference, Allow Reuse in Quest, Allow Disabled
* Create two stages - 10 and 20.
* Create two stages - 10 and 20.




Line 47: Line 45:
</source>
</source>
This will complete the quest once the Quest script has run its functions.
This will complete the quest once the Quest script has run its functions.
== Reference Alias ==
[[File:Ck_4.PNG|thumb|Fig. 1: Reference Alias]]
* Quests tab: Create a Reference Alias. For purposes of this example, the name of the alias is <code>SettingsHolotape</code>.
* Fill type: Specific Reference (none).
* Check: Optional, Quest Object, Reserves Reference, Allow Reuse in Quest, Allow Disabled




Line 133: Line 138:
*[[Quest]]
*[[Quest]]
*[[Holotape]]
*[[Holotape]]
*[[ReferenceAlias]]


[[Category:Scripting_Guides]]
[[Category:Scripting_Guides]]
[[Category:Tutorials]]
[[Category:Tutorials]]

Revision as of 04:17, 31 May 2020


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.

Creation:

  • 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.

Ck 1.PNG

  • Create two stages - 10 and 20.


Quest Stages

Stage 10:

Fig. 2: Quest 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:

Fig. 3: Quest 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.


Reference Alias

Fig. 1: Reference Alias
  • Quests tab: Create a Reference Alias. For purposes of this example, the name of the alias is SettingsHolotape.
  • Fill type: Specific Reference (none).
  • Check: Optional, Quest Object, Reserves Reference, Allow Reuse in Quest, Allow Disabled


Quest Script

On the Scripts tab, attach a new script:

Fig. 4: Quest Script Properties
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.

See Also