Author Topic: Making an NPC speak random phrase everytime you approach him  (Read 415 times)

Legacy_Alice24

  • Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Making an NPC speak random phrase everytime you approach him
« on: January 07, 2015, 10:29:34 am »


               

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?



               
               

               
            

Legacy_Alice24

  • Newbie
  • *
  • Posts: 32
  • Karma: +0/-0
Making an NPC speak random phrase everytime you approach him
« Reply #1 on: January 07, 2015, 10:30:32 am »


               

Nevermind, I figured it out '<img'> In the conversation there is a wizard where I can simply pick "Randomness"



               
               

               
            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
Making an NPC speak random phrase everytime you approach him
« Reply #2 on: January 07, 2015, 01:51:33 pm »


               

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.    
  3. 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)

  4.    
  5. Save the file and exit the Conversation Editor. 

  6.    
  7. Set the int variable "X2_USERDEFINED_ONSPAWN_EVENTS" = 2 on the NPC.

  8.    
  9. Create a custom OnUserDefined script for the creature (see example below).

  10.    
  11. 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);"

  12.    
  13. 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
   


//::///////////////////////////////////////////////


//:: Custom User Defined Event

//:: FileName

//:: Copyright © 2001 Bioware Corp.

//:://////////////////////////////////////////////

/*

    If you set an integer on the creature named

    "X2_USERDEFINED_ONSPAWN_EVENTS" then the

    creature will fire a pre- and a post-spawn

    event on itself, depending on the value of that

    variable:

    1 - Fire Userdefined Event 1510 (pre spawn)

    2 - Fire Userdefined Event 1511 (post spawn)

    3 - Fire both events

 

*/

//:://////////////////////////////////////////////

//:: Created By:

//:: Created On:

//:://////////////////////////////////////////////

 

const int EVENT_USER_DEFINED_PRESPAWN = 1510;

const int EVENT_USER_DEFINED_POSTSPAWN = 1511;

 

#include "nw_i0_generic"

 

void main()

{

    int nUser = GetUserDefinedEventNumber();

 

    if(nUser == EVENT_DIALOGUE) // ON DIALOGUE

    {

        // delete one-liner marker here as the action taken script in the conversation file wasn't always allowed to fire.

        DeleteLocalInt(OBJECT_SELF,"X0_CURRENT_ONE_LINER");

 

        int nRandom = d10(); // set the value to be equal to the number of one-liner nodes in the dialog file

        SetLocalInt(OBJECT_SELF,"X0_CURRENT_ONE_LINER",nRandom);

        SpeakOneLinerConversation();

    }

    else if (nUser == EVENT_USER_DEFINED_PRESPAWN)

    {

 

    }

    else if (nUser == EVENT_USER_DEFINED_POSTSPAWN)

    {

SetSpawnInCondition(NW_FLAG_ON_DIALOGUE_EVENT);

    }

}




               
               

               
            
            
            


            

            

                   
                   
                

         



                  
            
            
               
            
            
         
            

                   
  • Retour en haut

  •                    

                   
                   
                   
                   
                

               
         
      
   

      
      
      

      
      

         
      
   






   
   

      
      Retourner dans Builders - Scripting
      
   
   






   

   

      

   

       
          

  •    

          
                


  •          
       

          
                

  •          
       

          

  •    

          

  •    

          

  •    

          

  •    

          

  •    

          

  •    

          

  •    
       

   

   

   








   
   
   
   


   
   
   
   
   
   
   
   
   
   
   

               
               

                                               
  1. The BioWare Forum

  2.                            
                           
                               
  3. BioWare

  4.                            
                           

                               
  5. Legacy Games

  6.                            
                           

                               
  7. Neverwinter Nights

  8.                            
                           

                               
  9. Builders - Scripting

  10.                            
                           

                   

           

           
           

           
               

           
           


           
           

               
               

                       

  •                         'Flux
                       

  •                    
                           
                               

  •                                 Changer le thème
                                   
                               

  •                        
                       
                           

  •                             Français
                               
                           

  •                    
                       
                       
  • Aller en haut

  •                

           





       

           


               

               

                   
                   

                           
  • Website

  •                        
  • Game Patches

  •                        
  • Official DLC

  •                    

               

               

                   
                   

                           
  • Website

  •                        
  • Game Patches

  •                        
  • Official DLC

  •                    

               

               

                   
                   

                           
  • Website

  •                        
  • Game Patches

  •                        
  • Official DLC

  •                    

               

               

                   
                   

                           
  • Website

  •                        
  • Game Patches

  •                        
  • Official DLC

  •                        
  • Toolset

  •                    

               

               

                   
                   

                           
  • Projects

  •                        
  • Groups

  •                        
  • Albums

  •                        
  • Blogs

  •                        
  • Polls

  •                    

               


               

                    EA
                   
© 2016 EA International (Studio and Publishing) Ltd, All Rights Reserved