Jump to content

teleporting and then resurrecting NPC - scriping help needed


Elleh

Recommended Posts

Disclaimer: I am really, really clueless when It comes to scripting. So you might have to talk slowly. Very sorry for being a nusiance. ^^;

 

 

I've made a custom follower, and have successfully used the example script from the creationkit.com to teleport him from his holding cell to myself. Works a charm - shiny visuals and all.

 

 

What I want to do now is - upon his death - teleport his corpse back to his holding cell, and then resurrect him with his current inventory intact, so that he may be summoned again along with anything I might have given him to carry. I could just mark him as essential, or some such.... but that wouldn't be any fun.

 

 

I saw this basic

, and it seems pretty simple. It could be made to work with an NPC, not the player right? And I'm supposing I could just make a markerREF back in his cell for him to teleport to? But how do I make the event trigger on his death, and then resurrect him only after he has teleported?

 

 

It seems like it should be pretty simple, but I am quite hopeless at scripting. I followed the Creation Kit tutorials, but...... didn't learn much from them. Sadly. Any help would be much appreciated.

 

 

Edit: Huh. Misspelled the topic. My life.... OTL

Edited by Elleh
Link to comment
Share on other sites

To make it trigger on your NPC's death, use either the OnDeath or, my favorite, the OnDying event (OnDeath at least used to have some problems wherein it would not always fire -- no idea if those have been fixed, but I still stick to OnDying). This would have course have to be in a script on your NPC. For better visuals, you may want to consider using Utility.Wait, so that your NPC can die, you can see his corpse for a second or two, and then he gets teleported away. Or not -- up to you.

 

Resurrection is easy, too: just call Resurrect on your actor. After you teleport him away to his holding cell, of course -- could even use Utility.Wait again just to be sure, if you wanted to.

 

I haven't looked at that teleport spell tutorial, but there shouldn't be any issue with using it to teleport an NPC rather than the player. And, yes, you'd most likely teleport him to a markerREF in his cell. Or you could just use the same teleport -- shiny visuals and all -- you already use to summon him to the PC to instead "summon" him to a markerREF in his holding cell.

 

So you'd attach a script to your NPC that looks something roughly like this:

 

ObjectReference Property HoldingCellMarker Auto
 
Event OnDying()
    Utility.Wait(2.0) ;give the PC time for a dramatic "NOOOOOOO!" upon the NPC's death
    YourShinyTeleportSpell(HoldingCellMarker) ;presumes that the passed-in argument is where you are teleporting to
    Utility.Wait(2.0) ;Wait a couple of seconds to make sure you don't accidentally rez too early
    Self.Resurrect()
EndEvent

(Note: Consider this to be pseudo-code, not an actual script, although it should be rather close.)

Link to comment
Share on other sites

Thanks a ton, kromey! I'm going to take this info and poke around at it a bit to see if I can get it working. I'd most definitely like to use the shinyshiny teleport spell in reverse, considering it allready looks the way I want it to. And the Utility.Wait is a good idea too! Hadn't thought of that!

 

I'll come back to report my success (or failure. But one must remain optimistic!).

Link to comment
Share on other sites

Well, okay. I tried using the rough outline you gave me, kromey. The closest I got was...... teleporting and resurrecting myself. Ha! I was mostly excited that I could get it to do anything at all. As I said, I'm pretty clueless with this stuff.

 

How do I go about making this script (taken directly from the Creation Kit wiki), when attacted to my NPC instead of a Magic Effect, teleport said NPC back to his holding cell rather than to the player? I'm currently just using the COCMarkerHeading as my marker.

 

Scriptname SummonDremoraThrallScript extends activemagiceffect  
{Summons Dremora Thrall in front of player.}

Actor Property DremoraThrallRef Auto ; An ObjectReference will also work with the summon function
 
Event OnEffectStart(Actor akTarget, Actor akCaster)
        Summon(akCaster, DremoraThrallRef)
EndEvent
 
; GetFormFromFile below to enable 'Global' flag
Function Summon(ObjectReference akSummoner = None, ObjectReference akSummon = None, Float afDistance = 150.0, Float afZOffset = 0.0, ObjectReference arPortal = None, Int aiStage = 0) Global 
        While aiStage < 6
                aiStage += 1
                If aiStage == 1 ; Shroud summon with portal
                        arPortal = akSummon.PlaceAtMe(Game.GetFormFromFile(0x0007CD55, "Skyrim.ESM")) ; SummonTargetFXActivator disables and deletes itself shortly after stage 5
                ElseIf aiStage == 2 ; Disable Summon
                        akSummon.Disable()
                ElseIf aiStage == 3 ; Move portal in front of summoner
                        arPortal.MoveTo(akSummoner, Math.Sin(akSummoner.GetAngleZ()) * afDistance, Math.Cos(akSummoner.GetAngleZ()) * afDistance, afZOffset)
                ElseIf aiStage == 4 ; Move summon to portal
                        akSummon.MoveTo(arPortal)
                ElseIf aiStage == 5 ; Enable summon as the portal dissipates
                        akSummon.Enable()
                EndIf
                Utility.Wait(0.6)
        EndWhile
EndFunction

It could be even simpler than that. I don't need an effect when he gets moved to the marker (since I won't see it), only when he disappears from the spot where he died.

I first just tried using MoveTo without any of that fancy portal business. But as I mentioned, it resulted in me being teleported to his holding cell rather than his corpse. (As punishment for murdering my faithful follower I suppose?)

 

So what would a really simple teleport script for that look like? Barring the effects?

 

I just. Guh. My head hurts......

Link to comment
Share on other sites

If you want to attach this script to your NPC, first you need to change that first line to have it extend Actor instead of ActiveMagicEffect.

 

Then drop the OnEffectStart event altogether.

 

This leaves you with just the Summon function. If you put it in the same script as the one with your OnDying() event, all you have to do is call it -- passing in your marker as the akSummoner argument, and self as akSummon.

Link to comment
Share on other sites

Unfortunately, I have not quite been able to reverse the summon spell. But I did get my guy to moveto and resurrect in his holding cell. Yaaaaay......

 

That just left the issue of having no visual effect. Obviously, the guy just blinking out of existence looked very, very bad. So I played around with alternatives a bit and came up with a very simple solution to my problem:

Scriptname DeathDremoraThrallScript extends Actor
{Teleports Dremora Thrall to holding cell and resurrects him after death.}

ObjectReference Property HoldingCellMarker auto
Activator property banishFX auto

Event OnDying(Actor akKiller)
	Utility.Wait(5.0)
	Self.PlaceAtMe(BanishFX)
	MoveTo(HoldingCellMarker)
	Utility.Wait(2.0)
	Self.Resurrect()
EndEvent

That's it. Just found an activator that plays the default banishFX: "BanishTargetFXActivator". It looks great. :)

 

I'm going to tinker around with this a bit more and attempt to address some other issues. The biggest one being his inventory resetting once he's been resurrected. Obviously annoying. I went into this with the assumption that there was some sort of function that would resurrect the NPC with inventory intact - as the wiki claims that typing "Resurrect 1" into the console will do. But apparently this is not a thing, and does not work in the console either. I thought about just disabling the "I want to trade some things with you" dialog, but I still need to get into his inventory to get rid of that stupid hunting bow (could do it via console, but I'd rather not need to. Feels cheat-y.). This leaves me with a few options:

 

- Just don't give him anything to carry (as this is a personal mod, who cares right?)

- Extend that first utility.wait considerably to give me time to loot (but this would look strange, and chances are I'd be in the middle of pretty rough combat if it was enough to take him down)

- Pile of Ashes? Is this..... a thing? Here's what I thought about but haven't experimented with yet:

If I could drop an "ash pile" and it remained at his point of death while his corpse moved away, could I still have access to his inventory with the ash pile? Is that what ash piles do? If that were the case, I could add a sufficiently long delay to his resurrection and take what I need before it goes bye-bye. I would also have to somehow add a cooldown to the original summon spell, to prevent myself from accidentally summoning him while he is still dead. I wanted to do this anyway - like "cannot be summoned for 24 game hours after death" - but I'm unsure of how to approach it.

 

And kromey - you are very patient sir, thank you!

Link to comment
Share on other sites

What about this?

 

When he dies, after you teleport him but before you resurrect him:

 

Self.RemoveAllItems(HoldingCellChest, True, True)

This takes everything out of his inventory and places it into HoldingCellChest, which should be an empty chest you place in his holding cell (be sure it and the holding cell don't respawn).

 

Then, when you summon him, just before you teleport him to your location:

 

Self.RemoveAllItems() ;Just empty his current inventory (should ditch that stupid bow)
HoldingCellChest.RemoveAllItems(Self, True, True)

This puts everything you stashed on him earlier back in his inventory. (Note that this means you should put any items you want him to initially have on him in the chest, not on his person. And I have no idea how this will interact with outfits -- probably need that to be in the chest as well.)

 

Now, all that being said, I suspect the reason his inventory is resetting is because he and/or his holding cell are respawning. Make sure neither respawns. I don't think Resurrect() is supposed to reset inventory, so I suspect something else is doing that.

Link to comment
Share on other sites

kromey, on 14 Mar 2013 - 19:01, said:

Now, all that being said, I suspect the reason his inventory is resetting is because he and/or his holding cell are respawning. Make sure neither respawns. I don't think Resurrect() is supposed to reset inventory, so I suspect something else is doing that.

I am certain he does not respawn ("unique" checked, "respawn" un-checked). And I'm 95% certain his cell does not respawn, after I went through and unticked "respawn" on every item in the cell. Unless there is something else I should be looking at...? Tested it out to see if that was the issue - and no. Still resets his inventory. So.... I dunno? I am running a couple mods, but the only one that does anything to followers/npcs is the Unofficial Skyrim Patch.... but I'm unsure if this would affect resurrection or not.

 

That trick with the chest kind of passed my mind, but I didn't know RemoveAllItems worked that way. Cool!

 

I tried it out, and it mostly works. Firstly, I did not put any of his outfit in the chest and left it on his person. I did put his weapons in the chest and removed them from his inventory.

 

Here's where it gets weird: the very first time he is summoned - and only the first time - nothing from the chest appears in his inventory (except for the hunting bow OMG), but he is fully clothed. So, I take the bow, give him some items, kill him, and then summon him again..... and he has all of his weapons from the chest, his armor, and the items I gave him before I killed him..... and another hunting bow. After that, it works as expected. Doesn't duplicate items or anything. Well, other than spawning a hunting bow every flippin' time. Wut.

 

I also tried not giving him an outfit and putting all of his armor and weapons in the chest. Just summons him in his undies. After killing him and re-summoning him, he has all the items I put in the chest but does not have them equipped - and still gained a hunting bow. Possibly a mod conflict going on here, but I think Beth is just trolling me.

 

I think my next Epic Quest will involve lugging my 500 copies of "Hunting Bow" to the top of the Throat of the World and chucking them off a cliff. C:

 

Oh, and here's what I added to my scripts as you described. I can't imagine I did it wrong, but hey who's to say...

 

(Magic Effect)

Actor Property DremoraThrallRef Auto
ObjectReference Property HoldingCellChest auto
 

Event OnEffectStart(Actor akTarget, Actor akCaster)
       DremoraThrallRef.RemoveAllItems()
       HoldingCellChest.RemoveAllItems(DremoraThrallRef, True, True)
       Summon(akCaster, DremoraThrallRef)
EndEvent

(Actor)

ObjectReference Property HoldingCellMarker auto
ObjectReference Property HoldingCellChest auto
Activator Property banishFX auto

Event OnDying(Actor akKiller)
	Utility.Wait(4.0)
	Self.PlaceAtMe(BanishFX)
	MoveTo(HoldingCellMarker)
	Self.RemoveAllItems(HoldingCellChest, True, True)
	Utility.Wait(2.0)
	Self.Resurrect()
EndEvent

EDIT: Hold the phone. Just noticed I left the Wait time at 10 on the actor script (did this to test some things). :blink: Will need to re-evaluate the situation.......

 

EDIT EDIT: Fixed. No difference.....

Edited by Elleh
Link to comment
Share on other sites

Just throwing this out there... You'll need to read up on the commands on the CK wiki to work out how to do it. But perhaps something like this might help

 

Dremora has pre-placed gear, you add stuff, you change what he wears.

 

When stuff is added to him (OnItemAdded() event) you build a form list which contains all items that he then owns. The form list has to be blank in the CK and use AddForm to add the item to the form list.

 

Whenever stuff is removed you clear the form list (RemoveAddedForm is broken -- well not broken but it seems to work only ever once on any one form -- so you have to Revert the list instead) and rebuild it based on what he then currently has.

 

When he dies or is dying, you cycle thru the form list as if it were an array and see which items are equipped and make a new form list of just equipped items. Then transfer the items to the hidden container.

 

When he is summoned, transfer the items back to him, read into the equipped form list and make sure those items are equipped, then run the effects to summon him by your side.

 

In theory it should work. I have done the form list building and such before. I have never dealt with summoning so that's the wild card. Should work tho. The follower in this case is nothing more than another container and the form list thing works well between containers.

Link to comment
Share on other sites

Thanks for the input, Ishara! Although I think I should just come out and say that's a bit over my head. ^^; But I do believe I understand the general concept - remember what he wears and protect those items. I could give that a shot, but I was thinking of different angles I could approach this problem from, and I think I figured out a potential solution. I haven't had a chance to try at all yet, so it might not work. And if it doesn't, I'll likely give your idea I try. Could you perhaps suggest a script that might do some of the things you described, just to look at? Like reading into forms and all that? I have trouble working these things out without something in front of my face. I noticed you have some example scripts on your page that deal with containers - would one of those be appropriate?

 

Off topic, but that got me thinking..... there's a mod I used for a while that summoned and equipped a set of armor, but it would leave the player naked when it dissapeared. If I can figure that form list thing out, maybe I can get it to remember what my PC is wearing. Would make it a lot more useful. XD

Link to comment
Share on other sites

  • Recently Browsing   0 members

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