.IsEquipped() and .UnequipItem()

Post » Tue Jun 19, 2012 10:58 pm

I'm trying to make an anti-bow script to work as intended, perhaps I'm not writing it correctly.

Pardon the possibly really weird parsing. The weapon properties cover the main bow types in the game that bandits and other NPCs possibly use.

What the script is suppose to do is check if any of these bows are equipped, then unequip them and prevent them from re-equipping. But it's not working this way. Upon unequipping they can re-equip and I don't know why.
Spoiler

Scriptname MassUnequip extends activemagiceffect  ;=========\;PROPERTIES;=========\Weapon property Bow autoWeapon property Bow2 autoWeapon property Bow3 autoWeapon property Bow4 autoWeapon property Bow5 autoWeapon property Bow6 autoWeapon property Bow7 autoWeapon property Bow8 autoWeapon property Bow9 autoWeapon property Bow10 auto;=========\;EVENTS;=========\Event OnEffectStart(Actor akTarget, Actor akCaster)			actor actorRef = akTarget as actor			(akTarget as actor).UnequipAll() ; ← This is just for my own humor ;p		   if (akTarget as actor).IsEquipped(Bow)				  (akTarget as actor).UnequipItem(Bow, true)							elseif (akTarget as actor).IsEquipped(Bow2)				  (akTarget as actor).UnequipItem(Bow2, true)								elseif (akTarget as actor).IsEquipped(Bow3)					(akTarget as actor).UnequipItem(Bow3, true)									elseif(akTarget as actor).IsEquipped(Bow4)						(akTarget as actor).UnequipItem(Bow4, true)										elseif(akTarget as actor).IsEquipped(Bow5)							(akTarget as actor).UnequipItem(Bow5, true)											elseif(akTarget as actor).IsEquipped(Bow6)								(akTarget as actor).UnequipItem(Bow6, true)									elseif(akTarget as actor).IsEquipped(Bow7)							(akTarget as actor).UnequipItem(Bow7, true)				  					 elseif(akTarget as actor).IsEquipped(Bow8)						(akTarget as actor).UnequipItem(Bow8, true)								elseif(akTarget as actor).IsEquipped(Bow9)					(akTarget as actor).UnequipItem(Bow9, true)							elseif(akTarget as actor).IsEquipped(Bow10)				  (akTarget as actor).UnequipItem(Bow10, true)		endifEndEvent
User avatar
Karl harris
 
Posts: 3423
Joined: Thu May 17, 2007 3:17 pm

Post » Tue Jun 19, 2012 7:42 pm

(akTarget as actor).UnequipAll() ; ← This is just for my own humor ;p

Move that funny line to the bottom of the event.
I'm going to giggle here if that's all it was ;)
User avatar
Epul Kedah
 
Posts: 3545
Joined: Tue Oct 09, 2007 3:35 am

Post » Tue Jun 19, 2012 1:44 pm

If you mean the comment, I don't see why it would since it's commented out by the ;.

If you meant the ENTIRE line, yea sure I can do that and test it right now.

Edit: Nope. Still doesn't work. And removing that line didnt change anything either.
User avatar
Emilie Joseph
 
Posts: 3387
Joined: Thu Mar 15, 2007 6:28 am

Post » Tue Jun 19, 2012 10:54 pm

If you mean the comment, I don't see why it would since it's commented out by the ;.

If you meant the ENTIRE line, yea sure I can do that and test it right now.

Edit: Nope. Still doesn't work. And removing that line didnt change anything either.
Just in case, I'd like to point out that your ; was located at the end of the line, so the code was still running. The ; prevents all code being ran after it in the line, it does not prevent the entire line from being read. That would mean it is unequipping everything before the script ran, regardless of whether or not they have a bow equipped. Even moving it to the end would simply unequip everything anyways. That aside, you did say you removed it (and I think you should keep it removed) so that doesn't really have anything to do with your issue.

I have some...questions though.
1) Why are you casting your actor variable to an actor variable? There is no need to do that since akTarget is already an actor.
2) Are you trying to prevent all bows or just specific ones?
3) How exactly is this supposed to prevent them from re-equipping the bow? You don't have any actual code that prevents re-equipping the items.
4) Is this supposed to work for all actors or just the player?
User avatar
Aaron Clark
 
Posts: 3439
Joined: Fri Oct 26, 2007 2:23 pm

Post » Tue Jun 19, 2012 3:31 pm

Yep, the 'UnequipAll' line at the bottom makes a difference, as all the if/else statements that followed would *always* return false.
They won't have any bow as you just told them to take it off.
Probably best to comment it out altogether while testing so at least if you see a bow removed you know how it was removed.

@Delfof, The 'true' argument to unEquipped is the part that should stop them re-equipping the item. There's a similar argument to Equip. (Can be used for cursed rings etc.)

If the bows are still being re-equipped afterwards, then it's probably one of those function flags that only work for the player.
User avatar
Robert Jr
 
Posts: 3447
Joined: Fri Nov 23, 2007 7:49 pm

Post » Wed Jun 20, 2012 1:09 am

Actually that comment line was not present in the script in the CK. I just edited that in there in my post..sorry about that lol.

1. xxxxx as actor is out of habit. A habit I need to break.
2. All bows
3. UneuipItem(something, true) = prevents them from equipping http://www.creationkit.com/UnequipItem_-_Actor unless I misunderstood?
4. It's supposed to work on all actors, but mainly for those I see using bows.
User avatar
Taylor Bakos
 
Posts: 3408
Joined: Mon Jan 15, 2007 12:05 am

Post » Tue Jun 19, 2012 12:53 pm

I just tested out the UnequipItem function, and that flag preventing equip doesn't work. Tried casting it on myself, but I was still able to equip my weapon afterwards. BTW, this script is much shorter than what you had:

Spoiler
Scriptname TestMEScript extends activemagiceffect  Weapon twKeyword property WeapTypeBow autoEvent OnEffectStart(Actor akTarget, Actor akCaster)    tw = akTarget.GetEquippedWeapon()    ;if tw.HasKeyWord(WeapTypeBow)        akTarget.UnequipItem(tw, true)    ;endifEndEvent
User avatar
LijLuva
 
Posts: 3347
Joined: Wed Sep 20, 2006 1:59 am

Post » Wed Jun 20, 2012 3:12 am

Perhaps it will only work correctly under the Actor parent script -_-; which I was kinda hoping isn't the case.
User avatar
Rowena
 
Posts: 3471
Joined: Sun Nov 05, 2006 11:40 am

Post » Wed Jun 20, 2012 1:13 am

Aha! Well I hope you've learned your lesson of trying to be funny in code. This is serious business you know!

To detect if an actor has any bow equipped, then use 'if akActor.wornHasKeyword(WeapTypeBow)'
then use GetEquippedWeapon() to return what weapon it is. You might have to check both hands.
er... and after that try the unEquip(weapon, true)

If that flag doesn't work on NPCs, then maybe removeItem(),
Could also look at that disarm shout code for ideas too.

Edit: Note to self: remember to refresh threads after smoko.
User avatar
Marquis T
 
Posts: 3425
Joined: Fri Aug 31, 2007 4:39 pm

Post » Tue Jun 19, 2012 6:11 pm

Yeah I'll try that tommorow. Thanks for all the help.

Haha, I can see how my math teacher would react upon seeing this. "Why do you always go the LONG way?" because I understood long division better than short division..
User avatar
Sabrina Steige
 
Posts: 3396
Joined: Mon Aug 20, 2007 9:51 pm

Post » Tue Jun 19, 2012 5:04 pm

Here's an undate. Using the Actor script version doesn't change the situation either. I believe these simply cannot be prevented from bring re-equipped. They can be disarmed though(which is far better) however there is no details within the disarm shout that points to how the shout is structured. The only option left is to use the Disarming Bash perk entries and apply it to a spell.

Ah well, I'll just do that later. It's not part of my mod project anyway. Archers just make me mad, and I get sick of seeing them *everywhere*. They are an overused concept in this game.
User avatar
Svenja Hedrich
 
Posts: 3496
Joined: Mon Apr 23, 2007 3:18 pm

Post » Wed Jun 20, 2012 12:10 am

I was never able to get the abPreventEquip parameter of UnequipItem to stick. I was trying to use it on my follower, and it would seem to work for a bit, but then as soon as I accessed their inventory again, or we entered a new cell, it was as if the flag had been unset.
User avatar
Tania Bunic
 
Posts: 3392
Joined: Sun Jun 18, 2006 9:26 am

Post » Wed Jun 20, 2012 2:38 am

Ah well, I'll just do that later. It's not part of my mod project anyway. Archers just make me mad, and I get sick of seeing them *everywhere*. They are an overused concept in this game.
Can you blame them? I mean, if given the choice between whacking someone with a sword (best outcome: killing them and getting their blood all over me...ewww, worst outcome: them stabbing me instead...bummer) and plinking arrows at them from across the fort, I'd choose the latter.

Anywho...Instead of Disarming the bow, could you instead remove it from their inventory temporarily to some custom container somewhere? Then add it back, either when the effect ends or when they die.
User avatar
Glu Glu
 
Posts: 3352
Joined: Sun Apr 01, 2007 5:39 am

Post » Wed Jun 20, 2012 12:45 am

Maybe someone could update the creation kit wiki with the note that the abPreventEquip flag is bugged? I would do it myself, but I have absolutely no idea how.
User avatar
Gen Daley
 
Posts: 3315
Joined: Sat Jul 08, 2006 3:36 pm

Post » Tue Jun 19, 2012 11:27 pm

Maybe someone could update the creation kit wiki with the note that the abPreventEquip flag is bugged? I would do it myself, but I have absolutely no idea how.
Done!
User avatar
trisha punch
 
Posts: 3410
Joined: Thu Jul 13, 2006 5:38 am

Post » Tue Jun 19, 2012 2:10 pm

To prevent the player from equipping a bow you could use the OnObjectEquipped event, and then check if the object that was equipped has the bow keyword and if it does you could unequip it.
User avatar
Lexy Dick
 
Posts: 3459
Joined: Mon Feb 12, 2007 12:15 pm

Post » Tue Jun 19, 2012 6:25 pm

If you're avoiding using removeItem because you still want to be able to loot bows you could use DropObject instead... though this will have the side-effect of causing archers to all throw their bows to the ground when you enter a room (I'm also not sure what this means for clean up, as there's been some concern about what happens to weapons NPCs drop on death). Or will they just go pick them up? Can't say I've ever actually tried this.
User avatar
Leanne Molloy
 
Posts: 3342
Joined: Sat Sep 02, 2006 1:09 am

Post » Tue Jun 19, 2012 11:58 pm

I'm more demoralized than anything, and just..can't be bothered with this scripting stuff. I should go ahead and make my dungeons instead of waiting on that navmesh fix. Atleast I can do that right.

As for that being a bug... Enemy archers seem to have the same thing followers have, i.e. bows being generated somehow. There's mods that remove the follower bows though.
User avatar
Sheila Reyes
 
Posts: 3386
Joined: Thu Dec 28, 2006 7:40 am


Return to V - Skyrim