Jump to content

[LE] Script to Replace an Inventory Item With Another?


huggibee

Recommended Posts

Uff -- I hate to bring this back, but I've been having some major issues with the script up to the point where it no longer works and I can't remember how I got it to work before. At some point the script repetitively added the CLs and DLs over and over regardless of conditions I set, or simply just stopped working. Is there another way around this, or perhaps another script that might work?

Link to comment
Share on other sites

What kind of script are you using currently?

ReferenceAlias with Quest or ObjectReference directly attached to the baseobject

 

next is like IsharaMeradin scripts:

 

ScriptName LinenSwapScriptPlayerAlias extends ReferenceAlias
{this runs for the player, not for the linen}
  MiscObject Property CL auto ; clean linens
  MiscObject Property DL auto ; dirty linens

; Note: "Place a copy of starting linen item in the player alias inventory section  thus when quest is started, 
;            the player automatically gets the first item and thus we register for the update here." (IsharaMeradin)

  Bool isDirty = False


; -- EVENTs --
EVENT OnInit()
    Debug.Trace(" OnInit() - has been reached..  " +self)     ; debugging only
    self.AddInventoryEventFilter(CL)     ; add filter for clean item
    self.AddInventoryEventFilter(DL)     ; add filter for dirty item

    RegisterForSingleUpdateGameTime(8.0) ; register for an update in 8 game hours
ENDEVENT


EVENT OnUpdateGameTime()            ; timer is up after ingame 8 hours
    quest q = self.GetOwningQuest()
    Debug.Trace(" OnUpdateGameTime(" +isDirty+ ") - has been reached..  " +self)     ; debugging only

IF (q) && q.IsRunning()
ELSE
    RETURN   ; uninstalled or myQuest is not running
ENDIF

    miscObject MO

    IF ( !isDirty )   ; are current linens clean
        MO = DL        ; add the dirty linen
    ELSE              ; are current linens dirty
        MO = CL        ; add the clean linen
    ENDIF

;;;    Game.GetPlayer().AddItem(MO)
    self.GetReference().AddItem(MO)

    RegisterForSingleUpdateGameTime(8.0)     ; register for an update in 8 game hours
ENDEVENT


EVENT OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
IF (akBaseItem as MiscObject)
ELSE
    RETURN  ; failsafe, normally impossible caused by AddInventoryEventFilter(), not a miscobject was added to players inventory
ENDIF
;-----
IF (akBaseItem as MiscObject == CL)  && (isDirty)         ; is the added item clean linens
         isDirty = False ; indicate that the current item is clean
ELSEIF (akBaseItem as MiscObject == DL) && (!isDirty)     ; is the added item dirty linens
       isDirty = TRUE  ; indicate that current linen are dirty
ELSE
    RETURN  ; not the desired miscObject
ENDIF
;-----
    self.GetReference().RemoveItem(akBaseItem)   ; remove the dirty or clean item, if necessary
    RegisterForSingleUpdateGameTime(8)           ; register for an update in 8 game hours
ENDEVENT

Edited by ReDragon2013
Link to comment
Share on other sites

I was using reference alias -- and I placed a copy of the starting linens in the player inventory, but never received them upon game start. So maybe it's an issue of not getting the quest to run even though it's set to run on game start?

 

Edit: Attempted the script given, but nothing seems to happen. I think it must be an issue with getting the quest to run in the first place. :/

 

Edit02: So I found the issue with getting the script to run -- one of my ref alias refused to fill and thus delayed the quest. Thank you for your help!

Edited by huggibee
Link to comment
Share on other sites

After tinkering further, I'm able to get the script to fire, and after the first 8hrs, the clean linens are removed and the dirty linens are added -- great! . . . except, after the addition of new clean linens added via a custom crafting station, the script no longer fires. How can I fix this?

 

 

Scriptname Laundryswap extends ReferenceAlias

MiscObject Property CL Auto ; clean linens
MiscObject Property DL Auto ; dirty linens
Bool isDirty = false
Actor PlayerRef

Event OnInit()
AddInventoryEventFilter(CL) ; add filter for clean item
AddInventoryEventFilter(DL) ; add filter for dirty item
PlayerRef = Self.GetReference() as Actor ; cast the object reference that this alias points to as an actor and store it.
; if this give compile issues, just change to Game.GetPlayer()
RegisterForSingleUpdateGameTime(8) ; register for an update in 8 game hours
; place a copy of starting linen item in the player alias inventory section
; thus when quest is started, the player automatically gets the first item and thus we register for the update here
EndEvent

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
If akBaseItem as MiscObject == DL ; is the added item dirty linens
PlayerRef.RemoveItem(CL) ; remove the clean item
isDirty = true ; indicate that current linen are dirty
RegisterForSingleUpdateGameTime(8) ; register for an update in 8 game hours
EndIf
EndEvent

Event OnUpdateGameTime() ; timer is up
If isDirty == false ; are current linens clean
PlayerRef.AddItem(DL) ; add the dirty linen
EndIf
RegisterForSingleUpdateGameTime(8) ; register for an update in 8 game hours
EndEvent

 

Link to comment
Share on other sites

This block in your latest script code in the post above is part of the issue

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
If akBaseItem as MiscObject == DL ; is the added item dirty linens
PlayerRef.RemoveItem(CL) ; remove the clean item
isDirty = true ; indicate that current linen are dirty
RegisterForSingleUpdateGameTime(8) ; register for an update in 8 game hours
EndIf
EndEvent

Unlike the example that I posted on a previous page this one does not contain the necessary code to handle when clean linens are added to the player. See below:

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
  If akBaseItem as MiscObject == CL     ; is the added item clean linens
    PlayerRef.RemoveItem(DL)            ; remove the dirty item
    isDirty = false                     ; indicate that the current item is clean
    RegisterForSingleUpdateGameTime(8)  ; register for an update in 8 game hours
  ElseIf akBaseItem as MiscObject == DL ; is the added item dirty linens
    PlayerRef.RemoveItem(CL)            ; remove the clean item
    isDirty = true                      ; indicate that current linen are dirty
    RegisterForSingleUpdateGameTime(8)  ; register for an update in 8 game hours
  EndIf
EndEvent

If you only want the update event to run when the clean needs to become dirty, just remove the second RegisterForSingleUpdateGameTime line in the example above. After all, there would be no need to run the update event to swap from dirty to clean should the intent be to have the player craft / buy clean linens.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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