Author Topic: text input  (Read 481 times)

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
text input
« on: April 07, 2011, 07:42:10 pm »


               Hi folks, I'm working on a masters' dissertation in educational games. Of all the avenues that attracted me, as I have to produce an educational game, I was drawn to NWN as I've been a fan ever since it came out. I have to admit though - I was always weak at scripting. That said after half a year in this course, I've enjoyed some significant Java experience.

What I'd like to know is how easy it would be in implement a scanner or text input box. To give you a simple idea, I'd have a bridge that would require you to input several correct words to make the next piece of the bridge appear - the script would obviously be called from conversation, but I'm not sure how to implement it if it is, at all, possible.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
text input
« Reply #1 on: April 07, 2011, 08:06:17 pm »


               two ways:

1) use and invisible npc (no problem since you can click on it but also may be invisible but you need a script for that again) that starts a conversation where you can do it via OnConversation event (SetListenPattern) well quite hard to understand and I dont have any similar script in my module to show you

2) using a trigger and OnPlayerChat event you can make that once you enter trigger the OnPlayerChat event will listen this player and run a script you need. I got nice function for this if you would try this route.
               
               

               
            

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
text input
« Reply #2 on: April 07, 2011, 08:23:18 pm »


               I'd be up for taking a look, in the very least it'll let me know what I'm letting myself in for. As I understand the constraints of my project, I have to create a realtively short game, but one that educates.

Number 2 sounds interesting though - i take it the player walks into a trigger- you could probably alert the player to that with a simple floating text, then you can chat as normal with certain key words..
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
text input
« Reply #3 on: April 07, 2011, 09:14:41 pm »


               Ok will show you my way of doing that.

I have this in my OnPlayerChat event script

void main()
{
object oModule = OBJECT_SELF;
object oPC = GetPCChatSpeaker();
string listening_script = GetLocalString(oPC,"START_LISTENING");
 if(listening_script!="")
 {
 SetLocalInt(oModule,"GetRunningEvent()",15);
 ExecuteScript(listening_script,oPC);
 DeleteLocalInt(oModule,"GetRunningEvent()");
return;
 }
}


and now I got two custom functions that will start and stop listening of current player and they can be used inside one script like this

void StartListening(object oPlayer, string sScript)
{
SetLocalString(oPlayer,"START_LISTENING",sScript);
}

void StopListening(object oPlayer)
{
DeleteLocalString(oPlayer,"START_LISTENING");
}

void main()
{
int nEvent = GetLocalInt(GetModule(),"GetRunningEvent()");
if(nEvent == 15)//script fired from OnChat
 {
 object oPC = OBJECT_SELF;
 string sMessage = GetPCChatMessage();
 SetPCChatMessage();//message wont be displayed
 StopListening(oPC);//disable further listening
 ActionResumeConversation();//unpause conversation
 }
 else//script fired from conversation
 {
 object oPC = GetPCSpeaker();
 object oNPC = OBJECT_SELF;
 StartListening(oPC,"listen_template");//start listen the player
 ActionPauseConversation();//pause an conversation until player says something
 }
}

This is used for conversation, so if you use some npc or placeable (which cannot use the first option to do this cos it missing OnConversation event) you can have a conversation where will be:
you see a bridge, blah blah - continue (the script above must be set on this line in Actions Taken event)
say password nub - and now continue doesnt appear since the conversation is paused until you say something.

then you must make a two options depending if the player spoken correct password

(will complete this after I re-check something, stay tuned)
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
text input
« Reply #4 on: April 07, 2011, 09:25:55 pm »


               ok, you have to check in listen script above if the password spoken is a correct one

something like

if(sMessage == "password")
 {
SetLocalInt(oPC,"SAID_PASSWORD",TRUE);
 }


and then you need those two options and first (and "correct") line must have a conditional script to check "SAID_PASSWORD" to TRUE while second doesnt need any script just tell you that the password is incorrect and end a conversation.

If you want I can send you an example with everythin set already and working, so you would need just to change password and texts.

The trigger way would be easier it would looked like this:

void StartListening(object oPlayer, string sScript)
{
SetLocalString(oPlayer,"START_LISTENING",sScript);
}

void StopListening(object oPlayer)
{
DeleteLocalString(oPlayer,"START_LISTENING");
}

void main()
{
int nEvent = GetLocalInt(GetModule(),"GetRunningEvent()");
if(nEvent == 15)//script fired from OnChat
 {
 object oPC = OBJECT_SELF;
 string sMessage = GetPCChatMessage();
 SetPCChatMessage();//message wont be displayed uncomment if you want to display it
 StopListening(oPC);//disable further listening
  if(sMessage == "password)
  {
  //do whatever you want to do, teleport to waypoint? etc
  }
 }
 else//script fired from trigger
 {
 object oPC = GetEnteringObject();
  if(!GetIsPC(oPC))return;
StartListening(oPC,"listen_template");//start listen the player
 FloatingTextStringOnCreature("tell the password nub!",oPC);
 }
}


               
               

               


                     Modifié par ShaDoOoW, 07 avril 2011 - 08:26 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
text input
« Reply #5 on: April 07, 2011, 09:28:13 pm »


               Oh and I forgot to add that in order this to work you must change the "listen_template" in StartListening function to your script name.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
text input
« Reply #6 on: April 07, 2011, 11:37:09 pm »


               If you decide that you want to go the other route and have an object listening for the correct words, Here are a few old threads to look at.

SetListening() . . is it only for NPCs?

SetListenPattern()

It also does not hurt to look at the lexicon.

Function - GetIsListening

Function - SetListeningPatterns

Function - SetListening

Event - OnConversation

Function - GetListenPatternNumber
               
               

               
            

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
text input
« Reply #7 on: April 08, 2011, 12:06:17 pm »


               crap I totally forgot about the lexicon... thank you lightfoot '<img'>