Comrades,
I've been asked before how we do the conversations in our missions. Some people simply use sideChat since that's easiest, but it doesn't allow you to synchronize correctly (you'd need to wait or similar bollocks).
With Alwarren's script it's easy to generate a speech bikb file that contains the sentences that you wish your guys to speak. Here, I wish to explain how the things work in Arma (applies to 2 and 3).
First of all, all characters (player and AI) need to be made aware of their lines. This is done via kbAddTopic. The syntax for this is:
Note that the unit has to be local. I usually do this in the init.sqf, to make sure everyone (all clients and the server) do that. The appropriate line looks like this:
This example adds the topic "speech" to all units that can be played, as well as a unit HQ and the crew of the vehicle Cerberus.
I usually put everything speech related into a "kb" subfolder
The third and fourth array element, handler.fsm and eventhandler, are the handlers that are called when the unit hears a topic. The catch is, the handler.fsm is executed when the unit is an AI, and the eventhandler is executed when the unit is a player. This also means that if you want to have conversation between playable characters, you need to cope with the situation that the character might be currently played by a player, or not (in which case it's an AI).
To make this situation easier to handle, I use a script and an fsm that just "bounce" the incoming data to a combined script, kb\playerChatEvent.sqf. This script has to be executed once in init.sqf to make the code in it available.
The whole init.sqf fragment looks like this:
The bounce.fsm and bounce.sqf scripts are available in the example.zip file attached to this post. They call a function called FHQ_handleSpeech with the following parameters:
_to is the unit that heard the sentence. _from is the speaker (the sender of the sentence). _sentenceId is the name of the sentence, which corresponds to the class name in the bikb. _topic is the topic name ("speech" in our example above.
The usual thing to do when hearing a sentence is to reply with an appropriate line. This is usually done via kbTell (see below). To make things easier, I use a macro defined in playerChatEvent that does that.
Here's an excerpt from an actual playerChatEvent.sqf. The script is run on the machine _to is local to:
it checks if the recipient of the message is the leader of FHQ_playerGroup1 and then selects a reply according to the _sentenceId. Check the example.zip for a larger example.
As mentioned, kbTell is used to say something:
Note that, as usual, kbTell needs to be run on the machine unit is local to. I use the FHQ MP framework for this, but others work as well.
Hope that helps. if you need more information, just ask.
- V
I've been asked before how we do the conversations in our missions. Some people simply use sideChat since that's easiest, but it doesn't allow you to synchronize correctly (you'd need to wait or similar bollocks).
With Alwarren's script it's easy to generate a speech bikb file that contains the sentences that you wish your guys to speak. Here, I wish to explain how the things work in Arma (applies to 2 and 3).
First of all, all characters (player and AI) need to be made aware of their lines. This is done via kbAddTopic. The syntax for this is:
Code:
unit kbAddTopic [topicName, filename.bikb, handler.fsm, eventhandler].
Note that the unit has to be local. I usually do this in the init.sqf, to make sure everyone (all clients and the server) do that. The appropriate line looks like this:
Code:
{
  _x addTopic ["speech", "kb\speech.bikb", "kb\bounce.fsm", compile preprocessFileLineNumbers "kb\bounce.sqf"];
} forEach ((if (isMultiplayer) then {playableUnits} else {switchableUnits}) + [HQ] + crew cerberus);
This example adds the topic "speech" to all units that can be played, as well as a unit HQ and the crew of the vehicle Cerberus.
I usually put everything speech related into a "kb" subfolder
The third and fourth array element, handler.fsm and eventhandler, are the handlers that are called when the unit hears a topic. The catch is, the handler.fsm is executed when the unit is an AI, and the eventhandler is executed when the unit is a player. This also means that if you want to have conversation between playable characters, you need to cope with the situation that the character might be currently played by a player, or not (in which case it's an AI).
To make this situation easier to handle, I use a script and an fsm that just "bounce" the incoming data to a combined script, kb\playerChatEvent.sqf. This script has to be executed once in init.sqf to make the code in it available.
The whole init.sqf fragment looks like this:
Code:
// Add this somewhere in your init.sqf:
// Example: Add topic to all players, an entity called "HQ", and the cew of an AI controlled APC
call compile preprocessFileLineNumbers "kb\playerChatEvent.sqf";
{
  _x addTopic ["speech", "kb\speech.bikb", "kb\bounce.fsm", compile preprocessFileLineNumbers "kb\bounce.sqf"];
} forEach ((if (isMultiplayer) then {playableUnits} else {switchableUnits}) + [HQ] + crew cerberus);
The bounce.fsm and bounce.sqf scripts are available in the example.zip file attached to this post. They call a function called FHQ_handleSpeech with the following parameters:
Code:
_to = _this select 0;
_from = _this select 1;
_sentenceId = _this select 2;
_topic = _this select 3;
_to is the unit that heard the sentence. _from is the speaker (the sender of the sentence). _sentenceId is the name of the sentence, which corresponds to the class name in the bikb. _topic is the topic name ("speech" in our example above.
The usual thing to do when hearing a sentence is to reply with an appropriate line. This is usually done via kbTell (see below). To make things easier, I use a macro defined in playerChatEvent that does that.
Here's an excerpt from an actual playerChatEvent.sqf. The script is run on the machine _to is local to:
Code:
 if (_to == leader FHQ_playerGroup1) then {
   switch (_sentenceId) do {
            replycase("startAns1", _from, "start2");
            replycase("startAns2", _from, "start3");
            replycase("vehicleDown1", _from, "vehicleDownAns1");
     replycase("reachedHome1", _from, "reachedHomeAns1");
   };
 };
it checks if the recipient of the message is the leader of FHQ_playerGroup1 and then selects a reply according to the _sentenceId. Check the example.zip for a larger example.
As mentioned, kbTell is used to say something:
Code:
unit kbTell [receiver, topicName, sentence];
Note that, as usual, kbTell needs to be run on the machine unit is local to. I use the FHQ MP framework for this, but others work as well.
Hope that helps. if you need more information, just ask.
- V