Jump to content

[LE] what is wrong :GetEquippedArmorInSlot


Recommended Posts

Function BackupOutfit()
	BK_ArmorSlot01 = self.GetActorRef().GetEquippedArmorInSlot(30)
	BK_ArmorSlot02 = self.GetActorRef().GetEquippedArmorInSlot(31)
	BK_ArmorSlot03 = self.GetActorRef().GetEquippedArmorInSlot(32)
	BK_ArmorSlot04 = self.GetActorRef().GetEquippedArmorInSlot(33)
	BK_ArmorSlot05 = self.GetActorRef().GetEquippedArmorInSlot(34)
	BK_ArmorSlot06 = self.GetActorRef().GetEquippedArmorInSlot(35)
	BK_ArmorSlot07 = self.GetActorRef().GetEquippedArmorInSlot(36)
	BK_ArmorSlot08 = self.GetActorRef().GetEquippedArmorInSlot(37)
	BK_ArmorSlot09 = self.GetActorRef().GetEquippedArmorInSlot(38)
	BK_ArmorSlot10 = self.GetActorRef().GetEquippedArmorInSlot(39)
	BK_ArmorSlot11 = self.GetActorRef().GetEquippedArmorInSlot(40)
	BK_ArmorSlot12 = self.GetActorRef().GetEquippedArmorInSlot(41)
	BK_ArmorSlot13 = self.GetActorRef().GetEquippedArmorInSlot(42)
	BK_ArmorSlot14 = self.GetActorRef().GetEquippedArmorInSlot(43)
	BK_ArmorSlot15 = self.GetActorRef().GetEquippedArmorInSlot(44)
	BK_ArmorSlot16 = self.GetActorRef().GetEquippedArmorInSlot(45)
	BK_ArmorSlot17 = self.GetActorRef().GetEquippedArmorInSlot(46)
	BK_ArmorSlot18 = self.GetActorRef().GetEquippedArmorInSlot(47)
	BK_ArmorSlot19 = self.GetActorRef().GetEquippedArmorInSlot(48)
	BK_ArmorSlot20 = self.GetActorRef().GetEquippedArmorInSlot(49)
	BK_ArmorSlot21 = self.GetActorRef().GetEquippedArmorInSlot(52)
	BK_ArmorSlot22 = self.GetActorRef().GetEquippedArmorInSlot(53)
	BK_ArmorSlot23 = self.GetActorRef().GetEquippedArmorInSlot(54)
	BK_ArmorSlot24 = self.GetActorRef().GetEquippedArmorInSlot(55)
	BK_ArmorSlot25 = self.GetActorRef().GetEquippedArmorInSlot(56)
	BK_ArmorSlot26 = self.GetActorRef().GetEquippedArmorInSlot(57)
	BK_ArmorSlot27 = self.GetActorRef().GetEquippedArmorInSlot(58)
	BK_ArmorSlot28 = self.GetActorRef().GetEquippedArmorInSlot(59)
	BK_ArmorSlot29 = self.GetActorRef().GetEquippedArmorInSlot(60)
	Debug.notification("BackupOutfit:")
	debug.notification(BK_ArmorSlot01)
	debug.notification(BK_ArmorSlot03)
	debug.notification(BK_ArmorSlot05)
	debug.notification(BK_ArmorSlot09)
	debug.notification(BK_ArmorSlot11)
	debug.notification(BK_ArmorSlot15)
	debug.notification(BK_ArmorSlot19)
	debug.notification(BK_ArmorSlot21)
	debug.notification(BK_ArmorSlot25)
	debug.notification(BK_ArmorSlot29)
EndFunction

Function RestoreOutfit()
	self.GetActorRef().EquipItem(BK_ArmorSlot01)
	self.GetActorRef().EquipItem(BK_ArmorSlot02)
	self.GetActorRef().EquipItem(BK_ArmorSlot03)
	self.GetActorRef().EquipItem(BK_ArmorSlot04)
	self.GetActorRef().EquipItem(BK_ArmorSlot05)
	self.GetActorRef().EquipItem(BK_ArmorSlot06)
	self.GetActorRef().EquipItem(BK_ArmorSlot07)
	self.GetActorRef().EquipItem(BK_ArmorSlot08)
	self.GetActorRef().EquipItem(BK_ArmorSlot09)
	self.GetActorRef().EquipItem(BK_ArmorSlot10)
	self.GetActorRef().EquipItem(BK_ArmorSlot11)
	self.GetActorRef().EquipItem(BK_ArmorSlot12)
	self.GetActorRef().EquipItem(BK_ArmorSlot13)
	self.GetActorRef().EquipItem(BK_ArmorSlot14)
	self.GetActorRef().EquipItem(BK_ArmorSlot15)
	self.GetActorRef().EquipItem(BK_ArmorSlot16)
	self.GetActorRef().EquipItem(BK_ArmorSlot17)
	self.GetActorRef().EquipItem(BK_ArmorSlot18)
	self.GetActorRef().EquipItem(BK_ArmorSlot19)
	self.GetActorRef().EquipItem(BK_ArmorSlot20)
	self.GetActorRef().EquipItem(BK_ArmorSlot21)
	self.GetActorRef().EquipItem(BK_ArmorSlot22)
	self.GetActorRef().EquipItem(BK_ArmorSlot23)
	self.GetActorRef().EquipItem(BK_ArmorSlot24)
	self.GetActorRef().EquipItem(BK_ArmorSlot25)
	self.GetActorRef().EquipItem(BK_ArmorSlot26)
	self.GetActorRef().EquipItem(BK_ArmorSlot27)
	self.GetActorRef().EquipItem(BK_ArmorSlot28)
	self.GetActorRef().EquipItem(BK_ArmorSlot29)
	Debug.notification("RestoreOutfi:")
	debug.notification(BK_ArmorSlot01)
	debug.notification(BK_ArmorSlot03)
	debug.notification(BK_ArmorSlot05)
	debug.notification(BK_ArmorSlot09)
	debug.notification(BK_ArmorSlot11)
	debug.notification(BK_ArmorSlot15)
	debug.notification(BK_ArmorSlot19)
	debug.notification(BK_ArmorSlot21)
	debug.notification(BK_ArmorSlot25)
	debug.notification(BK_ArmorSlot29)
endfunction 

How to backup and restore the initial Outfit ?it don't work

 

debug dispaly:none

Edited by pxd2050
Link to comment
Share on other sites

GetEquippedArmorInSlot is an SSE exclusive function (see Actor script for details). You cannot use it with LE.

 

That begs the question, are you working with LE or SSE? I ask because the code is for SSE and this forum thread is in the LE section.

thank you very much. this is work  for SSE,What to do if forum thread can't use in SSE?

Scriptname outfit__script extends ReferenceAlias  

import debug
import utility

Event OnDeath(Actor akKiller)
	ClearBuffer()
   	 self.clear()
endEvent

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 BK_ArmorSlot01 auto hidden
Form Property BK_ArmorSlot02 auto hidden
Form Property BK_ArmorSlot03 auto hidden
Form Property BK_ArmorSlot04 auto hidden
Form Property BK_ArmorSlot05 auto hidden
Form Property BK_ArmorSlot06 auto hidden
Form Property BK_ArmorSlot07 auto hidden
Form Property BK_ArmorSlot08 auto hidden
Form Property BK_ArmorSlot09 auto hidden
Form Property BK_ArmorSlot10 auto hidden
Form Property BK_ArmorSlot11 auto hidden
Form Property BK_ArmorSlot12 auto hidden
Form Property BK_ArmorSlot13 auto hidden
Form Property BK_ArmorSlot14 auto hidden
Form Property BK_ArmorSlot15 auto hidden
Form Property BK_ArmorSlot16 auto hidden
Form Property BK_ArmorSlot17 auto hidden
Form Property BK_ArmorSlot18 auto hidden
Form Property BK_ArmorSlot19 auto hidden
Form Property BK_ArmorSlot20 auto hidden
Form Property BK_ArmorSlot21 auto hidden
Form Property BK_ArmorSlot22 auto hidden
Form Property BK_ArmorSlot23 auto hidden
Form Property BK_ArmorSlot24 auto hidden
Form Property BK_ArmorSlot25 auto hidden
Form Property BK_ArmorSlot26 auto hidden
Form Property BK_ArmorSlot27 auto hidden
Form Property BK_ArmorSlot28 auto hidden
Form Property BK_ArmorSlot29 auto hidden

Form Property EmptySlot auto hidden

EVENT OnCellLoad()
	wait(0.25)
	EquipCurrentArmor()
	EquipCurrentWeapon()
EndEVENT

EVENT OnLoad()
	wait(0.25)
	EquipCurrentArmor()
	EquipCurrentWeapon()
EndEVENT

EVENT OnEnable()
	EquipCurrentArmor()
	EquipCurrentWeapon()
endEVENT

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
	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 (akBaseObject as Armor)
		RemoveFromArmorSlot(akBaseObject)
	elseif  (akBaseObject as Weapon)
		RemoveFromWeaponSlot(akBaseObject)
	endif
endEvent

Function ClearBuffer()
	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
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot02 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot02 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot03 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot03 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot04 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot04 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot05 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot05 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot06 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot06 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot07 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot07 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot08 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot08 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot09 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot09 = akBaseItem
		FoundEmptySlot = TRUE
	endif
	if (ArmorSlot10 == EmptySlot) && (FoundEmptySlot == FALSE)
		ArmorSlot10 = akBaseItem
		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

Function BackupOutfit()
	BK_ArmorSlot01 = self.GetActorRef().GetEquippedArmorInSlot(30)
	BK_ArmorSlot02 = self.GetActorRef().GetEquippedArmorInSlot(31)
	BK_ArmorSlot03 = self.GetActorRef().GetEquippedArmorInSlot(32)
	BK_ArmorSlot04 = self.GetActorRef().GetEquippedArmorInSlot(33)
	BK_ArmorSlot05 = self.GetActorRef().GetEquippedArmorInSlot(34)
	BK_ArmorSlot06 = self.GetActorRef().GetEquippedArmorInSlot(35)
	BK_ArmorSlot07 = self.GetActorRef().GetEquippedArmorInSlot(36)
	BK_ArmorSlot08 = self.GetActorRef().GetEquippedArmorInSlot(37)
	BK_ArmorSlot09 = self.GetActorRef().GetEquippedArmorInSlot(38)
	BK_ArmorSlot10 = self.GetActorRef().GetEquippedArmorInSlot(39)
	BK_ArmorSlot11 = self.GetActorRef().GetEquippedArmorInSlot(40)
	BK_ArmorSlot12 = self.GetActorRef().GetEquippedArmorInSlot(41)
	BK_ArmorSlot13 = self.GetActorRef().GetEquippedArmorInSlot(42)
	BK_ArmorSlot14 = self.GetActorRef().GetEquippedArmorInSlot(43)
	BK_ArmorSlot15 = self.GetActorRef().GetEquippedArmorInSlot(44)
	BK_ArmorSlot16 = self.GetActorRef().GetEquippedArmorInSlot(45)
	BK_ArmorSlot17 = self.GetActorRef().GetEquippedArmorInSlot(46)
	BK_ArmorSlot18 = self.GetActorRef().GetEquippedArmorInSlot(47)
	BK_ArmorSlot19 = self.GetActorRef().GetEquippedArmorInSlot(48)
	BK_ArmorSlot20 = self.GetActorRef().GetEquippedArmorInSlot(49)
	BK_ArmorSlot21 = self.GetActorRef().GetEquippedArmorInSlot(52)
	BK_ArmorSlot22 = self.GetActorRef().GetEquippedArmorInSlot(53)
	BK_ArmorSlot23 = self.GetActorRef().GetEquippedArmorInSlot(54)
	BK_ArmorSlot24 = self.GetActorRef().GetEquippedArmorInSlot(55)
	BK_ArmorSlot25 = self.GetActorRef().GetEquippedArmorInSlot(56)
	BK_ArmorSlot26 = self.GetActorRef().GetEquippedArmorInSlot(57)
	BK_ArmorSlot27 = self.GetActorRef().GetEquippedArmorInSlot(58)
	BK_ArmorSlot28 = self.GetActorRef().GetEquippedArmorInSlot(59)
	BK_ArmorSlot29 = self.GetActorRef().GetEquippedArmorInSlot(60)
	Debug.notification("BackupOutfit:")
	debug.notification(BK_ArmorSlot01)
	debug.notification(BK_ArmorSlot03)
	debug.notification(BK_ArmorSlot05)
	debug.notification(BK_ArmorSlot09)
	debug.notification(BK_ArmorSlot11)
	debug.notification(BK_ArmorSlot15)
	debug.notification(BK_ArmorSlot19)
	debug.notification(BK_ArmorSlot21)
	debug.notification(BK_ArmorSlot25)
	debug.notification(BK_ArmorSlot29)
EndFunction

Function RestoreOutfit()
	self.GetActorRef().EquipItem(BK_ArmorSlot01)
	self.GetActorRef().EquipItem(BK_ArmorSlot02)
	self.GetActorRef().EquipItem(BK_ArmorSlot03)
	self.GetActorRef().EquipItem(BK_ArmorSlot04)
	self.GetActorRef().EquipItem(BK_ArmorSlot05)
	self.GetActorRef().EquipItem(BK_ArmorSlot06)
	self.GetActorRef().EquipItem(BK_ArmorSlot07)
	self.GetActorRef().EquipItem(BK_ArmorSlot08)
	self.GetActorRef().EquipItem(BK_ArmorSlot09)
	self.GetActorRef().EquipItem(BK_ArmorSlot10)
	self.GetActorRef().EquipItem(BK_ArmorSlot11)
	self.GetActorRef().EquipItem(BK_ArmorSlot12)
	self.GetActorRef().EquipItem(BK_ArmorSlot13)
	self.GetActorRef().EquipItem(BK_ArmorSlot14)
	self.GetActorRef().EquipItem(BK_ArmorSlot15)
	self.GetActorRef().EquipItem(BK_ArmorSlot16)
	self.GetActorRef().EquipItem(BK_ArmorSlot17)
	self.GetActorRef().EquipItem(BK_ArmorSlot18)
	self.GetActorRef().EquipItem(BK_ArmorSlot19)
	self.GetActorRef().EquipItem(BK_ArmorSlot20)
	self.GetActorRef().EquipItem(BK_ArmorSlot21)
	self.GetActorRef().EquipItem(BK_ArmorSlot22)
	self.GetActorRef().EquipItem(BK_ArmorSlot23)
	self.GetActorRef().EquipItem(BK_ArmorSlot24)
	self.GetActorRef().EquipItem(BK_ArmorSlot25)
	self.GetActorRef().EquipItem(BK_ArmorSlot26)
	self.GetActorRef().EquipItem(BK_ArmorSlot27)
	self.GetActorRef().EquipItem(BK_ArmorSlot28)
	self.GetActorRef().EquipItem(BK_ArmorSlot29)
	Debug.notification("RestoreOutfi:")
	debug.notification(BK_ArmorSlot01)
	debug.notification(BK_ArmorSlot03)
	debug.notification(BK_ArmorSlot05)
	debug.notification(BK_ArmorSlot09)
	debug.notification(BK_ArmorSlot11)
	debug.notification(BK_ArmorSlot15)
	debug.notification(BK_ArmorSlot19)
	debug.notification(BK_ArmorSlot21)
	debug.notification(BK_ArmorSlot25)
	debug.notification(BK_ArmorSlot29)
endfunction

Edited by pxd2050
Link to comment
Share on other sites

You could re-post or ask a moderator to move the thread to the appropriate location: SSE section of the forums

 

You may want to try GetWornForm instead. With no documentation for the proper usage of GetEquippedArmorInSlot I have no idea how to assist with that.

 

One thing that might help speed up your script: Replace all instances of self.GetActorRef() with a local variable. For example:

 

 

Actor myRef
Event OnInit()
  myRef = Self.GetReference() as Actor
EndEvent
 
;later on
myRef.Equipitem(BK_ArmorSlot29)

 

 

 

 

Another thing I noticed is your use of the EmptySlot property variable. This is unnecessary. You are hiding the property so that nothing can be assigned to it. In actuality this is nothing more than If ArmorSlot01 != None

 

Link to comment
Share on other sites

ah,thank your replay.

just your answer make me know :why Le have not mod can restore initial Outfit,because have not fuction just as GetEquippedArmorInSlot() to do.

As the first mod, I will spend more time on it

Forgive me for my poor English ahhh

Link to comment
Share on other sites

What IsharaMeradin already wrote: "One thing that might help speed up your script: Replace all instances of self.GetActorRef() with a local variable."

 

The scriptname is very poor and not unique enough, this schould be changed. I also use an array to decrease the amount of properties.

 

 

 

Scriptname outfit__script extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/8968643-what-is-wrong-getequippedarmorinslot/

  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        ; empty by default

  Bool bBusy                                ; [default=False]


;---------------------
FUNCTION ClearBuffer()
;---------------------
    form fm                ; fm = EmptySlot

    WeaponSlot01 = fm
    WeaponSlot02 = fm
    WeaponSlot03 = fm

    ArmorSlot01 = fm
    ArmorSlot02 = fm
    ArmorSlot03 = fm
    ArmorSlot04 = fm
    ArmorSlot05 = fm
    ArmorSlot06 = fm
    ArmorSlot07 = fm
    ArmorSlot08 = fm
    ArmorSlot09 = fm
    ArmorSlot10 = fm
ENDFUNCTION


; -- EVENTs --

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


;EVENT OnUnLoad()                ; 1a
;    ClearBuffer()
;IF self.GetReference()
;    self.Clear()
;ENDIF
;ENDEVENT


EVENT OnLoad()                    ; 2
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    Utility.Wait(0.25)
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDEVENT


EVENT OnCellLoad()                ; 3
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    Utility.Wait(0.25)
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDVENT


EVENT OnEnable()                ; 4*  This is not a native event, and it will never trigger by exception.
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDEVENT


;=====================================
auto State Waiting
;=================
EVENT OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)  ; 5
IF (akBaseItem as Armor)
    AddToArmorSlot(akBaseItem)
    self.GetActorReference().EquipItem(akBaseItem)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (akBaseItem as Weapon)
    AddToWeaponSlot(akBaseItem)
    self.GetActorReference().EquipItem(akBaseItem)
ENDIF
ENDEVENT

EVENT OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)  ; 6
IF (akBaseObject as Armor)
    RemoveFromArmorSlot(akBaseObject)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (akBaseObject as Weapon)
    RemoveFromWeaponSlot(akBaseObject)
ENDIF
ENDEVENT
;=======
endState


; -- FUNCTIONs -- (1) + 6

; **********************************************************
; *** EQU ***
; **************

;----------------------------
FUNCTION EquipCurrentWeapon()
;----------------------------
    actor selfRef = self.GetActorReference()

IF ( selfRef )
ELSE
    RETURN    ; - STOP -    alias has no valid Ref
ENDIF
;---------------------
    IF ( WeaponSlot01 )
        selfRef.EquipItem(WeaponSlot01)
    ENDIF
    IF ( WeaponSlot02 )
        selfRef.EquipItem(WeaponSlot02)
    ENDIF
    IF ( WeaponSlot03 )
        selfRef.EquipItem(WeaponSlot03)
    ENDIF
ENDFUNCTION


;---------------------------
FUNCTION EquipCurrentArmor()
;---------------------------
    actor selfRef = self.GetActorReference()

IF ( selfRef )
ELSE
    RETURN    ; - STOP -    alias has no valid Ref
ENDIF
;---------------------
    IF ( ArmorSlot01 )
        selfRef.EquipItem(ArmorSlot01)
    ENDIF
    IF ( ArmorSlot02 )
        selfRef.EquipItem(ArmorSlot02)
    ENDIF
    IF ( ArmorSlot03 )
        selfRef.EquipItem(ArmorSlot03)
    ENDIF
    IF ( ArmorSlot04 )
        selfRef.EquipItem(ArmorSlot04)
    ENDIF
    IF ( ArmorSlot05 )
        selfRef.EquipItem(ArmorSlot05)
    ENDIF
    IF ( ArmorSlot06 )
        selfRef.EquipItem(ArmorSlot06)
    ENDIF
    IF ( ArmorSlot07 )
        selfRef.EquipItem(ArmorSlot07)
    ENDIF
    IF ( ArmorSlot08 )
        selfRef.EquipItem(ArmorSlot08)
    ENDIF
    IF ( ArmorSlot09 )
        selfRef.EquipItem(ArmorSlot09)
    ENDIF
    IF ( ArmorSlot10 )
        selfRef.EquipItem(ArmorSlot10)
    ENDIF
ENDFUNCTION


; **********************************************************
; *** ADD ***
; **************

;-------------------------------
FUNCTION AddToArmorSlot(Form fm)
;-------------------------------
IF ( !ArmorSlot01 )
    ArmorSlot01 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot02 )
    ArmorSlot02 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot03 )
    ArmorSlot03 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot04 )
    ArmorSlot04 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot05 )
    ArmorSlot05 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot06 )
    ArmorSlot06 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot07 )
    ArmorSlot07 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot08 )
    ArmorSlot08 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot09 )
    ArmorSlot09 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot10 )
    ArmorSlot10 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
    Debug.Notification("All armor slots filled!")
ENDFUNCTION


;--------------------------------
FUNCTION AddToWeaponSlot(Form fm)
;--------------------------------
IF ( !WeaponSlot01 )
    WeaponSlot01 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !WeaponSlot02 )
    WeaponSlot02 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !WeaponSlot03 )
    WeaponSlot03 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
    Debug.Notification("All weapon slots filled!")
ENDFUNCTION


; **********************************************************
; *** REM ***
; **************

;------------------------------------
FUNCTION RemoveFromArmorSlot(Form fm)  ; check every slot to prevent item dupe bug
;------------------------------------
    IF (ArmorSlot01 == fm)
        ArmorSlot01 = None
    ENDIF
    IF (ArmorSlot02 == fm)
        ArmorSlot02 = None
    ENDIF
    IF (ArmorSlot03 == fm)
        ArmorSlot03 = None
    ENDIF
    IF (ArmorSlot04 == fm)
        ArmorSlot04 = None
    ENDIF
    IF (ArmorSlot05 == fm)
        ArmorSlot05 = None
    ENDIF
    IF (ArmorSlot06 == fm)
        ArmorSlot06 = None
    ENDIF
    IF (ArmorSlot07 == fm)
        ArmorSlot07 = None
    ENDIF
    IF (ArmorSlot08 == fm)
        ArmorSlot08 = None
    ENDIF
    IF (ArmorSlot09 == fm)
        ArmorSlot09 = None
    ENDIF
    IF (ArmorSlot10 == fm)
        ArmorSlot10 = None
    ENDIF
ENDFUNCTION


;-------------------------------------
FUNCTION RemoveFromWeaponSlot(Form fm)
;-------------------------------------
    IF (WeaponSlot01 == fm)
        WeaponSlot01 = None
    ENDIF
    IF (WeaponSlot02 == fm)
        WeaponSlot02 = None
    ENDIF
    IF (WeaponSlot03 == fm)
        WeaponSlot03 = None
    ENDIF
ENDFUNCTION


; **********************************************************
; *** BAK ***
; **************

  Form[] PROPERTY BK_ArmorSlot auto Hidden    ;  BK_ArmorSlot01 .. BK_ArmorSlot29 -->  BK_ArmorSlot[0] ..  BK_ArmorSlot[30]

;----------------------
FUNCTION BackupOutfit()
;----------------------
    actor selfRef = self.GetActorReference()

    IF (BK_ArmorSlot.Length == 0)
        BK_ArmorSlot = new Form[31]
    ENDIF

    Debug.notification("BackupOutfit:")

int i = 30
    WHILE (i < 50)
        BK_ArmorSlot[i - 30] = selfRef.GetEquippedArmorInSlot(i)    ; BK_ArmorSlot[0] = selfRef.GetEquippedArmorInSlot(30)
        i = i + 1
    ENDWHILE

    i = 52
    WHILE (i < 61)
        BK_ArmorSlot[i - 30] = selfRef.GetEquippedArmorInSlot(i)    ; BK_ArmorSlot[22] = selfRef.GetEquippedArmorInSlot(52)
        i = i + 1
    ENDWHILE

;/ ***
    debug.notification(BK_ArmorSlot01)
    debug.notification(BK_ArmorSlot03)
    debug.notification(BK_ArmorSlot05)
    debug.notification(BK_ArmorSlot09)
    debug.notification(BK_ArmorSlot11)
    debug.notification(BK_ArmorSlot15)
    debug.notification(BK_ArmorSlot19)
    debug.notification(BK_ArmorSlot21)
    debug.notification(BK_ArmorSlot25)
    debug.notification(BK_ArmorSlot29)
*** /;
ENDFUNCTION


;-----------------------
FUNCTION RestoreOutfit()
;-----------------------
    actor selfRef = self.GetActorReference()

    IF (BK_ArmorSlot.Length == 0)
        Debug.Notification("Array is empty!!")
    ELSE
        Debug.notification("RestoreOutfi:")
    ENDIF

IF ( BK_ArmorSlot )
    int i = 0
    WHILE (i < BK_ArmorSlot.Length)
        form fm = BK_ArmorSlot[i]
        IF (fm) && !selfRef.IsEquipped(fm)            ; does not work for torches !!!
            selfRef.EquipItem(fm)
        ENDIF
        i = i + 1
    ENDWHILE
ENDIF

;/ ***
    debug.notification(BK_ArmorSlot01)
    debug.notification(BK_ArmorSlot03)
    debug.notification(BK_ArmorSlot05)
    debug.notification(BK_ArmorSlot09)
    debug.notification(BK_ArmorSlot11)
    debug.notification(BK_ArmorSlot15)
    debug.notification(BK_ArmorSlot19)
    debug.notification(BK_ArmorSlot21)
    debug.notification(BK_ArmorSlot25)
    debug.notification(BK_ArmorSlot29)
*** /;
ENDFUNCTION

 

 

Edited by ReDragon2013
Link to comment
Share on other sites

What IsharaMeradin already wrote: "One thing that might help speed up your script: Replace all instances of self.GetActorRef() with a local variable."

 

The scriptname is very poor and not unique enough, this schould be changed. I also use an array to decrease the amount of properties.

 

 

 

Scriptname outfit__script extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/8968643-what-is-wrong-getequippedarmorinslot/

  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        ; empty by default

  Bool bBusy                                ; [default=False]


;---------------------
FUNCTION ClearBuffer()
;---------------------
    form fm                ; fm = EmptySlot

    WeaponSlot01 = fm
    WeaponSlot02 = fm
    WeaponSlot03 = fm

    ArmorSlot01 = fm
    ArmorSlot02 = fm
    ArmorSlot03 = fm
    ArmorSlot04 = fm
    ArmorSlot05 = fm
    ArmorSlot06 = fm
    ArmorSlot07 = fm
    ArmorSlot08 = fm
    ArmorSlot09 = fm
    ArmorSlot10 = fm
ENDFUNCTION


; -- EVENTs --

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


;EVENT OnUnLoad()                ; 1a
;    ClearBuffer()
;IF self.GetReference()
;    self.Clear()
;ENDIF
;ENDEVENT


EVENT OnLoad()                    ; 2
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    Utility.Wait(0.25)
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDEVENT


EVENT OnCellLoad()                ; 3
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    Utility.Wait(0.25)
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDVENT


EVENT OnEnable()                ; 4*  This is not a native event, and it will never trigger by exception.
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDEVENT


;=====================================
auto State Waiting
;=================
EVENT OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)  ; 5
IF (akBaseItem as Armor)
    AddToArmorSlot(akBaseItem)
    self.GetActorReference().EquipItem(akBaseItem)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (akBaseItem as Weapon)
    AddToWeaponSlot(akBaseItem)
    self.GetActorReference().EquipItem(akBaseItem)
ENDIF
ENDEVENT

EVENT OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)  ; 6
IF (akBaseObject as Armor)
    RemoveFromArmorSlot(akBaseObject)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (akBaseObject as Weapon)
    RemoveFromWeaponSlot(akBaseObject)
ENDIF
ENDEVENT
;=======
endState


; -- FUNCTIONs -- (1) + 6

; **********************************************************
; *** EQU ***
; **************

;----------------------------
FUNCTION EquipCurrentWeapon()
;----------------------------
    actor selfRef = self.GetActorReference()

IF ( selfRef )
ELSE
    RETURN    ; - STOP -    alias has no valid Ref
ENDIF
;---------------------
    IF ( WeaponSlot01 )
        selfRef.EquipItem(WeaponSlot01)
    ENDIF
    IF ( WeaponSlot02 )
        selfRef.EquipItem(WeaponSlot02)
    ENDIF
    IF ( WeaponSlot03 )
        selfRef.EquipItem(WeaponSlot03)
    ENDIF
ENDFUNCTION


;---------------------------
FUNCTION EquipCurrentArmor()
;---------------------------
    actor selfRef = self.GetActorReference()

IF ( selfRef )
ELSE
    RETURN    ; - STOP -    alias has no valid Ref
ENDIF
;---------------------
    IF ( ArmorSlot01 )
        selfRef.EquipItem(ArmorSlot01)
    ENDIF
    IF ( ArmorSlot02 )
        selfRef.EquipItem(ArmorSlot02)
    ENDIF
    IF ( ArmorSlot03 )
        selfRef.EquipItem(ArmorSlot03)
    ENDIF
    IF ( ArmorSlot04 )
        selfRef.EquipItem(ArmorSlot04)
    ENDIF
    IF ( ArmorSlot05 )
        selfRef.EquipItem(ArmorSlot05)
    ENDIF
    IF ( ArmorSlot06 )
        selfRef.EquipItem(ArmorSlot06)
    ENDIF
    IF ( ArmorSlot07 )
        selfRef.EquipItem(ArmorSlot07)
    ENDIF
    IF ( ArmorSlot08 )
        selfRef.EquipItem(ArmorSlot08)
    ENDIF
    IF ( ArmorSlot09 )
        selfRef.EquipItem(ArmorSlot09)
    ENDIF
    IF ( ArmorSlot10 )
        selfRef.EquipItem(ArmorSlot10)
    ENDIF
ENDFUNCTION


; **********************************************************
; *** ADD ***
; **************

;-------------------------------
FUNCTION AddToArmorSlot(Form fm)
;-------------------------------
IF ( !ArmorSlot01 )
    ArmorSlot01 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot02 )
    ArmorSlot02 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot03 )
    ArmorSlot03 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot04 )
    ArmorSlot04 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot05 )
    ArmorSlot05 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot06 )
    ArmorSlot06 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot07 )
    ArmorSlot07 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot08 )
    ArmorSlot08 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot09 )
    ArmorSlot09 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot10 )
    ArmorSlot10 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
    Debug.Notification("All armor slots filled!")
ENDFUNCTION


;--------------------------------
FUNCTION AddToWeaponSlot(Form fm)
;--------------------------------
IF ( !WeaponSlot01 )
    WeaponSlot01 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !WeaponSlot02 )
    WeaponSlot02 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !WeaponSlot03 )
    WeaponSlot03 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
    Debug.Notification("All weapon slots filled!")
ENDFUNCTION


; **********************************************************
; *** REM ***
; **************

;------------------------------------
FUNCTION RemoveFromArmorSlot(Form fm)  ; check every slot to prevent item dupe bug
;------------------------------------
    IF (ArmorSlot01 == fm)
        ArmorSlot01 = None
    ENDIF
    IF (ArmorSlot02 == fm)
        ArmorSlot02 = None
    ENDIF
    IF (ArmorSlot03 == fm)
        ArmorSlot03 = None
    ENDIF
    IF (ArmorSlot04 == fm)
        ArmorSlot04 = None
    ENDIF
    IF (ArmorSlot05 == fm)
        ArmorSlot05 = None
    ENDIF
    IF (ArmorSlot06 == fm)
        ArmorSlot06 = None
    ENDIF
    IF (ArmorSlot07 == fm)
        ArmorSlot07 = None
    ENDIF
    IF (ArmorSlot08 == fm)
        ArmorSlot08 = None
    ENDIF
    IF (ArmorSlot09 == fm)
        ArmorSlot09 = None
    ENDIF
    IF (ArmorSlot10 == fm)
        ArmorSlot10 = None
    ENDIF
ENDFUNCTION


;-------------------------------------
FUNCTION RemoveFromWeaponSlot(Form fm)
;-------------------------------------
    IF (WeaponSlot01 == fm)
        WeaponSlot01 = None
    ENDIF
    IF (WeaponSlot02 == fm)
        WeaponSlot02 = None
    ENDIF
    IF (WeaponSlot03 == fm)
        WeaponSlot03 = None
    ENDIF
ENDFUNCTION


; **********************************************************
; *** BAK ***
; **************

  Form[] PROPERTY BK_ArmorSlot auto Hidden    ;  BK_ArmorSlot01 .. BK_ArmorSlot29 -->  BK_ArmorSlot[0] ..  BK_ArmorSlot[30]

;----------------------
FUNCTION BackupOutfit()
;----------------------
    actor selfRef = self.GetActorReference()

    IF (BK_ArmorSlot.Length == 0)
        BK_ArmorSlot = new Form[31]
    ENDIF

    Debug.notification("BackupOutfit:")

int i = 30
    WHILE (i < 50)
        BK_ArmorSlot[i - 30] = selfRef.GetEquippedArmorInSlot(i)    ; BK_ArmorSlot[0] = selfRef.GetEquippedArmorInSlot(30)
        i = i + 1
    ENDWHILE

    i = 52
    WHILE (i < 61)
        BK_ArmorSlot[i - 30] = selfRef.GetEquippedArmorInSlot(i)    ; BK_ArmorSlot[22] = selfRef.GetEquippedArmorInSlot(52)
        i = i + 1
    ENDWHILE

;/ ***
    debug.notification(BK_ArmorSlot01)
    debug.notification(BK_ArmorSlot03)
    debug.notification(BK_ArmorSlot05)
    debug.notification(BK_ArmorSlot09)
    debug.notification(BK_ArmorSlot11)
    debug.notification(BK_ArmorSlot15)
    debug.notification(BK_ArmorSlot19)
    debug.notification(BK_ArmorSlot21)
    debug.notification(BK_ArmorSlot25)
    debug.notification(BK_ArmorSlot29)
*** /;
ENDFUNCTION


;-----------------------
FUNCTION RestoreOutfit()
;-----------------------
    actor selfRef = self.GetActorReference()

    IF (BK_ArmorSlot.Length == 0)
        Debug.Notification("Array is empty!!")
    ELSE
        Debug.notification("RestoreOutfi:")
    ENDIF

IF ( BK_ArmorSlot )
    int i = 0
    WHILE (i < BK_ArmorSlot.Length)
        form fm = BK_ArmorSlot[i]
        IF (fm) && !selfRef.IsEquipped(fm)            ; does not work for torches !!!
            selfRef.EquipItem(fm)
        ENDIF
        i = i + 1
    ENDWHILE
ENDIF

;/ ***
    debug.notification(BK_ArmorSlot01)
    debug.notification(BK_ArmorSlot03)
    debug.notification(BK_ArmorSlot05)
    debug.notification(BK_ArmorSlot09)
    debug.notification(BK_ArmorSlot11)
    debug.notification(BK_ArmorSlot15)
    debug.notification(BK_ArmorSlot19)
    debug.notification(BK_ArmorSlot21)
    debug.notification(BK_ArmorSlot25)
    debug.notification(BK_ArmorSlot29)
*** /;
ENDFUNCTION

 

 

 

What IsharaMeradin already wrote: "One thing that might help speed up your script: Replace all instances of self.GetActorRef() with a local variable."

 

The scriptname is very poor and not unique enough, this schould be changed. I also use an array to decrease the amount of properties.

 

 

 

Scriptname outfit__script extends ReferenceAlias
; https://forums.nexusmods.com/index.php?/topic/8968643-what-is-wrong-getequippedarmorinslot/

  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        ; empty by default

  Bool bBusy                                ; [default=False]


;---------------------
FUNCTION ClearBuffer()
;---------------------
    form fm                ; fm = EmptySlot

    WeaponSlot01 = fm
    WeaponSlot02 = fm
    WeaponSlot03 = fm

    ArmorSlot01 = fm
    ArmorSlot02 = fm
    ArmorSlot03 = fm
    ArmorSlot04 = fm
    ArmorSlot05 = fm
    ArmorSlot06 = fm
    ArmorSlot07 = fm
    ArmorSlot08 = fm
    ArmorSlot09 = fm
    ArmorSlot10 = fm
ENDFUNCTION


; -- EVENTs --

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


;EVENT OnUnLoad()                ; 1a
;    ClearBuffer()
;IF self.GetReference()
;    self.Clear()
;ENDIF
;ENDEVENT


EVENT OnLoad()                    ; 2
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    Utility.Wait(0.25)
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDEVENT


EVENT OnCellLoad()                ; 3
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    Utility.Wait(0.25)
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDVENT


EVENT OnEnable()                ; 4*  This is not a native event, and it will never trigger by exception.
IF ( bBusy )
    RETURN    ; - STOP -
ENDIF
;---------------------
    bBusy = TRUE
    EquipCurrentArmor()
    EquipCurrentWeapon()
    bBusy = False
ENDEVENT


;=====================================
auto State Waiting
;=================
EVENT OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)  ; 5
IF (akBaseItem as Armor)
    AddToArmorSlot(akBaseItem)
    self.GetActorReference().EquipItem(akBaseItem)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (akBaseItem as Weapon)
    AddToWeaponSlot(akBaseItem)
    self.GetActorReference().EquipItem(akBaseItem)
ENDIF
ENDEVENT

EVENT OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)  ; 6
IF (akBaseObject as Armor)
    RemoveFromArmorSlot(akBaseObject)
    RETURN    ; - STOP -
ENDIF
;---------------------
IF (akBaseObject as Weapon)
    RemoveFromWeaponSlot(akBaseObject)
ENDIF
ENDEVENT
;=======
endState


; -- FUNCTIONs -- (1) + 6

; **********************************************************
; *** EQU ***
; **************

;----------------------------
FUNCTION EquipCurrentWeapon()
;----------------------------
    actor selfRef = self.GetActorReference()

IF ( selfRef )
ELSE
    RETURN    ; - STOP -    alias has no valid Ref
ENDIF
;---------------------
    IF ( WeaponSlot01 )
        selfRef.EquipItem(WeaponSlot01)
    ENDIF
    IF ( WeaponSlot02 )
        selfRef.EquipItem(WeaponSlot02)
    ENDIF
    IF ( WeaponSlot03 )
        selfRef.EquipItem(WeaponSlot03)
    ENDIF
ENDFUNCTION


;---------------------------
FUNCTION EquipCurrentArmor()
;---------------------------
    actor selfRef = self.GetActorReference()

IF ( selfRef )
ELSE
    RETURN    ; - STOP -    alias has no valid Ref
ENDIF
;---------------------
    IF ( ArmorSlot01 )
        selfRef.EquipItem(ArmorSlot01)
    ENDIF
    IF ( ArmorSlot02 )
        selfRef.EquipItem(ArmorSlot02)
    ENDIF
    IF ( ArmorSlot03 )
        selfRef.EquipItem(ArmorSlot03)
    ENDIF
    IF ( ArmorSlot04 )
        selfRef.EquipItem(ArmorSlot04)
    ENDIF
    IF ( ArmorSlot05 )
        selfRef.EquipItem(ArmorSlot05)
    ENDIF
    IF ( ArmorSlot06 )
        selfRef.EquipItem(ArmorSlot06)
    ENDIF
    IF ( ArmorSlot07 )
        selfRef.EquipItem(ArmorSlot07)
    ENDIF
    IF ( ArmorSlot08 )
        selfRef.EquipItem(ArmorSlot08)
    ENDIF
    IF ( ArmorSlot09 )
        selfRef.EquipItem(ArmorSlot09)
    ENDIF
    IF ( ArmorSlot10 )
        selfRef.EquipItem(ArmorSlot10)
    ENDIF
ENDFUNCTION


; **********************************************************
; *** ADD ***
; **************

;-------------------------------
FUNCTION AddToArmorSlot(Form fm)
;-------------------------------
IF ( !ArmorSlot01 )
    ArmorSlot01 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot02 )
    ArmorSlot02 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot03 )
    ArmorSlot03 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot04 )
    ArmorSlot04 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot05 )
    ArmorSlot05 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot06 )
    ArmorSlot06 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot07 )
    ArmorSlot07 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot08 )
    ArmorSlot08 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot09 )
    ArmorSlot09 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !ArmorSlot10 )
    ArmorSlot10 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
    Debug.Notification("All armor slots filled!")
ENDFUNCTION


;--------------------------------
FUNCTION AddToWeaponSlot(Form fm)
;--------------------------------
IF ( !WeaponSlot01 )
    WeaponSlot01 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !WeaponSlot02 )
    WeaponSlot02 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
IF ( !WeaponSlot03 )
    WeaponSlot03 = fm
    RETURN    ; - STOP -
ENDIF
;---------------------
    Debug.Notification("All weapon slots filled!")
ENDFUNCTION


; **********************************************************
; *** REM ***
; **************

;------------------------------------
FUNCTION RemoveFromArmorSlot(Form fm)  ; check every slot to prevent item dupe bug
;------------------------------------
    IF (ArmorSlot01 == fm)
        ArmorSlot01 = None
    ENDIF
    IF (ArmorSlot02 == fm)
        ArmorSlot02 = None
    ENDIF
    IF (ArmorSlot03 == fm)
        ArmorSlot03 = None
    ENDIF
    IF (ArmorSlot04 == fm)
        ArmorSlot04 = None
    ENDIF
    IF (ArmorSlot05 == fm)
        ArmorSlot05 = None
    ENDIF
    IF (ArmorSlot06 == fm)
        ArmorSlot06 = None
    ENDIF
    IF (ArmorSlot07 == fm)
        ArmorSlot07 = None
    ENDIF
    IF (ArmorSlot08 == fm)
        ArmorSlot08 = None
    ENDIF
    IF (ArmorSlot09 == fm)
        ArmorSlot09 = None
    ENDIF
    IF (ArmorSlot10 == fm)
        ArmorSlot10 = None
    ENDIF
ENDFUNCTION


;-------------------------------------
FUNCTION RemoveFromWeaponSlot(Form fm)
;-------------------------------------
    IF (WeaponSlot01 == fm)
        WeaponSlot01 = None
    ENDIF
    IF (WeaponSlot02 == fm)
        WeaponSlot02 = None
    ENDIF
    IF (WeaponSlot03 == fm)
        WeaponSlot03 = None
    ENDIF
ENDFUNCTION


; **********************************************************
; *** BAK ***
; **************

  Form[] PROPERTY BK_ArmorSlot auto Hidden    ;  BK_ArmorSlot01 .. BK_ArmorSlot29 -->  BK_ArmorSlot[0] ..  BK_ArmorSlot[30]

;----------------------
FUNCTION BackupOutfit()
;----------------------
    actor selfRef = self.GetActorReference()

    IF (BK_ArmorSlot.Length == 0)
        BK_ArmorSlot = new Form[31]
    ENDIF

    Debug.notification("BackupOutfit:")

int i = 30
    WHILE (i < 50)
        BK_ArmorSlot[i - 30] = selfRef.GetEquippedArmorInSlot(i)    ; BK_ArmorSlot[0] = selfRef.GetEquippedArmorInSlot(30)
        i = i + 1
    ENDWHILE

    i = 52
    WHILE (i < 61)
        BK_ArmorSlot[i - 30] = selfRef.GetEquippedArmorInSlot(i)    ; BK_ArmorSlot[22] = selfRef.GetEquippedArmorInSlot(52)
        i = i + 1
    ENDWHILE

;/ ***
    debug.notification(BK_ArmorSlot01)
    debug.notification(BK_ArmorSlot03)
    debug.notification(BK_ArmorSlot05)
    debug.notification(BK_ArmorSlot09)
    debug.notification(BK_ArmorSlot11)
    debug.notification(BK_ArmorSlot15)
    debug.notification(BK_ArmorSlot19)
    debug.notification(BK_ArmorSlot21)
    debug.notification(BK_ArmorSlot25)
    debug.notification(BK_ArmorSlot29)
*** /;
ENDFUNCTION


;-----------------------
FUNCTION RestoreOutfit()
;-----------------------
    actor selfRef = self.GetActorReference()

    IF (BK_ArmorSlot.Length == 0)
        Debug.Notification("Array is empty!!")
    ELSE
        Debug.notification("RestoreOutfi:")
    ENDIF

IF ( BK_ArmorSlot )
    int i = 0
    WHILE (i < BK_ArmorSlot.Length)
        form fm = BK_ArmorSlot[i]
        IF (fm) && !selfRef.IsEquipped(fm)            ; does not work for torches !!!
            selfRef.EquipItem(fm)
        ENDIF
        i = i + 1
    ENDWHILE
ENDIF

;/ ***
    debug.notification(BK_ArmorSlot01)
    debug.notification(BK_ArmorSlot03)
    debug.notification(BK_ArmorSlot05)
    debug.notification(BK_ArmorSlot09)
    debug.notification(BK_ArmorSlot11)
    debug.notification(BK_ArmorSlot15)
    debug.notification(BK_ArmorSlot19)
    debug.notification(BK_ArmorSlot21)
    debug.notification(BK_ArmorSlot25)
    debug.notification(BK_ArmorSlot29)
*** /;
ENDFUNCTION

 

 

 

thank your wonderful reply

I will try it first,just a minute

Link to comment
Share on other sites

  • Recently Browsing   0 members

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