Jump to content

Papyrus - Get Reference to Script Owner


Donutfiend84

Recommended Posts

I'm writing a fairly simple script, and adding it to some bandits. Currently I set a function to trigger OnCombatStateChanged. From here, I need to get a reference to the object that called this function. Basically, which ever actor just changed states and triggered it.

 

It feels like this should be easy to do, but I can't seem to figure out how. Is there anything similar to a 'This' keyword, or a way to get the Actor through an event object? (event.getInstigator() or the like?)

Link to comment
Share on other sites

Let me be a bit more specific. Here is a section of code that sums up what I am trying to do. This script will be attached in the creation kit, to a series of bandits.

 

Scriptname AlertPlayerOfCombat extends Actor  
{ }

Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
if (akTarget == Game.GetPlayer())
 if (aeCombatState == 1)
	
  Actor instigator = <Get a reference to the specific bandit's actor here>
		
 endIf
endIf
endEvent

Link to comment
Share on other sites

If i understand well, the script is attached to the bandit.

 

And you want the one who changed is state to do something?

 

Since the script is attached to the one changing combat state, what about using "self"?

 

Thanks a ton, that is exactly what I was looking for.

 

I did not even realize that was a keyword. When 'this' didn't work I was crawling through the documentation of get functions, looking for how to get a reference. Somehow dodged that crucial bit of info through some 5 or 6 tutorials too. Nonetheless, thanks again.

Link to comment
Share on other sites

  • Recently Browsing   0 members

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