Jump to content

How can I make an NPC say a random phrase?


jjws888
 Share

You are about to reply to a thread that has been inactive for 4493 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Just by creating a new script you can create simple NPCs with one line of dialouge, but I want my NPC to say different stuff.

I was wondering what the code would be for a script that makes the object talk on a click, but instead of saying just one thing, it would choose a phrase randomly out of a few lines.

We have this NPC that's addicted to fish, and we want her to say a random fish-related thing each time she's clicked, so how do I do that?

Could someone post or link me a script for such a thing? I can't seem to find one on the marketplace.

 

Thanks in advance!

Link to comment
Share on other sites

You're not going to find a script that does exactly that.  It's a custom application, so it would need to be written specifically for you. We are not here to write scripts or to find them for you, but we can tell you what you'll have to do to write your own, or modify one that you have.  In this case, you need to create a list with interesting phrases and then call them from that list when you trigger the script with a touch, or some other signal.  For example, if you have a list that says

list FishChat = ["I love to go fishing, just for the halibut.", "I'm a sole food man.", "My favorite actress will always be Marlin Monroe."];

you can trigger the phrases randomly from a touch_start event with code like

 

touch_start (integer num){     
list
FishChat = ["I love to go fishing, just for the halibut.", "I'm a sole food man.", "My favorite actress will always be Marlin Monroe."];
integer Choice = (integer)llFrand(llGetListLength(FishChat)); llSay(0, llList2String(FishChat,Choice);}

 Take a look in the LSL wiki to see how the llFrand function and  llList2String and llGetListLength work.  If you don't want to tackle writing this yourself, then I suggest posting a note in the Wanted section of the Commerce forums to find a scripter to hire.

 

Link to comment
Share on other sites

That is quite easy. You make a list of sentences.

list Sentences = ["Blah blah blah","Bleh bleh bleh", "Blih blih blih","Bloh bloh bloh","Bluh bluh bluh"];

 And you pick one at random in the touch() event.

integer i = llFloor(llFrand( (float)llGetListLength(Sentences) ));llSay(0, llList2String(Sentences, i));

 Just like that...

Edit: (And Rolig beat me on the finish line...)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4493 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...