How would I change my script to drop torches?

Post » Mon Nov 19, 2012 6:07 pm

How would I change the following to include torches?
This script is used as part of a perk I made to to knock the blocking weapon from the opponents hands to the ground.

So I would need to detect the torch (LeftHand == 11 I would think) but how do I drop it? What is a torch? Is it a weapon?



Scriptname aadpDisarmScript extends ActiveMagicEffectEvent OnEffectStart(Actor akTarget, Actor akCaster)actor ME = akTargetint LeftHand = me.GetEquippedItemType(0)int RightHand = me.GetEquippedItemType(1)if LeftHand == 0 && RightHand > 0 ;-- this is done to find the Right hand weapon that is blocking.Weapon Myweapon = me.GetEquippedWeapon(false)   me.UnequipItem(Myweapon)	me.DropObject(Myweapon, 1)  	 elseif LeftHand > 0 && LeftHand != 10 ;-- this is done to find the LEFT weapon that is blocking OR 2h weapon blocking.	   Weapon Myweapon = me.GetEquippedWeapon(true)		me.UnequipItem(Myweapon)		me.DropObject(Myweapon, 1)	   elseif lefthand == 10	  armor BlockShield = me.GetEquippedShield()	 me.UnequipItem(BlockShield)   me.DropObject(BlockShield, 1)endifendevent
User avatar
benjamin corsini
 
Posts: 3411
Joined: Tue Jul 31, 2007 11:32 pm

Post » Mon Nov 19, 2012 4:40 am

You don't need the 'Me' as *akTarget is already there. Still looking at it and have reorganized the conditions (sorry, but couldn't help myself)
Spoiler
Light Property Torch01 AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)	akTarget.UnequipSpell(akTarget.GetEquippedSpell(0), 0) ; If spells are applicable	akTarget.UnequipSpell(akTarget.GetEquippedSpell(1), 1) ; If spells are applicable	Int iLeftHand = akTarget.GetEquippedItemType(0)	If iLeftHand		If iLeftHand == 11 ; Torch			akTarget.UnequipItem(Torch01, False, True)			akTarget.DropObject(Torch01)		ElseIf iLeftHand == 10 ; Shield			Armor kARMO = akTarget.GetEquippedShield()			akTarget.UnequipItem(kARMO)			akTarget.DropObject(kARMO)		Else ; Weapons			Weapon kLeftWEAP = akTarget.GetEquippedWeapon(True)			akTarget.UnequipItem(kLeftWEAP)			akTarget.DropObject(kLeftWEAP)		EndIf	EndIf	Weapon kRightWEAP = akTarget.GetEquippedWeapon()	If kRightWEAP		akTarget.UnequipItem(kRightWEAP, False, True)		akTarget.DropObject(akTarget.GetEquippedWeapon(False), 1) 	EndIfEndEvent
http://www.creationkit.com/GetEquippedItemType_-_Actor should be able to detect torches with...
akTarget.GetEquippedItemType(0) == 11
...I'm certain.


* akTarget might not even be necessary. Do ActiveMagicEffect scripts allow for implicit use of Actor/ObjectReference functions for akTarget?
User avatar
Wayland Neace
 
Posts: 3430
Joined: Sat Aug 11, 2007 9:01 am

Post » Mon Nov 19, 2012 6:42 am

err... thanks but you HAVE to keep the unequip in the code otherwise the actor may drop a weapon (extra one but same base form) they have in inventory instead of the one they are holding. Extra torches or a secondary dagger for dual combat (but not equiped) for example.

So the torch is a WEAPON form?


I always cast the actor to "ME" or "Attacker" because I can cut and paste many of my other "utility" chunks of code if needed.
And there have been situations where the code would not work with akCaster and aksource (in onhit ) until it was cast to an actor. I had a onhit script that would not work, posted it for help, then I was told to do this.... and that fixed it. :shrug:




You don't need the 'Me' as *akTarget is already there. Still looking at it and have reorganized the conditions (sorry, but couldn't help myself)
Spoiler
Event OnEffectStart(Actor akTarget, Actor akCaster)	Int iLeftHand = akTarget.GetEquippedItemType(0)	Int iRightHand = akTarget.GetEquippedItemType(1)	If iLeftHand ; > 0		If iLeftHand == 10			Armor kARMO = akTarget.GetEquippedShield()			;akTarget.UnequipItem(kARMO)			akTarget.DropObject(kARMO, 1)		Else ; If iLeftHand != 10			Weapon kWEAP = akTarget.GetEquippedWeapon(true)			;akTarget.UnequipItem(kWEAP)			akTarget.DropObject(kWEAP, 1)		EndIf	ElseIf iRightHand ; && iLeftHand == 0		Weapon kWEAP = akTarget.GetEquippedWeapon(False)		;akTarget.UnequipItem(kWEAP)		akTarget.DropObject(kWEAP, 1)	EndIfEndEvent
http://www.creationkit.com/GetEquippedItemType_-_Actor should be able to detect torches with...
akTarget.GetEquippedItemType(0) == 11
...I'm certain.


* akTarget might not even be necessary. Do ActiveMagicEffect scripts allow for implicit use of Actor/ObjectReference functions for akTarget?
User avatar
Taylor Thompson
 
Posts: 3350
Joined: Fri Nov 16, 2007 5:19 am

Post » Mon Nov 19, 2012 9:41 am

  • Reference dropped: In my experience, http://www.creationkit.com/DropObject_-_ObjectReference preferentially drops the equipped instance. Oops. It's RemoveItem that does this, IIRC.
  • Torches: They're LIGH forms. Torch01 "Torch" [LIGH:0001D4EC] is the only one used.
  • Me var: In OnHit's case, I can see the point in caching to shave the expense of casting multiple times.
    Spoiler
    • Multiple uses:
      Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, Bool abBashAttack, Bool abHitBlocked)	Actor Me = akAggressor	Me.SetAlpha(42.0)	Me.ClearLookAt()EndEvent
    • If only one use:
      Event OnHit(ObjectReference akAggressor, Form akSource, Projectile akProjectile, Bool abPowerAttack, Bool abSneakAttack, Bool abBashAttack, Bool abHitBlocked)	(akAggressor As Actor).SetAlpha(42.0)EndEvent
    In OnEffectStart's case, akTarget is already of the Actor type.
User avatar
Kieren Thomson
 
Posts: 3454
Joined: Sat Jul 21, 2007 3:28 am

Post » Mon Nov 19, 2012 2:15 pm

I'll admit it makes sense to have a standard name so you can reuse code more easily, but in cases where you need to cast akCaster to an Actor you don't actually need to create a new local variable. The following would work just as well in those scenarios and negate the need for an extra variable:
Event OnEffectStart(Actor akTarget, Actor akCaster)	akTarget = akTarget as Actor	; ...EndEvent
Alternately, if you like the name "Me", then you could just specify that as the name of the parameter:
Event OnEffectStart(Actor Me, Actor akCaster)	; Me = Me as Actor ; If necessary	; ...EndEvent

Cipscis

EDIT:

That said, the compiler will probably still create a bunch of extra "temp" variables in the background when you compile your script. I'm not sure if this approach will always end up with a smaller compiled script, but it's probably worth knowing at least that you can reassign the value of parameters within a function.

Cipscis
User avatar
Peter P Canning
 
Posts: 3531
Joined: Tue May 22, 2007 2:44 am

Post » Mon Nov 19, 2012 6:37 am

If akObject is equipped, the game will first search for unequipped items in inventory to drop. Only when there are no more unequipped items will it drop the equipped items.

see here: http://www.creationkit.com/DropObject_-_ObjectReference :wink:

Unless you are saying the Wiki is incorrect? That could certainly be the case. :ermm:

edit: I used your code and it works great! I only added back in the unequips until I know for sure they are not necessary.


In my experience, http://www.creationkit.com/DropObject_-_ObjectReference preferentially drops the equipped instance. Torches are LIGH forms.
User avatar
WTW
 
Posts: 3313
Joined: Wed May 30, 2007 7:48 pm

Post » Mon Nov 19, 2012 10:27 am

I was wondering about that, thanks!


I'll admit it makes sense to have a standard name so you can reuse code more easily, but in cases where you need to cast akCaster to an Actor you don't actually need to create a new local variable. The following would work just as well in those scenarios and negate the need for an extra variable:
Event OnEffectStart(Actor akTarget, Actor akCaster)	akTarget = akTarget as Actor	; ...EndEvent
Alternately, if you like the name "Me", then you could just specify that as the name of the parameter:
Event OnEffectStart(Actor Me, Actor akCaster)	; Me = Me as Actor ; If necessary	; ...EndEvent

Cipscis

EDIT:

That said, the compiler will probably still create a bunch of extra "temp" variables in the background when you compile your script. I'm not sure if this approach will always end up with a smaller compiled script, but it's probably worth knowing at least that you can reassign the value of parameters within a function.

Cipscis
User avatar
Donald Richards
 
Posts: 3378
Joined: Sat Jun 30, 2007 3:59 am

Post » Mon Nov 19, 2012 1:36 pm

Unless you are saying the Wiki is incorrect? That could certainly be the case. :ermm:
Ah. It was RemoveItem that preferentially removes the equipped instance.
edit: I used your code and it works great! I only added back in the unequips until I know for sure they are not necessary.
Cool. Did it catch the torches too? If not, I've edited the script a bit since so it should now catch and handle anything in either hand.
User avatar
Motionsharp
 
Posts: 3437
Joined: Sun Aug 06, 2006 1:33 am


Return to V - Skyrim