OFPEC Forum

Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: granQ on 16 Aug 2009, 23:53:52

Title: End mission when all makers turn red
Post by: granQ on 16 Aug 2009, 23:53:52
I am making a mission where you can capture cities, like warfare, now this will be sorta dynamic but all markers (cities, bases) will be added into an array. What I want to do is run some code once ALL markers are red, any ideas how to make it nice and smart?

lets say we got this to play with

markers_array

getmarkercolor "ColorRed"

thanks for your help
Title: Re: End mission when all makers turn red
Post by: i0n0s on 17 Aug 2009, 00:10:08
Code: [Select]
_red = true;
{
_red = _red and (markerColor _x == "ColorRed");
} forEach markers_array
Be aware, no markers are red ;)
(And untested)
Title: Re: End mission when all makers turn red
Post by: granQ on 17 Aug 2009, 00:28:22
i like your idea even if I must say at current stage it shouldn't work.

if the marker is blue, then it will be:

_red = true and false

which is strange for me??
Title: Re: End mission when all makers turn red
Post by: i0n0s on 17 Aug 2009, 00:56:34
Just some boolean logic:
andtruefalseortruefalse
truetruefalsetruetruetrue
falsefalsefalsefalsetruefalse

true combined with false via and will result in false.
So _red will get to false and never can get back to true since false combined via and will only be false.

and is a check if both values are true. or will check if one of those is true.

And this inspires me to new code:
Code: [Select]
_red = true;
_i = 0;
while {_red} do {
_red = _red and (markerColor (markers_array select _i) == "ColorRed");
_i = _i + 1;
};
In basic the same code as above, but as soon as it encounters a non red marker it will exit the loop.
Title: Re: End mission when all makers turn red
Post by: granQ on 17 Aug 2009, 01:32:48
made a minor edit to it, thanks a lot.. think we got cased closed :)

Thanks a lot you would probably throw up if you saw what I tried to do.
Code: [Select]
_red = true;
_i = 0;
while {_red} do {
_red = _red and (markerColor (markers_array select _i) == "ColorRed");
if (_i == count mmai_towns) then {_i = 0};
_i = _i + 1;
};