Aller au contenu

Photo

Idle NPC talking


  • Veuillez vous connecter pour répondre
19 réponses à ce sujet

#1
K Kin

K Kin
  • Members
  • 109 messages
So in the cmapaign, i've noticed that NPC's walk and text appears over their head.

I tried looking into the campaign using toolset and whatnot, but i believed i deleted it >_<

Also looked around through some websites and found nothing, so it might be what I'm searching :P

Would anyone know how this works? Atm, i think it's to do with the heartbeat script, but i have no idea how to make a script that would do what I'm looking for :3

#2
Claudius33

Claudius33
  • Members
  • 258 messages
 Yes you attach the script on the heartbeat event. Use the SpeakString function. Don't forget to finish your script by exucting the default script (in order to have the idle animation, or a walking animation if the NPC is patrolling).

Below a sample taken from Sarmates!. The floating banter is a bit randomized and issued in French or in English depending on a global variable.

// matrone in palace (recurrent)

void main()
{
    string s;
    if (GetGlobalInt("FR"))
         switch (Random(3))
         {
             case 0 : s = "Dépêchez vous! Le Primus Pilus veut que ses ordres soient transmis avant la fin de la journée!"; break;
             case 1 : s = "Les Daces sont vraiment toutes des feignasses!"; break;
             case 2 : s = "Eh toi, travailles toi au lieu de te faire les ongles!"; break;
         }
    else
          switch (Random(3))
          {
             case 0 : s = "Hurry up! The Primus Pilus wants his orders sent by the end of day!"; break;
             case 1 : s = "Dacians females are all lazy slobs!"; break;
             case 2 : s = "Hey you, work instead of manucuring your nails!"; break;
          }
    SpeakString(s);
    ExecuteScript("nw_c2_default1", OBJECT_SELF);
}

Modifié par Claudius33, 01 septembre 2013 - 07:59 .


#3
K Kin

K Kin
  • Members
  • 109 messages
// matrone in palace (recurrent)

void main()
{    
        string s;
        if (GetGlobalInt("ENG"))
             switch (Random(4))
               {              
                   case 0 : s = "We are the rightous ones.."; break;
                   case 1 : s = "..in his eyes."; break;
                   case 2 : s = "And let us smite these monsters.."; break;
                   case 3 : s = "..unto their deaths"; break;
               }
       SpeakString(s);   
       ExecuteScript("nw_c2_default1", OBJECT_SELF);
}



I'm a noob at programming, but would you say this is right :P 

Save & compile, then add script to the NPC's heartbeat slot

Modifié par K Kin, 01 septembre 2013 - 11:08 .


#4
Claudius33

Claudius33
  • Members
  • 258 messages
You don't need to test the language, (my mods are bilingual). Morever you must remove the test, because it will always returns FALSE, unless you have set a specific global variable, useless for an English only mod. Remove the line, save and compile then attach it to the hearbeat slot.

 // your own comment

void main()
{     
        string s;
        switch (Random(4))
        {              
                   case 0 : s = "We are the rightous ones.."; break;
                   case 1 : s = "..in his eyes."; break;
                   case 2 : s = "And let us smite these monsters.."; break;
                   case 3 : s = "..unto their deaths"; break;
         }
       SpeakString(s);    
       ExecuteScript("nw_c2_default1", OBJECT_SELF);
}




Modifié par Claudius33, 01 septembre 2013 - 11:22 .


#5
K Kin

K Kin
  • Members
  • 109 messages
I tested it after posting and all the npcs (forgot they all had nw_c2_default1 lol) and they all spoke, but showed no text.

Thanks for the help, ill test it now :)

#6
K Kin

K Kin
  • Members
  • 109 messages
Posted Image

Having the problem where both messages pop up every heartbeat, and multiple times, any idea :C?

#7
rjshae

rjshae
  • Members
  • 4 491 messages
Instead of embedding the conversation strings in a script, I just use ActionSpeakOneLiner("conversation_name").

In the conversation, you can use a series of one liners, all but the last with a 'gc_rand_1of' condition (set up per the script's notes).

#8
Claudius33

Claudius33
  • Members
  • 258 messages
Could you post your script as you have set it?

By the way, do you want to have
  • the 4 lines in sequence once, one by one?
  • the for lines in sequence many times (ie every heartbeat), one by one?
  • one line picked randomly once?
  • one line picked randomly many times?


#9
K Kin

K Kin
  • Members
  • 109 messages
I want it so that;

case 0 : s = "We are the rightous ones.."; break;
case 1 : s = "..in his eyes."; break;
case 2 : s = "And let us smite these monsters.."; break;
case 3 : s = "..unto their deaths"; break;

They are in order and spoke every 6 seconds such as:

Case 1 first;

Case 2 after seconds, and so on..

Then (in the future) ill add more lines, so in reality, it'll be like 10 cases.

All play in order with the 6 seconds apart, and then repeat again once all lines are spoken.

My current script is (wanted to test it, so its not full):


// your own comment

void main()
{
string s;
switch (Random(4))
{
case 0 : s = "We are the rightous ones.."; break;
case 1 : s = "..in his eyes."; break;
case 2 : s = "And let us smite these monsters.."; break;
case 3 : s = "..unto their deaths"; break;
}
SpeakString(s);
ExecuteScript("npctalk1", OBJECT_SELF);
}

(Changed it back from what u see in the pic)

#10
andysks

andysks
  • Members
  • 1 650 messages
rjshae I tried this as well but failed. I looked into the OC and they also use it like that, when the people have to evacuate the city for example. When I tried to do it it was not working... could you explain what exactly you do? Because so far I also use heartbeats but they tend to be kinda sloppy sometimes if the string is too big and then he needs to go to the next one... and stuff like that.

#11
Claudius33

Claudius33
  • Members
  • 258 messages
Sorry for the late answer, back at work today.
You musn't call your own script by ExecuteScript, you are creating a loop, that explain why lines are displayed again and again. You must call the NWN2 default script instead.

To do what you want you need also a counter to display line 0 during the first heartbeat then line 1 during the second heartbeat and so on. Use a local integer variable attached to the NPC. Let's call it "Counter". Although not mandatory because 0 is default value, it's a good habit to set the variable in the NPC properties. When the counter reaches 3, reset it to 0.

The script should look now :

// your comment

void main()
{
        object oNPC = OBJECT_SELF;
        int c = GetLocalInt(oNPC, "Counter");        // read the counter

        switch©                                  // display the corresponding line
       {          
                   case 0 : s = "We are the rightous ones.."; break;
                   case 1 : s = "..in his eyes."; break;
                   case 2 : s = "And let us smite these monsters.."; break;
                   case 3 : s = "..unto their deaths"; break;
        }
       
        c++;                           // increment counter
        if (c > 3) c = 0;         // loop back when all lines exhausted
        SetLocalInt(oNPC, "Counter", c);                      // store the counter
        ExecuteScript("nw_c2_default1", oNPC);       // execute NWN2 default script
}

Modifié par Claudius33, 02 septembre 2013 - 06:38 .


#12
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 592 messages
I would just use conversations to do this. I have examples of vendors shouting out specific lines in my Silverwand Sample Campaign.

Regards

#13
K Kin

K Kin
  • Members
  • 109 messages
I'm a noob at variables aswell ;3

Thanks for the help so far Claudius, but i have no idea what to do on this bit >_<

Posted Image

#14
Claudius33

Claudius33
  • Members
  • 258 messages
@K Kin
Click ok, the variable is attached to your NPC (the properties panel will show it).
Now replace the heartbeat script by yours and you should be set.

@Kaldor,

Sure, you can do that ( one line shooted in sequence and repeat) with a convo, testing the counter on each convo line, and incrementing it (or resetting it to 0). Nevertheless you still need a heartbeat script to fire the convo every heartbeat.

Of course both method have their pros and cons.

#15
K Kin

K Kin
  • Members
  • 109 messages
This is what it looks like now, but he doesn't talk in-game.

(With the list of scripts, i use the bold one, but i've clicked off it to show its bold)


 Posted Image

--

Posted Image

--

Posted Image

#16
Claudius33

Claudius33
  • Members
  • 258 messages
K Kin, naming your own script nw_c2_default1 is not not good at all, you are overriding the default script killing the heartbeat standard script.

Name it with another name (personally i put a prefix related to my mod name, for instance sm for Sarmates! to differentiate my scripts from the NWN2 scripts. Let's say mm (my mod) for now, so something like mm_npc_talk, rename the script, save and compile, then attach it on the OnHearbeat slot.

Edit : I have just noticed that the line string s; is missing (my mistake), insert it before the int c = ... line.

Modifié par Claudius33, 05 septembre 2013 - 07:18 .


#17
K Kin

K Kin
  • Members
  • 109 messages
// HAM Deacon

void main()
{
         object oNPC = OBJECT_SELF;
         string s;
         int c = GetLocalInt(oNPC, "Counter"); // read the counter

         switch© // display the corresponding line
         {
                      case 0 : s = "We are the rightous ones.."; break;
                      case 1 : s = "..in his eyes."; break;
                      case 2 : s = "And let us smite these monsters.."; break;
                      case 3 : s = "..unto their deaths"; break;
         }

        c++; // increment counter
        if (c > 3) c = 0; // loop back when all lines exhausted
        SetLocalInt(oNPC, "Counter", c); // store the counter
        ExecuteScript("nw_c2_default1", oNPC); // execute NWN2 default script
        }


Is my final script, with it not being overriding the default one this time, it's not working at all (He isn't speaking at all) :/

Modifié par K Kin, 05 septembre 2013 - 08:40 .


#18
Claudius33

Claudius33
  • Members
  • 258 messages
I'm really sorry, my fault again, I had to work for the office very late yesterday and today and didn't pay attention enough.

The line SpeakString(s);  is missing. It explains why the character doesn't talk.

Just put before the ExecuteScript line

Modifié par Claudius33, 05 septembre 2013 - 08:55 .


#19
K Kin

K Kin
  • Members
  • 109 messages
Thanks a lot for the help and putting up with my newbieness :P Please dont blame yourself.

In the future, if i were to add new lines, would i just add another case, like;

case 4 : s = "blah blah blah;

and edit the 3, to 4;

if (c > 3) c = 0;

#20
Claudius33

Claudius33
  • Members
  • 258 messages
Yes, exactly.