Jump to content

Need help:how to get the actor that I'm talking to by script


kfhuangy

Recommended Posts

I wrote script in my MOD to get the actor in dialogue by

"

Actor myPlayer=Game.GetPlayer()

Actor npcActor=myPlayer.GetDialogueTarget()

"

But the value of the "npcActor" is none.I try other way by

"

Actor npcActor=Game.FindClosestActorFromRef(Game.GetPlayer(), 500.0)

"

but always return my player's ID.So how can I do to get the actor that I'm talking to

sorry for my poor english

Link to comment
Share on other sites

The notes on FindClosestActorFromRef says that if you use an actor as the ref, then that actor will always be the one returned. So you can't use it like that... I think you should use FindClosestActor along with some math to do what you want.

 

Example:

 

;;; find the player's coordinates ;;;
float anglez = Game.GetPlayer().GetAngleZ()
float posx = Game.GetPlayer().GetPositionX()
float posy = Game.GetPlayer().GetPositionY()
float posz = Game.GetPlayer().GetPositionZ()

;;; distance ;;;
float offset = 150.0

;;; calculate the coordinates of the point that is 'offset' units in front of player ;;;
posx += offset * math.sin(anglez)
posx += offset * math.cos(anglez)

;;; now find the closest actor to the new coordinates ;;;
Actor npcActor = Game.FindClosestActor(posx, posy, posz, offset)

Edited by fg109
Link to comment
Share on other sites

The notes on FindClosestActorFromRef says that if you use an actor as the ref, then that actor will always be the one returned. So you can't use it like that... I think you should use FindClosestActor along with some math to do what you want.

 

Example:

 

;;; find the player's coordinates ;;;
float anglez = Game.GetPlayer().GetAngleZ()
float posx = Game.GetPlayer().GetPositionX()
float posy = Game.GetPlayer().GetPositionY()
float posz = Game.GetPlayer().GetPositionZ()

;;; distance ;;;
float offset = 150.0

;;; calculate the coordinates of the point that is 'offset' units in front of player ;;;
posx += offset * math.sin(anglez)
posx += offset * math.cos(anglez)

;;; now find the closest actor to the new coordinates ;;;
Actor npcActor = Game.FindClosestActor(posx, posy, posz, offset)

thx,I try it

Link to comment
Share on other sites

My guess is you're going to have to make some assumptions. Don't most script processing (except the dialog scripts) STOP when you're talking? Meaning, if you're script is not part of the dialog scripts then you're not going to get the target because by the time it runs, you're no longer talking. I think fg109 ihas you more or less on the right track, you're going to have to do some approximation and have it make some assumptions.

 

You can also use a FindRandomActorFromRef rather than approximating from some distance. Just throw yourself in a while loop until the ref returned isn't the player. I did this for an "Infection" proof of concept where people literally carry a disease/spell and have a random chance of infecting another victim within 3 feet of them as long as it's not the player.

 

Where does your script run?

Edited by MofoMojo
Link to comment
Share on other sites

My guess is you're going to have to make some assumptions. Don't most script processing (except the dialog scripts) STOP when you're talking? Meaning, if you're script is not part of the dialog scripts then you're not going to get the target because by the time it runs, you're no longer talking. I think fg109 ihas you more or less on the right track, you're going to have to do some approximation and have it make some assumptions.

 

You can also use a FindRandomActorFromRef rather than approximating from some distance. Just throw yourself in a while loop until the ref returned isn't the player. I did this for an "Infection" proof of concept where people literally carry a disease/spell and have a random chance of infecting another victim within 3 feet of them as long as it's not the player.

 

Where does your script run?

I add this script in Quest->Player Dialogue->Topic Info window,so it may be "touch off"(I mean make the script begin) by dialogue.I don't know why it can't work...I have try fg109's way,but it return my player's ID, too.I think I can create a No-Harm spell to make script happen,so I can use "GetTargetActor" to get the actor or referent.

thank to all of you

Link to comment
Share on other sites

  • Recently Browsing   0 members

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