Attaching a script to an inventory object

Post » Sun Jun 29, 2014 5:44 pm

This should be a simple one for you scripting vets. I'm trying some toy problems to learn the ropes of Skyrim modding but I've encountered an issue I didn't expect to.

I created a new object in the Creation Kit (a duplicate Gold Ring by another name). I know that this object exists and works as expected because I added it to my inventory by console command.

I have tried to attach the following simple script to the object:

Scriptname helloItem extends ObjectReference   Event OnEquip()    debug.messagebox("hello")EndEvent

For some reason, nothing happens when I equip the item in-game. Any ideas?

User avatar
Sheila Esmailka
 
Posts: 3404
Joined: Wed Aug 22, 2007 2:31 am

Post » Sun Jun 29, 2014 5:49 pm

should be OnEquipped() and not OnEquip()

Also the event have a parameter:

Event OnEquipped(Actor akActor)  if(akActor == game.getplayer()) ;use this condition if you want that only the player will trig the script    doStuff here...  endIfendEvent
User avatar
Joey Avelar
 
Posts: 3370
Joined: Sat Aug 11, 2007 11:11 am

Post » Sun Jun 29, 2014 5:28 pm

Thanks for the quick response. You're right, I didn't notice that mistake...

I've changed my script to:

Scriptname helloItem extends ObjectReference   Event OnEquipped(Actor akActor)    debug.messagebox("hello")EndEvent

Still nothing happens when I equip the item in-game.

User avatar
Alba Casas
 
Posts: 3478
Joined: Tue Dec 12, 2006 2:31 pm

Post » Sun Jun 29, 2014 1:51 pm

Reading again your #1 post, I see that you have simply added it in the inventory.

Well, the OnEquipped() event is triggered only when the player or NPC equips the item. If you want to trigger a script when an item is added in an inventory, you have to use the OnContainerChanged() event.

http://www.creationkit.com/OnContainerChanged_-_ObjectReference

User avatar
~Amy~
 
Posts: 3478
Joined: Sat Aug 12, 2006 5:38 am

Post » Sun Jun 29, 2014 8:24 pm

For complete clarity, this is what I'm doing / have done:

  • I added the item to my inventory.
  • I saved the game.
  • I modify scripts, compile them, and save the .esp file.
  • I launch game and load.
  • I open my inventory and equip the item.
  • Nothing happens, repeat from step 3.
User avatar
Loane
 
Posts: 3411
Joined: Wed Apr 04, 2007 6:35 am

Post » Mon Jun 30, 2014 5:38 am

Solution has been found!

Something about the method above doesn't quite work for some reason. Dumping the ring from my inventory, picking it up, and THEN equipping it worked as expected.

I'd love an explanation for why, but the problem is solved. Thanks MannyGT.

User avatar
Meghan Terry
 
Posts: 3414
Joined: Sun Aug 12, 2007 11:53 am


Return to V - Skyrim