[script] Possible to duplicate items via script?

Post » Sun Nov 18, 2012 9:12 pm

Hello all! First post here.

I'm currently trying to make a spell that would cast an enchantment to my currently equipped weapon, but only lasts for a limited time (the new SKSE has a setEnchantment function now - I can mention SKSE in this forum right?). Problem is, if the weapon isn't unique the enchantment applies to EVERY identical weapon in the game. This means that if my enemy has the same sword as I do and I cast the spell, then both of our weapons will have the enchantment. So is there a way to duplicate my weapon using script? And if possible a function that removes the item once the magic effect wears off (to avoid game bloating)? The idea is to duplicate my weapon > add it to my inventory > set enchantment > equip. My script works so far, other than that particular problem.

Any help would be much appreciated!

Here's my current code.

Scriptname castEnchantment extends activemagiceffect  Enchantment Property thisEnchantment  Auto  WEAPON Property thisWeapon  Auto  Enchantment Property noEnchantment  Auto  Event OnEffectStart(Actor ckTarget, Actor ckCaster)   RegisterForUpdate(0.1)   thisWeapon = Game.GetPlayer().GetEquippedWeapon() as Weapon   thisWeapon.setEnchantment(thisEnchantment)   Game.GetPlayer().UnequipSpell(thisSpell, 0)EndEventEvent OnUpdate()   if(Game.GetPlayer().IsWeaponDrawn())	 thisWeapon.setEnchantment(noEnchantment)	 UnregisterForUpdate()   endifEndEventEvent OnEffectFinish(Actor ckTarget, Actor ckCaster)   thisWeapon.setEnchantment(noEnchantment)   UnregisterForUpdate()EndEvent
User avatar
Claire
 
Posts: 3329
Joined: Tue Oct 24, 2006 4:01 pm

Post » Sun Nov 18, 2012 9:09 pm

(Please note: I have taken a large dose of stupid, this morning, so please treat this with some caution ... I hope to be back to normal tomorrow!)

(Please note: Normally, I'm pretty rubbish at answering stuff!)


You are enchanting the BASE-WEAPON, not an "instance" of it.

There are ways to get that to happen ... but I'm a little confused.

Are you trying to enchant only one particular weapon, or any weapon that the player is carrying?

If the former, then an alias - or a script on that weapon itself - may well work.

If any weapon ... then I don't know


ALSO: Note that running scripts/effects on a weapon in the player's inventory (or any container, I think?) is not relaible (if it works at all).
User avatar
Lloyd Muldowney
 
Posts: 3497
Joined: Wed May 23, 2007 2:08 pm

Post » Sun Nov 18, 2012 11:15 pm

Yeh I think the alias route is what you need. not 100% sure if the enchantment part works on references. I would've checked, but I'm at work at the moment. Ah well, here's how you'de set it up, I'm just not sure if it will compile

Make a new quest alias, leave in un-filled, make sure you tick the "optional" checkbox.

I've edited your script to reflect the alias method:

Scriptname castEnchantment extends activemagiceffect  Enchantment Property thisEnchantment  Auto  ReferenceAlias Property Alias_thisWeapon  Auto  Enchantment Property noEnchantment  Auto  Event OnEffectStart(Actor ckTarget, Actor ckCaster)   RegisterForSingleUpdate(0.1)   Alias_thisWeapon.ForceRefTo(Game.GetPlayer().GetEquippedWeapon() as ObjectReference)   Alias_thisWeapon.setEnchantment(thisEnchantment)   Game.GetPlayer().UnequipSpell(thisSpell, 0)EndEventEvent OnUpdate()   if(Game.GetPlayer().IsWeaponDrawn())	 Alias_thisWeapon.setEnchantment(noEnchantment)	 RegisterForSingleUpdate(0.1)   endifEndEventEvent OnEffectFinish(Actor ckTarget, Actor ckCaster)   Alias_thisWeapon.setEnchantment(noEnchantment)   Alias_thisWeapon.Clear()EndEvent

I also changed the registerforupdate() into a RegisterForSingleUpdate() because I've seen so many people say that the former can cause problems with someones save

Like I said I'm not sure if this script will compile because I've got a feeling the "setEnchantment()" will only work on a base weapon :shrug:

EDIT: I just noticed that in the OnEffectStart() event, you are unequipping "thisSpell" on the player, but you havn't defined "thisSpell" as a property???

- Hypno
User avatar
Josephine Gowing
 
Posts: 3545
Joined: Fri Jun 30, 2006 12:41 pm

Post » Sun Nov 18, 2012 10:33 pm

Thanks for the assist. My current workaround is to use a "blank" weapon that will get the stats and model of the player's weapon. It's a pretty roundabout way. That reference alias is interesting though. I've personally never tried that yet. I'll be sure to check it out. Thanks again!

Edit: On this thisSpell variable - I missed out the last line of the code. I added that one at the last minute. Supposedly there's a spell property under there. Sorry for the confusion.
User avatar
Mylizards Dot com
 
Posts: 3379
Joined: Fri May 04, 2007 1:59 pm


Return to V - Skyrim