Help with a script to summon NPCs?

Post » Tue Nov 20, 2012 2:42 am

So I want to summon an NPC with a spell that has this script (taken from the creation kit wiki) attached to it:

Event OnEffectStart(Actor akTarget, Actor akCaster)		Summon(akCaster, MyNPC)EndEventFunction Summon(ObjectReference akSummoner = None, ObjectReference akSummon = None, Float afDistance = 150.0, Float afZOffset = 0.0, ObjectReference arPortal = None, Int aiStage = 1)		While aiStage &--#60; 6				aiStage += 1				If aiStage == 1 ; Shroud summon with portal						arPortal = akSummon.PlaceAtMe(Game.GetForm(0x0007CD55)) ; SummonTargetFXActivator disables and deletes itself				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)		EndWhileEndFunction

I have successfully compiled the script (put myNPC as an Actor property) and the spell shows up in game. But the spell doesn't summon the NPC, it plays the summon vfx and then ends.

Help?

edit: for clarification the magic effect is set up as a 'script' effect, and it shows up ingame, so the problem probably has to with the script and not the spell itself.
User avatar
Rachel Tyson
 
Posts: 3434
Joined: Sat Oct 07, 2006 4:42 pm

Post » Tue Nov 20, 2012 4:59 am

But the spell doesn't summon the NPC, it plays the summon vfx and then ends.


What type of spell is it? Target location? Because the script only runs when the effect is applied to an actor, if it doesn't have an actor target the script will never run. You should make it a "self" casted spell with no hit effect, so the script runs on the caster (who is also the target.)

Also, I noticed:
;SummonTargetFXActivator disables and deletes itself

Isn't the portal going to disable itself before it's moved to the location where the summoned actor is to be placed? Not that it matters too much because the summoned actor will be moved there either way, but it seems like you were supposed to spawn two separate portals, one for the summoned actor to disappear in, and one for the actor to appear in front of the caster in.

Also,
Game.GetForm(0x0007CD55)


Don't use this. You should make it a property.
User avatar
Hilm Music
 
Posts: 3357
Joined: Wed Jun 06, 2007 9:36 pm

Post » Mon Nov 19, 2012 9:56 pm

Isn't the portal going to disable itself before it's moved to the location where the summoned actor is to be placed? Not that it matters too much because the summoned actor will be moved there either way, but it seems like you were supposed to spawn two separate portals, one for the summoned actor to disappear in, and one for the actor to appear in front of the caster in.
No. It takes a bit of time for SummonTargetFXActivator to run its course and the stages of the Summon function are timed accordingly (I wrote it). Using GetForm allows it to be a 'Global' function, but yeah, a property would probably be slightly faster if only using it in one place.

cruelflames: Is the MyNPC Actor Property filled with/pointed at your actor?
User avatar
Emma Parkinson
 
Posts: 3401
Joined: Wed Jul 26, 2006 5:53 pm

Post » Tue Nov 20, 2012 10:34 am

No. It takes a bit of time for SummonTargetFXActivator to run its course and the stages of the Summon function are timed accordingly (I wrote it). Using GetForm allows it to be a 'Global' function, but yeah, a property would probably be slightly faster if only using it in one place.

But it's in a magic effect script and has no global keyword. O_o Do you just mean in case the thread starter decided to move it to a global function...?
User avatar
Stephanie Nieves
 
Posts: 3407
Joined: Mon Apr 02, 2007 10:52 pm

Post » Tue Nov 20, 2012 10:17 am

But it's in a magic effect script and has no global keyword. O_o What do you mean exactly?
As in a http://www.creationkit.com/Function_Reference#Function_Header function (that doesn't need to know anything about the object its glued to).
User avatar
Dean Brown
 
Posts: 3472
Joined: Fri Aug 31, 2007 10:17 pm

Post » Mon Nov 19, 2012 11:23 pm

As in a http://www.creationkit.com/Function_Reference#Function_Header function (that doesn't need to know anything about the object its glued to).

Yeah, sorry, I edited my post, I guess you just meant in case he decides to make it one in the future.
User avatar
Mimi BC
 
Posts: 3282
Joined: Sat Oct 07, 2006 10:30 pm

Post » Tue Nov 20, 2012 11:40 am

Yeah, sorry, I edited my post, I guess you just meant in case he decides to make it one in the future.
Yeah. If it were to be reused in multiple contexts or whatever. Global functions are faster than non global functions, as an added bonus. If it's just the one use though, I'd go with a property.
User avatar
+++CAZZY
 
Posts: 3403
Joined: Wed Sep 13, 2006 1:04 pm

Post » Tue Nov 20, 2012 2:08 pm

Thanks for the replies, I somehow got it to work on a recompile. Strange... but I can cast the spell and the NPC can be summoned anywhere :)

Do any of you have an idea how to change the summoning vfx (the blue shimmery effect that appears around a summonable creature as it fades in) into something else? I tried making a new FXActivator with a different VFX nif (the Valor summon one) and added that to the script but when I cast the spell the NPC just disappears and reappears in the same spot after a while.
User avatar
Jenna Fields
 
Posts: 3396
Joined: Mon Dec 11, 2006 11:36 am


Return to V - Skyrim