Jump to content

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 don't 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

function RestoreOutfit()
	outfit OldOutfit = GetFormValue(ActorRef,"OldOutfit") as outfit
	ActorRef.setoutfit(NoOutfit)
	Utility.Wait(0.1)
	ActorRef.setoutfit(OldOutfit)
	ActorRef.AddItem(Gold002,1)
	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, "NewItem", (NewItem as form))		
	Debug.notification("NewItem1 "+NewItem.GetNumForms())
endfunction

function SetVanillaOutfit(outfit cloths)
	ActorRef.setoutfit(NoOutfit)
	Utility.Wait(0.1)
	ActorRef.setoutfit(cloths)
	ActorRef.AddItem(Gold002,1)
	NewItem.Revert()
	form ItemRef
	int i = cloths.GetNumParts()
	while i >= 0
		ItemRef = cloths.GetNthPart(i)
		NewItem.addform(ItemRef,1,1)
		i -= 1
	endwhile
	SetFormValue(ActorRef, "NewItem", (NewItem as form))	
	Debug.notification("NewItem2 "+NewItem.GetNumForms())
endfunction
Edited by pxd2050
Link to comment
Share on other sites

  • Recently Browsing   0 members

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