Jump to content

[LE] Papyrus wildcard property setting


JobVanDam

Recommended Posts

I'm not even sure how to explain this but I will try.

 

The script has been graciously provided by kryptopyr (with permission):

Scriptname WAF_ArmorSwapScript extends ObjectReference 
Armor Property ThisItem Auto ;this is the item that this script is attached to

Armor Property NewItem Auto ;this is the item we want to swap it for
Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

if akNewContainer == Game.GetPlayer()

  Game.GetPlayer().RemoveItem(ThisItem, 1, true)

  Game.GetPlayer().AddItem(NewItem, 1, true)

endIf

endEvent

As you can see it's pretty basic. Once an item is added to the player's inventory it is removed and replaced with another.

What I would like is to be able to pass ANY item to it. I am using it in 2 different scenarios:

One is upon looting a certain armor piece it is removed from the player's inventory then replaced with a misc object.

The second instance is upon adding a certain misc item to the player's inventory it is removed and replaced with a light object.

 

Is there a property which would accept ANY type of form so I could pass any item to this script?

Or would I have to put a condition before those statements checking if it's a armor object? A misc object? A light object? etc.

Link to comment
Share on other sites

Unfortunately there's no generic property you can fill from the CK. Form is the generic object type but the CK won't recognize it to let you set a value.

 

You can use a set of those scripts with different properties types you can fill. (So one might have an armor and a light while another would have a light and a miscobject, etc.)

 

You could also include two of each of the object types and then check to see which ones are filled.

Scriptname WAF_ItemSwapScript extends ObjectReference 

; Fill one of these with the item that this script is attached to
Armor Property ThisArmor Auto
Weapon Property ThisWeapon Auto
MiscObject Property ThisMiscObject Auto
Book Property ThisBook Auto
     ; There are more types possible but include only what you need

; Fill one of these with the item to swap it for
Armor Property NewArmor Auto
Weapon Property NewWeapon Auto
MiscObject Property NewMiscObject Auto
Book Property NewBook Auto
     ; There are more types possible but include only what you need


Event OnContainerChanged(ObjectReference akNewContainer, ObjectReference akOldContainer)

if akNewContainer == Game.GetPlayer()

  if ThisArmor
     Game.GetPlayer().RemoveItem(ThisArmor, 1, true)
  elseif ThisWeapon
     Game.GetPlayer().RemoveItem(ThisWeapon, 1, true)
  elseif ThisMiscObject
     Game.GetPlayer().RemoveItem(ThisMiscObject, 1, true)
  elseif ThisBook
     Game.GetPlayer().RemoveItem(ThisBook, 1, true)
  endif

  if NewArmor
     Game.GetPlayer().AddItem(NewArmor, 1, true)
  elseif NewWeapon
     Game.GetPlayer().AddItem(NewWeapon, 1, true)
  elseif NewMiscObject
     Game.GetPlayer().AddItem(NewMiscObject, 1, true)
  elseif NewBook
     Game.GetPlayer().AddItem(NewBook, 1, true)
  endif

endIf

endEvent

On the positive side Book actually includes scrolls and MiscObject covers keys, soul gems, and many other things.

Link to comment
Share on other sites

Another option would be to pass in a form list, but that's also kludgey since you'd then need a new formlist for each different kind of object, or supply an index (which would become a maintenance nightmare). If you're only using it for a limited set of objects it might be worth considering. Also possible, if the thing reliably starts as an objectreference in the game world, would be to have an OnLoad event fire that grabs the base form and saves it.

Edited by foamyesque
Link to comment
Share on other sites

  • Recently Browsing   0 members

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