Jump to content

Trying to teleport an NPC to the player with a script.


Undivide

Recommended Posts

Basically, I'm attempting to use a script to teleport my custom follower to the player upon activation, but all the script does is make my player hop.

Scriptname ReiTeleport extends Activemagiceffect

Activemagiceffect property teleportrei auto

EVENT OnEffectFinish(Actor Reiko, Actor akCaster)
akCaster = Game.GetPlayer()
Reiko.MoveTo(akCaster, 5.0 * Math.Sin(akCaster.GetAngleZ()), 5.0 * Math.Cos(akCaster.GetAngleZ()), akCaster.GetHeight() - 0)

EndEvent

http://s21.postimg.org/61va76n47/prob1.png

I've tried both target actor and target self.

 

 

Any clue on what I'm doing wrong?

Link to comment
Share on other sites

Try this

 

 

Scriptname ReiTeleport extends Activemagiceffect

Activemagiceffect property teleportrei auto

EVENT OnEffectFinish(Actor Reiko, Actor akCaster)
  If akCaster == Game.GetPlayer()
    Reiko.MoveTo(akCaster, 5.0 * Math.Sin(akCaster.GetAngleZ()), 5.0 * Math.Cos(akCaster.GetAngleZ()), akCaster.GetHeight() - 0)
  EndIf
EndEvent 

 

 

Link to comment
Share on other sites

Duh!

 

Why didn't I see it?

You changed the target inside the event call and you didn't set up a property for your follower. The below compiles. It may (and should) work for you.

 

What I did was setup a property for your NPC actor, a property for the player, a property for current follower.

When the effect starts, the follower is compared to your NPC actor. If it is a match, the follower should teleport to the player with the coordinates that you've calculated.

 

 

 

ScriptName ReiTeleport Extends ActiveMagicEffect

Actor Property PlayerRef Auto ; auto-fills
ReferenceAlias Property Follower Auto ;select DialogueFollower as the quest then Follower as the alias
Actor Property Reiko Auto ;your follower

Event OnEffectStart(Actor akTarget, Actor akCaster) ;finish might be fine but start may help with initial troubleshooting and setup
	If (Follower.GetReference() as Actor).GetActorBase() == Reiko.GetActorBase() ;does the follower reference match your NPC actor
		Float X = 5.0 * Math.Sin(PlayerRef.GetAngleZ())
		Float Y = 5.0 * Math.Cos(PlayerRef.GetAngleZ())
		Float Z = PlayerRef.GetHeight() - 0
		Follower.GetReference().MoveTo(PlayerRef, X, Y, Z)
	EndIf
EndEvent

Be sure to click the properties button and fill out the information properly.

Link to comment
Share on other sites

Thanks for the help, Ishara. Now I have another issue. The script only works when I'm near the follower and teleports inconsistently, but it's a huge step up from where I started. Haha.

In papyrus logs, it gives me this:

[10/21/2013 - 09:45:04PM] ae::monitor: Reiko registered with AE
[10/21/2013 - 09:45:04PM] Error: Cannot call Is3DLoaded() on a None object, aborting function call
stack:
[
Link to comment
Share on other sites

There is no Is3dLoaded() call in the script I provided. Where is that coming from?

 

I used teleport locally to move the player and then the follower from one location to an internal cell. The follower wouldn't port till after the player moved out of a trigger in the internal cell so I know the MoveTo command can function without the follower being near.

Link to comment
Share on other sites

it was near the Reiko Script in the log, so I thought it had something to do with it. I was very wrong.

Anywho, I've figured something out.

 

 

ScriptName ReiTeleport Extends ActiveMagicEffect

;import Utility
;import Game

Actor Property PlayerRef Auto ; Player
Actor Property Reiko Auto ; Reiko 
ObjectReference Property Marking auto

 ;Message Property msgKeyMenu Auto (reserved for a later version)

; Location 
int property OffX Auto
int property OffY Auto

; int iButton (Reserved)



Event OnEffectStart(Actor Reiko, Actor akCaster)
PlayerRef = akCaster

; iButton = msgKeyMenu.Show() (Reserved)
 
If (Reiko.GetParentCell() !=  PlayerRef.GetParentCell() || Reiko.GetParentCell() ==  PlayerRef.GetParentCell())

	Marking.Moveto (PlayerRef)
	Reiko.MoveTo(Marking, OffX, OffY, 0, false)
	    	

	EndIf

EndEvent

 

 

 

I took a look at the way Haven Bag handled teleportation, so I created a marker that moves when the effect is activated .

 

Thank you very much for your assistance! I'll be putting you in the credits section of my mod if you don't mind. :laugh:

Edited by Undivide
Link to comment
Share on other sites

  • Recently Browsing   0 members

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