Equip item on WeaponDraw

Post » Wed Jun 20, 2012 9:00 am

hi guys, I'm working on a mod to equip different items when the player or any other actor is drawing his weapon, but I stuck on the script, it would cool a little help. i attach this on the old shield that must be replaced by the new shield when the actor draw his weapon, but nothing happens

import Utilityimport GameActor ShieldActorArmor Property NewShield Auto Event OnEquipped(Actor akActor)   Utility.Wait(1)   ShieldActor = akActor   registerForUpdate(1)endEventEvent OnUpdate()    if (ShieldActor.IsWeaponDrawn()) && (ShieldActor.GetEquippedShield() == self)     ShieldActor.AddItem(NewShield, 1, true)     ShieldActor.EquipItem(NewShield, true)     ShieldActor.RemoveItem(self, 1, true)   elseif !(ShieldActor.IsWeaponDrawn()) && (ShieldActor.GetEquippedShield() == NewShield)     ShieldActor.AddItem(self, 1, true)     ShieldActor.EquipItem(self, true)     ShieldActor.RemoveItem(NewShield, 1, true)   endifEndEventEvent OnUnequipped(Actor akActor)   UnregisterForUpdate()endEvent
User avatar
Tinkerbells
 
Posts: 3432
Joined: Sat Jun 24, 2006 10:22 pm

Post » Wed Jun 20, 2012 4:43 pm

Did you try dropping the shield and then picking it back up? Correct me if I'm wrong, but items added directly to your inventory through script/console don't run their scripts unless they have an OnInit or else they get loaded in the game world first.
User avatar
Sarah Bishop
 
Posts: 3387
Joined: Wed Oct 04, 2006 9:59 pm

Post » Wed Jun 20, 2012 6:39 am

you are right, when I drop the shield, it works, but only for a moment, then stops working, I guess there is something wrong with the script, I changed it this way but still does not work well:

import Utilityimport GameActor ShieldActorArmor Property NewShield AutoArmor Property OldShield AutoEvent OnEquipped(Actor akActor)   ShieldActor = akActorendEventEvent OnLoad()   Utility.Wait(1)   registerForUpdate(1)endEventEvent OnUpdate()   if (ShieldActor.IsWeaponDrawn()) && (ShieldActor.GetEquippedShield() == OldShield)	 ShieldActor.EquipItem(NewShield, false, true)	 ShieldActor.RemoveItem(OldShield, 1, true)   elseif !(ShieldActor.IsWeaponDrawn()) && (ShieldActor.GetEquippedShield() == NewShield)	 ShieldActor.EquipItem(OldShield, false, true)	 ShieldActor.RemoveItem(NewShield, 1, true)   endifEndEvent;Event OnUnequipped(Actor akActor);   UnregisterForUpdate();endEvent
User avatar
katsomaya Sanchez
 
Posts: 3368
Joined: Tue Jun 13, 2006 5:03 am

Post » Wed Jun 20, 2012 3:13 pm

How do you know it works for a moment and then stops working?
User avatar
SWagg KId
 
Posts: 3488
Joined: Sat Nov 17, 2007 8:26 am

Post » Wed Jun 20, 2012 6:12 am

just a heads up, even if you get it working it will immediately break if the player uses hotkey/favorites to switch between weapons.

the hotkey bypasses all subsequent OnEquip events and your script will stop running after it fires its first OnEquip.

if you want to take a look, i have a script that swaps armor meshes when the player draws his weapon to make it appear like a blade is extended out of his gauntlets:

http://skyrim.nexusmods.com/downloads/file.php?id=5696

under the misc section in downloads: armblade beta. the weapon works for the most part (but not in 1st person, but that's a race related issue) but you are more than welcomt to browse the script and hopefully get some ideas for direction
User avatar
Killah Bee
 
Posts: 3484
Joined: Sat Oct 06, 2007 12:23 pm

Post » Wed Jun 20, 2012 3:17 pm

thanks for the help but i had to solve it by attaching the script to the player's actor...because from the shield doesn't work for me
User avatar
Cedric Pearson
 
Posts: 3487
Joined: Fri Sep 28, 2007 9:39 pm


Return to V - Skyrim