Aller au contenu

Photo

How to make Monsters say multiple things in combat?


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

#1
Vhaeraun Baenre

Vhaeraun Baenre
  • Members
  • 45 messages
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?

#2
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
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 .


#3
ffbj

ffbj
  • Members
  • 593 messages
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 .


#4
Alupinu

Alupinu
  • Members
  • 528 messages
Knightmare! Stealing that script! Thanks. :)

#5
TSMDude

TSMDude
  • Members
  • 865 messages
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.

#6
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

Alupinu wrote...

Knightmare! Stealing that script! Thanks. :)


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 .


#7
Alupinu

Alupinu
  • Members
  • 528 messages
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.


#8
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

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 IPB

#9
Alupinu

Alupinu
  • Members
  • 528 messages
LMAO! Great minds think alike!

#10
Vhaeraun Baenre

Vhaeraun Baenre
  • Members
  • 45 messages
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 :)

#11
Alupinu

Alupinu
  • Members
  • 528 messages
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

#12
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

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 :)


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.

#13
Alupinu

Alupinu
  • Members
  • 528 messages
Wait! This is NWN1? Well... the script works well in NWN2 as well. :)

#14
_Knightmare_

_Knightmare_
  • Members
  • 643 messages

Alupinu wrote...

Wait! This is NWN1? Well... the script works well in NWN2 as well. :)


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