Gaming
 

Conversation sorter

From NWNWiki

Contents

[edit] What It Does

Sorts a multilevel conversation and performs an action based on your decisions at the end.

All kinds of options can be set by conversing with NPCs.

[edit] How It Works

  • clear the local variable "option" at the beginning of the conversation
  • add choices to the left of the existing ones (I allow 9 choices per question)
  • sort using if or whatever type of programming you want at the end.

[edit] The Scripts

Clear

void main()
{
SetLocalInt(GetPCSpeaker(),"option",0);
}

[edit] ActionTaken

This is a sample option. You'll only ever need 9

void main()
{
int nSelection = 1;
int nMult=1;
int nMemory = GetLocalInt( GetPCSpeaker(), "option" );
while (nMemory>=nMult) { nMult=nMult*10; }
nSelection = nSelection * (nMult);
int nOption = nMemory + nSelection;
SetLocalInt( GetPCSpeaker(), "option", nOption );
}

[edit] Conversation end (normal)

This is a sample. You need one per conversation

void main()
{
int nTemp; int nP1; int nP2;
int nString = GetLocalInt( GetPCSpeaker(), "option" );
if (nString>=1) {nTemp=nString/10; nP1=(nString-nTemp*10); nString=nTemp;}
if (nString>=1) {nTemp=nString/10; nP2=(nString-nTemp*10); nString=nTemp;}
string sMessage = "First answer="+IntToString(nP1) +" Second answer="+ IntToString(nP2);
SendMessageToAllDMs(sMessage);
SendMessageToPC( GetPCSpeaker(), sMessage);
}

The variable "option" is reusable.
The option scripts (1-9) are reusable. I use set_option_1 - set_option_9 for mine. Please use those conventions so that conversations you make will be easily sharable among the community.