Jump to content

Getting Actor data from ObjectReference - Papyrus


vinniewryan

Recommended Posts

Hello, I'm trying to use the following function to obtain an Actor property from the ObjectReference returned by the function. Here's what I have:

 

Event OnCrosshairRefChange(ObjectReference o)

Actor a = o.GetBaseObject() as Actor
Debug.Notification("Target: " + o)
Debug.Notification("Target: " + a)

EndEvent

This returns:
Target: [Form

Target: None

 

I'm trying to turn 'a' into the Actor which 'o' is referencing. Any ideas on how I can do this?
I also know that none of these are working because in another function, I checked the race of the target Actor / ObjectReference against every race in the game, and it returns False on any target NPC.

 

Thanks!

Edited by vinniewryan
Link to comment
Share on other sites

Actor extends object reference which means you do not need to get the base to get the actor reference.

Event OnCrosshairRefChange(ObjectReference O)
  Actor A = O as Actor
  ;... other stuff
EndEvent

From there you can use GetActorBase or GetLeveledActorBase as needed.

 

 

@steelfeathers

GetBaseActor does not exist. I think you meant GetActorBase but that is called on an actor and not an object reference. The compiler would complain about that one.

Link to comment
Share on other sites

Thank you for the ideas.

@ IsharaMeradin, when using the method you've provided, the debug text still returns incorrect data. Sometimes it returns the name of the Actor's attached script, other times it just says "[Actor", or "[ObjectReference" if run on an object. Shouldn't this return the Actor's name?

Actor A = O as Actor
debug.Notification("Target: " + A)

Anyway, even when I try to use:

if (a.GetRace() == "BretonRace" || a.GetRace() == "NordRace")

- for every single race, they all return "False". GetRace is a member of the Actor script so it seems that that information simply isn't transferring when I use "a = o as Actor"

 

Edit: I tried

debug.Notification("Target: " + a.GetBaseObject().GetName())

and now it's returning the Actor's name properly.

 

As for GetRace, I had to import a Race property for each Race I wanted to check, and use

Race Property SkyrimRace Auto
Race r = SkyrimRace
Actor a = o as Actor
if a.GetRace() == r

and now it works :)

Edited by vinniewryan
Link to comment
Share on other sites

You cannot return an actor's name without using SKSE's GetName() function

GetRace() does not return a string. So your comparisons will always be false. You need to compare it to the desired race records thus you fill properties in the CK with your desired values.

 

Try something like this instead. It requires SKSE if it was not obvious:

 

 

This should work, but I have not actually tested it.

Race Property BretonRace Auto
{Variable name same as race record -- auto fill it.}
Race Property NordRace Auto
{Variable name same as race record -- auto fill it.}

Actor TargetActor

Event OnCrosshairRefChange(ObjectReference O)
	If O ;a valid reference
		If O as Actor ;is an actor
			TargetActor == O as Actor
			Debug.Trace("Target Actor: "+TargetActor.GetActorBase().GetName())
			If TargetActor.GetActorBase().GetRace() == BretonRace
				Debug.Trace("Target Actor is a Breton")
			ElseIf TargetActor.GetActorBase().GetRace() == NordRace
				Debug.Trace("Target Actor is a Nord")
			Else
				Debug.Trace("Target Actor is of some other race")
			EndIf
		Endif
	EndIf
EndEvent 

 

 

eh.. you edited while I was typing... saw when I switched to full edit mode. Oh well, leaving it all.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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