Jump to content

Teleport Script Redux


TyrisBel

Recommended Posts

You use custom map markers right? Which means messing around with them won't be breaking the game.

 

I suggest putting a huge trigger zone around each of the markers. Each map marker should be initially disabled and linked to it's respective trigger zone. A script should be put on the trigger zone, something like:

 

ScriptName CustomTriggerScript extends ObjectReference

Event OnTriggerEnter(ObjectReference akActionRef)

if (akActionRef == Game.GetPlayer())
	GetLinkedRef().Enable()
endif

EndEvent

 

Then in your teleport script, you simply add a check to see whether or not the map marker you're teleporting to is enabled.

Edited by fg109
Link to comment
Share on other sites

What I have at the moment is this, which should work but it doesn't

ObjectReference Property TeleportMarkerDestination  Auto
ObjectReference Property TeleportMarkerBugPrevent  Auto
ObjectReference Property FTMarker Auto
ObjectReference Player

       


Event OnActivate(ObjectReference akActionRef)

bool canFastTravel = FTMarker.CanFastTravelToMarker()

               If canFastTravel == True
                               Player = Game.GetPlayer()
                               Player.MoveTo(TeleportMarkerBugPrevent)
                               Utility.Wait(0.15)
                               Player.MoveTo(TeleportMarkerDestination)
               else
                       Debug.MessageBox("You can only teleport to cities you have already visited.")
               endif

EndEvent

 

This compiles fine, but when I try it ingame it always gives the false reply regardless whether the whiterun marker is enabled or not, is this because fast travel is disabled in the cell? (if it was enabled, there would be no point in having teleporters) I'm not a coder, so I know Im doing something stupid

Link to comment
Share on other sites

This compiles fine, but when I try it ingame it always gives the false reply regardless whether the whiterun marker is enabled or not, is this because fast travel is disabled in the cell? (if it was enabled, there would be no point in having teleporters) I'm not a coder, so I know Im doing something stupid

 

I just tested the "CanFastTravelToMarker()" function and it seems to work fine... I also tried checking it while I was in the outdoors, in Proudspire Manor, and in Breezehome, and it worked correctly every time. But then again, I'm not sure exactly which markers you're trying and whether or not that makes a difference. I tried "WhiterunMapMarkerREF" in the cell "WhiterunOrigin".

Link to comment
Share on other sites

Just beat me to it :) I seem to have got it working , I am using "WhiterunMapMarkerREF" in the cell "WhiterunOrigin" for FTMarker

 

Scriptname FFT_TeleP_Whiterun extends ObjectReference  

ObjectReference Property TeleportMarkerDestination  Auto
ObjectReference Property TeleportMarkerBugPrevent  Auto
ObjectReference Property FTMarker Auto
ObjectReference Player

Event OnActivate(ObjectReference akActionRef)

	Player = Game.GetPlayer()
	bool canFastTravel = FTMarker.CanFastTravelToMarker()

		If canFastTravel == False
			Debug.Notification("You can only teleport to cities you have already visited.")
        	 	else
			 Player.MoveTo(TeleportMarkerBugPrevent)
      			 Utility.Wait(0.15)
      			 Player.MoveTo(TeleportMarkerDestination)
		endif

EndEvent

 

Now going to try something someone on Bethforums suggested to avoid the double load screen, then on to the follower problem :P

Link to comment
Share on other sites

Glad you got that worked out. I realize that what you did (checking for fast travel) is much better than what I suggested with the trigger zones. But I think you can use a trigger zone to get the followers to follow you. Just place a trigger zone around the stones in your house that will keep track of what NPCs are inside it. When the player teleports, if the NPC is running a follow package, then it should be moved along with the player. Give me a minute while I work out a script for that.
Link to comment
Share on other sites

I worked out the script... it took much longer than I thought. Obviously I still have a lot to learn about Papyrus. :confused:

 

 

ScriptName fg109TestActivatorScript extends ObjectReference


ObjectReference[] NPCs
Package ActorPackage
Package Property Follow Auto


Event OnInit()

NPCs = new ObjectReference[10]

EndEvent


Event OnTriggerEnter(ObjectReference akActionRef)

if (akActionRef as Actor)
	ActorPackage = (akActionRef as Actor).GetCurrentPackage()
	if (ActorPackage.GetTemplate() == Follow)
		if (GetArrayIndex(NPCs, akActionRef) < 0)
			AddToArray(NPCs, akActionRef)
		endif
	endif
endif

EndEvent


Event OnTriggerLeave(ObjectReference akActionRef)

if (GetArrayIndex(NPCs, akActionRef) >= 0)
	RemoveFromArray(NPCs, akActionRef)
endif

EndEvent


Function TeleportFollowers()

int index = 0
while (index < NPCs.length)
	if (NPCs[index] == None)
		ClearArray(NPCs)
		Return
	else
		NPCs[index].MoveTo(Game.GetPlayer())
	endif
	index += 1
endwhile
ClearArray(NPCs)

EndFunction


;;;;;The following functions are for manipulating the array.;;;;;


int Function GetArrayIndex(ObjectReference[] TempRefArray, ObjectReference TempRef)

;;;returns the index of the reference in the array, or -1 if not in array;;;
int index = 0
while (index < TempRefArray.length)
	if (TempRef == TempRefArray[index])
		Return index
	endif
	index += 1
endwhile
Return -1

EndFunction


bool Function AddToArray(ObjectReference[] TempRefArray, ObjectReference TempRef)

;;;returns true if successful, false if not;;;
int index = 0
while (index < TempRefArray.length)
	if (TempRefArray[index] == None)
		TempRefArray[index] = TempRef
		Return true
	endif
	index += 1
endwhile
Return false

EndFunction


bool Function RemoveFromArray(ObjectReference[] TempRefArray, ObjectReference TempRef)

;;;returns true if successful, false if not;;;
int index = GetArrayIndex(TempRefArray, TempRef)
if (index < 0)
	Return false
endif
while (index < TempRefArray.length)
	if (index + 1 == TempRefArray.length)
		TempRefArray[index] == None
	else
		TempRefArray[index] = TempRefArray[index + 1]
	endif
	index += 1
endwhile
Return true

EndFunction


Function ClearArray(ObjectReference[] TempRefArray)

int index = 0
while (index < TempRefArray.length)
	TempRefArray[index] = None
	index += 1
endwhile

EndFunction

 

 

I've compiled it successfully, but haven't tried it out. After the player is teleported, after waiting a second or so, you should have something call the TeleportFollowers() function in this script. The script is supposed to be able to keep track of 10 followers, but you could probably change it to any number you want.

Edited by fg109
Link to comment
Share on other sites

Well after spending all that time with the script... I realized that an even better solution is to have your stone cast a spell at the player with a huge magnitude! :wallbash:

 

The spell effect would be scripted so that if the affected actor is either the player or a follower, to move to your teleport marker. No need for arrays to keep track of anything at all!

Link to comment
Share on other sites

That does sound more elegant...but I didn't even know activators could cast spells. Let me keep trying with this, and if I can get it to work, then we'll make more optimal.

 

It also seems strange that I can't find the equivalent of GetCurrentFollower. Just seems common sense to me that something like that should exist, but damned if I see it on the wiki

Edited by TyrisBel
Link to comment
Share on other sites

  • Recently Browsing   0 members

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