Jump to content

[LE] How to use EquipItemEx or EquipItemByID correctly?


qwertypol012

Recommended Posts

Greetings everyone,

 

I have a script in which it has some functions to equip and unequip items to NPCs, and it includes player-enchanted items as well. First, i tried to use EquipItemEx (i've filled the parameters as well), but it didn't seem to work. My enchanted amulet, enchanted ring, and unenchanted pair of gauntlets weren't equipped by the NPC. Then i changed it to use EquipItemByID (filled the parameters as well), but still the same result.

 

Reading the description of EquipItemEx it's written that it forces the actor to equip the first item in the specified form's extralist, while EquipItemByID is for adding an item without an extralist. I have no idea what extralist is (no explanation provided there). So i'm assuming it has something to do with it, but whatever i'm not sure about it.

 

So here's a part of my code for this equipping-unequipping functionality:

 

 

Scriptname qlBerserk_QuestScript extends Quest Conditional

; properties and variables

;-----------------------------------------------------
FUNCTION myF_AE(Actor player, Int i, Bool bAdd = TRUE)  ; internal helper
;-----------------------------------------------------
    form fm

    IF ( bAdd )
        fm = player.GetWornForm(i)                    ; called from MakeForm()
    ELSE
        fm = PlayerEquipmentBrsk.GetWornForm(i)       ; called from RevertForm()
    ENDIF

IF (fm as Armor)
ELSE
    RETURN    ; - STOP -    nothing worn at this slot
ENDIF
;---------------------
IF ( bAdd )
    PlayerEquipmentBrsk.AddItem(fm, absilent=TRUE)       ; (A)dd
    PlayerEquipmentBrsk.EquipItemById(fm, fm.GetFormID(), 0, TRUE, TRUE)    ; (E)quip
ELSE
    player.EquipItemById(fm, fm.GetFormID(), 0, False, TRUE)                ; equip only
ENDIF
ENDFUNCTION


;------------------------------
FUNCTION MakeForm(Actor player)  ; outsourced code from OnEffectStart()
;------------------------------
IF ( player )
ELSE
    RETURN    ; - STOP -    invalid parameter
ENDIF
;---------------------
;    check if gauntlets are being worn or not, then add and equip them to the dummy if they are
    myF_AE(player, 0x00000008)                    ; myF_AE(player, 0x00000008, TRUE)

;    check if a full head helmet is being worn or not, then add and equip it to the dummy if it is
    myF_AE(player, 0x00000003)

;    check if a head only helmet is being worn or not, then add and equip it to the dummy if it is
    myF_AE(player, 0x00000001)

;    check if a hair only helmet is being worn or not, then add and equip it to the dummy if it is
    myF_AE(player, 0x00000002)

; This was to check if the NPC was equipping the stuff or not...
    PlayerEquipmentBrsk.Moveto(player)

; other stuff from this function
ENDFUNCTION


;--------------------------------
FUNCTION RevertForm(Actor player)
;--------------------------------
IF ( player )
ELSE
    RETURN    ; - STOP -    invalid parameter
ENDIF
;---------------------
    Deintegrate.Play(player)                            ; *** effectShader
    Utility.Wait(2.0)

    player.UnequipItem(ArmorBerserkerWBoots2 as Form,    false)
    player.UnequipItem(ArmorBerserkerWCuirass2 as Form,  false)
    player.UnequipItem(ArmorBerserkerGauntlets2 as Form, false)
    player.UnequipItem(ArmorBerserkWHelmet as Form,      false)

    player.EquipItem(ArmorBerserkerCuirass as Form,      false, true)
    player.EquipItem(ArmorBerserkerBoots as Form,        false, true)

;check if gauntlets are being worn or not
    myF_AE(player, 0x00000008, False)

;check if a full head helmet is being worn or not
    myF_AE(player, 0x00000003, False)

;check if a head only helmet is being worn or not
    myF_AE(player, 0x00000001, False)

;check if a hair only helmet is being worn or not
    myF_AE(player, 0x00000002, False)

;other stuff from this function
ENDFUNCTION



;------------------------------
FUNCTION myF_BerserkerAE(Int i)         ; called from copy_player_gears_to_replacement(Actor player)
;------------------------------
    actor player = Game.GetPlayer()
	form fm
    fm = player.GetWornForm(i)                            ; SKSE required !!
    IF (fm as Armor)
        BerserkerRef.AddItem(fm, absilent=true)
        BerserkerRef.EquipItemById(fm, fm.GetFormID(), 0, TRUE, TRUE)        ; SKSE required !!
    ENDIF
ENDFUNCTION


;------------------------------------------------------
FUNCTION copy_player_gears_to_replacement(Actor player)
;------------------------------------------------------
IF ( !BerserkerRef )
    RETURN    ; - STOP -    fail earlier
ENDIF
;---------------------
    form fm
    weapon w
    spell sp
    shout sh

    myF_BerserkerAE(0x00000200)      ; Shield
    myF_BerserkerAE(0x00000020)      ; Amulet
    myF_BerserkerAE(0x00000040)      ; Ring

    w = player.GetEquippedWeapon(False)                ; right hand
    IF ( w )
        BerserkerRef.AddItem(w as Form, absilent=TRUE)
        BerserkerRef.EquipItemById(w as Form, (w as Form).GetFormID(), 1, TRUE, TRUE)
    ENDIF

    w = player.GetEquippedWeapon(TRUE)                ; left hand
    IF ( w )
        BerserkerRef.AddItem(w as Form, absilent=TRUE)
        BerserkerRef.EquipItemById(w as Form, (w as Form).GetFormID(), 2, TRUE, TRUE)
    ENDIF

; other stuff from this function
ENDFUNCTION

; other remaining codes 

 

 

 

So, how do we use them correctly?

 

Edit: It seems that i have managed to make it work somehow. I'm now using EquipItemEx and i added some formlists which are to be filled whenever an item is about to be equipped by the NPC. I'm not sure why but suddenly it worked in my recent tests. So i'll stick with it and do a bit of modification to the script to check in what extent it'll keep working.

Edited by qwertypol012
Link to comment
Share on other sites

  • Recently Browsing   0 members

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