Creating "onequipped" scripts

Post » Mon Jun 18, 2012 4:27 pm

I'm having a hard time scripting and applying my scripts to items..

My Steps taken are:
  • Duplicate a non enchanted Amulet
  • Rename Amulet
  • Add Script to item in the "edit" mode when you right click and edit the new Amulet in object window:
Scriptname Teeko extends ObjectReferenceArmor Property TeekoJewelry AutoEvent OnObjectequipped(Form akBaseObject, ObjectReference akReference)if akBaseObject as ArmorDebug.Trace("This actor just equipped a piece of armor!")endIfGame.GetPlayer().ModActorValue("critchance", 10)Game.GetPlayer().ModActorValue("health", 800)endEventEvent OnObjectUnequipped(Form akBaseObject, ObjectReference akReference)if akBaseObject as ArmorDebug.Trace("This actor just unequipped a piece of armor!")endIfGame.GetPlayer().ModActorValue("critchance", -10)Game.GetPlayer().ModActorValue("health", -800)endEvent
  • Save
  • Equip item in-game... health is not increased, so my only guess is crit chance is also not increased.
(only added health to script so I have something to physically see)

Help would be appreciated :biggrin:
User avatar
Cat Haines
 
Posts: 3385
Joined: Fri Oct 27, 2006 9:27 am

Post » Mon Jun 18, 2012 9:59 pm

I'm back to work tomorrow morning, can anyone shed light on this subject? thanks :D
User avatar
Charleigh Anderson
 
Posts: 3398
Joined: Fri Feb 02, 2007 5:17 am

Post » Mon Jun 18, 2012 7:47 pm

If I'm understanding this correctly (I seem to not be doing that alot lately)... You made an amulet and attached a script to it that modifies the player's Actor Values when equipped?

If so, you should be using OnEquipped(Actor akActor) instead of OnObjectEquipped. I modified your script a little, didn't try it out, though.

Scriptname Teeko extends ObjectReferenceEvent OnEquipped(Actor akActor)	Debug.Trace("This actor just equipped my amulet! :)")	Game.GetPlayer().ModActorValue("critchance", 10)	Game.GetPlayer().ModActorValue("health", 800)EndEventEvent OnUnequipped(Actor akActor)	Debug.Trace("This actor just equipped my amulet... :(")  	Game.GetPlayer().ModActorValue("critchance", -10)	Game.GetPlayer().ModActorValue("health", -800)		; You could also try akActor.ModActorValue( [blah] ) as well, if you want it to apply to anyone that equips this.	; Also, using Game.GetPlayer() will probably cause the player's values to change regardless of who equips this.EndEvent
You could also use magic effects and spells to modify these. Not sure if you can alter critchance this way, though.

Also, why not just enchant the amulet?
User avatar
Rachie Stout
 
Posts: 3480
Joined: Sun Jun 25, 2006 2:19 pm

Post » Mon Jun 18, 2012 6:09 pm

If I'm understanding this correctly (I seem to not be doing that alot lately)... You made an amulet and attached a script to it that modifies the player's Actor Values when equipped?

If so, you should be using OnEquipped(Actor akActor) instead of OnObjectEquipped. I modified your script a little, didn't try it out, though.

Scriptname Teeko extends ObjectReferenceEvent OnEquipped(Actor akActor)	Debug.Trace("This actor just equipped my amulet! :)")	Game.GetPlayer().ModActorValue("critchance", 10)	Game.GetPlayer().ModActorValue("health", 800)EndEventEvent OnUnequipped(Actor akActor)	Debug.Trace("This actor just equipped my amulet... :(")  	Game.GetPlayer().ModActorValue("critchance", -10)	Game.GetPlayer().ModActorValue("health", -800)		; You could also try akActor.ModActorValue( [blah] ) as well, if you want it to apply to anyone that equips this.	; Also, using Game.GetPlayer() will probably cause the player's values to change regardless of who equips this.EndEvent
You could also use magic effects and spells to modify these. Not sure if you can alter critchance this way, though.

Also, why not just enchant the amulet?

I'll try this out.
Also, if I'm going to enchant the amulet, wouldn't it lead back to a script anyway?
For example: Create amulet, create enchantment, create magic effect... which requires a script

Does that make sense? I don't know lol

Thanks for replying :D
User avatar
Georgia Fullalove
 
Posts: 3390
Joined: Mon Nov 06, 2006 11:48 pm

Post » Mon Jun 18, 2012 10:54 am

I'll try this out.
Also, if I'm going to enchant the amulet, wouldn't it lead back to a script anyway?
For example: Create amulet, create enchantment, create magic effect... which requires a script

Does that make sense? I don't know lol

Thanks for replying :biggrin:
Don't need a script for that. Short guide:

You've got one part done, your amulet. Now you need to create the Magic Effects (I'm not overly familiar with how this works). Then you create enchantment that uses the magic effect. Then you add it to your amulet. There's a field somewhere on amulet's record page for enchantments.
User avatar
Javier Borjas
 
Posts: 3392
Joined: Tue Nov 13, 2007 6:34 pm

Post » Mon Jun 18, 2012 5:13 pm

Can someone please explain the reason why OnEquip is used as opposed to OnObjectEquip in this case? I assume it's because the script that's being run here is attached to an object, is this case an amulet. Want to make sure that's right, and also... where exactly WOULD you use OnObjectEquip then?

Second, the OnEquip function seems to have a bug. If the Object is not picked up from the world (for example, if you use the console to put the object into your inventory) the equip effect won't work. You have to drop the object, pick it back up, THEN it works. Anyone know any workarounds to this? I want to start my object off with a vendor, and am afraid that after bought (since the object isn't outside containers yet) it will not work unless the player drops it and then picks it back up. :|
User avatar
chloe hampson
 
Posts: 3493
Joined: Sun Jun 25, 2006 12:15 pm

Post » Mon Jun 18, 2012 10:45 am

Can someone please explain the reason why OnEquip is used as opposed to OnObjectEquip in this case? I assume it's because the script that's being run here is attached to an object, is this case an amulet. Want to make sure that's right, and also... where exactly WOULD you use OnObjectEquip then?

Yes (well, "item" would be a better word than "object," but I know what you mean). http://www.creationkit.com/OnEquipped_-_ObjectReference is an event triggered by a particular weapon/piece of apparel, and passed to scripts that extend it; http://www.creationkit.com/OnObjectEquipped_-_Actor is triggered by the actor who equipped the weapon/apparel, and is passed to scripts that extend the actor. Theoretically the same sorts of things can be done with either, but often one is more efficient than the other--depending on whether there are many instances of the item in the game world or if it is a unique item, whether it should have an effect on all actors who might equip it or just one particular actor, etc.
User avatar
Jade Barnes-Mackey
 
Posts: 3418
Joined: Thu Jul 13, 2006 7:29 am

Post » Mon Jun 18, 2012 2:04 pm

OK thanks for the response, much appreciated. Little by little, getting a better grasp here.

I can see how to attach scripts to actors in general, but what happens when the actor is the player? So if I want to fire off a script when the PLAYER (not just any actor) equips an item, for example... where is this script created and attached?
User avatar
Matt Gammond
 
Posts: 3410
Joined: Mon Jul 02, 2007 2:38 pm

Post » Mon Jun 18, 2012 7:55 am

unfortunately OnEquip is a very unreliable function call. the fact that many of skyrim's vanilla gear that use it is broken because of it, is a testament to this.


in any case, if you want to restrict access to only the player (i.e. the script is only applied to player and not NPCs)

you would put the code inside an if statement, so that it will only fire if the action is performed only by the player and ignored if not:


Event OnEquipped(Actor akActor)   If (akActor == Game.GetPlayer())	   ;rest of your code here   EndIfEndEvent
User avatar
katie TWAVA
 
Posts: 3452
Joined: Tue Jul 04, 2006 3:32 am

Post » Mon Jun 18, 2012 6:50 pm

Why is it broken? I've used OnObjectEquipped in all my scripts I'm doing for my mod as a "cost effective" way to do what I want to do, and it's worked fine for me so far. Though, my script is attached to the player directly via a quest alias, not attached to a specific item (I assume that's what OnEquip is supposed to do?).
User avatar
Juliet
 
Posts: 3440
Joined: Fri Jun 23, 2006 12:49 pm

Post » Mon Jun 18, 2012 11:19 am

Korjax, Amethyst means the OnEquip function, not the OnObjectEquipped function. It seems the problems relate to the former, not the latter.
User avatar
Ross Thomas
 
Posts: 3371
Joined: Sat Jul 21, 2007 12:06 am


Return to V - Skyrim