Scripting: How to check if an ObjectReference is an actor?

Post » Mon Jun 18, 2012 6:25 pm

If a funciton is passed an Object reference, is there any simple check to see if that object is an actor or not?

If I'm going to call the Delete() function, I want to make sure I'm not erasing an NPC from the game. I could cast the Objectreference to Actor then try to call a function that only a "real" actor could do, but are there any "Safe" functions that would determine if it's an actor or, say, a weapon that's sitting on the ground?
User avatar
Danny Blight
 
Posts: 3400
Joined: Wed Jun 27, 2007 11:30 am

Post » Tue Jun 19, 2012 12:18 am

If you try to cast it to type Actor, and it's not an Actor, the result of the cast will be None, so this should work:
if (MyObjectReference as Actor)	; MyObjectReference is an Actorelse	; MyObjectReference is not an Actorendif

Cipscis

EDIT:

If you want to check the type of the base object, try something like this:
if (MyObjectReference.GetBaseObject() as Weapon)	; MyObjectReference is a Weaponelse	; MyObjectReference is not a Weaponendif

Cipscis
User avatar
Jaylene Brower
 
Posts: 3347
Joined: Tue Aug 15, 2006 12:24 pm


Return to V - Skyrim