corrado33 Posted September 8, 2018 Share Posted September 8, 2018 Say I have a script that moves items into a chest. But I want to be able to change which chest it moves things into in game. How... would I do that? The way I would do it in CK is simply to change the reference in the script properties. I've seen mods do this via a custom spell, and I've seen mods do this via crouch activating. Unfortunately none of those mods have script source codes :( Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 8, 2018 Share Posted September 8, 2018 Basic example: Scriptname SomeScriptAssignedToThePlayer Extends ReferenceAlias ObjectReference Property ContainerA Auto ObjectReference Property ContainerB Auto Actor Property PlayerRef Auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) If akBaseItem as Ingredient PlayerRef.RemoveItem(akBaseItem,aiItemCount,true,ContainerA) ElseIf akBaseItem as Food PlayerRef.RemoveItem(akBaseItem.aiItemCount,true,ContainerB) EndIf EndEvent Basically, whatever event you use to trigger the action there needs to be conditions in place that direct the script to the container with which to use. Unless you're wanting to change the target container for an already established pairing of items to container. For that, you'd need to do the following ScriptName SomeScriptAttachedToThePlayer Extends ReferenceAlias ObjectReference Property ContainerA Auto Actor Property PlayerRef Auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) ContainerA = Game.GetFormFromFile(0x00123456,"SomeModName.esp") as ObjectReference If akBaseItem as Ingredient PlayerRef.RemoveItem(akBaseItem,aiItemCount,true,ContainerA) EndIf EndEvent Inserting the single GetFormFromFile line changes the target container to the new container. This can be done when you want to make a change to the behavior of a script without affecting the properties stored on the item record itself. Link to comment Share on other sites More sharing options...
corrado33 Posted September 8, 2018 Author Share Posted September 8, 2018 Basic example: Scriptname SomeScriptAssignedToThePlayer Extends ReferenceAlias ObjectReference Property ContainerA Auto ObjectReference Property ContainerB Auto Actor Property PlayerRef Auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) If akBaseItem as Ingredient PlayerRef.RemoveItem(akBaseItem,aiItemCount,true,ContainerA) ElseIf akBaseItem as Food PlayerRef.RemoveItem(akBaseItem.aiItemCount,true,ContainerB) EndIf EndEvent Basically, whatever event you use to trigger the action there needs to be conditions in place that direct the script to the container with which to use. Unless you're wanting to change the target container for an already established pairing of items to container. For that, you'd need to do the following ScriptName SomeScriptAttachedToThePlayer Extends ReferenceAlias ObjectReference Property ContainerA Auto Actor Property PlayerRef Auto Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer) ContainerA = Game.GetFormFromFile(0x00123456,"SomeModName.esp") as ObjectReference If akBaseItem as Ingredient PlayerRef.RemoveItem(akBaseItem,aiItemCount,true,ContainerA) EndIf EndEvent Inserting the single GetFormFromFile line changes the target container to the new container. This can be done when you want to make a change to the behavior of a script without affecting the properties stored on the item record itself.Thanks for advice, however I don't think I was clear enough in the OP. I want a way to dynamically set the "target container" of a script. I'm well aware of how to sort things via script into different containers. I think I could use your second bit of code except it's missing the main part that I want. Namely how to get an object reference from in game to the script. So let's say this. I have a button in a test cell next to 15 chests. I want to be able to cast a spell at or crouch activate ONE of the chests to mark it as "target." Then I press the button and my script runs and it adds items to that specific chest. However, I don't just want this to work in my test cell. I want it to work ANYWHERE (meaning I don't already know the formIDs of the chests, they're not contained in my .esp file) So if there were a "storeFormInFile" function I could use that. I could also use a special "object" placed in the special "chest". The object would be part of my mod. But then how on earth would I search through every container of a cell to find which form contained my special object. Optimally, I'd like to have a way to create object pairs and store them some way, so that I can "link" say a mannequin and a chest. (But again, ANY mannequin and ANY container, not just ones in my specific test cell.) Then, I could press a button and that mannequin would pull items from that container to "auto dress." Sorry, I know I must be confusing, I'm very new to skyrim modding. ;( Link to comment Share on other sites More sharing options...
IsharaMeradin Posted September 8, 2018 Share Posted September 8, 2018 I can get you a means of getting the target mannequin and target container. Doesn't create "a pair" but does let the player select any mannequin and any container to use. Attach to a quest that will run the full duration of the mod's life. Scriptname SomeQuestScript Extends Quest Int Property HotKeyValue Auto ButtonScript Property BScript Auto ;Fill property with correct button holding the script Event OnInit() RegisterForKey(HotKeyValue) EndEvent Event OnKeyDown(Int KeyCode) If KeyCode == HotKeyValue ObjectReference Ref = Game.GetCurrentCrosshairRef() If Ref != None If (Ref.GetBaseObject().GetType() == 28) ;container BScript.TargetContainer = Ref ElseIf Ref as Actor ;may be mannequin or other NPC, for compatibility reasons cannot distinguish between the two, players must take care. BScript.TargetMannequin = Ref EndIf EndIf EndIf EndEvent Press designated key when targeting a container or mannequin, this stores the target(s) in the properties on the button script. The above requires SKSE to function. Even if you convert to a spell and remove all the hotkey stuff the necessary GetCurrentCrosshairRef comes from SKSE. ScriptName ButtonScript Extends ObjectReference ObjectReference Property TargetContainer = None Auto ;has to be a property for other scripts to access Actor Property TargetMannequin = None Auto ;has to be a property for other scripts to access Bool ButtonToggle = false Event OnActivate(ObjectReference akActionRef) If akActionRef == PlayerRef If ButtonToggle == true TargetContainer.RemoveAllItems(TargetMannequin) ;mannequin should auto equip when items are added to it ButtonToggle = false Else TargetMannequin.UnequipAll() ;should strip the mannequin naked TargetMannequin.RemoveAllItems(TargetContainer) ;removes any items to the target container ButtonToggle = true EndIf EndIf EndEvent This lets your button toggle between equipping from one container and unequipping then storing in the container. Probably want to use states as a safety net in case the player spams the button. Should be obvious but when linking two scripts like this, the one being called upon needs to be created first so that the compiler can find the information for the other script. As far as transferring items from the player to a container, you have to know what items to transfer. You cannot use RemoveAllItems as it will take the player's equipped gear as well. It may be better to simply let the player deposit whatever to a container manually. You can use a formlist and every item on that list will be transferred but that means either pre-filling in the CK or somehow filling when Items pass in to or out of the player's hands. The logical thing in a limited setup would be a formlist for each container and that container adds the items to its formlist as they are initially placed within by the player. But in a wide any combination setup, I cannot think of a viable method. Hope this is helpful, sorry I cannot think of additional ways to obtain what you are looking for. Link to comment Share on other sites More sharing options...
Recommended Posts