Author Topic: Conversation Nodes  (Read 329 times)

Legacy_Devari

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Conversation Nodes
« on: May 31, 2011, 01:49:55 pm »


               Hey peeps, having a little trouble with conversations and scripting, now I am not 100% sure if its possible but I figure i'll ask just in case, see I wish to use one script on the ActionsTabs for multiple conversation choices. So basically the thing is if a player clicks Choice A or Choice B or Choice C they execute the same script, but in the script I want to be able to define the differences.

I've tried using GetPCChatMessage to see if that would help at all, I didn't think it would  and I was right. So I was wondering is there a way to get that the conversation node so I can use that as a check to what choice the player did.

This is so I dont have to create a seperate script for each relatable item in the menu..

Cheers
- Dev
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Conversation Nodes
« Reply #1 on: May 31, 2011, 03:50:50 pm »


               You need to use NWNX and the nwnx_events plugin, to get these functions:

   int GetCurrentNodeType();
   int GetCurrentNodeID();
   int GetCurrentAbsoluteNodeID();

It's been released for both linux and windows, but as far as I know only the linux plugin offers the above functions. Linkage

Funky
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Conversation Nodes
« Reply #2 on: May 31, 2011, 04:05:45 pm »


               There is a Branch of the nwnx svn, called Events_Update

http://nwn.virusman....s/events_update

I dont know if it works, but it contains conversation node code.


char* CNWNXEvents::OnRequest (char* gameObject, char* Request, char* Parameters)
{
   Log(2,"Request: \\"%s\\"\\n",Request);
   Log(2,"Params:  \\"%s\\"\\n",Parameters);
   this->pGameObject = gameObject;
   this->nGameObjectID = *(dword *)(gameObject+0x4);

   if (ConditionalScriptRunning)
   {
      if (strncmp(Request, "GET_NODE_ID", 11) == 0)
      {
         if (strlen(Parameters) > 2)
            sprintf(Parameters, "%d", nCurrentNodeID);
         return NULL;
      }
      else if (strncmp(Request, "GET_ABSOLUTE_NODE_ID", 20) == 0)
      {
         if (strlen(Parameters) > 2)
            sprintf(Parameters, "%d", nCurrentAbsoluteNodeID);
         return NULL;
      }
      else if (strncmp(Request, "GET_NODE_TYPE", 13) == 0)
      {
         if (strlen(Parameters) > 1)
            sprintf(Parameters, "%d", nNodeType);
         return NULL;
      }
      else if (strncmp(Request, "GET_NODE_TEXT", 13) == 0)
      {
         if(!pConversation) return NULL;
         int nLocaleID = atoi(Parameters);
         const char *pText = NULL;

         if(nNodeType == StartingNode || nNodeType == EntryNode)
         {
            CDialogEntry *pEntry = &pConversation->EntryList[nCurrentAbsoluteNodeID];
            CExoLocString *pNodeText = &pEntry->Text;
            pText = pNodeText->GetStringText(nLocaleID);
         }
         else if(nNodeType == ReplyNode)
         {
            CDialogReply *pReply = &pConversation->ReplyList[nCurrentAbsoluteNodeID];
            CExoLocString *pNodeText = &pReply->Text;
            pText = pNodeText->GetStringText(nLocaleID);
         }
         else return NULL;

         if(!pText) return NULL;
         int len = strlen(pText);
         char *pNewText = (char *) malloc(len+1);
         strncpy(pNewText, pText, len);
         pNewText[len]=0;
         return pNewText;

         return NULL;
      }
      else if (strncmp(Request, "SET_NODE_TEXT", 13) == 0)
      {
         if(!pConversation) return NULL;
         int nLocaleID;
         int nParamLen = strlen(Parameters);
         //char *sNewText = (char *) malloc(nParamLen);
         char *nLastDelimiter = strrchr(Parameters, '¬');
         if (!nLastDelimiter || (nLastDelimiter-Parameters)<0)
         {
            Log(0, "o nLastDelimiter error\\n");
            //free(sNewText);
            return NULL;
         }
         int nTextLen = nParamLen-(nLastDelimiter-Parameters)+1;
         char *sNewText = (char *) malloc(nTextLen);
         if(sscanf(Parameters, "%d¬", &nLocaleID)<1)
         {
            Log(0, "o sscanf error\\n");
            free(sNewText);
            return NULL;
         }
         strncpy(sNewText, nLastDelimiter+1, nTextLen-1);

         CExoLocStringElement *pLangEntry=NULL;

         if(nNodeType == StartingNode || nNodeType == EntryNode)
         {
            CDialogEntry *pEntry = &pConversation->EntryList[nCurrentAbsoluteNodeID];
            CExoLocString *pNodeText = &pEntry->Text;
            pLangEntry = pNodeText->GetLangEntry(nLocaleID);

         }
         else if(nNodeType == ReplyNode)
         {
            CDialogReply *pReply = &pConversation->ReplyList[nCurrentAbsoluteNodeID];
            CExoLocString *pNodeText = &pReply->Text;
            pLangEntry = pNodeText->GetLangEntry(nLocaleID);
         }

         if(!pLangEntry){ free(sNewText); return NULL; } //do nothing if there is no text
         if(pLangEntry->Text.Text)
         {
            free(pLangEntry->Text.Text);
            pLangEntry->Text.Text = sNewText;
            pLangEntry->Text.Length = strlen(sNewText)+1;
         }
         return NULL;
      }
   }

   if (ActionScriptRunning)
   {
      if (strncmp(Request, "GET_SELECTED_NODE_ID", 20) == 0)
      {
         if (strlen(Parameters) > 1)
            sprintf(Parameters, "%d", nSelectedNodeID);
         return NULL;
      }
      else if (strncmp(Request, "GET_SELECTED_ABSOLUTE_NODE_ID", 29) == 0)
      {
         if (strlen(Parameters) > 1)
            sprintf(Parameters, "%d", nSelectedAbsoluteNodeID);
         return NULL;
      }
      else if (strncmp(Request, "GET_SELECTED_NODE_TEXT", 22) == 0)
      {
         if(!pConversation) return NULL;
         int nLocaleID = atoi(Parameters);
         CDialogReply *pReply = &pConversation->ReplyList[nSelectedAbsoluteNodeID];
         CExoLocString *pNodeText = &pReply->Text;
         const char *pText = pNodeText->GetStringText(nLocaleID);
         if(!pText) return NULL;
         int len = strlen(pText);
         char *pNewText = (char *) malloc(len+1);
         strncpy(pNewText, pText, len);
         pNewText[len]=0;
         return pNewText;
      }
   }

   if (!scriptRun) return NULL; //The following functions are accessible only from event script
   if ((strncmp(Request, "GET_EVENT_ID", 12) && strncmp(Request, "GETEVENTID", 10)) == 0)
   {
      if (strlen(Parameters) > 1)
      sprintf(Parameters, "%d", nEventID);
      return NULL;
   }
   if (strncmp(Request, "GET_EVENT_SUBID", 15) == 0)
   {
      if (strlen(Parameters) > 1)
         sprintf(Parameters, "%d", nEventSubID);
      return NULL;
   }
   else if (strncmp(Request, "GET_EVENT_POSITION", 18) == 0)
   {
      if (strlen(Parameters) > 24)
         sprintf(Parameters, "%f¬%f¬%f", vPosition.x, vPosition.y, vPosition.z);
   }
   else if (strncmp(Request, "GET_ITEM_RADIAL", 18) == 0)
   {
      if (strlen(Parameters) > 1)
         sprintf(Parameters, "%d", nRadial);
   }
   else if (strncmp(Request, "BYPASS", 6) == 0)
   {
      bBypass = atoi(Parameters);
   }

   return NULL;
}


               
               

               
            

Legacy_Devari

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Conversation Nodes
« Reply #3 on: May 31, 2011, 04:07:09 pm »


               Cheers both of you, i'll have a look at NWNX and see if I can made head or tail of the event node stuff, cheers.