Jump to content
Sign in to follow this  
Petethegoat

Name a unit, then use that name in trigger activation

Recommended Posts

_this disableAI "MOVE"; 

_trg = createTrigger["EmptyDetector", getPos _this];
_trg setTriggerStatements["this", "[b][color="#B22222"]_this[/color][/b] enableAI 'MOVE'", ""];

This is how my code would ideally look. This doesn't work though, because the created trigger can't use the _this variable when it's activated because of scope.

I planned to solve this by giving each unit a random vehicleVarName in the script, and then using that name in the trigger, but I can't get a static var name version of the random name I give each unit.

What I need is a way for multiple created triggers to point at specific units, without manual setup in the editor. I want something equivalent to naming a unit in the editor, and then using their name within a trigger.

e:

Here's my non-functional attempt:

pg_globalName= str random 100000;
_unit setVehicleVarName pg_globalName;

_trg setTriggerStatements["this", "missionNamespace getVariable pg_globalName enableAI 'MOVE';", ""];

I'm not totally sure why this doesn't work.

e:

Here's my original script in full (with the scope issues)

_unit = _this select 0;
_enemy = _this select 1;   //"EAST" "WEST" "GUER" "CIV" "ANY"
_stance = _this select 2;   //"UP" "DOWN" "Middle"
_range = _this select 3;   //trigger radius, in meters
_unit setUnitPos _stance;
_unit disableAI "MOVE"; 
_trg = createTrigger["EmptyDetector", getPos _unit];
_trg setTriggerArea[_range, _range, 0, false];
_trg setTriggerActivation[_enemy, "PRESENT", false];
_trg setTriggerStatements["this", "_unit enableAI 'MOVE'", ""];

e:

Solved this by not using triggers at all. Here's the finished script:

_unit = _this select 0;
_enemy = _this select 1;	//"EAST" "WEST" "GUER" "CIV" "ANY"
_stance = _this select 2;	//"UP" "DOWN" "Middle"
_range = _this select 3;	//trigger radius, in meters
_unit setUnitPos _stance;
_unit forceSpeed 0;

_quit = false;
while{!_quit} do
{
sleep 1;
_nme = _unit findNearestEnemy _unit;
if(_unit distance _nme < _range) then
{
//	_unit enableAI "MOVE";
	_unit forceSpeed -1;
	_quit = true;
}
}

Edited by Petethegoat
Solved.

Share this post


Link to post
Share on other sites

To clarify, I need the trigger to activate when BLUFOR are present, which rules that out for me (so far as I'm aware).

Share this post


Link to post
Share on other sites

Uh, right. I need both at once.

Here's my original script in full (with the scope issues)

_unit = _this select 0;
_enemy = _this select 1;   //"EAST" "WEST" "GUER" "CIV" "ANY"
_stance = _this select 2;   //"UP" "DOWN" "Middle"
_range = _this select 3;   //trigger radius, in meters
_unit setUnitPos _stance;
_unit disableAI "MOVE"; 
_trg = createTrigger["EmptyDetector", getPos _unit];
_trg setTriggerArea[_range, _range, 0, false];
_trg setTriggerActivation[_enemy, "PRESENT", false];
_trg setTriggerStatements["this", "_unit enableAI 'MOVE'", ""];

So the OP is correct, but I need it without using triggerAttachVehicle, ideally. I suppose I could not use triggers at all, and just write the activation myself.

Share this post


Link to post
Share on other sites

Im curious how to set a trigger to fire when one unit is present. Say that unit is named s1. how would I setup the trigger?

Share this post


Link to post
Share on other sites

Petethegoat, this should pass the name of the unit to a trigger

_unit = _this select 0;
_enemy = _this select 1;   //"EAST" "WEST" "GUER" "CIV" "ANY"
_stance = _this select 2;   //"UP" "DOWN" "Middle"
_range = _this select 3;   //trigger radius, in meters
_unit setUnitPos _stance;
missionnamespace setvariable ["unitname",_unit];
_unit disableAI "MOVE"; 
_trg = createTrigger["EmptyDetector", getPos _unit];
_trg setTriggerArea[_range, _range, 0, false];
_trg setTriggerActivation[_enemy, "PRESENT", false];
_trg setTriggerStatements["this", "(missionnamespace getvariable 'unitname') enableAI 'MOVE'", ""];

or you can make the name work like any other named unit, just pass the name to the script

null=[this,"west","down",20,"whatever"] execvm "trigtest.sqf"

_unit = _this select 0;
_enemy = _this select 1;   //"EAST" "WEST" "GUER" "CIV" "ANY"
_stance = _this select 2;   //"UP" "DOWN" "Middle"
_range = _this select 3;   //trigger radius, in meters
_name = _this select 4; // name the unit

_unit setUnitPos _stance;

_unit setVehicleVarName _name;
call compile format["%1 = _unit", _name];

_unit disableAI "MOVE"; 
_trg = createTrigger["EmptyDetector", getPos _unit];
_trg setTriggerArea[_range, _range, 0, false];
_trg setTriggerActivation[_enemy, "PRESENT", false];
_trg setTriggerStatements["this", "whatever enableAI 'MOVE'", ""];

Share this post


Link to post
Share on other sites
Here's my non-functional attempt:

pg_globalName= str random 100000;
_unit setVehicleVarName pg_globalName;

_trg setTriggerStatements["this", "missionNamespace getVariable pg_globalName enableAI 'MOVE';", ""];

I'm not totally sure why this doesn't work.

Your problem is that you're passing the value of pg_globalName (an object) to the getVariable command instead of the name of the variable. you need missionNamespace getVariable "pg_globalName";

Also, regular assignment uses the mission namespace, so

pg_globalName = _unit;

and

pg_globalName enableAI "MOVE";

will do.

And if you need to just detect the distance in a circle, it's easier to just script it yourself, instead of relying on a trigger.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×