Jump to content
Kyancyan

(Request) Randomized 'sideChat' result.

Recommended Posts

Hey folks, sorry if this is a duplicate I searched all over, didn't find anything that looked like what I needed. 

I'm working on a little S.T.A.L.K.E.R-esque mission for some friends of mine who are fans of the games, and I was hoping to add some randomized 'sideChat'-based dialogue for them to see as they walked through repeatable triggers centered around groups of AI at the safezones.

I've created an array with all the different sentences of dialogue but I'm utterly clueless on how I would take a randomized sentence from the array and make the [west, "HQ"] sideChat "(randomly-selected dialogue)";  code reference it.
I'm not even sure if dialogue storage is the proper application of arrays but that's what I get for being a scripting novice, so I apologize in advance if this is braindead simple.

Also, if anyone could point me in the right direction as to how to do the same thing to a playSound3D command, that would be excellent - I've got a selection of sounds I'd like to randomly play in hand-picked houses all over the map.

Share this post


Link to post
Share on other sites

Thanks for the swift response, I appreciate it.

Good to know I wasn't too far off at least, I was tinkering with selectRandom but couldn't figure out the syntax. 

Would this be made any easier or simpler if the array was already defined in init.sqf?
Just so each trigger doesn't have to have duplicates of the massive amount of options I've set up.

Share this post


Link to post
Share on other sites
6 hours ago, Kyancyan said:

Would this be made any easier or simpler if the array was already defined in init.sqf?

Yes, if you declared a global variable in the init.sqf it will be available in all other scripts. In that case it would look something like this:

//--- init.sqf
TAG_greetings = ["Hello.", "Hi.", "Good day."];
//--- Wherever you want:
[west, "HQ"] sideChat (selectRandom TAG_greetings);

Your own TAG_ prefix serves the purpose so that your variable is absolutely unique and can not overwrite/be overwritten by the script of another author. I use TER_ for example.

Share this post


Link to post
Share on other sites

Oh and also you could give the Functions Library a shot if you have code that is reused on multiple occasions. It will save you from editing all that code in different places.

  • Like 1

Share this post


Link to post
Share on other sites

Perfect, thanks for all your help 7erra, everything is working perfectly now thanks to you.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×