Jump to content

[LE] Auto-Delete Item Script


Recommended Posts

This is my first script so bare with me. The goal is to have it automatically disable/delete the weapons and armor if they are dropped from the inventory into the game world or moved into a different container. So far, I've managed to get it to work when dropped into the world, but it will not delete the item once it has moved into a container. Can anyone tell me what I'm doing wrong?

Scriptname __fade extends ActiveMagicEffect
{My first script!}

Event OnItemRemoved(Form akForm, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
  debug.messagebox("item removed: form=" + akForm.GetName() + ", item=" + akform)
	  if akForm == my_armor || akForm == my_armor2 || akForm == weapon1 || akForm == weapon2 || akForm == weapon3 || akForm == weapon4
		if akDestContainer
			debug.messagebox("put in container")
			akItemReference.Disable()
		   Debug.Trace("The item dissipates as I let go of it.")
	  else
			debug.messagebox("dropped on ground")
			akItemReference.Disable()
		   Debug.Trace("The item dissipates as I let go of it.")
	  endIf
  endIf
endEvent

Armor Property my_armor  Auto  

WEAPON Property weapon1  Auto  

WEAPON Property weapon2  Auto  

Armor Property my_armor2  Auto  

WEAPON Property weapon3  Auto  

WEAPON Property weapon4  Auto  

Armor Property armor_light  Auto  

Link to comment
Share on other sites

As IsharaMeradin said.


You could also do 2 EVENTS:


Event OnItemRemoved(Form akForm, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) > Just for the "dropped on ground"


Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) > Just for the "put in container".

Link to comment
Share on other sites

 

As IsharaMeradin said.
You could also do 2 EVENTS:
Event OnItemRemoved(Form akForm, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) > Just for the "dropped on ground"
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) > Just for the "put in container".

 

They could but then they'd have to condition both to rule out the other. Better to stick with a single event and handle both scenarios within.

Link to comment
Share on other sites

 

 

As IsharaMeradin said.
You could also do 2 EVENTS:
Event OnItemRemoved(Form akForm, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer) > Just for the "dropped on ground"
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer) > Just for the "put in container".

 

They could but then they'd have to condition both to rule out the other. Better to stick with a single event and handle both scenarios within.

 

Yeap... you're right...

Link to comment
Share on other sites

Just in case you want to modify your effect script. Keep in mind unique script names are very important!

 

hesAutoRemoveMGEFScript

 

Scriptname hesAutoRemoveMGEFScript extends ActiveMagicEffect
; https://forums.nexusmods.com/index.php?/topic/7647153-auto-delete-item-script/

  FormList PROPERTY myList auto        ; your own created list with 7 entries as follow

 ;WEAPON Property weapon1 auto  
 ;WEAPON Property weapon2 auto  
 ;WEAPON Property weapon3 auto  
 ;WEAPON Property weapon4 auto

 ;Armor Property my_armor    auto
 ;Armor Property my_armor2   auto  
 ;Armor Property armor_light auto


; -- EVENT --

; https://www.creationkit.com/index.php?title=Find_-_FormList

EVENT OnItemRemoved(Form akBaseItem, Int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
IF (akBaseItem as Weapon) || (akBaseItem as Armor)
ELSE
    RETURN    ; - STOP -
ENDIF
;---------------------
    int i = myList.Find(akBaseItem)
    IF (i >= 0)
        myF_Action(akBaseItem, akDestContainer, aiItemCount, akItemReference)
    ENDIF
ENDEVENT



; -- FUNCTION --

; https://www.creationkit.com/index.php?title=RemoveItem_-_ObjectReference
; https://www.creationkit.com/index.php?title=GetName_-_Form

;----------------------------------------------------------------------------------------------------------------------
FUNCTION myF_Action(Form akBaseItem, ObjectReference akDestContainer, Int aiItemCount, ObjectReference akItemReference)
;----------------------------------------------------------------------------------------------------------------------
    Debug.MessageBox("Removed form is " + akBaseItem + ", name = " +akBaseItem.GetName())        ; ***  SKSE required!

    IF ( akDestContainer )
        Debug.MessageBox("put in container")                                                     ; ***
        akDestContainer.RemoveItem(akBaseItem, aiItemCount, TRUE)
    
    ELSEIF ( akItemReference )
        IF (aiItemCount == 1)
            Debug.MessageBox("dropped on ground")                                                ; ***
            akItemReference.DisableNoWait()
            akItemReference.Delete()
        ELSE
            Debug.MessageBox("dropped itemstack on ground, let it be!")                          ; ***
            RETURN    ; - STOP -    you cannot delete all items, only the first
        ENDIF
    ENDIF

    Debug.Trace("The item dissipates as I let go of it.")
ENDFUNCTION

 

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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