Jump to content

OnItemAdded


tobbe84

Recommended Posts

I'm trying to make a script that auto equips an armour when it's added to the players inventory but of course it doesn't work... Can somebody tell me what I should add or change?

 

Scriptname XXXXXscript extends ObjectReference

 

Armor Property XXXXX Auto

 

Event OnItemAdded(Actor akActor)

 

akActor.EquipItem(XXXXX, false, true)

EndEvent

 

The Compilation Error Message is: (5,0): the parameter types of function onitemadded in the empty state on script dbarmorequipscript do not match the parent script objectreference

Edited by tobbe84
Link to comment
Share on other sites

According to the wiki, the syntax for OnItemAdded is

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)

Note that there's no Actor here, although it could (I think? Not really up on how Papyrus handles tricksy things like polymorphism) stand in for the Form parameter. However, akBaseItem is the item added to the container.

 

Really, though, we need to back up -- even if you get this script to compile, it won't work. To quote the wiki, OnItemAdded is the "event received when an item is inserted into this object's container." Obviously, your armor isn't a container, but rather the player is (at least, the player's the relevant "container" in this context). So, you'd need to add this script to the player, not the armor. Which is best accomplished via an alias in a "dummy" quest, rather than trying to modify the player object directly, which would just cause no end to the compatibility nightmares.

 

So what you really want is something like this (again, added to the player via a quest alias):

Armor property YourSpiffyArmor auto

Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
 if akBaseItem == YourSpiffyArmor
   Game.GetPlayer().EquipItem(akItemReference, false, true)
 endIf
endEvent

(Note that I've left off the Scriptname line here -- this is because I'm unsure if it should extend Actor, ObjectReference, ActorAlias, or what. Adding a new script to the player's quest alias, however, should automatically give you the Scriptname line, and you can probably use whatever it gives you as-is.)

Link to comment
Share on other sites

Same way you'd create any quest -- I haven't memorized the whole menu scheme, but you can find the quests section easily enough, and then you just make a new one with a single stage set to Starts Active (or something to that effect, going totally from memory here as I'm at work). Then head over the Quest Aliases tab, make your alias for the player, and add your script.
Link to comment
Share on other sites

For this it would probably be easier having the script within your Armor, you just then have to use a different Event.

 

Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)
 If (akNewContainer As Actor) == Game.GetPlayer()
   (akNewContainer As Actor).EquipItem(self as Form, false, true)
 EndIf
EndEvent

Edited by tunaisafish
Link to comment
Share on other sites

  • Recently Browsing   0 members

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