Aller au contenu

Photo

Making an NPC speak random phrase everytime you approach him


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

#1
Alice24

Alice24
  • Members
  • 19 messages

Hi guys. I'd like an NPC to speak a random phrase (from a big collection of possible phrases) each time a player clicks him.

 

How can I make it possible?



#2
Alice24

Alice24
  • Members
  • 19 messages

Nevermind, I figured it out :) In the conversation there is a wizard where I can simply pick "Randomness"



#3
Pstemarie

Pstemarie
  • Members
  • 2 745 messages

The random toggle in the script wizard only sets that particular string to be spoken if a the SC variable is within the random range defined. I think this is more likely what you are looking for:

 

http://forum.bioware...esting-finding/

 

Basically, what you do is

  1. Create a conversation for the NPC that contains several one-line nodes that do NOT have a PC response. Make sure the one-liners are ABOVE any other conversation nodes for the NPC (e.g. if you have a NPC that enters into a conversation with the PC once a quest has been completed). 
  2. For each conversation node you need to assign x0_d2_hen_line## as the SC script (where ## is the number of the node in the file - e.g. node 1 uses x0_d2_hen_line1.nss as its SC script)
  3. Save the file and exit the Conversation Editor. 
  4. Set the int variable "X2_USERDEFINED_ONSPAWN_EVENTS" = 2 on the NPC.
  5. Create a custom OnUserDefined script for the creature (see example below).
  6. Edit the line "int nRandom = d10();" to however many one-liner nodes are in your dialog file. If your number doesn't correspond to a dice function, use the Random function instead: "int nRandom = Random(##);" where ## = the number of one-liners -1 (e.g. if you have 16 one-liners use "int nRandom = Random(15);"
  7. Save the file and exit the Script Editor.

When you click on the creature it will now speak a random line from its conversation file.

 

Note, the example in the other thread is called from the Heartbeat event via the OnUserDefined script. That's because I wanted the NPC to perform random tasks which included spouting off random phrases (i.e. he cusses quite a bit while at work). The script provided below, converts this to a Dialog event and removes the additional coding that modified the NPC's behavior.

 

Spoiler