Determine the type of an ObjectReference in Papyrus

Post » Wed Jun 20, 2012 4:03 pm

I've been experimenting and reading online for hours now, and I'm getting nowhere.

Basically what I'm trying to do:
  • A chest has a script attached which has OnItemAdded/OnItemRemoved events.
  • I need to be able to determine what type of object is placed in the chest (specifically if it's a weapon, armor or anything else).
Is there no function on an ObjectReference to determine what type it is? GetType or something?

This is my "best" attempt so far but it fails. It will never say Weapon! or Armor! no matter what I put in the chest...
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)if (akSourceContainer == Game.GetPlayer())  Debug.MessageBox("The player game me " + aiItemCount + "x " + akBaseItem)  if (akItemReference.GetBaseObject() as Weapon)   Debug.MessageBox("Weapon!")  endIf  if (akItemReference.GetBaseObject() as Armor)   Debug.MessageBox("Armor!")  endIfendIfendEvent
User avatar
(G-yen)
 
Posts: 3385
Joined: Thu Oct 11, 2007 11:10 pm

Post » Wed Jun 20, 2012 6:00 am

Try "akBaseItem as Weapon" etc..
akItemReference is often 'None'
User avatar
Julie Ann
 
Posts: 3383
Joined: Thu Aug 23, 2007 5:17 am

Post » Wed Jun 20, 2012 10:02 am

I concur, 'akBaseItem' is almost guaranteed to contain something - then you don't even need the GetBaseObject.
User avatar
Danielle Brown
 
Posts: 3380
Joined: Wed Sep 27, 2006 6:03 am

Post » Wed Jun 20, 2012 11:04 am

Thanks guys. Turns out I'm an idiot I was using the wrong variable :(
Should have been using akBaseItem, now it works...
User avatar
bimsy
 
Posts: 3541
Joined: Wed Oct 11, 2006 3:04 pm


Return to V - Skyrim