Jump to content
Sign in to follow this  
blasturbator

Tug'o'war style trigger

Recommended Posts

So i'm trying to get the trigger created by the following function to change a marker from red to green when all opfor units are eliminated and blufor are present, and from green to red if opfor enter the area again.

the function:

SL_fnc_createTriggers = {
private ["_markers","_pos","_trigE"];

{
	_pos = getMarkerPos _x;
	_trigE = createTrigger ["EmptyDetector", _pos ];
	_trigE setTriggerActivation ["ANY", "PRESENT", true];
	_trigE setTriggerArea [50, 50, 0, true];
	_trigE setTriggerStatements ["{(side _x) == resistance} count thisList == 0 AND {(side _x) == west } count thisList >= 1", format["""%1"" setMarkerColor ""ColorGreen"";",_x], ""];

} foreach _this;

};

The key area here is obviously this line:

_trigE setTriggerStatements ["{(side _x) == resistance} count thisList == 0 AND {(side _x) == west } count thisList >= 1", format["""%1"" setMarkerColor ""ColorGreen"";",_x], ""];

At the moment the trigger makes the marker turn green the moment any blufor enter regardless of the number of opfor and stays that way regardless of the opfor presence, needless to say, this defeats the object of these triggers. My initial idea was to change the activation parameter to contain an if statement but to be honest i don't fully understand how these triggers work or if that is even possible :eek:

I would just blindly experiment but testing these things requires quite a bit of effort so i thought I'd see if any of you more experienced fellows could lend your brains to the cause?

Share this post


Link to post
Share on other sites

In general terms, the solution would be to add a second trigger.

Looking at the one there, it is set to fire when there are no "resistance" troops (independent, not opfor), and at least one "west" troop (now also known as blufor for consistency, so i recommend changing that too).

What you need is a trigger to fire when there are 1 or more "opfor" troops that changes the thing red. Then, another trigger, which fires when there are 0 opfor troops, to change the marker green.

The trigger to turn the marker red must only do so when the marker is not already red, so I would add global variables or find a way to otherwise check the marker color for each trigger. And, of course, the green trigger should only fire when the marker IS red.

In the syntax you provided,

{(side _x) == resistance} count thisList == 0 AND {(side _x) == west } count thisList >= 1

represents the "conditions" of the trigger - what circumstances under which it will fire, so you want to formulate these sections based on the above constraints.

format["""%1"" setMarkerColor ""ColorGreen"";",_x]

defines a string of code that executes when the trigger is executed, with the _x going into the place marked %1 and being part of the "foreach" statement enclosing the whole block. (_x represents the current iteration's corresponding array element)

I realize this is a lot to take on, but you will learn so much by working this out yourself that I hesitate to try and solve it myself. :cool:

Share this post


Link to post
Share on other sites

So taking what you said into account then firing wildly into the dark, this is my first plan xD

SL_fnc_createTriggers = {
   private ["_markers","_pos","_trigE"];

   {
       _pos = getMarkerPos _x;
       _trigE = createTrigger ["EmptyDetector", _pos ];
       _trigE setTriggerActivation ["ANY", "PRESENT", true];
       _trigE setTriggerArea [50, 50, 0, true];
       _trigE setTriggerStatements ["{(side _x) == east} count thisList == 0 AND {(side _x) == west } count thisList >= 1", format["""%1"" setMarkerColor ""ColorGreen"";",_x], ""];
	_trigE = createTrigger ["EmptyDetector1", _pos ];
       _trigE setTriggerActivation ["ANY", "PRESENT", true];
       _trigE setTriggerArea [50, 50, 0, true];
       _trigE setTriggerStatements ["{(side _x) == west} count thisList == 0 AND {(side _x) == east } count thisList >= 1", format["""%1"" setMarkerColor ""ColorRed"";",_x], ""];

   } foreach _this;

}; 

I pretty much already know this won't work... It looks far too simple x)

Would a check to see if it is already a certain colour really be necessary? changing from red to red doesn't seem like it'd break anything.

That said if i changed this line in both

        _trigE setTriggerActivation ["ANY", "PRESENT", true];

to this line in both

        _trigE setTriggerActivation ["ANY", "PRESENT", false];

And found a way to make one trigger reset another trigger, they could alternate nicely.

Edited by Blasturbator

Share this post


Link to post
Share on other sites

Well, the condition to change it from green to red was, I thought, for any OPFOR at all to be present, regardless of BLUFOR, so that condition would need slightly adjusted ;)

Anyway, the thing you said about making one trigger reset another is exactly why I was suggesting to check if the marker had already changed color in the trigger conditions. Basically triggers are either one-off, or infinitely repeatable (according to their standard behavior, anyway). Thus we would use infinitely repeatable triggers, but be more selective about what it takes to trigger them :)

Sorry it's really late and I don't have much time to look over this but if I get a chance tomorrow I will return.

Share this post


Link to post
Share on other sites

With colCheck = false in a game logic

SL_fnc_createTriggers = {
   private ["_markers","_pos","_trigE"];

   {
       _pos = getMarkerPos _x;
       _trigE = createTrigger ["EmptyDetector", _pos ];
       _trigE setTriggerActivation ["ANY", "PRESENT", true];
       _trigE setTriggerArea [50, 50, 0, true];
       _trigE setTriggerStatements ["{(side _x) == east} count thisList == 0 AND {(side _x) == west } count thisList >= 1 AND (!colCheck)", format["""%1"" setMarkerColor ""ColorGreen"";",_x] colCheck = true, ""];
	_trigE = createTrigger ["EmptyDetector1", _pos ];
       _trigE setTriggerActivation ["ANY", "PRESENT", true];
       _trigE setTriggerArea [50, 50, 0, true];
       _trigE setTriggerStatements ["{(side _x) == east } count thisList >= 1 AND colCheck", format["""%1"" setMarkerColor ""ColorRed"";",_x] colCheck = false, ""];

   } foreach _this;

}; 

Should serve as a decent check, I didn't know how to format it properly though, i put (!colCheck) to mean colCheck = false but im not sure thats how it works. The problem with this though, is that this function creates more than one of these so having colCheck in a game logic wouldn't work... i'd have to make it a private var?

SL_fnc_createTriggers = {
   private ["_markers","_pos","_trigE","colCheck"];

   {
	colCheck = false;
	_pos = getMarkerPos _x;
       _trigE = createTrigger ["EmptyDetector", _pos ];
       _trigE setTriggerActivation ["ANY", "PRESENT", true];
       _trigE setTriggerArea [50, 50, 0, true];
       _trigE setTriggerStatements ["{(side _x) == east} count thisList == 0 AND {(side _x) == west } count thisList >= 1 AND (!colCheck)", format["""%1"" setMarkerColor ""ColorGreen"";",_x] colCheck = true, ""];
	_trigE = createTrigger ["EmptyDetector1", _pos ];
       _trigE setTriggerActivation ["ANY", "PRESENT", true];
       _trigE setTriggerArea [50, 50, 0, true];
       _trigE setTriggerStatements ["{(side _x) == east } count thisList >= 1 AND colCheck", format["""%1"" setMarkerColor ""ColorRed"";",_x] colCheck = false, ""];

   } foreach _this;

}; 

Like that maybe?

Edited by Blasturbator
code mistake

Share this post


Link to post
Share on other sites

Been a couple of weeks and i still haven't got around to making this work, can anyone give me a hand?

Share this post


Link to post
Share on other sites

colCheck shouldn't be declared private; it's not a private variable. Also, the "on activation" part of the trigger statements should be

format["""%1"" setMarkerColor ""ColorRed"";[b] colCheck = false"[/b],_x], ""];
or
format["""%1"" setMarkerColor ""ColorRed"";",_x][b] +" colCheck = false"[/b], ""];

Maybe that helps?

Share this post


Link to post
Share on other sites

Well it helped me fix one of the bugs at least :)

I think colCheck does need to be private because lots of these triggers are generated around the map it isnt just one, so if colCheck was public wouldnt any one of those triggers change the value for the others as well?

this is the current line i'm testing (which is a pain because doing this in sp takes forever)

        _trigE setTriggerStatements ["{(side _x) == OPF_F} count thisList == 0 AND {(side _x) == west } count thisList >= 1 AND colCheck = false", ""format["""%1"" setMarkerColor ""ColorGreen""; colCheck = true; waitUntil {(side _x) == east } count thisList >= 1 AND colCheck = true; format["""%1"" setMarkerColor ""ColorRed""; colCheck = false;", ""];

Share this post


Link to post
Share on other sites

Wouldn't sector control modules be better for this, I don't like using triggers for counting units from multiple side it take forever to get right.

I found an old script from A2 I used to produce something similar to what your after, maybe.

It doesn't have markers but that should be easy to fix, just change the hints to markers and colors.

 // null=[this,50] execvm "area_control.sqf"
     private ["_unitsW","_unitsE"];


     _areaC = _this select 0;// center of area
     _areaS = _this select 1;// radius of area

     while {true} do { 

     _list = nearestobjects [getpos _areaC,["man","truck","car","tank"],_areaS];

    _unitsW = {side _x  == West} count _list;
    _unitsE = {side _x  == East} count _list;


     //hint str _unitsA;
     switch (true) do {

     case (_unitsW == 0 and _unitsE == 0): {hint "None"};
     case (_unitsW == _unitsE) : {hint "Even"}; 

        case (_unitsW != 0 and _unitsE == 0) : {hint "Blue"};
     case (_unitsE != 0 and _unitsW == 0) : {hint "Red"};

     case (_unitsW > _unitsE)  : {hint "Advantage West"};  
     case (_unitsW < _unitsE)  : {hint "Advantage East"};  

        }; // endcase
        sleep 2;
      };//endwhile

Call by using this placed in game logic null=[this,50] execvm "area_control.sqf" and save script as area_control.sqf

Edited by F2k Sel

Share this post


Link to post
Share on other sites

sector control modules would work, but the script im using creates these triggers all over the map, literally hundreds of them. I'm not gonna use modules for all of that :P

Share this post


Link to post
Share on other sites
Well it helped me fix one of the bugs at least :)

I think colCheck does need to be private because lots of these triggers are generated around the map it isnt just one, so if colCheck was public wouldnt any one of those triggers change the value for the others as well?

The game only recognises a variable as local if it has an underscore in front of it (wiki), but the main issue is that triggers can only access and affect global variables. So the least you'd have to do is either to generate a separate variable name for each trigger, or use setVariable on the trigger itself. F2k Sel's script seems to handle it in a nice functional manner without any variables, though.

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  

×