possible to activate a script when items added to container?

Post » Sat Aug 16, 2014 4:46 pm

Hi, I'm pretty new to scripting - I've only actually made two scripts so far. I was wondering if it's possible for an object to have multiple scripts, and for one of the scripts on the object to get 'activated' when certain items get added to a container. Depending what items are added, a different script on the object will get 'activated'. If that makes any sense... If it's possible, I have no idea what sort of script I'd need to use to do this. As I said, I'm very new to scripting :3 If anyone is willing to help me out here, I'd really appreciate it. Thank you!

User avatar
Liv Staff
 
Posts: 3473
Joined: Wed Oct 25, 2006 10:51 pm

Post » Sat Aug 16, 2014 1:59 pm

They would fire simultaneously if you have the same event on multiple scripts. It's best to stick to one event and use IF statements to condition different outcomes. States is something else you could use to avoid the multiple event thing, but I don't think they would help you in this case.
User avatar
Catherine Harte
 
Posts: 3379
Joined: Sat Aug 26, 2006 12:58 pm

Post » Sat Aug 16, 2014 2:35 am

I agree with B1gBad. You could attach something like this to the container:

Scriptname ActWhenItemAdded extends ObjectReferenceFormlist property ItemList01 autoFormlist property ItemList02 autoEvent OnInit()    AddInventoryEventFilter(ItemList01)    AddInventoryEventFilter(ItemList02)EndEventEvent OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)    if (ItemList01.HasForm(akBaseItem))        ;do thing one to your object    elseif (ItemList02.HasForm(akBaseItem))        ;do thing two to your object    endifEndEvent

Edit: After that, you just need to make your two formlists in the Creation Kit, and fill them into the properties ItemList01 and ItemList02 using the "Properties" button on your attached script.

User avatar
mimi_lys
 
Posts: 3514
Joined: Mon Apr 09, 2007 11:17 am

Post » Sat Aug 16, 2014 7:16 am

For example, add this script to your container, making sure to fill your properties:

Scriptname ContainerIfScript Extends ObjectReferenceObjectReference Property Item1 Auto; if you wanted more than 1 item to trigger a certain if statement, use a formlist insteadObjectReference Property Item2 AutoObjectReference Property Item3 AutoEvent Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)	If akBaseItem == Item1		;do something	ElseIf akBaseItem == Item2		;do something	ElseIf akBaseItem == Item3		;do something	Else		;one of your items was not added		;do something elseEndEvent
User avatar
Invasion's
 
Posts: 3546
Joined: Fri Aug 18, 2006 6:09 pm

Post » Sat Aug 16, 2014 4:08 am

Don't forget to add "EndIf" after that Else.

User avatar
CArlos BArrera
 
Posts: 3470
Joined: Wed Nov 21, 2007 3:26 am

Post » Sat Aug 16, 2014 4:23 pm

Thank you all for replying :smile: Okay well your responses have helped, but I'm still a bit stuck. I now get how I should do the script, but what I don't understand, or know if it's even possible, is, basically the 'container' and the 'object' aren't the same item. So what I mean is when you add certain items to the container (and I've now made a form list for each of the possiblities - they're like recipes), a DIFFERENT item, the 'object' will get a script sort of "turned on", where, when you activate it, it will give you a certain item (the product of the 'recipe'). Does that make sense? I've started writing the script, but I'm now stuck what to do when the thing I want to happen isn't on the same item as this script is attached too :S I hope I didn't make that too complicated lol, if you can help me I'd really appreciate it (and I'll credit you for helping me out when my mod is finished :smile: ) Thank you!!

User avatar
zoe
 
Posts: 3298
Joined: Sun Nov 12, 2006 1:09 pm


Return to V - Skyrim