Jump to content

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


huggibee

Recommended Posts

Hello! I'm looking for a bit of help with creating a script that would remove a misc object from an inventory after set amount of time and replace it with another misc object. I'm also looking to have this script apply to NPC inventories as well if it's possible, not just the player's. I've been working on a small mod for myself and have everything sorted except for this darned script, but as much as I try, I'm just not experienced enough to write it up myself. If it helps, the misc objects I'm referring to are washed and unwashed linens, and after about 8 in game hours, I'd like the washed linens to "become" unwashed.

 

If anyone would be willing to help me out with this, I'd be really grateful! Thanks! :happy:

Link to comment
Share on other sites

It would look something like this:

Scriptname yourscriptname extends objectreference

Event yourevent()

     If Actor.IsEquipped(WashedLinens)
          RegisterForUpdate(1440.0)
     EndIf

EndEvent

Event OnUpdate()

    If Actor.IsEquipped(WashedLinens)
          Actor.RemoveItem(WashedLinens)
          Actor.AddItem(UnwashedLinens)
          Actor.EquipItem(UnwashedLinens)
          UnregisterForUpdate()
     EndIf

EndEvent

MiscObject Property WashedLinens Auto

MiscObject Property UnwashedLinens Auto

But I have not tested that out. Also there would have to be another script that would give the "washed linens" back to them somehow after it was removed.

 

The update at 1440.0 seconds = 24 real-time minutes. This should = 8 in-game hours.

Edited by jucoking
Link to comment
Share on other sites

Ah, thank you! That's exactly what I was looking for! I'll be testing it out then -- and just to be sure I'm not doing anything wrong, I would apply the script to the misc obj Washed Linens and then simply hook up the properties in CK, correct?

 

Again, thanks so much for the reply!

Link to comment
Share on other sites

It did! Thanks so much for your help thus far and replies! -- but it seems I've run into an issue compiling the script. Would you be willing to help me sort it? Here's the tweaked script and the errors the CK spits at me. I'm not quite sure how to resolve the errors, and google has been little help.

 

 

 

Scriptname _A_LinensUpdate extends objectreference
Event yourevent()
If Actor.IsEquipped(WashedLinens)
RegisterForUpdate(10)
EndIf
EndEvent
Event OnUpdate()
If Actor.IsEquipped(WashedLinens)
Actor.RemoveItem(WashedLinens)
Actor.AddItem(UnwashedLinens)
Actor.EquipItem(UnwashedLinens)
UnregisterForUpdate()
EndIf
EndEvent
MiscObject Property UnwashedLinens Auto
MiscObject Property WashedLinens Auto

 

 

Starting 1 compile threads for 1 files...
Compiling "_A_LinensUpdate"...
C:\Users\McGui\OneDrive\Documents\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\_A_LinensUpdate.psc(5,14): cannot call the member function IsEquipped alone or on a type, must call it on a variable
C:\Users\McGui\OneDrive\Documents\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\_A_LinensUpdate.psc(13,13): cannot call the member function IsEquipped alone or on a type, must call it on a variable
C:\Users\McGui\OneDrive\Documents\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\_A_LinensUpdate.psc(14,16): cannot call the member function RemoveItem alone or on a type, must call it on a variable
C:\Users\McGui\OneDrive\Documents\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\_A_LinensUpdate.psc(15,16): cannot call the member function AddItem alone or on a type, must call it on a variable
C:\Users\McGui\OneDrive\Documents\Steam\steamapps\common\skyrim\Data\Scripts\Source\temp\_A_LinensUpdate.psc(16,16): cannot call the member function EquipItem alone or on a type, must call it on a variable
No output generated for _A_LinensUpdate, compilation failed.
Link to comment
Share on other sites

You have the word Actor which is an object type. You need to be using a variable such as a property variable that is declared as an Actor or ObjectReference object type. And yourevent() is a non-existent event. Both it and the use of Actor were done as place holders in the example.

 

Are your "linens" misc objects? If so, there is no need to equip and unequip them.

 

I would set it up as follows:

A management quest set to be start game enabled.

Script attached to the quest:

 

 

ScriptName LinenSwapManagerScript Extends Quest
 
MiscObject Property CL Auto ; clean linens
MiscObject Property DL Auto ; dirty linens
 
Function SwapLinen(Actor TheDude, Bool Swap)
  If Swap == True
    TheDude.RemoveItem(CL,1)
    TheDude.AddItem(DL,1)
  Else
    TheDude.RemoveItem(DL,1)
    TheDude.AddItem(CL,1)
  EndIf
EndFunction

 

 

 

Script on the misc object(s)

NOTE: Create quest script first or this will fail to compile

 

 

ScriptName LinenObjectScript Extends MiscObject
 
LinenSwapManagerScript Property LSMS Auto ;the first word of this line MUST match the script filename on the quest
Bool Property isDirty = false Auto ;set to true in CK for the dirty linen object
Actor myPerson
 
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
  If akNewContainer as Actor ;did we get put into an actor inventory
    myPerson = akNewContainer as Actor
    RegisterForSingleUpdateGameTime(8) ; register for an update in 8 game hours
  ElseIf !akNewContainer || akNewContainer != Actor ; removed to the void, dropped to the ground or put into a container
    UnRegisterForUpdateGameTime()
  EndIf
EndEvent
 
Event OnUpdateGameTime()
  If isDirty == false
    LSMS.SwapLinen(myPerson, true) ; swap the clean for dirty
  Else
    LSMS.SwapLinen(myPerson, false) ; swap the dirty for clean
  EndIf
  RegisterForSingleUpdateGameTime(8) ; register for an update in 8 game hours
EndEvent

 

 

You can put the swap code all on one script but I would prefer to separate it out. No need to have multiple instances of the object script with the property data for the linen objects stored in memory, only need that done once.

Link to comment
Share on other sites

Ah! Thank you so much! Thanks for really putting things into place for me! I can't wait to test it out -- I really appreciate it!

 

Edit: With the swap script, the compiler seems to have an issue with 11,46 ( ElseIf !akNewContainer || akNewContainer != Actor ; removed to the void, dropped to the ground or put into a container) The error is Actor is not a variable.

Edited by huggibee
Link to comment
Share on other sites

Personally I probably would keep the swap logic in one script, since all you really need is a property for the next item in the swaps; the script on the miscobjects already knows what itself is, and you have access to that through the special 'self' variable. The quest therefore doesn't save you any properties (since you still need to hold the quest), it introduces an extra object (the quest itself), and it adds an extra conditional check (to figure out which version of the swap it should be executing).

 

If you had more sophisticated requirements or the swap tied into larger systems offloading that behaviour to a quest would make more sense, but as presented it looks like additional complexity you don't need.

 

I'd also check on behaviour if you drop and regrab the miscobject just before the timer runs out. Ishara's logic will reset the timer if that happens, which may not be desired.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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