Author Sticky: Post Working Scripts Here
Elricstorm Posted: Wednesday, 10 July 07:56PM
Impersonation Script
by Elricstorm
with help on one of the scripts from David Gaider, Elmer the Destroyer, Beauwrath, and eMotion.

Scenario: An NPC wants you to retrieve a ring for him to release him from his ghostly prison. When you recover the ring and give it back to the NPC he suddenly manifests into another person altogether and lets you know that you have freed him from his prison. Before you can do anything to him, he teleports away.

First, you need to create NPC1 and attach a quest dialog to him or her as you would for any other quest, setting the dialog nodes for their respective variables so that one dialog asks the PC(s) to find the item (start of the quest), and one node is when the PC(s) return the item (end of the quest). I won't go into how to set that part up because most of it is trivial and you can find a lot of information on how to write up a simple quest conversation.

Secondly, you need to create NPC2 (the manifested form) that the first NPC will change into. Create him and set his advanced tab to "Plot" so that he can't be hurt. Write down his blueprint resref NOT his tag somewhere for future reference.

Thirdly, on the conversation for NPC1 you need to place the following script into the actions taken portion of the (end the quest) dialog. Normally in this dialog on the "Text Occurs When.." you will be looking for an item in the inventory of the PC speaker, say the tag is curse_ring. On the "actions taken" tab of the same dialog node you need to put in the following script.

NWScript:
void main()

{

    object currentSpeaker = GetPCSpeaker();

    // Note: string below is the tag of the ring

    object oItemToTake

        = GetItemPossessedBy(currentSpeaker, "curse_ring");

    if(GetIsObjectValid(oItemToTake)) {

        DestroyObject(oItemToTake);

        location mylocation = GetLocation(OBJECT_SELF);

        DestroyObject(OBJECT_SELF);

        effect VisualEffectToShow =

            EffectVisualEffect( VFX_FNF_SUNBEAM );

        ApplyEffectAtLocation(

            DURATION_TYPE_TEMPORARY,

            VisualEffectToShow,

            mylocation,

            20.0

        );

        // Note: string below is a blueprint resref

        // of a "custom" person I created.

        CreateObject(

            OBJECT_TYPE_CREATURE,

            "dralthar",

            mylocation

        );

    }

}



This script will take the item with the tag, curse_ring and destroy that item. It will then destroy NPC1 and create a visual effect for Sunbeam and create the new NPC2 that has the blueprint resref "dralthar" at the same location.

On NPC2, the npc that will be created, you need to do two more things. In the OnSpawn script you need to uncomment the two following lines for set spawn in conditions.

(NW_FLAG_PERCIEVE_EVENT);
(NW_FLAG_ON_DIALOGUE_EVENT);

In the UserDefined, you need to create a new script for the following:

NWScript:
void main()

{

  int nUser = GetUserDefinedEventNumber();

  if (nUser == 1002)  // ON PERCEIVE

  {

    ClearAllActions();

    DelayCommand(1.0, ActionPlayAnimation(ANIMATION_LOOPING_TALK_NORMAL));

    DelayCommand(2.0, ClearAllActions());

    DelayCommand(2.0, ActionSpeakString("Place in text that the NPC will say out loud to the PCs here."));

    DelayCommand(3.0, ClearAllActions());

    DelayCommand(3.0, ActionCastFakeSpellAtObject(SPELL_SPHERE_OF_CHAOS, OBJECT_SELF, PROJECTILE_PATH_TYPE_DEFAULT));

    DelayCommand(5.0, DestroyObject(OBJECT_SELF));

  }

  else if(nUser == 1004) // ON DIALOGUE

   {

    ClearAllActions();

    DelayCommand(1.0, ActionPlayAnimation(ANIMATION_FIREFORGET_VICTORY2));

    DelayCommand(3.0, ClearAllActions());

    DelayCommand(3.0, ActionCastFakeSpellAtObject(SPELL_SPHERE_OF_CHAOS, OBJECT_SELF, PROJECTILE_PATH_TYPE_DEFAULT));

    DelayCommand(5.0, DestroyObject(OBJECT_SELF));

   }

}



This will cause the new NPC2 to automatically perceive the character when he spawns into view and initiate the action queue above. If the PCs try to interrupt him by speaking with him, the queue will still be initiated. If the PCs try to attack him, they will not be able to hurt him and he will still initiate the action.

You can alter the action queues to place sounds in or anything you like.

Have fun.