Arma 3 Scripting

Arma 3: Headless Client

  • Also known as Arma 3 Headless Client

Topic · Markdown · JSON · original wiki page

Multiple Connections and Addresses are allowed in the case of more than one Headless Client

headlessClients[] = { "xxx.xxx.xxx.xxx", ... };

Additionally to define clients with unlimited bandwidth and nearly no latency you must include theirs IPs in the server.cfg too:

localClient[] = { "127.0.0.1", ... };

Headless Clients are rather similar to players:

Spawning the AI

  1. Add a Headless Client entity to the mission:

    1. Add a player unit

    2. Then you can insert a Headless Client unit:

      SIDE: Game Logic, CLASS: Virtual Entities, UNIT: Headless Client, CONTROL: Playable, NAME: somename
      
    3. Don't forget to set NAME property, it is necessary for the Headless Client to work correctly. The name can also be used to identify Headless Clients in scripts (by checking it against player).

    4. Each Headless Client unit will add one Headless Client slot - missions may contain multiple Headless Client units

  2. Create a script that will spawn AI (in the examples below we will use "init_HC.sqf"). To execute it on the Headless Client you have the two following options.

    Execute the script at mission start

    • This method will make your mission spawn the AI only if a Headless Client is present. However it is the most simple to set up.
    1. Add the following to the beginning of init.sqf:

      if (!hasInterface && !isServer) then
      {
          execVM "init_HC.sqf";
      };
      

    Execute the script via a mission parameter

    • If you intend to share your mission this method is more desirable as it means players do not need a Headless Client to play it.
    1. First define a function to be used to run the headless client script file. Here's what it should look like in description.ext:

      class cfgFunctions
      {
          class myTag
          {
              class myCategory
              {
                  class myFunction {};
              };
          };
      };
      

      The reason we want to define a function is because it can be used within the mission parameter framework to execute the AI spawning script as soon as possible while still allowing the mission to reliably work with or without a headless client.

    2. Add the following code to your function:

      if ((_this select 0) == 1) then
      {    // Run on the HC only
          if !(isServer or hasInterface) then
          {
              execVM "init_HC.sqf";
          };
      } else {
          // Run on the server only
          if (isServer) then
          {
              execVM "init_HC.sqf";
          };
      };
      

      This code will be passed the value of the mission parameter defined in the next step, which is where the magic variable _this comes from. It executes the AI spawning script based on the value of the parameter and whether the local machine is the server or a headless client.

    3. Finally define a mission parameter that players can use to enable/disable use of the headless client. Here's what it should look like in description.ext:

      class params
      {
          class headlessClient
          {
              title = "Headless Client";
              texts[] = {"Disabled","Enabled"};
              values[] = {0, 1};
              default = 0;
              function = "myTag_fnc_myFunction";
              isGlobal = 1;
          };
      };
      

The two important values here are "function" and "isGlobal". The function value must correspond to the name of the function defined in step 1. The isGlobal value must be set to 1 so that the function is ran by all machines. This means that the function is executed on any headless clients as well as the server so that it can decide where it is suitable to execute the AI spawning script (based on the value of the parameter).

  1. Repeat step 1 for the amount of Headless Clients your mission is designed to use. For multiple you must use the NAME property from step 1 to identify them individually within init_HC.sqf

Server

  1. add headless client IP address into server.cfg (you can use more than one address):

    headlessClients[] = { "xxx.xxx.xxx.xxx", "xxx.xxx.xxx.xxx", "xxx.xxx.xxx.xxx" };
    
  2. to run Arma 3 Dedicated Server use one of these commands:

    Windows: arma3server.exe -config=server.cfg
    Windows: arma3.exe -server -config=server.cfg
    Linux: arma3server -config=server.cfg
    

Headless Client

  1. to run Arma 3 Headless Client use one of these commands:

    Windows: arma3server.exe -client -connect=xxx.xxx.xxx.xxx -password=yourpass
    Windows: arma3.exe -client -connect=xxx.xxx.xxx.xxx -password=yourpass
    Linux: arma3server -client -connect=xxx.xxx.xxx.xxx -password=yourpass
    
  2. your client will be automatically connected to a free headless client slot

  3. you can run arbitrary number of headless clients on the same machine

Overview of running options

Mods

Headless Clients are excluded from signature verification, therefore any mod can be used with the "-mod=" option.

"-serverMod=" does not work when used alongside "-client".

GUI

See Also