Jump to content
Sign in to follow this  
jakkob4682

how to? create triggers from an array, and then assign a unique variable name to each

Recommended Posts

i.e.

using "I" as global variable in a for from loop

for "I" from 0 to (count _array - 1 ) do
{
t = createTrigger _params;
// how do I assign a unique id to each trigger? i.e. t1,t2,t3,t4 etc
}

Share this post


Link to post
Share on other sites

Try this:

for "I" from 0 to ((count _array) - 1) do {missionNamespace setVariable ["t" + (str I), createTrigger _params]};

Share this post


Link to post
Share on other sites

here is the problem I am having,

Using DAC I am trying to create the zones dynamically with an array of locations. The problem I am having is even using

_array = nearestLocations [player,["NameCity","NameVillage"],1500];
for "i" from 0 to (count _array - 1) do
{
_loc = _array select i;
_pos = position _loc;

_t = createTrigger ["EmptyDetector",_pos];
missionNameSpace setVariable ["zone" + (str i),_t];
};

z = missionNameSpace getVariable ("zone" + (str i));
//setTriggerArea and activation
//now the problem is that DAC requires a named zone inside the array passed to the function, which is spawned from the onAct of the trigger, 
when I use the array null = ['z',[i,0,0],[3,1,50,50],[],[],[],[0,6,0,1]] spawn DAC_Zone from z setTriggerStatements ["time >1","null =  ['z',[i,0,0],[3,1,50,50],[],[],[],[0,6,0,1]] spawn DAC_Zone",""] I get an error that there are two zones with the same name even though z refers to each trigger created from the array.
//

Share this post


Link to post
Share on other sites

Unless I'm missing something, z isn't referring to each, it's referring to the last one created. It's outside the cycle and doesn't have a cycle of its own.

Share this post


Link to post
Share on other sites
so would I need to put z in the for from loop then?

--- edit -- mmm, I made a post but had to rethink it because using the Format command will be difficult used in conjunction with setTriggerStatements.

I would think yes, but not certain. Putting it in a loop of it's own could work as well. I know it can be done, just need to think it through. May have to put a loop inside a loop to keep Format from having a fit. It needs special attention when encountering strings inside the format.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

Try this and see if it works:

_array = nearestLocations [player,["NameCity","NameVillage"],3000];
_count = 0;

{
//Get the position
_loc = _array select _count;
_pos = position _loc;

//Set the trigger.
_t = createTrigger ["EmptyDetector",_pos];

//Format the zone variable.
missionNameSpace setVariable [format ["zone%1",_count],_t];
z = missionNameSpace getVariable format ["zone%1",_count];

//Format the trigger statement.
_onAct = format ["null = [z,[%1,0,0],[3,1,50,50],[],[],[],[0,6,0,1]] spawn DAC_Zone;",_count];

//setTriggerArea and activation
z setTriggerStatements ["time >1",_onAct,""];

// Index up for the next zone
_count = _count +1;
} forEach _array;

An issue I ran into was the z variables causing this error to be thrown in .rpt:

Error in expression <null = [17523: <no shape>,[0,0,0],[3,1,50,50],[],[],[],>
 Error position: <<no shape>,[0,0,0],[3,1,50,50],[],[],[],>
 Error Invalid number in expression
Error in expression <null = [17524: <no shape>,[1,0,0],[3,1,50,50],[],[],[],>
 Error position: <<no shape>,[1,0,0],[3,1,50,50],[],[],[],>
 Error Invalid number in expression

debugger didn't like the <no shape> in the zone ID. Don't know if DAC will reject it since 'z' identifies the zone by variable name.

Edited by OpusFmSPol

Share this post


Link to post
Share on other sites

only creates one zone :(. Wondering if there is a function in DAC to create the zones dynamically now.

---------- Post added at 09:32 AM ---------- Previous post was at 08:11 AM ----------

found this, wondering if it will work

// ["nameOfTheZone","nameOfTheScript"] execVM "CreateSector.sqf"
// "nameOfTheScript" = You can start a script if the sector is conquered by friendly units

_sector = call compile (_this select 0);
_callString = _this select 1;

sleep (1 + random 1);

_area = triggerArea _sector;
_id = round (random 10000);

call compile format["sec%1 = createTrigger [""EmptyDetector"",position _sector]",_id];
call compile format["sec%1 setTriggerActivation [""ANY"", ""PRESENT"", true]",_id];
if(((triggerArea _sector) select 2) == 0) then
{
call compile format["sec%1 setTriggerArea [(_area select 0), (_area select 1), 0, true ]",_id];
}
else
{
call compile format["sec%1 setTriggerArea [(_area select 1), (_area select 0), 0, true ]",_id];
};
call compile format["sec%1 setTriggerStatements [""this"", """", """"]",_id];

mySectors = mySectors + [[call compile format["sec%1",_id],_callString]];

Share this post


Link to post
Share on other sites

The single zone could have to do with the range setting. You had 1500 originally; I used 3000 on Utes in order to have Strelka and Kamenyy detected. If you place hint str count _array under the first line, it'll tell you on screen how many town/villages were detected.

--- edit-- Another possibility is this?:

_onAct = format ["null = [""zone%1"",[%1,0,0],[3,1,50,50],[],[],[],[0,6,0,1]] spawn DAC_Zone;",_count];

Edited by OpusFmSPol
the finicky format got me again

Share this post


Link to post
Share on other sites

got it working thanks man. Now to find a way to get DAC working w/ HAC :cool:

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  

×