NorseDude - Part III: Coding Cut-Scenes

NorseDude's Cut-Scene Tutorial

Note: these tutorials were written prior to the new cut-scene functionality added by BioWare in patch 1.30.


The purpose of these tutorials: To help the average NWN module maker create his or her own cut-scenes in NWN. Simple as that.


Requirements: Not much, but I do expect you to know at least the basics in module-creation. When I say "Create a NPC named 'Bob' with the Tag 'bob'", I will not tell you how to do just that since I expect you to know that already.


My e-mail: norsedude@tiscali.no


Part III: At Last... the Code!

By now you should have one Area with four rooms, one guard, one leader and a door with the Tag "guard_door". So, let's begin. To start somewhere, right-click on Scripts and create a new one. We need three scripts, and I suggest you name them "cutscene_1_1", "cutscene_1_2", and "cutscene_1_3". It's easy to remember, and you usually need at least three scripts in a cut-scene. If you have five cut-scenes, that's fifteen scripts right there - plus all the other scripts you might add to them (I'm working on a module right now that have 220+ scripts and 70+ conversations so far, so trust me when I say it's handy to have a name you can easily remember).


Type this code in the first script - cutscene_1_1 (please, do not just copy and paste it; you'll learn it much better if you type it on your own):


// cutscene_1_1
void main()
{
     object oGuard = GetObjectByTag("guard");
     object oLeader = GetObjectByTag("leader");
     object oPC = GetLastPerceived();

     object oDoor = GetObjectByTag("guard_door");

     if (GetIsPC(oPC))
     {
          SetCommandable(FALSE,oPC);
          DelayCommand(10.0, SetCommandable(TRUE, oPC));
          AssignCommand(oPC, SpeakString("Lead the way!"));
          AssignCommand(oPC, ActionForceFollowObject(oGuard));
          AssignCommand(oGuard, ActionOpenDoor(oDoor));
          AssignCommand(oGuard, ActionForceMoveToObject(oLeader, FALSE));
          AssignCommand(oPC, ClearAllActions());
     }
}

Done? Good. Here's some more code for you - cutscene_1_2:


// cutscene_1_2
int StartingConditional()
{
     int l_iResult;

     l_iResult = !GetIsObjectValid(GetPCSpeaker()) &&
          GetLocalInt(OBJECT_SELF, "TalkingToGuard") == 10;

     return l_iResult;
}

With me so far? Good. The third script - cutscene_1_3 - goes like this:


#include "nw_i0_plot"
// cutscene_1_3
void main()
{
     object oGuard=GetObjectByTag("guard");

     if (GetLocalInt(OBJECT_SELF,"TalkingToGuard") == 0 &&
          CanSeePlayer() &&
          GetObjectSeen(oGuard))
     {
          SetLocalInt(OBJECT_SELF, "TalkingToGuard", 10);
          ActionStartConversation(oGuard);
     }
}

I know this was a lot of code all at once, but we're still not done. We need a few more things. A series of conversations is the first. Why would we follow a guard for no reason? And even if the guard and his leader communicate through sign-language, won't that be just a bit boring for the player? No, we better let everyone know what is going on. First, we need a conversation for the guard. This one is straight forward, just make a regular conversation and name it whatever you want. The clue is this conversation will start the entire cut-scene, so we need to include a line in the conversation that starts it. It can of course be anything, but for now let's go with something like "Come." or "Follow me." Under the "Actions Taken", place the first script (cutscene_1_1).


Now make the conversation for the leader. This is the part where it starts getting a bit messy. First we need to make a conversation line for the guard. We could make one for the leader, but it's handy to learn this from the start. Make a new line and type something like "A prisoner, boss.". Go to the Speaker Tag and select the guard from the list. Now, add a response from the player leave it blank and add a response for the NPC. Type something like "I'll take it from here." and check the Speaker Tag. It should be blank, so the conversation says "[OWNER] I'll take it from here."


Two more things to do before we are done. In the conversation you just made, check the "Text appears when..." and select the second script. This will make sure the cut-scene launches when it's supposed to and also makes sure you can talk to the leader just like you would any other NPC. I know it don't make sense if you are taken prisoner, but what if the leader was a shop-keeper and the other NPC a friend? The possibilities are endless.


When all this is done, there's just one little thing left. Go to the leader properties and put the third script (cutscene_1_3) in the onHeartbeat slot.


Save your module and check it out? I'll see you in Part 4.




 author: Michael Kenyon, editor: Charles Feduke