Pascal Lamers Pascal Lamers - 1 year ago 199
C Question

Arma 3 - addAction with dynamic variables to specific Object

Playing around with custom composition spawning in Arma 3. I am currently using "LARs Composition Spawn Script" (https://forums.bistudio.com/forums/topic/191902-eden-composition-spawning/) to spawn a custom compostion. Spawning compositions around the map works like a charm.

In the composition there is one object (AI) whith varname "quest_giver". To this specific Object I want to add an Action. My current code is:

// SPAWN RANDOM COMPOSITION ON RANDOM POSITION
_spawned_composition = [ _random_composition, _pos, [0,0,0], random 360 ] call LARS_fnc_spawnComp;

// GET OBJECTS FROM THE SPAWNED COMP BACK (ARRAY)
_objects = [_spawned_composition] call LARs_fnc_getCompObjects;

// TRYING TO ITERATE THROUGH OBJECTS TO FIND "quest_giver"
// AND ADD ACTION TO IT.
{
_type = typeName _x;
if (_type == "GROUP") then {
_units = units _x;
{
_var = missionNamespace getVariable ["name", _x];
_name = typeOf _var;
if (_name == "quest_giver") then {
player globalChat format["%1",_name];
//_speak = _x addAction ["Speak", {hint format ["Hello, it works !"]}];
};
} forEach _units;
};
} forEach _objects;


Error at
If(_name == "quest_giver")
where _name is an OBJECT but "quest_giver" of course a STRING. So I get
Error Generic error in expression
.

However, _var = missionNamespace getVariable ["name",_x]; returns "quest_giver". But it as an OBJECT, since typeOf _var returns "OBJECT" not STRING.

I just can't figure out the most simpliest thing here I guess. Any idea, if this would even work in theory ?




What I am trying to achieve


  • Create various custom compositions, where on Object in it is always the "quest_giver". Works so far.

  • Choose random comp and spawn it on random position in the world. Works so far.

  • Add action to the quest giver so player can speak to him. Text Pop up with simple text, content would be a random quest ala bring me 5 x Water Bottles.



I know my way around before and after the add action part but can't figure out how to add action to this specific object. ...

Answer Source

unless I'm mistaken, you seem to be confused about how to get the unit's name? it might be you want to get a name var from the unit's namespace (if the thing you're using does put it there):

_name = _x getVariable ["name" /*var name*/, "" /*default value*/]; 
if (_name == "quest_giver") then { 
//...

or more likely (if it's about the name set via editor) with the name function:

if ((name _x) == "quest_giver") then {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download