AdloraHealer Posted December 8, 2015 Posted December 8, 2015 (edited) As it says on the title, I added a teleport spell to a player home mod and it simply doesn't work. I created the magiceffect, copy-pasted a script in there (it was one someone wrote for me like 3 years ago because I don' know anything much about scripts), added in the properties, connected all the relevant spells to the effect, threw one of the spells into a spellbook, and.... I can learn the spell, but not teleport. Maybe it's a problem with the script itself, in which case I'll provide it here and someone who knows what they're looking at can tell me what to type and where. Scriptname _shadowstarteleporthomescript extends activemagiceffect Actor property PlayerREF AutoObjectReference property TeleportMarker AutoObjectReference property MyTempMarker AutoSpell property ShadowstarTeleportHome autoSpell property ShadowstarTeleportReturn autoGlobalVariable property PlayerX autoGlobalVariable property PlayerY autoGlobalVariable property PlayerZ auto Event OnSpellCast(Form akSpell) Spell spellCast = akSpell as Spell if spellCast && spellCast ==ShadowstarTeleportHome PlayerX.SetValue(Game.GetPlayer().GetPositionX()) PlayerY.SetValue(Game.GetPlayer().GetPositionY()) PlayerZ.SetValue(Game.GetPlayer().GetPositionZ()) Game.GetPlayer().AddSpell(ShadowstarTeleportReturn, true) Game.GetPlayer().RemoveSpell(ShadowstarTeleportHome, true) debug.notification("Teleport home") Game.GetPlayer().MoveTo(TeleportMarker) endIf if spellCast && spellCast ==ShadowstarTeleportReturn MyTempMarker.Disable() MyTempMarker.MoveTo(Game.GetPlayer()) MyTempMarker.Enable() MyTempMarker.AddToMap( True ) debug.notification("Teleport back") Game.GetPlayer().MoveTo(MyTempMarker) Game.GetPlayer().AddSpell(ShadowstarTeleportHome, true) Game.GetPlayer().RemoveSpell(ShadowstarTeleportReturn, true) endIf endEvent Or maybe the problem is in the magiceffect, or one of the two spells, in which case, I'll give you the mod, all neatly 7zipped so anyone with a heart of gold can take a look at it and maybe see mistakes I can't. Yes, the source for the script is included in the mod file. A word of note, it does require General stores to run, but I'm sure one could remove the dependency through tes5Edit or something just for testing purposes. https://www.mediafire.com/?8rz2m9lrrv3ekxp Thank you in advance. I really hope someone will help me. For someone who knows what they're doing and/or has worked with spells and scripts before it shouldn't take too long I imagine, but I am but a humble noob. Edited December 8, 2015 by AdloraHealer
sLoPpYdOtBiGhOlE Posted December 8, 2015 Posted December 8, 2015 Sorry, I really can't DL 64MB to debug your code.Pure guess on my part and I haven't tested it and only going by the wiki.But OnSpellCast() event would be attached to to an Objectreference, eg: player.Not a magic effect attached to a spell.So for example:You have an script that extends objectreference and is attached to your object, your OnSpellCast event is fired when the the object casts a spell.From the looks of your script you have the script attached to a Magic Effect.If so then you would be using OnEffectStart() and OnEffectFinish events.If your wanting to use OnSpellCast event then make your script extend ReferenceAlias.Attach your script to an Alias in an empty quest, and that that alias holds the player.(I have not tested if OnSpellCast works from a reference alias and have not tested it, so this is an assumption it would work).If you like I can knock up a brief example of doing either method if you like.(By brief I mean a 3kb archive that can be attached to the post so you can dissect it an work it out for your own use.)
Deleted31005User Posted December 8, 2015 Posted December 8, 2015 (edited) My mod Tel Nalta II has a teleport spell as well, so you can dig in there and try to reverse-engineer it if you like, but my spell only teleports the player to 1 specific spot and it also checks the players mana, costs 100 mana to cast and has a 2 hour delay on it.Also I did not create any of these scripts myself, so don't ask me for any assistance regarding actual scripting.The mod is pretty big (250MB 7zip which is 800MB unpacked) but if you do decide to dig in there then I highly recommend you do not unpack the .bsa file but rather edit your SkyrimEditor.ini so the CK automatically looks inside .bsa without the need to unpack it. (on the bottom of my description I explain how you can do this)However for scripts you still need to unpack them out of the .bsa or otherwise you cannot look at their source code inside the CK, so if you are interested into looking at my teleport script (Tel_Nalta_Script_Recall_To_Tel_Nalta.psc) then you might have to unpack that one.All my own script .psc files are included in the .bsa. If you don't feel like downloading the entire mod just to look at one script, then send me a PM and I'll copy it in there. Edited December 8, 2015 by Guest
cdcooley Posted December 8, 2015 Posted December 8, 2015 That script looks overly complicated to me. If the script is on a magic effect and you're just looking for a teleport spell that takes you to the house when you are somewhere else and then sends you back to the previous location if recast in the house, your script should be something like this: ScriptName CDC_TeleportScript extends ActiveMagicEffect ObjectReference Property HomeMarker Auto {A marker where the caster will be moved to when teleport is cast.} ObjectReference Property ReturnMarker Auto {A second marker originally placed at the same location as the home marker.} Event OnEffectStart(Actor akTarget, Actor akCaster) if akCaster.GetDistance(HomeMarker) < 5000 ; if already at home (i.e. near the home marker) akCaster.MoveTo(ReturnMarker) ; go to return marker else ; if not at home ReturnMarker.MoveTo(akCaster) ; set return marker akCaster.MoveTo(HomeMarker) ; then go home endif EndEvent You could replace the GetDistance check with a location check if the home is multi-cell. if akCaster.GetCurrentLocation().IsSameLocation(HomeMarker.GetCurrentLocation()) I also recommend adding a condition on that magic effect so that the teleport will fail if the player is in combat.
sLoPpYdOtBiGhOlE Posted December 9, 2015 Posted December 9, 2015 Here's my take using OnSpellCast() event from a reference alias script. Basically it'll add the Teleport Me spell to you when loaded.It uses 1 empty spell based on conjuration. Cast it and it teleports you to Whiterun Bannered Mare Inn.Cast it again and it teleports you to your last location. Wasn't phased if the user is already in the home location or not.this was the script I used attached to a player alias.ScriptName AAA_TeleportAliasScript Extends ReferenceAlias ObjectReference Property HomeMarker Auto Static Property xMarker Auto Spell property AAA_TeleportSpell auto Actor Player ObjectReference ReturnMarker Event OnInit() Player = Game.GetPlayer() Player.AddSpell(AAA_TeleportSpell, True) EndEvent Event OnSpellCast(Form akSpell) Spell WhichSpell = akSpell as Spell If WhichSpell && WhichSpell == AAA_TeleportSpell If ReturnMarker Player.MoveTo(ReturnMarker) ReturnMarker.Delete() ReturnMarker = None Else ReturnMarker = Player.PlaceAtMe(xMarker) Player.MoveTo(HomeMarker) EndIf EndIf EndEvent Here's an example esp of using it.If you open it in CK the use AAA_Teleport as a filter in the object window to see the forms it uses.(Source and compiled script supplied in archive)
AdloraHealer Posted December 9, 2015 Author Posted December 9, 2015 Thank you so much!! Especially to you, cdcooley and sLoPpY. I'll try both of your scripts out! So far, CdCooley's one is simple, elegant, and it works well. I haven't tried sLoPpY's option, but I will and I'll let you know! Thanks tons!
Recommended Posts