Author Topic: How to make Monsters say multiple things in combat?  (Read 463 times)

Legacy_Vhaeraun Baenre

  • Jr. Member
  • **
  • Posts: 71
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« on: December 12, 2010, 07:45:30 am »


               on the FAQ there is this:

) First, build the NPCs conversation useing these guild lines.

+Root
[line1]NPC - "Say my greeting when I perceive a PC"
[line2]NPC - "Say my Battle cry if I'm attacked!"
[line3]NPC - "Start my normal conversation here."

NOTE: Line 1 and Line 2 CAN NOT have a PC response on them.

In
the convo editor, select line one. In the "Text Appears When" script
box, drop down the menu and select the script named "nw_d2_gen_check".
Click on line 2 and in the same "Text Appears When" script node, select
the script named "nw_d2_gen_combat". Make sure Line 1 is at the top, and
line 2 is just underneath. Save the convo.

Now, open the
properties for the NPC. Go to the Scripts TAB and click "Edit" in the
OnSpawn script. Uncomment (remove the 2 "//") these 2 lines,
SetSpawnInCondition( NW_FLAG_SPECIAL_CONVERSATION);
SetSpawnInCondition( NW_FLAG_SPECIAL_COMBAT_CONVERSATION);

Resave the script with a new name and be sure it is attached to the NPCs OnSpawn script node.

The
NPC should say his greeting (line 1) when he sees a PC. He will repeat
this line each time a PC is perceived. If he is attacked, he should say
his combat saying (line 2).

NOTE: If the NPC is already a Hostile
creature, Line 1 should be a battle cry, something like "ATTACK!" or
"CHARGE!" as he will only say this once OnPerception. Line 2 will repeat
during combat.


Which is great if I simply wanted a monster to say something as a battle cry and then repeat another saying while in combat. What I need is the option to have a random pool of sayings that the mob could say.

Example:
Zombies that could say:
"Brainssssss"
"Uuuuuhhhhhnn"
"Brains!"



simple way to do this?
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #1 on: December 12, 2010, 01:19:47 pm »


               Personally I would use a custom Heartbeat script on the creatures in question and forget the tutorial directions you quoted.

Something like this:

void main()
{
object oSelf = OBJECT_SELF;

// If creature is not currently in combat, just do the normal Heartbeat Script and that's it
if(!GetIsInCombat(oSelf))
      {
      ExecuteScript("nw_c2_default1", oSelf);
      return;
      }

// If creature is in combat, do the rest of this script
string sSpeak;

int nRand = d3(); // Roll a single 3 sided die and note the result
switch (nRand)
      {
      case 1 : sSpeak = "Brainssssss"; break; // If die roll result was a 1
      case 2 : sSpeak = "Uuuuuhhhhhnn"; break; // If die roll result was a 2
      case 3 : sSpeak = "Brains!"; break; // If die roll result was a 3
      }
 
// Speak the line randomly chosen above 
AssignCommand(oSelf, SpeakString(sSpeak));

// Execute the default Heartbeat script so the creature does the other stuff it should
ExecuteScript("nw_c2_default1", oSelf);
}

You can add in more randomly chosen lines by changing the die roll in the line int nRand = d3();  to a different die, and then add in more "case" lines using the same format I have there.

Also, make sure that "nw_c2_default1" is in fact the default heartbeat script for creatures in NWN1 (I looked in NWN2 for the script name so might be different).

Script above not tested in game, but should compile with no problems. The creatures will say a random line every 6 seconds they are in combat.
               
               

               


                     Modifié par _Knightmare_, 12 décembre 2010 - 01:25 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #2 on: December 12, 2010, 03:13:34 pm »


               Mostly I use the voicesets for this kind of thing, although I do have a few npc's who do random speak strings like ondamaged: 'Mother was right, I should have never left home.' Or

Screenshot: http://nwvault.ign.c...ge.php?id=64580

In answer to your respawning door question:

http://nwvault.ign.c....Detail&id=3020
               
               

               


                     Modifié par ffbj, 12 décembre 2010 - 03:42 .
                     
                  


            

Legacy_Alupinu

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #3 on: December 12, 2010, 04:54:22 pm »


               Knightmare! Stealing that script! Thanks. '<img'>
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #4 on: December 12, 2010, 05:33:51 pm »


               Another coolio thing to do on zombies is have them stop when a player gets knocked down and have yourself a little yummy time complete with soundeffects and gore....



You can have the zombies even do a Walker type and ignore everything else with some randomness and eat the fallen guy vs attack the still standing ones.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #5 on: December 12, 2010, 06:03:30 pm »


               

Alupinu wrote...

Knightmare! Stealing that script! Thanks. '<img'>


LOL, no problem - enjoy!

Personally, when I do something along these lines, I don't want the creature to ALWAYS say a line EVERY round. So, I just add in a further random check which alters part of my code above:

void main()
{
object oSelf = OBJECT_SELF;

// If creature is not currently in combat, just do the normal Heartbeat Script and that's it
if(!GetIsInCombat(oSelf))
      {
      ExecuteScript("nw_c2_default1", oSelf);
      return;
      }

// If creature is in combat, do the rest of this script

string sSpeak;

int nChance = Random(100 +1); // Roll a random percentage between 1 and 100

if(nChance <= 25) // If random chance roll is less than or equal to 25%
     {
     int nRand = d3(); // Roll a single 3 sided die and note the result
     switch (nRand)
           {
           case 1 : sSpeak = "Brainssssss"; break; // If die roll result was a 1
           case 2 : sSpeak = "Uuuuuhhhhhnn"; break; // If die roll result was a 2
           case 3 : sSpeak = "Brains!"; break; // If die roll result was a 3
           }
     // Speak the line randomly chosen above 
     AssignCommand(oSelf, SpeakString(sSpeak)); 
     }

// Execute the default Heartbeat script so the creature does the other stuff it should
ExecuteScript("nw_c2_default1", oSelf);
}

That way each creature has a 25% chance per round of combat (ie. every 6 seconds) of speaking a random line. That percentage chance can be changed easy by just editing the "25" value in the line if(nChance <= 25)  to whatever percentage you want. If the Random roll is greater than 25, they will just do the normal Heartbeat stuff and not say anything that specific round.
               
               

               


                     Modifié par _Knightmare_, 12 décembre 2010 - 06:25 .
                     
                  


            

Legacy_Alupinu

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #6 on: December 12, 2010, 06:32:08 pm »


               Play tested Knightmares script. Works great! Except my creatures where a little too chatty. (LOL) Solution, add a couple of blank lines. 3 blank lines out of 6 lines gives my creature a 50% chance of saying something each heart beat.



I guess I could have set up the script as a conditional to only fire 50% of the time but I hate trying to set up conditionals they always get me confused.

               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #7 on: December 12, 2010, 06:33:16 pm »


               

Alupinu wrote...

Play tested Knightmares script. Works great! Except my creatures where a little too chatty. (LOL) Solution, add a couple of blank lines. 3 blank lines out of 6 lines gives my creature a 50% chance of saying something each heart beat.

I guess I could have set up the script as a conditional to only fire 50% of the time but I hate trying to set up conditionals they always get me confused.


Check my post right before your here.'Image
               
               

               
            

Legacy_Alupinu

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #8 on: December 12, 2010, 06:33:36 pm »


               LMAO! Great minds think alike!
               
               

               
            

Legacy_Vhaeraun Baenre

  • Jr. Member
  • **
  • Posts: 71
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #9 on: December 12, 2010, 06:49:57 pm »


               ffbj:  the ondamaged chat is a brilliant idea.. i will have to do that too





Knightmare: Thanks for the script! but wouldnt so many onheartbeat scripts make my module too laggy? its planned to be a large PW and i want a vast majority of the monsters to be able to say random things during combat



oh and thanks for adding the option for them to have a chance to say nothing at all, i forgot to ask for that too '<img'>
               
               

               
            

Legacy_Alupinu

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #10 on: December 12, 2010, 07:05:31 pm »


               Yes the percent conditional seems to be the final touch. Thanks again Knightmare. Play testing showed the script to work fine. But for my scenario I set it to 30%, I have chatty zombies. LOL
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #11 on: December 12, 2010, 07:07:39 pm »


               

Vhaeraun Baenre wrote...

Knightmare: Thanks for the script! but wouldnt so many onheartbeat scripts make my module too laggy? its planned to be a large PW and i want a vast majority of the monsters to be able to say random things during combat

oh and thanks for adding the option for them to have a chance to say nothing at all, i forgot to ask for that too '<img'>


Every creature in your module is already running a heartbeat script every round anyway by default as long as they are existing in the module.  We're just replacing that script with another one.
               
               

               
            

Legacy_Alupinu

  • Newbie
  • *
  • Posts: 14
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #12 on: December 12, 2010, 07:20:35 pm »


               Wait! This is NWN1? Well... the script works well in NWN2 as well.  '<img'>
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
How to make Monsters say multiple things in combat?
« Reply #13 on: December 12, 2010, 09:15:53 pm »


               

Alupinu wrote...

Wait! This is NWN1? Well... the script works well in NWN2 as well. '<img'>


Lol, well yeah, the vast majority of scripts will work for both games. 'Image