Jump to content

[LE] Help me troubleshoot my teleportation script?


lesleymac

Recommended Posts

Hi, all!

 

I'm new to modding, but not new to programming, which is why this scripting trouble is driving me nuts.

So, I made a player home (Sanctuary), and I'd like to be able to access it with a spell. The spell side of things is fine, but I"m having some trouble with the magic effect, specifically the magic effect script.

 

How the script is supposed to work: You cast the spell from somewhere in Tamriel, and the spell saves your current x, y and z, then teleports you to the interior of my player home. If you cast the spell from inside my player home ("macCell"), then the cell uses the x, y, and z values with .SetPosition to return you to your original location.

 

The problem: Seems that the Global variables for X, Y and Z never get set? Even if I try and set them to straightforward literal floats, they stubbornly refuse to change from the default value (set when I created the globals in Creation Kit.)

 

Here's some scripting:

 

;***Current debug script***
Scriptname macSanctuaryTeleport extends activemagiceffect
Location Property macCell Auto
Location Property currentCell Auto
ObjectReference Property Sanctuary Auto
GlobalVariable Property macPreviousX Auto
GlobalVariable Property macPreviousY Auto
GlobalVariable Property macPreviousZ Auto
Event OnEffectStart(Actor akTarget, Actor akCaster)
currentCell = akCaster.GetCurrentLocation()
if (currentCell.IsSameLocation(macCell))
debug.MessageBox("macPreviousX - " + macPreviousX.GetValue() as string + "\nmacPreviousY - " + macPreviousY.GetValue() as string + "\nmacPreviousZ - " + macPreviousZ.GetValue() as string)
else
float x = akCaster.X
float y = akCaster.Y
float z = akCaster.Z
SetPreviousLocation(x, y, z)
debug.MessageBox("macPreviousX - " + macPreviousX.GetValue() as string + "\nmacPreviousY - " + macPreviousY.GetValue() as string + "\nmacPreviousZ - " + macPreviousZ.GetValue() as string)
endIf
EndEvent

 

Function SetPreviousLocation(float x, float y, float z)
macPreviousX.SetValue(x)
macPreviousY.SetValue(y)
macPreviousZ.SetValue(z)
EndFunction

 

 

and here's a practice run:

***Practice Run***

Scriptname macSanctuaryTeleport extends activemagiceffect

 

Location Property macCell Auto

Location Property currentCell Auto

ObjectReference Property Sanctuary Auto

GlobalVariable Property macPreviousX Auto

GlobalVariable Property macPreviousY Auto

GlobalVariable Property macPreviousZ Auto

 

Event OnEffectStart(Actor akTarget, Actor akCaster)

currentCell = akCaster.GetCurrentLocation()

if (currentCell.IsSameLocation(macCell))

Utility.Wait(1.5)

Game.FadeOutGame(False, True, 2.0, 1.0)

Game.GetPlayer().SetPosition(macPreviousX, macPreviousY, macPreviousZ)

else

float x = akCaster.X

float y = akCaster.Y

float z = akCaster.Z

SetPreviousLocation(x, y, z)

Game.GetPlayer().MoveTo(Sanctuary)

endIf

EndEvent

Function SetPreviousLocation(float x, float y, float z)

macPreviousX.SetValue(x)

macPreviousY.SetValue(y)

macPreviousZ.SetValue(z)

EndFunction

 

 

and some screenshots:

 

My magic effect setup in CK

 

 

 

Where the global variables are initially declared in CK

 

 

The inevitable result of the debug script

 

 

Edited by lesleymac
Link to comment
Share on other sites

Easier solution, have two xMarkers in your custom home. When the player casts the spell out in the game world, move one of the xMarkers to their current location and send the player to the other xMarker. Then when they cast the spell from the home, move the player to the xMarker that they left behind and then send it back to the home (or leave it where it is as it will move as needed provided your property points to the specific placed reference).

Link to comment
Share on other sites

if you want to keep your approach for teleport, maybe next is working for you..

 

macSanctuaryTeleportSript

 

Scriptname macSanctuaryTeleportSript extends ActiveMagicEffect
; https://forums.nexusmods.com/index.php?/topic/8118138-help-me-troubleshoot-my-teleportation-script/
 
  GlobalVariable PROPERTY macLastX auto     ; macPreviousX
  GlobalVariable PROPERTY macLastY auto
  GlobalVariable PROPERTY macLastZ auto

  ObjectReference PROPERTY home auto        ; Sanctuary


; -- EVENTs --

EVENT OnEffectStart(Actor akTarget, Actor akCaster)
IF (akCaster == Game.GetPlayer())
    myF_Action(akCaster)
ENDIF
ENDEVENT

EVENT OnEffectFinish(Actor akTarget, Actor akCaster)
ENDEVENT


; -- FUNCTION --

; https://www.creationkit.com/index.php?title=GetEditorLocation_-_ObjectReference
; https://www.creationkit.com/index.php?title=EnablePlayerControls_-_Game

;--------------------------------
FUNCTION myF_Action(Actor player)
;--------------------------------
    location loc = player.GetCurrentLocation()
    float fx
    float fy
    float fz

    IF (loc) && loc.IsSameLocation( home.GetEditorLocation() )    ; make sure Sanctuary has a valid location!
        ; player is at home, let him teleport to last stored position outside home

        fx = macLastX.GetValue()
        fy = macLastY.GetValue()
        fz = macLastZ.GetValue()
        
        IF (fx == 0.0) && (fy == 0.0) && (fz == 0.0)
            Debug.Notification("Teleport place is empty..")
        ELSE
            Game.DisablePlayerControls(TRUE, False, False, False, False, TRUE, TRUE, False)
            ; do not allow movement, menu and activation

            Utility.Wait(1.5)                             ; just wait a bit
            Game.FadeOutGame(False, TRUE, 2.0, 1.0)       ; mask the teleport
            player.SetPosition(fx, fy, fz)                ; move player to last stored position
            Utility.Wait(0.25)                            ; let the game finish cell changing

            Game.EnablePlayerControls(TRUE, False, False, False, False, TRUE, TRUE, False)
        ENDIF

    ELSE
        ; player is anywhere else, teleport him back to home

        fx = player.GetPositionX()
        fy = player.GetPositionY()
        fz = player.GetPositionZ()

        macLastX.setValue(fx)
        macLastY.setValue(fy)
        macLastZ.setValue(fz)

        player.MoveTo(home)
    ENDIF
ENDFUNCTION

 

 

Link to comment
Share on other sites

Easier solution, have two xMarkers in your custom home. When the player casts the spell out in the game world, move one of the xMarkers to their current location and send the player to the other xMarker. Then when they cast the spell from the home, move the player to the xMarker that they left behind and then send it back to the home (or leave it where it is as it will move as needed provided your property points to the specific placed reference).

 

I like this solution. Much more straightforward.

 

With regards to the original solution, the only thing I can think of is that the properties aren't initialized. Have you checked your papyrus log?

Link to comment
Share on other sites

  • Recently Browsing   0 members

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