You can get around having to use global variables by simply storing stuff on the triggers. I made an example where you create a single marker in the editor. The script then creates and sets up the necessary values. There is also a callback functionality to use when the triggers change condition:
PHP Code:
#define TIMEOUT_MIN (10)
#define TIMEOUT_MID (15)
#define TIMEOUT_MAX (20)
/*
Creates triggers and a marker to show who dominates an area
*/
CreateAreaMonitor = {
private ["_triggerSide","_trigger","_marker","_sides","_code","_triggers"];
_marker = _this select 0;
_sides = _this select 1;
_code = if (count _this > 2) then {_this select 2} else { {} };
_triggers = [];
//Create triggers for each side
{
_triggerSide = _x call SideToTriggerConditionSide;
_trigger = createTrigger ["EmptyDetector", getMarkerPos _marker];
_trigger setTriggerTimeout [TIMEOUT_MIN, TIMEOUT_MID, TIMEOUT_MAX, false];
_trigger setTriggerActivation [_triggerSide, "PRESENT", true];
//Replicate marker area
_trigger setTriggerArea [getMarkerSize _marker select 0, getMarkerSize _marker select 1, markerDir _marker, markerShape _marker == "RECTANGLE"];
_trigger setTriggerStatements ["this", "0 = [thisTrigger, true] call AreaMonitorChange;", "0 = [thisTrigger, false] call AreaMonitorChange;"];
//Set data
_trigger setVariable ["AM_Marker", _marker];
_trigger setVariable ["AM_Side", _x];
_trigger setVariable ["AM_Code", _code];
_triggers set [count _triggers, _trigger];
} forEach _sides;
{_x setVariable ["AM_Triggers", _triggers];} forEach _triggers;
};
SideToTriggerConditionSide = {
["WEST","EAST","GUER","CIV"] select ([west,east,resistance,civilian] find _this);
};
TriggerConditionSideToSide = {
[west, east, resistance, civilian] select (["WEST","EAST","GUER","CIV"] find _this);
};
SideToMarkerColor = {
["ColorBlue", "ColorRed", "ColorGreen", "ColorYellow"] select ([west,east,resistance,civilian] find _this);
};
//Called whenever a trigger goes from activated to deactivated
AreaMonitorChange = {
private ["_color","_side","_triggered","_triggers","_marker","_numActivated","_forEachIndex","_activated","_activations"];
_triggered = _this select 0;
//Unfortunately triggerActivated returns true whilst running the "On De-Act".
_activated = _this select 1;
_triggers = _triggered getVariable "AM_Triggers";
_marker = _triggered getVariable "AM_Marker";
_activations = [];
_activations resize (count _triggers);
{
if (_x == _triggered) then {
_activations set [_forEachIndex, _activated];
} else {
_activations set [_forEachIndex, triggerActivated _x];
};
} forEach _triggers;
_numActivated = {_x} count _activations;
_color = "Default";
//Nobody there
if (_numActivated == 0) then {
//Go grey
_color = "Default";
};
//Too many?
if (_numActivated > 1) then {
//Find some congested color representing contested area - what about grey?
_color = "Default";
};
if (_numActivated == 1) then {
//Find the side who dominates
_side = (_triggers select (_activations find true)) getVariable "AM_Side";
_color = _side call SideToMarkerColor;
};
_marker setMarkerColor _color;
//Handler receives [TRIGGER, SIDE, SIDE_PRESENT]
[_triggered, _triggered getVariable "AM_Side", _activated] call (_triggered getVariable "AM_Code");
};
First load the script:
PHP Code:
[] call compile preProcessFile "FILE.sqf";
Then you activate the markers:
PHP Code:
_markers = ["CityMrk1", "CityMrk2", "ForestMrk3"];
//Let's say we want to spawn stuff whenever west enters anyone of those triggers:
_handler = {
private ["_trigger", "_side", "_present"];
_trigger = _this select 0; //The trigger that just activated or deactivated
_side = _this select 1; //The side that caused the (De)-activation
_present = _this select 2; //Whether the side is now present
if (_side == west && _present) then {
//Blufor is now there
//Spawn some enemies .....
//.....??
//Profit
};
};
//Now put it all together, we only care about blufor and guerilla (resistance):
{
[_x, [west, resistance], _handler] call CreateAreaMonitor;
} forEach _markers;
That will automatically create triggers that manage the marker. Eg. if only blufor is in the area then the marker would go blue. If only guerrilla then green. If both then grey atm, but that can be changed.