Home   Help Search Login Register  

Author Topic: How to make AI Say something random?  (Read 1829 times)

0 Members and 1 Guest are viewing this topic.

Offline Landdon

  • Members
  • *
How to make AI Say something random?
« on: 04 Aug 2008, 01:37:37 »
I am working on a mission where a team must infiltrate an area.  One of the things I would to use, to dispel reality is to have the OPFOR say (play a ogg sound file) when they are a set distance or less to the OPFOR AI.   I would assume a trigger, but I am just starting to learn how to script, and I'm not sure how to do this in Arma. I have made the ogg sound files already, after that I'm not sure on how to proceed.  If anyone has the time to provide me with an example could you please post it here.  Thanks! 

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
Re: How to make AI Say something random?
« Reply #1 on: 04 Aug 2008, 04:11:27 »
greetings,

there are many ways to do what you want. the easiest is:

define the sound(s) in the description.ext:
Code: [Select]
// Sounds
class cfgSounds
{
sounds[] = {};

class jet1
{
name = "Jet1";
sound[] = {"\sounds\JetPass.ogg", 0.5, 1.2};
titles[] = {};
};

class valk
{
name = "Valk";
sound[] = {"\sounds\Valk.ogg", 100, 1};
titles[] = {};
};
};

then make sure your sound file(s) are in your mission folder. add a trigger to the area... in the activation line put:

Code: [Select]
playsound "jet1";


but if you want to get really tricky.. i'd suggest you look at wolfrug's awesome DSAI

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to make AI Say something random?
« Reply #2 on: 04 Aug 2008, 10:50:11 »
Loki explained how to define sounds, but missed out the randomness and that an AI had to speak (say), rather than the sound just be played to the player (playsound: played directly without coming from a set position). Assuming you'd named your OPFOR soldier opfor1 and defined three sounds as Loki described (in the example, talk1, talk2 and talk3 classes):

Code: (trigger On Act) [Select]
opfor1 say (["talk1", "talk2", "talk3"] select (floor (random 3)));
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline loki72

  • Former Staff
  • ****
    • Loki's Nightmare
Re: How to make AI Say something random?
« Reply #3 on: 04 Aug 2008, 13:54:02 »
 :whistle:

i didn't know that.

thanks

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: How to make AI Say something random?
« Reply #4 on: 05 Aug 2008, 17:10:15 »
Just a note...

Unless they've changed the random command from OFP to ArmA, you should be aware that the random command is local. This means, that the code Spooner posted will not work fully in multiplayer.

Don't get me wrong, the AI will still say something, problem is just that the unit will very likely say different things on different computers...

Clicky

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to make AI Say something random?
« Reply #5 on: 05 Aug 2008, 17:27:59 »
@Garcia: Yes, that was an oversight on my behalf. I read the title/question, not the forum name :whistle:

You should have linked to my MP scripting tutorial, rather than to the Biki. Would have made me look even more daft ;P There is even an example in there of how to say random things in an MP setting ::)

@Landdon:
Simplest thing to do would be to always play the same sound file. After all, how many times will players play the mission to get bored of the enemies saying the same then when you get near? Anyway, here is a solution that has everyone hearing the same thing (untested, since I'd need to set up sounds and have multiple people playing to prove it worked):

Code: (init.sqf) [Select]
speakHandler =
{
    _speaker = (_this select 1) select 0;
    _sound = (_this select 1) select 1;

    _speaker say _sound;
};

"speak" addPublicVariableEventHandler speakHandler;

// Call with [person, "soundName"] to make person say something for every client.
speakMP =
{
    if (not isServer) exitWith {};

    // Run locally (SP or MP host only)
    ["speak", _this] call speakHandler;

    // Run on clients (MP only)
    speak = _this;
    publicVariable "speak";
};

Code: (Trigger On Act) [Select]
[opfor1, ["talk1", "talk2", "talk3"] select (floor (random 3))] call speakMP;
« Last Edit: 05 Aug 2008, 17:38:21 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Garcia

  • Members
  • *
  • Leeds United is the best football team...EVER!
Re: How to make AI Say something random?
« Reply #6 on: 05 Aug 2008, 22:44:33 »
@Garcia: Yes, that was an oversight on my behalf. I read the title/question, not the forum name :whistle:

You should have linked to my MP scripting tutorial, rather than to the Biki. Would have made me look even more daft ;P There is even an example in there of how to say random things in an MP setting ::)

There's a lot I could do to make you look daft, like adding a example that works in MP ;) But then again, wasn't really much after that :D IMO it's not too important as long as what the AI says is just for athmosphere...even if the mission is played a lot, people would probably not care if the AI said different things on each client :whistle: