Jump to content

Help with conditional teleport scripting


Recommended Posts

Hi all,

Hoping someone can lend a hand with a basic teleportation script, which I've attached to a spell. The teleportation aspect works fine - including for the player's horse - but what I'm struggling with is the IF condition. I've added a 'home' keyword to the interior and exterior locations in my mod, which are attached to the interior and exterior cells, but the intended check in the script below doesn't seem to fire. Regardless of whether the player is in one of those two cells or not, the spell functions as usual and teleports the player to the destination.

I'm guessing I've done something daft in the logic, so a second pair of eyes and any advice would be greatly appreciated    🙂   Thank you!

 

____________________________________________________________________________

Scriptname a107SCRIPTTeleport extends activemagiceffect  

ObjectReference Property HomeMarker Auto
ObjectReference Property StableMarker Auto
Keyword Property HomeLocation Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
Actor Player = Game.GetPlayer()
Actor PlayerHorse = Game.GetPlayersLastRiddenHorse()

If Player.GetCurrentLocation().HasKeyword(HomeLocation)
    Debug.Notification("You are already at Kynesgarde.")

Else
    Game.DisablePlayerControls()
    Utility.Wait(1.5)
    Game.FadeOutGame(False, True, 2.0, 1.0)
    akCaster.MoveTo(HomeMarker)
    Game.EnableFastTravel()
    Game.FastTravel(HomeMarker)
    PlayerHorse.MoveTo(StableMarker)
    Game.EnablePlayerControls()

EndIf
EndEvent

____________________________________________________________________________

Link to comment
Share on other sites

Are you testing on a new game or using COC from the main menu?  If not, the cells in question may not have updated to reflect the added keyword.  And if you are, I do not see why it would not be giving the proper notification.

Link to comment
Share on other sites

Apologies, I'm not sure what you mean by "using COC from the main menu", but yes, you were absolutely right - the updated keyword hadn't fed through to the cells in the save I was using for testing. A brand new save has fixed it. Thank you, IsharaMeradin, appreciate you taking a look!

 

Edit: spoke too soon. Only works in interior cell. But I'm tempted to take the partial win - it was only ever a nice-to-have anyway.

Link to comment
Share on other sites

Right - figured it out. I'd created a patch for my mod and Interesting NPCs, but at some point I'd accidentally knocked my mod's master requirement flag off the patch - which meant that when both were loaded, the keyword was tied to the interior cell (no conflict), but wiped from the exterior cell (conflict) when the patch was applied. Phew...

Thanks again for the assist, it was useful to know that it wasn't an issue with the script, that helped me find the actual issue.

Link to comment
Share on other sites

COC from the main menu:  Open the console (~ key), enter COC followed by a cell name (i.e. COC Riverwood)

This would port the basic player character to the designated location.  It can be useful during testing.

 

Glad you were able to solve your situation.

Link to comment
Share on other sites

well if no one, going to point it out your logic is flawed, not saying it not going to work, just saying it is not sharpest tool in the shed, when I look at your code, I see the player asking a follower to take them home, poorly done,  if it is the payer casting? it needs an overhaul bady 

  1. you need one property I would make it the Cell your teleporting too
  2. you need no private variables, good I know you do not have any
  3. just in check the player is the caster and the location is the target cell Ok BTW the second is a not or reverse logic 
  4. write the body of the code with no variables
  5. if that make no sense your code logic  need work

I will write and example and BRB, BTW I will use brackets with the IF which is optional in Papyrus, but may help explain the validation logic  better, maybe or it will do your head in

EDIT

LOL I needed two extra properties, sorry it being a long time since I wrote code for skyrim😁😁😁

Cell Property targetCell Auto
ObjectReference Property HomeMarker  Auto
ObjectReference Property StableMarker  Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

	If ((akCaster == Game.GetPlayer()) && (!targetCell.IsAttached()))

		akCaster.MoveTo(HomeMarker)
		Game.FastTravel(HomeMarker)
		Game.GetPlayersLastRiddenHorse().MoveTo(StableMarker)
	EndIf
EndEvent

Notice nothing for window garage disposal  to clean up either, NADA Nothing! and uses less CPU time and memory allocation  too

just in case I will explain the !

if the player is the caster and if not the target call is attached (not the current location) do something cool. The use of the bracket is like  BODMAS  and allows better control on how it is validated, or calculated, it is not used much in Papyrus, but payrus does support it, even though it was not require here,  if your clever enough to use it,  some very clever complicated reverse logic does not work without it,  so consider this an unnecessary  introduction to reverse logic

or simply  if this is true and this is true too do something cool, so how simple is that? true and true is what I want👍🏽👍🏽👍🏽👍🏽

BTW in code it is easier to see if is not than if something is.. I know that will go over 99% of people heads, but I am happy to show examples in payrus that prove it ))  isDisabled() is Native, isEnabled()  is a Function  that returns !isDisabled() they do that because it is easier, it was not an  arbitrary random choice

btw you can lose the cell and keep the keyword,  but a cell is more concise,  Big(0) wise, in my opinion only

https://www.google.com/search?q=Big(0)&sourceid=chrome&ie=UTF-8

Link to comment
Share on other sites

btw that is not beginner code  like you normally see in these forum, I am not pandering to you, but asking you to step up and write good code, I am sick of seeing shitty code and OP thanking people for shitty coding!!!! that why mine looks different )) and long winded explanation 

BTW Random Reader if the spell is to be cast by a Follower for Immersion reason,  "let's go home" in some follower dialogue 

Scriptname travelTo extends activemagiceffect

Cell Property targetCell Auto
ObjectReference Property HomeMarker  Auto
ObjectReference Property StableMarker  Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)

	If ((akTarget == Game.GetPlayer()) && (!targetCell.IsAttached()))

		akTarget.MoveTo(HomeMarker)
		Game.FastTravel(HomeMarker)
		Game.GetPlayersLastRiddenHorse().MoveTo(StableMarker)
	EndIf
EndEvent

Notice how simple the change is, now the player is the target, that it...  all I am gonna say... 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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