Jump to content

Help request with script for adding a weapon to inventory after equipping an armor piece


noktrum666

Recommended Posts

Hi there!

Can any one help me with writing a script that will add a weapon to players inventory after a specific piece of armour was equipped (not just a piece that sits in player inventory, but actually equipped on the player)? I have absolutely zero knowledge and experience in scripting and the mod that I’m working on requires that particular functionality... in few places.

 

I have already studied CK wiki for the script commands, I know that the base for my script will be additem and onequipped… but I have no idea what so ever how to forge that in to a working script. No clue how or where to paste the code. Will it be attached to a magic effect, that will be attached to the armour piece, or maybe the weapon itself?

 

Also… will it be possible to remove this particular weapon from player inventory when the armour piece is unequipped? I believe there is a command in papyrus for that – onunequipped, but I’m not sure if this is for that or is it only my wishfully thinking. Any help on this will be much appreciated. Thank you!

Link to comment
Share on other sites

There's 2 ways to accomplish this.

  1. OnItemEquipped triggered on an actor when items are equipped. Then check for the item you want to handle and proceed accordingly. This has to be placed on any actor you want to effect.
  2. OnEquipped triggered on the armor itself. This is a script that would be placed on the armor record in CK. If it will be a new unique item this might be preferable to hooking the actor equip.

Whichever method you choose there is an equivalent UnEquip event for it.

 

If you want to support alternative actors besides the player then the script on the armor itself would be the only realistically viable method. Though it will only work properly for new spawns of an item after you place the script on the armor record.

 

If you only want to support the player you can use a reference alias and then don't have to worry about whether it's a pre-existing spawned item or a new one or whatever:

  • Make a quest
  • On the quest add a reference alias for the player
  • Make a script on the reference alias for an OnItemEquipped event
  • in the OnItemEquipped event check for the armor you want to trigger on and then fire the equipitem for the weapon of your choice.
  • In the same script you can put an OnItemUnequipped to check for removal of the armor and then removeitem/unequip the weapon.
Link to comment
Share on other sites

Right... cant comply this script for some reason. Can any one look and see if there is an error in this code? (Probably is, this is my first script ever)

 

 

 

Scriptname YV_WristBladesP1Script extends ObjectReference
{Adding Blades to Right hand Guantlet Item}

Event OnEquipped(Actor akActor)
If (akActor == Game.GetPlayer())
Game.GetPlayer().AddItem(YautjaWristBlades2)
EndIf
EndEvent

Event OnUnequipped(Actor akActor)
If (akActor == Game.GetPlayer())
Game.GetPlayer().RemoveItem(YautjaWristBlades2)
EndIf
EndEvent

Link to comment
Share on other sites

Right! Its done and working fine in game. Just for any one else who is working on the same feature - here is the working script (I know this is probably basic stuff, but hey ho! I did not have a clue 24 hours ago, I'm sure theres more out there like me ;) )

 

 

 

Scriptname AddingWeaponScript extends ObjectReference
{Adding Blades to Right hand Guantlet Item}

Weapon Property YourWeapon auto

Event OnEquipped(Actor akActor)
If (akActor == Game.GetPlayer())
Game.GetPlayer().AddItem(YourWeapon)
EndIf
EndEvent

Event OnUnequipped(Actor akActor)
If (akActor == Game.GetPlayer())
Game.GetPlayer().RemoveItem(YourWeapon)
EndIf
EndEvent

 

 

 

Basically, just put this code in notepad, save as psc file, drop it in your data/scripts/source/user , open CK, select the script in Script Manager, compile it and add it in script section of your armor item. Remember to edit weapon property and select the weapon you desire. Done!

Link to comment
Share on other sites

A! U see, thats the next thing I'm trying to do now... make this particular weapon "not droppable"... unfortunetly the "cant drop" box in CK armor properties is not doing its job, or at least its not doing that specific thing, so this item can by dupicated just by reequiping the armor and droping the blades all the time. I will try to make it as a quest/legendary item. This is how some vanilla weapons are not droppable in the game. It might work. We will see ;)

 

Unlease ofcourse, some one already knows the way and will be kind enough to share his knowlage :D

Link to comment
Share on other sites

So there's a couple options available here.

  1. If you can ensure only one of the armor is ever made. Use a quest whose Reference Alias creates the weapon in a container somewhere (probabaly a hidden holding cell). Have that reference flagged as quest. Then have your armor script do the AddItem with the QuestReferenceAlias.GetReference() so it gets the exact instance of the weapon. Now it is not droppable. You'll need to change your unequip to put it back in the container using the same method instead of outright deleting it.
  2. If it is possible to have multiple armor and by extension multiple weapons you can use a reference collection. Instead of using the alias to create the item your armor script would have to spawn the item somewhere, add it to the reference collection which has the quest flag on, and then move it to the actor inventory. Now it's marked as quest and cannot be dropped. When removing you'd need to remove it from the reference collection and then from the inventory.
  3. Instead of making it non droppable you could just make it force equipped and then it can only be removed by unequipping the armor. This may be undesirable by some users though. See the wiki page for EquipItem. The quick and dirty ActorRef.EquipItem(Weapon, true)
Link to comment
Share on other sites

  • Recently Browsing   0 members

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