Jump to content

[LE] How to set LeveledItem whith StorageUtil?


pxd2050

Recommended Posts

I use StorageUtil to set outfit just as :SetFormValue(ActorRef, "OldOutfit", (OldOutfit as form)) ,outfit OldOutfit = GetFormValue(ActorRef,"OldOutfit") as outfit.

It do work.

but when I use StorageUtil to set LeveledItem :SetFormValue(ActorRef, "NewItem", (NewItem as form)) , NewItem = GetFormValue(ActorRef,"NewItem") as LeveledItem.

It do'nt work. return Newitem is null.

Can you help me?

sorry,I speak English is bad.

Scriptname outfit__Quest extends Quest 

Import StorageUtil
import debug
import UI
import utility

ReferenceAlias[] Property Targets Auto 
LeveledItem Property NewItem auto
Outfit Property NoOutfit  Auto 
Outfit Property NewOutfit  Auto  
MiscObject Property Gold002 Auto
bool  IsFollower
Actor ActorRef

Function AddSubject(Actor akSpeaker)
	RegisterForMenu("ContainerMenu")
	ActorRef = akSpeaker
	int isInslot = FindSubject(akSpeaker)
	if isInslot > -1
		NewItem = GetFormValue(ActorRef,"NewItem") as LeveledItem
		return
	endif
	Int slot = FindEmpty()
	If slot == -1
		debug.notification("Slots are full, release someone first.")
		RemoveSubject()
		return
	endif
	Targets[slot].ForceRefTo(akSpeaker)
	BackupOutfit()
EndFunction

Int Function FindSubject(Actor akSpeaker)
	Int iElement =  Targets.Length
	Int i = 0
	While i < iElement
		if Targets[i].GetActorRef() == akSpeaker
			return i
		EndIf
		i += 1
	EndWhile
	return -1
EndFunction

Int Function FindEmpty()
	Int iElement =  Targets.Length
	Int i = 0
	While i < iElement
		if Targets[i].GetActorRef() == None
			return i
		EndIf
		i += 1
	EndWhile
	return -1
EndFunction

Function RemoveSubject()
	int i = 0
	while i < 11
		Targets[i].clear()
		i += 1
	endwhile
	Debug.notification("0-10 is removed from list.")
EndFunction

Event OnMenuOpen(String MenuName)
	if ActorRef.IsPlayerTeammate()
		IsFollower = true
		ActorRef.SetPlayerTeammate(false)
	endif
	ActorRef.setoutfit(NoOutfit)
	Utility.Wait(0.1)
	int i = NewItem.GetNumForms()
	form ItemRef
	while i >= 0
		ItemRef = NewItem.GetNthForm(i)
		ActorRef.EquipItem(ItemRef)
		i -= 1
	endwhile
	ActorRef.AddItem(Gold002,1)		
	Debug.notification("NewItem3 "+NewItem.GetNumForms())
endEvent

Event OnMenuClose(String MenuName)
	NewItem.Revert()
	form ItemRef
	int i = 31
	while i >= 0
		ItemRef = ActorRef.GetEquippedArmorInSlot(i+30)
		NewItem.addform(ItemRef,1,1)
		i -= 1
	endwhile
	ActorRef.setoutfit(NoOutfit)
	ActorRef.setoutfit(NewOutfit)
	ActorRef.AddItem(Gold002,1)
	if IsFollower
		ActorRef.SetPlayerTeammate(true)
		IsFollower = false		
	endif
	SetFormValue(ActorRef, "NewItem", (NewItem as form))		
	Debug.notification("NewItem4 "+NewItem.GetNumForms())
	UnregisterForMenu("ContainerMenu")
endEvent

function BackupOutfit()
	ActorBase aActorBase = ActorRef.GetActorBase()
	outfit OldOutfit = aActorBase.GetOutfit()
	NewItem.Revert()
	form ItemRef
	int i = OldOutfit.GetNumParts()
	while i >= 0
		ItemRef = OldOutfit.GetNthPart(i)
		NewItem.addform(ItemRef,1,1)
		i -= 1
	endwhile
	SetFormValue(ActorRef, "OldOutfit", (OldOutfit as form))
	SetFormValue(ActorRef, "NewItem", (NewItem as form))		
	Debug.notification("NewItem0 "+NewItem.GetNumForms())
endfunction


Edited by pxd2050
Link to comment
Share on other sites

I have not used StorageUtil before so I am not sure how it all works together. But are you certain that whatever object you are looking for is actually a LeveledItem? Do you have papyrus logging turned on? Does the log indicate any errors in relation to this?

thank you for your post

I have define "LeveledItem Property NewItem auto" and have no errors in papyrus compile in CK..

but play in game,"NewItem = GetFormValue(ActorRef,"NewItem") as LeveledItem", I try anything but NewItem is alway 0. Maby GetFormValue() can't be use for "as LeveledItem" but "as outfit" can use?

This quest take me 3 days. :pinch:

Link to comment
Share on other sites

Does the NewItem property have an actual leveled item assigned to it? Cause I'm wondering if a leveled list or form list might be better for whatever you are doing.

how to save and load a form list?how to use it with SetFormValue() and GetFormValue() or other function like this?

this is my first mod,how to do?

Edited by pxd2050
Link to comment
Share on other sites

I need different NPCs to use own newitem,one way is use TES5Edit to edit esp for more than 100 NPC's newitem, I think this way is too stupid.

but if use SetFormValue() and GetFormValue() , all NPC only use NewItem = GetFormValue(ActorRef,"NewItem") as LeveledItem to get their own newitem.

I can't use CK,I use TES5Edit.

All in all, thank you very much。

I will try form list

Edited by pxd2050
Link to comment
Share on other sites

You have your form list created in the Creation Kit filled with the content you want. You wouldn't need to save it to an external file and recall it later. What exactly are you trying to accomplish?

Forget the most important question: I don't know how to edit outfit in script. Here I use TES5Edit to set outfit = LeveledItem in ESP (refer to other MODS), so in this script set LeveledItem NewItem is to change outfit. because LeveledItem can modify but outfit not modify.

Maybe you can tell me how to edit outfit directly in script?

Edited by pxd2050
Link to comment
Share on other sites

There is the SetOutfit function. It runs on the ActorBase rather than on the actor. I noticed that you used it already in your posted code. Is it not working?

 

Or are you wanting to edit rather than replace an existing outfit? If so, that is not possible via papyrus script at least not that I am aware.

 

I suppose it might be possible to write a script for TES5Edit to go through the NPCs and add whatever new item(s) to the outfits if they exist. But that is beyond me.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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