Jump to content

[LE] How to determines actor's inventory is open?


pxd2050

Recommended Posts

; Registers for OnMenuOpen and OnMenuClose events for the given menu.
; Registrations have to be refreshed after each game load.
; For a list of valid menu names, see UI.psc.
Function RegisterForMenu(string menuName) native
Function UnregisterForMenu(string menuName) native
Function UnregisterForAllMenus() native

Event OnMenuOpen(string menuName)
endEvent

Event OnMenuClose(string menuName)
endEvent

Maybe I can use OnMenuOpen(string menuName) to do it, but what is OpenInventory's menuname?

This is my first time programming, the problem is very stupid, and my English is poor, please don't laugh

Edited by pxd2050
Link to comment
Share on other sites

Why are you opening an NPCs inventory to equip armor? If it is a follower, you can open the inventory via dialog fragment and then give them armor while the inventory is open. They will then use the best defensive piece of gear for each body slot without you having to do anything beyond closing the inventory menu.

 

If you want an NPC to wear a specific piece of gear, add it to their inventory with AddItem and then make them equip it with EquipItem. No need to open the inventory in that scenario.

 

The menuName of the inventory is "InventoryMenu". You can see that for yourself by looking at the UI.psc file provided with SKSE or at the UI wiki page. Just remember, OnMenuOpen and OnMenuClose both require SKSE to be properly installed including the PSC files that are not needed for in-game functionality.

Link to comment
Share on other sites

Thank you for your timely help. Many mods can do the functions you mentioned, such as: (Simple NPC Outfit Manager ), but these mods are too complicated. I designed this mod for the sense of immersion: talk to NPC - opening inventory - put on the equipment, that's it. But the problem I encountered was that when changing the scene, NPC replaced the original equipment.

Based on the information you provided, I'll readjust the code. Here is the original code:



Scriptname outfit__script extends ReferenceAlias

import debug
import utility

Form Property WeaponSlot01 auto hidden
Form Property WeaponSlot02 auto hidden
Form Property WeaponSlot03 auto hidden

Form Property ArmorSlot01 auto hidden
Form Property ArmorSlot02 auto hidden
Form Property ArmorSlot03 auto hidden
Form Property ArmorSlot04 auto hidden
Form Property ArmorSlot05 auto hidden
Form Property ArmorSlot06 auto hidden
Form Property ArmorSlot07 auto hidden
Form Property ArmorSlot08 auto hidden
Form Property ArmorSlot09 auto hidden
Form Property ArmorSlot10 auto hidden

Form Property EmptySlot auto hidden
Bool Property Lock = true auto hidden

EVENT OnDeath(Actor akKiller)
ClearBuffer()
self.Clear()
ENDEVENT

EVENT OnLoad()
lock == true
wait(0.1)
EquipCurrentArmor()
EquipCurrentWeapon()
ENDEVENT

EVENT OnCellLoad()
lock == true
wait(0.1)
EquipCurrentArmor()
EquipCurrentWeapon()
ENDEVENT

EVENT OnEnable()
lock == true
wait(0.1)
EquipCurrentArmor()
EquipCurrentWeapon()
endEVENT

Function StateIsOn()
if Lock == false
debug.notification("unlocked.")
Else
lock = false
debug.notification("turn unlocked.")
Endif
EndFunction

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
if lock == true
EquipCurrentArmor()
EquipCurrentWeapon()
return
endif
if (akBaseItem as Armor)
AddToArmorSlot(akBaseItem)
self.GetActorRef().EquipItem(akBaseItem)
elseif (akBaseItem as Weapon)
AddToWeaponSlot(akBaseItem)
self.GetActorRef().EquipItem(akBaseItem)
endif
endEvent

Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
if lock == true
EquipCurrentArmor()
EquipCurrentWeapon()
return
endif
if (akBaseObject as Armor)
RemoveFromArmorSlot(akBaseObject)
elseif (akBaseObject as Weapon)
RemoveFromWeaponSlot(akBaseObject)
endif
endEvent

Function ClearBuffer()
lock = false
debug.notification("turn unlocked.")
ArmorSlot01 = EmptySlot
ArmorSlot02 = EmptySlot
ArmorSlot03 = EmptySlot
ArmorSlot04 = EmptySlot
ArmorSlot05 = EmptySlot
ArmorSlot06 = EmptySlot
ArmorSlot07 = EmptySlot
ArmorSlot08 = EmptySlot
ArmorSlot09 = EmptySlot
ArmorSlot10 = EmptySlot
WeaponSlot01 = EmptySlot
WeaponSlot02 = EmptySlot
WeaponSlot03 = EmptySlot
EndFunction

Function EquipCurrentArmor()
if self.GetActorRef() == None
Return
Endif
if (ArmorSlot01 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot01)
endif
if (ArmorSlot02 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot02)
endif
if (ArmorSlot03 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot03)
endif
if (ArmorSlot04 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot04)
endif
if (ArmorSlot05 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot05)
endif
if (ArmorSlot06 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot06)
endif
if (ArmorSlot07 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot07)
endif
if (ArmorSlot08 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot08)
endif
if (ArmorSlot09 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot09)
endif
if (ArmorSlot10 != EmptySlot)
self.GetActorRef().EquipItem(ArmorSlot10)
endif
endFunction

Function EquipCurrentWeapon()
if self.GetActorRef() == None
Return
Endif
if (WeaponSlot01 != EmptySlot)
self.GetActorRef().EquipItem(WeaponSlot01)
endif
if (WeaponSlot02 != EmptySlot)
self.GetActorRef().EquipItem(WeaponSlot02)
endif
if (WeaponSlot03 != EmptySlot)
self.GetActorRef().EquipItem(WeaponSlot03)
endif
endFunction

Function AddToArmorSlot(Form akBaseItem)
bool FoundEmptySlot = FALSE
if (ArmorSlot01 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot01 = akBaseItem
Debug.notification("ArmorSlot01:" + ArmorSlot01)
FoundEmptySlot = TRUE
endif
if (ArmorSlot02 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot02 = akBaseItem
Debug.notification("ArmorSlot02:" + ArmorSlot02)
FoundEmptySlot = TRUE
endif
if (ArmorSlot03 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot03 = akBaseItem
Debug.notification("ArmorSlot03:" + ArmorSlot03)
FoundEmptySlot = TRUE
endif
if (ArmorSlot04 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot04 = akBaseItem
Debug.notification("ArmorSlot04:" + ArmorSlot04)
FoundEmptySlot = TRUE
endif
if (ArmorSlot05 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot05 = akBaseItem
Debug.notification("ArmorSlot05:" + ArmorSlot05)
FoundEmptySlot = TRUE
endif
if (ArmorSlot06 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot06 = akBaseItem
Debug.notification("ArmorSlot06:" + ArmorSlot06)
FoundEmptySlot = TRUE
endif
if (ArmorSlot07 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot07 = akBaseItem
Debug.notification("ArmorSlot07:" + ArmorSlot07)
FoundEmptySlot = TRUE
endif
if (ArmorSlot08 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot08 = akBaseItem
Debug.notification("ArmorSlot08:" + ArmorSlot08)
FoundEmptySlot = TRUE
endif
if (ArmorSlot09 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot09 = akBaseItem
Debug.notification("ArmorSlot09:" + ArmorSlot09)
FoundEmptySlot = TRUE
endif
if (ArmorSlot10 == EmptySlot) && (FoundEmptySlot == FALSE)
ArmorSlot10 = akBaseItem
Debug.notification("ArmorSlot10:" + ArmorSlot10)
FoundEmptySlot = TRUE
endif
FoundEmptySlot = FALSE
endFunction

Function AddToWeaponSlot(Form akBaseItem)
bool FoundEmptySlot = FALSE
if (WeaponSlot01 == EmptySlot) && (FoundEmptySlot == FALSE)
WeaponSlot01 = akBaseItem
FoundEmptySlot = TRUE
endif
if (WeaponSlot02 == EmptySlot) && (FoundEmptySlot == FALSE)
WeaponSlot02 = akBaseItem
FoundEmptySlot = TRUE
endif
if (WeaponSlot03 == EmptySlot) && (FoundEmptySlot == FALSE)
WeaponSlot03 = akBaseItem
FoundEmptySlot = TRUE
endif
FoundEmptySlot = FALSE
endFunction


Function RemoveFromArmorSlot(Form akBaseItem)
bool FoundMatchingSlot = FALSE
if (ArmorSlot01 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot01 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot02 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot02 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot03 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot03 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot04 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot04 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot05 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot05 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot06 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot06 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot07 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot07 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot08 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot08 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot09 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot09 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (ArmorSlot10 == akBaseItem) && (FoundMatchingSlot == FALSE)
ArmorSlot10 = EmptySlot
FoundMatchingSlot = TRUE
endif
endFunction

Function RemoveFromWeaponSlot(Form akBaseItem)
bool FoundMatchingSlot = FALSE
if (WeaponSlot01 == akBaseItem) && (FoundMatchingSlot == FALSE)
WeaponSlot01 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (WeaponSlot02 == akBaseItem) && (FoundMatchingSlot == FALSE)
WeaponSlot02 = EmptySlot
FoundMatchingSlot = TRUE
endif
if (WeaponSlot03 == akBaseItem) && (FoundMatchingSlot == FALSE)
WeaponSlot03 = EmptySlot
FoundMatchingSlot = TRUE
endif
endFunction


Edited by pxd2050
Link to comment
Share on other sites

Why are you opening an NPCs inventory to equip armor? ---just for immersion

They will then use the best defensive piece of gear for each body slot without you having to do anything beyond closing the inventory menu. ---This is what I want to avoid, I don't need better, I just want to look good


I found that NPC clothes will be changed when converting scenes, so I want to create a lock so that it can only be opened when openinventory is in order to avoid it. . I want to try whether it is feasible.

In addition, I found that the English of machine translation is better than that of me. ha-ha

Edited by pxd2050
Link to comment
Share on other sites

It work.............It work......................,

With your help, I finally realized this mod

one thing,The menuName of the inventory is "ContainerMenu",not "InventoryMenu".

After completing this mod, I will upload it for your advice

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	if IsMenuOpen("ContainerMenu") == false
		EquipCurrentArmor()
		EquipCurrentWeapon()
		return
	endif
	if (akBaseItem as Armor) 
		AddToArmorSlot(akBaseItem)
		self.GetActorRef().EquipItem(akBaseItem)
	elseif (akBaseItem as Weapon)
		AddToWeaponSlot(akBaseItem)
		self.GetActorRef().EquipItem(akBaseItem)
	endif
endEvent

Event OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)
	if IsMenuOpen("ContainerMenu") == false
		EquipCurrentArmor()
		EquipCurrentWeapon()
		return
	endif
	if (akBaseObject as Armor)
		RemoveFromArmorSlot(akBaseObject)
	elseif  (akBaseObject as Weapon)
		RemoveFromWeaponSlot(akBaseObject)
	endif
endEvent
Edited by pxd2050
Link to comment
Share on other sites

  • Recently Browsing   0 members

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