Gather Data addAction

Arma3 v1.50
Here’s a method for collecting “data” to complete a task in ArmA 3 using some new commands which make this process so much easier than in ArmA 2. This assumes that you have set a task called getDataTask either via scripting or by placing down a CreateTask module.

First place your object. By default we’ll only remove the addAction from the object once the data is collected however the script also supports an option to delete the object. Use of the new remoteExec command means that this is multiplayer compatible without lots of tricks or extra code!

object’s init field:

this addAction ["Gather Data", "data.sqf", ["getDataTask"]];

This will add an action to the object allowing the player to use the item to gather data from it. “getDataTask” is the name of the task we’ll complete. data.sqf is the script which will run.


// this addAction ["Gather Data", "data.sqf", ["getDataTask"]]; 
// ["getDataTask", true] to optionally delete object.

// Grab input.
params ["_object", "_caller", "_id", "_args"];

// Grab arguments, task name String and optional Boolean to delete object.
_taskID = _args param [0];
_deleteObject = _args param[1, false];

// Remove addAction from object.
[_object, _id] remoteExec ["removeAction", 0, true];

// Have Base call out who found the intel.
[[side _caller, "base"], format["%1 gathered the data!", name _caller]] remoteExec ["sideChat", 0, true];

// Succeed the task.
[_taskID, "Succeeded", true] remoteExec ["BIS_fnc_taskSetState", 0, true];

// If optional delete flag set, remove the object where it's local.
if (_deleteObject) then {
	_object remoteExec ["deleteVehicle", _object];

The first two lines are comments showing how to use the script. To optionally delete the object change the arguments array to include the true statement as shown on the second line.

The input section is where we capture all the input from the addAction command and shows the use of the new (from v1.48) params and param commands. Here’s a comparison of the ArmA 2 vs ArmA 3 versions of this code:

ArmA 2:

private ["_object", "_caller", "_id", "_args", "_taskID", "_deleteObject"];
_object = _this select 0;
_caller = _this select 1;
_id = _this select 2;
_args = _this select 3;
_taskID = _args select 0;
_deleteObject = if (count _args > 1) then {_args select 1} else {false};

ArmA 3:

params ["_object", "_caller", "_id", "_args"];
_taskID = _args param [0];
_deleteObject = _args param[1, false];

I love how much more compact the new code is!

One of the main problems with using addAction is that it’s effects are local, meaning things you did in the script would only apply to the player who activated the addAction. This meant that to remove an action you had to find a way to remove it on all players which was often headache causing. With the introduction of remoteExec commands with ArmA 3 version 1.50 it’s now very simple to do just that!

For the rest of the script all the commands will be executed via remoteExec to make sure all players execute the commands even though they were run from a local addAction. Here’s a comparison of how the remoteExec command works:

Previously you’d have to run this on all clients:

_object removeAction _id; 

Now the 0 on the right side means this will be run on all clients.

[_object, _id] remoteExec ["removeAction", 0, true];

Later on we use another feature of the remoteExec to delete an object where it’s local, again letting a local addAction control something nonlocal.

// Notice the 0 from before is replaced with an object, so only runs where _object is local
_object remoteExec ["deleteVehicle", _object];

In the script we also use some commands to make the “base” of whichever side found the items call out the name of the player who found it and use the BIS_fnc_setTaskState function to display a notification of the task succeeding and marking it as completed.

There’s been a ton of great new commands for ArmA 3 which really makes things a lot easier to code.

  1. No comments yet.
(will not be published)