Jump to content

[LE] Creating paired swords. Need scripting help.


azazellz

Recommended Posts

I want to create some kind of "paired swords" (or dual), and need help with papyrus script.

Scriptname _PairedSwords extends ObjectReference  

WEAPON Property SwordLeft  Auto  

Event OnEquipped(Actor akActor)
    akActor.AddItem(SwordLeft, 1, true)
    akActor.EquipItemEx(SwordLeft, 2, true, false)
EndEvent

Event OnUnequipped(Actor akActor)
    akActor.UnEquipItemEx(SwordLeft, 2, false)
    akActor.RemoveItem(SwordLeft, 1, true)
EndEvent

This script attached to right-handed sword.

If player equip this sword, in his inventory silently appears left-handed sword (without "playable" tag, so player can't see it), and automatically equips into left hand.
If player un-equip right-hand sword, left sword also un-equipes, and removes from inventory.

So, my problem is: even if I setted "true" flag in "equipitemex", player still can equip any other weapon into left hand, but I wish to prevent it.
Any help?

P.s. ah, and sorry about my bad english =)

Edited by azazellz
Link to comment
Share on other sites

I'm not sure there is a way to make it unequipable. If it was me, I would add a script to the left-hand sword with an OnUnequipped event to re-equip the sword. Something like:

Event OnUnequipped(Actor akActor)
   If (akActor.GetEquippedWeapon() == SwordRight)
      akActor.EquipItem(SwordLeft, 2, true, false)
   EndIf
EndEvent
Link to comment
Share on other sites

 

I'm not sure there is a way to make it unequipable.

 

Both the basic EquipItem function and SKSE's EquipItemEx functions have a flag you can set to prevent unequipping. You can see this in action in the base game with the Cursed Ring of Hircine. The functions will (or at least, SHOULD) do what he wants them to do.

 

However my first question is: Does the OnEquip event in fact fire and equip the left-hand sword at all?

Edited by foamyesque
Link to comment
Share on other sites

 

I'm not sure there is a way to make it unequipable. If it was me, I would add a script to the left-hand sword with an OnUnequipped event to re-equip the sword. Something like:

Simple EquipItem (not EquipItemEx) equiping sword only into right hand. So, after equiping right-hand sword with this script, you became comletely unarmed =)

 

 

Both the basic EquipItem function and SKSE's EquipItemEx functions have a flag you can set to prevent unequipping. You can see this in action in the base game with the Cursed Ring of Hircine. The functions will do what he wants them to do.

 

However my first question is: Does the OnEquip event in fact fire and equip the left-hand sword at all?

 

Well, actually you can't simple unequip left-hand sword (because you can't see it in inventory - "playble" tag is not set).

But you can equip another sword into left hand - and that i wish to prevent.

 

And yes, OnEquipped event works - adding sword and equiping it.

Link to comment
Share on other sites

Just to be clear; you're trying to make a right-handed sword behave like a two-handed sword, right?

 

If I'm understanding your goal, you want to prevent the player from equipping anything in their left hand while the sword is equipped in their right hand. But you want your sword to have the perks, animations, etc of a one-handed sword, correct?

Link to comment
Share on other sites

Just to be clear; you're trying to make a right-handed sword behave like a two-handed sword, right?

 

If I'm understanding your goal, you want to prevent the player from equipping anything in their left hand while the sword is equipped in their right hand. But you want your sword to have the perks, animations, etc of a one-handed sword, correct?

No.

I trying to create dual swords - i.e. when you equip one sword into right hand, another automatically equips into left hand, and cannot be unequipped until you unequip right-hand sword.

And when you unequip right sword, left one automatically disappear.

I made all that i want, except restriction to equip anything (except auto-equipable special left-handed sword) into left hand while right-hand sword still equipped.

 

P.s. my english is sooo terrible...

Edited by azazellz
Link to comment
Share on other sites

Well, thanks to Levionte i found solution.

Instead of his suggestion using simple EquipItem (that don't allow choose slot or hand for equipping weapons) I used EquipItemEx, and now all works perfectly.

 

So, script for right hand weapon:

Scriptname _PairedSwords_RIGHT extends ObjectReference  

WEAPON Property SwordLeft  Auto  

Event OnEquipped(Actor akActor)
    akActor.AddItem(SwordLeft, 1, true)
    akActor.EquipItemEx(SwordLeft, 2, true, false)
EndEvent

Event OnUnequipped(Actor akActor)
    akActor.UnEquipItemEx(SwordLeft, 2, false)
    akActor.RemoveItem(SwordLeft, 1, true)
EndEvent

Script for left weapon:

Scriptname _PairedSwords_LEFT extends ObjectReference  

WEAPON Property SwordRight  Auto  
WEAPON Property SwordLeft  Auto  

Event OnUnequipped(Actor akActor)
	If (akActor.GetEquippedWeapon() == SwordRight)
		akActor.EquipItemEx(SwordLeft, 2, true, false)
   EndIf
EndEvent
Link to comment
Share on other sites

  • 2 weeks later...

After some testing, i figured out, that this scripts works fine only for player.

If you try to give weapon, with this scripts attached, to any NPC, they go into a loop, endlessly spawning left-hand weapon.
And I absolutely can not understand why this happens.

Any ideas?

Edited by azazellz
Link to comment
Share on other sites

My guess would be that the AI of the NPC prefers not to dual wield, so it is trying to unequip the left hand weapon and equip only the right hand weapon. Because it's not designed to anticipate weapon sets, it gets confused and goes into a loop when it can't equip only the right hand weapon.
Link to comment
Share on other sites

My guess would be that the AI of the NPC prefers not to dual wield, so it is trying to unequip the left hand weapon and equip only the right hand weapon. Because it's not designed to anticipate weapon sets, it gets confused and goes into a loop when it can't equip only the right hand weapon.

Yes, you right.

All I had to do was add a check for the presence of the left sword in the inventory before adding it, and check for already equipped left sword before equiping it.

Now the scripts look like this:

Scriptname _PairedSwords_RIGHT extends ObjectReference  

WEAPON Property SwordLeft  Auto  
WEAPON Property SwordRight  Auto  

Event OnEquipped(Actor akActor)
	Utility.WaitMenuMode(0.2)
	if akActor.GetItemCount (SwordLeft) == 0
		akActor.AddItem(SwordLeft, 1, true)
		endif
	If akActor.IsEquipped(SwordLeft) == False
		akActor.EquipItemEx(SwordLeft, 2, true, false)
		endif
EndEvent

Event OnUnequipped(Actor akActor)
	Utility.WaitMenuMode(0.2)
	akActor.UnEquipItemEx(SwordLeft, 2, false)
	akActor.RemoveItem(SwordLeft, 1, true)
EndEvent
Scriptname _PairedSwords_LEFT extends ObjectReference  

WEAPON Property SwordRight  Auto  
WEAPON Property SwordLeft  Auto  

Event OnUnequipped(Actor akActor)
    If akActor.IsEquipped(SwordRight)
        akActor.EquipItemEx(SwordLeft, 2, true, false)
   EndIf
EndEvent
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...