Jump to content
FederalRazer89

Rounding is replacing a number with any

Recommended Posts

I am have been working on a script that can find a position in cities and villages as away to randomly generate positions in populated areas. Now that i found a way to make it a bit more effectiv, i get a problem with the rounding commans like "floor" and "round". When i use hint to check what the varible outputs it say "any".

 

I need to be able to round the numbers to select which position to place markers.
The rest of the script can randomly generate position, but is a bit limited and is somewhat susceptible to multiple markers on same position.

Part of the script:

Spoiler

    for "_i" from 0 to 1000 do 
    {
//FED_CampPos_Array is a array with city/village position generated from another script

    _Number1  = ((random [0,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-1]));     
    _Number2  = ((random [1,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-2]));
    _Number3  = ((random [2,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-3]));
    _Number4  = ((random [3,(count FED_CampPos_Array)*0.4,(count FED_CampPos_Array)-4]));
    _Number5  = ((random [4,(count FED_CampPos_Array)*0.5,(count FED_CampPos_Array)-5]));
    _Number6  = ((random [5,(count FED_CampPos_Array)*0.6,(count FED_CampPos_Array)-6]));
    _Number7  = ((random [6,(count FED_CampPos_Array)*0.7,(count FED_CampPos_Array)-7]));
    _Number8  = ((random [7,(count FED_CampPos_Array)*0.8,(count FED_CampPos_Array)-8]));
    _Number9  = ((random [8,(count FED_CampPos_Array)*0.8,(count FED_CampPos_Array)-9]));
    _Number10 = ((random [9,(count FED_CampPos_Array)*0.8,(count FED_CampPos_Array)-10]));
    
    sleep 0.1;
    
    _NumberSelect1  = floor _Number1;        //All of this outputs "any" with hint
    _NumberSelect2  = floor _Number2;
    _NumberSelect3  = floor _Number3;
    _NumberSelect4  = floor _Number4;
    _NumberSelect5  = floor _Number5;
    _NumberSelect6  = floor _Number6;
    _NumberSelect7  = floor _Number7;
    _NumberSelect8  = floor _Number8;
    _NumberSelect9  = floor _Number9;
    _NumberSelect10 = floor _Number10;

    
    
    
    _Numbercompare = [_NumberSelect1,_NumberSelect2,_NumberSelect3,_NumberSelect4,_NumberSelect5,_NumberSelect6,_NumberSelect7,_NumberSelect8,_NumberSelect9,_NumberSelect10];
        for "_j" from 0 to ((count _Numbercompare) - 1) do
        {
            
           _testVal = _Numbercompare select _j;
           _fail    = 0;
           if (_testVal == _NumberSelect1) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect2) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect3) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect4) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect5) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect6) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect7) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect8) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect9) then {_fail = _fail + 1};
           if (_testVal == _NumberSelect10) then {_fail = _fail + 1};

        };
       
       if (_fail == 1) exitWith {};

    };

sleep 0.1;

_campPos1 = (FED_CampPos_Array select (_NumberSelect1)); 
_campPos2 = (FED_CampPos_Array select (_NumberSelect2));
_campPos3 = (FED_CampPos_Array select (_NumberSelect3));
_campPos4 = (FED_CampPos_Array select (_NumberSelect4)); 
_campPos5 = (FED_CampPos_Array select (_NumberSelect5)); 
    _campPos6  = [0,0,0]; 
    _campPos7  = [0,0,0]; 
    _campPos8  = [0,0,0]; 
    _campPos9  = [0,0,0];
    _campPos10 = [0,0,0];

    if (_checkvalue >= _sizevalue) then
    {
    _campPos6  = (FED_CampPos_Array select (_NumberSelect6)); 
    _campPos7  = (FED_CampPos_Array select (_NumberSelect7)); 
    _campPos8  = (FED_CampPos_Array select (_NumberSelect8)); 
    _campPos9  = (FED_CampPos_Array select (_NumberSelect9));
    _campPos10 = (FED_CampPos_Array select (_NumberSelect10));
    };
_CampPosArray = [_campPos1,_campPos2,_campPos3,_campPos4,_campPos5,_campPos6,_campPos7,_campPos8,_campPos9,_campPos10];
 


 

I know a way that i could make this without the "floor" or "round" functions but it weird that it dosent work. Is this a bug or did i use the functions wrong?

I am lost on this so any suggestions would be appreciated.

Share this post


Link to post
Share on other sites

I think you are using an incorrect syntax for the round command.

_Number1  = ((random [0,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-1]));

https://community.bistudio.com/wiki/round

Are you trying to select a random element from an array? If so, I suggest you use the selectRandom command instead.

https://community.bistudio.com/wiki/selectRandom

Share this post


Link to post
Share on other sites

I am sort of trying to use a random element, but i want to test it so i am sure that it is not the same as the others. When i used the selectRandom directly there would be serveral instances of the same position for multiple markers.

What would be the right syntax for the round command?

I used this before, but will rewrite it.

Spoiler


if (CampTestCycle == 230) exitWith {hint "Cant create camps, try restart or chose a bigger map"};
CampTestCycle = CampTestCycle + 1;

//Camp marker positions
_Center     = [(getNumber(configFile >> "CfgWorlds" >> worldName >> "mapsize"))*0.5,(getNumber(configFile >> "CfgWorlds" >> worldName >> "mapsize"))*0.5];
_mapsize    = (_Center select 0)*2;
_checkvalue = _Center select 0;
if (CampTestCycle >= 100) then {_checkvalue = 1};
_checkvalue = 100000;
_sizevalue  = 10000;
_fail       = 0;

 

sleep 0.1;

_campPos1 = (selectRandom FED_CampPos_Array ); 
_campPos2 = (selectRandom FED_CampPos_Array );
_campPos3 = (selectRandom FED_CampPos_Array );
_campPos4 = (selectRandom FED_CampPos_Array ); 
_campPos5 = (selectRandom FED_CampPos_Array ); 
    _campPos6  = [0,0,0]; 
    _campPos7  = [0,0,0]; 
    _campPos8  = [0,0,0]; 
    _campPos9  = [0,0,0];
    _campPos10 = [0,0,0];

    if (_checkvalue >= _sizevalue) then
    {
    _campPos6  = (selectRandom FED_CampPos_Array); 
    _campPos7  = (selectRandom FED_CampPos_Array); 
    _campPos8  = (selectRandom FED_CampPos_Array); 
    _campPos9  = (selectRandom FED_CampPos_Array);
    _campPos10 = (selectRandom FED_CampPos_Array);
    };
_CampPosArray = [_campPos1,_campPos2,_campPos3,_campPos4,_campPos5,_campPos6,_campPos7,_campPos8,_campPos9,_campPos10];


//Check Distance
    _Dist = 2000;
    
    if (CampTestCycle >= 80) then {_Dist = 1700};
    if (CampTestCycle >= 120) then {_Dist = 1500};    
    if (CampTestCycle >= 140) then {_Dist = 1000};
    if (CampTestCycle >= 160) then {_Dist = 700};
    if (CampTestCycle >= 170) then {_Dist = 500};
    if (CampTestCycle >= 180) then {_Dist = 300};
    if (CampTestCycle >= 200) then {_Dist = 200};
    if (CampTestCycle >= 220) then {_Dist = 100};

    
    for "_i" from 0 to ((count _CampPosArray)-1) do
    {
    _PosCompare = _CampPosArray select _i;

    
    if ((_campPos1 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
        if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
        if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
        if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
        if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
        if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
        if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
        if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
        if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
        if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

        };
    if ((_campPos2 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
        if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
        if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
        if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
        if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
        if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
        if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
        if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
        if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
        if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

        };
    if ((_campPos3 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
        if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
        if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
        if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
        if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
        if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
        if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
        if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
        if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
        if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

        };
    if ((_campPos4 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
        if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
        if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
        if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
        if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
        if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
        if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
        if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
        if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
        if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

        };
    if ((_campPos5 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
        if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
        if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
        if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
        if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
        if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
        if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
        if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
        if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
        if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

        };
 
            if (_checkvalue >= _sizevalue) then
            {    
                        if ((_campPos6 distance _PosCompare) <= _Dist) then 
                            {
                            if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
                            if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
                            if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
                            if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
                            if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
                            if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
                            if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
                            if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
                            if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
                            if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

                            };
                        if ((_campPos7 distance _PosCompare) <= _Dist) then 
                            {
                            if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
                            if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
                            if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
                            if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
                            if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
                            if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
                            if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
                            if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
                            if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
                            if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

                            };
                        if ((_campPos8 distance _PosCompare) <= _Dist) then 
                            {
                            if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
                            if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
                            if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
                            if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
                            if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
                            if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
                            if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
                            if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
                            if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
                            if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

                            };
                        if ((_campPos9 distance _PosCompare) <= _Dist) then 
                            {
                            if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
                            if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
                            if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
                            if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
                            if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
                            if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
                            if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
                            if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
                            if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
                            if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

                            };
                        if ((_campPos10 distance _PosCompare) <= _Dist) then 
                            {
                            if (_i == 0) then {_campPos1 = (selectrandom FED_CampPos_Array)};
                            if (_i == 1) then {_campPos2 = (selectrandom FED_CampPos_Array)};
                            if (_i == 2) then {_campPos3 = (selectrandom FED_CampPos_Array)};
                            if (_i == 3) then {_campPos4 = (selectrandom FED_CampPos_Array)};
                            if (_i == 4) then {_campPos5 = (selectrandom FED_CampPos_Array)};
                            if (_i == 5) then {_campPos6 = (selectrandom FED_CampPos_Array)};
                            if (_i == 6) then {_campPos7 = (selectrandom FED_CampPos_Array)};
                            if (_i == 7) then {_campPos8 = (selectrandom FED_CampPos_Array)};
                            if (_i == 8) then {_campPos9 = (selectrandom FED_CampPos_Array)};
                            if (_i == 9) then {_campPos10 = (selectrandom FED_CampPos_Array)};

                            };
            };
                    
    };
sleep 0.1;
// Second pass

_TryAgain = 0;
    for "_i" from 0 to ((count _CampPosArray)-1) do
    {
    _PosCompare = _CampPosArray select _i;

    
    if ((_campPos1 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = 1};
        if (_i == 1) exitWith {_TryAgain = 1};
        if (_i == 2) exitWith {_TryAgain = 1};
        if (_i == 3) exitWith {_TryAgain = 1};
        if (_i == 4) exitWith {_TryAgain = 1};
        if (_i == 5) exitWith {_TryAgain = 1};
        if (_i == 6) exitWith {_TryAgain = 1};
        if (_i == 7) exitWith {_TryAgain = 1};
        if (_i == 8) exitWith {_TryAgain = 1};
        if (_i == 9) exitWith {_TryAgain = 1};

        };
    if ((_campPos2 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = 1};
        if (_i == 1) exitWith {_TryAgain = 1};
        if (_i == 2) exitWith {_TryAgain = 1};
        if (_i == 3) exitWith {_TryAgain = 1};
        if (_i == 4) exitWith {_TryAgain = 1};
        if (_i == 5) exitWith {_TryAgain = 1};
        if (_i == 6) exitWith {_TryAgain = 1};
        if (_i == 7) exitWith {_TryAgain = 1};
        if (_i == 8) exitWith {_TryAgain = 1};
        if (_i == 9) exitWith {_TryAgain = 1};

        };
    if ((_campPos3 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = 1};
        if (_i == 1) exitWith {_TryAgain = 1};
        if (_i == 2) exitWith {_TryAgain = 1};
        if (_i == 3) exitWith {_TryAgain = 1};
        if (_i == 4) exitWith {_TryAgain = 1};
        if (_i == 5) exitWith {_TryAgain = 1};
        if (_i == 6) exitWith {_TryAgain = 1};
        if (_i == 7) exitWith {_TryAgain = 1};
        if (_i == 8) exitWith {_TryAgain = 1};
        if (_i == 9) exitWith {_TryAgain = 1};

        };
    if ((_campPos4 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = 1};
        if (_i == 1) exitWith {_TryAgain = 1};
        if (_i == 2) exitWith {_TryAgain = 1};
        if (_i == 3) exitWith {_TryAgain = 1};
        if (_i == 4) exitWith {_TryAgain = 1};
        if (_i == 5) exitWith {_TryAgain = 1};
        if (_i == 6) exitWith {_TryAgain = 1};
        if (_i == 7) exitWith {_TryAgain = 1};
        if (_i == 8) exitWith {_TryAgain = 1};
        if (_i == 9) exitWith {_TryAgain = 1};

        };
    if ((_campPos5 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = 1};
        if (_i == 1) exitWith {_TryAgain = 1};
        if (_i == 2) exitWith {_TryAgain = 1};
        if (_i == 3) exitWith {_TryAgain = 1};
        if (_i == 4) exitWith {_TryAgain = 1};
        if (_i == 5) exitWith {_TryAgain = 1};
        if (_i == 6) exitWith {_TryAgain = 1};
        if (_i == 7) exitWith {_TryAgain = 1};
        if (_i == 8) exitWith {_TryAgain = 1};
        if (_i == 9) exitWith {_TryAgain = 1};

        };
                if (_checkvalue >= _sizevalue) then    
                {    
                    if ((_campPos6 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = 1};
                        if (_i == 1) exitWith {_TryAgain = 1};
                        if (_i == 2) exitWith {_TryAgain = 1};
                        if (_i == 3) exitWith {_TryAgain = 1};
                        if (_i == 4) exitWith {_TryAgain = 1};
                        if (_i == 5) exitWith {_TryAgain = 1};
                        if (_i == 6) exitWith {_TryAgain = 1};
                        if (_i == 7) exitWith {_TryAgain = 1};
                        if (_i == 8) exitWith {_TryAgain = 1};
                        if (_i == 9) exitWith {_TryAgain = 1};

                        };
                    if ((_campPos7 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = 1};
                        if (_i == 1) exitWith {_TryAgain = 1};
                        if (_i == 2) exitWith {_TryAgain = 1};
                        if (_i == 3) exitWith {_TryAgain = 1};
                        if (_i == 4) exitWith {_TryAgain = 1};
                        if (_i == 5) exitWith {_TryAgain = 1};
                        if (_i == 6) exitWith {_TryAgain = 1};
                        if (_i == 7) exitWith {_TryAgain = 1};
                        if (_i == 8) exitWith {_TryAgain = 1};
                        if (_i == 9) exitWith {_TryAgain = 1};

                        };
                    if ((_campPos8 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = 1};
                        if (_i == 1) exitWith {_TryAgain = 1};
                        if (_i == 2) exitWith {_TryAgain = 1};
                        if (_i == 3) exitWith {_TryAgain = 1};
                        if (_i == 4) exitWith {_TryAgain = 1};
                        if (_i == 5) exitWith {_TryAgain = 1};
                        if (_i == 6) exitWith {_TryAgain = 1};
                        if (_i == 7) exitWith {_TryAgain = 1};
                        if (_i == 8) exitWith {_TryAgain = 1};
                        if (_i == 9) exitWith {_TryAgain = 1};

                        };
                    if ((_campPos9 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = 1};
                        if (_i == 1) exitWith {_TryAgain = 1};
                        if (_i == 2) exitWith {_TryAgain = 1};
                        if (_i == 3) exitWith {_TryAgain = 1};
                        if (_i == 4) exitWith {_TryAgain = 1};
                        if (_i == 5) exitWith {_TryAgain = 1};
                        if (_i == 6) exitWith {_TryAgain = 1};
                        if (_i == 7) exitWith {_TryAgain = 1};
                        if (_i == 8) exitWith {_TryAgain = 1};
                        if (_i == 9) exitWith {_TryAgain = 1};

                        };
                    if ((_campPos10 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = 1};
                        if (_i == 1) exitWith {_TryAgain = 1};
                        if (_i == 2) exitWith {_TryAgain = 1};
                        if (_i == 3) exitWith {_TryAgain = 1};
                        if (_i == 4) exitWith {_TryAgain = 1};
                        if (_i == 5) exitWith {_TryAgain = 1};
                        if (_i == 6) exitWith {_TryAgain = 1};
                        if (_i == 7) exitWith {_TryAgain = 1};
                        if (_i == 8) exitWith {_TryAgain = 1};
                        if (_i == 9) exitWith {_TryAgain = 1};

                        };
                };    
    
    if (_TryAgain == 1) exitWith {};
    };


if (_TryAgain == 1) exitWith {sleep 0.1;[] spawn fn_FED_CampControl};
 

 

Share this post


Link to post
Share on other sites

Uhm... You could subtract the selected position from the array, one by one as they are picked. Example:

_array = [[1, 1, 1], [2, 2, 2], [3, 3, 3]];
_selected = selectRandom _array;
_array = _array - _selected;

https://community.bistudio.com/wiki/Array#Subtraction

Not tested! There is probably a better way to do this as well. Can't think right now.

Share this post


Link to post
Share on other sites

Tried it but the array size didnt decrese, and apperantly the loop hit the limit that i put in place.
Can it be because its a global array?

Share this post


Link to post
Share on other sites
9 hours ago, HazJ said:

I think you are using an incorrect syntax for the round command.


_Number1  = ((random [0,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-1]));

https://community.bistudio.com/wiki/round

Are you trying to select a random element from an array? If so, I suggest you use the selectRandom command instead.

https://community.bistudio.com/wiki/selectRandom

 

Round? Where is round command in that code? And what round has to do with selectRandom?

Share this post


Link to post
Share on other sites

True

I have tried "round" and "floor". But of both of them should achieve similar result, which is enough for my usage.

Share this post


Link to post
Share on other sites

Mistakes, easily done as it was early... My bad.

@Grumpy Old Man - lol... When you make a post that's incorrect or something, I'll be there returning the favour.

Same to you as well... @killzone_kid

Share this post


Link to post
Share on other sites
1 hour ago, HazJ said:

Mistakes, easily done as it was early... My bad.

@Grumpy Old Man - lol... When you make a post that's incorrect or something, I'll be there returning the favour.

Same to you as well... @killzone_kid

 

Are you absolutely sure you want to play this game? Because the amount of mistakes and misleading info in your posts is overwhelming, won't be difficult at all to keep humiliating you on regular basis.

Share this post


Link to post
Share on other sites
18 hours ago, HazJ said:

Mistakes, easily done as it was early... My bad.

@Grumpy Old Man - lol... When you make a post that's incorrect or something, I'll be there returning the favour.

Same to you as well... @killzone_kid

 

:yay:

 

11 hours ago, FederalRazer89 said:

Well i make a lot of mistakes, and that have made me learn new stuff.

it happens.

 

 

Your original syntax of random was perfectly fine, unless it wasn't intended? Looks good to me.

Are you still getting the "any" error when using the floor command? Might check if the FED_CampPos_Array is not defined at this point, would result in an any error.

Any reason for using floor in the first place? Round should work just fine, as long as the above mentioned array is defined.

Could output an error message like this in the beginning of your snippet:

if (isNil "FED_CampPos_Array") exitWith {systemchat "FED_CampPos_Array not defined!"};
if (FED_CampPos_Array isEqualTo []) then {systemchat "FED_CampPos_Array is empty!"};

Could you please sum up what you're actually trying to achieve? There might (most likely) be an easier approach to your problem.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I have checked if the array is defiend counts about 30-40 elements, another script that need to generate the locations before this script is executed. And if you defiene the array with just some random numbers then you can test it yourself.

Example: Copy if you want to see the results. It will output "any" and the 10 chosen values of the array.

Spoiler

FED_CampPos_Array = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14];

for "_i" from 0 to 100 do 

    _Number1  = ((random [0,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-1]));      
    _Number2  = ((random [1,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-2])); 
    _Number3  = ((random [2,(count FED_CampPos_Array)*0.3,(count FED_CampPos_Array)-3])); 
    _Number4  = ((random [3,(count FED_CampPos_Array)*0.4,(count FED_CampPos_Array)-4])); 
    _Number5  = ((random [4,(count FED_CampPos_Array)*0.5,(count FED_CampPos_Array)-5])); 
    _Number6  = ((random [5,(count FED_CampPos_Array)*0.6,(count FED_CampPos_Array)-6])); 
    _Number7  = ((random [6,(count FED_CampPos_Array)*0.7,(count FED_CampPos_Array)-7])); 
    _Number8  = ((random [7,(count FED_CampPos_Array)*0.8,(count FED_CampPos_Array)-8])); 
    _Number9  = ((random [8,(count FED_CampPos_Array)*0.8,(count FED_CampPos_Array)-9])); 
    _Number10 = ((random [9,(count FED_CampPos_Array)*0.8,(count FED_CampPos_Array)-10])); 
     
     
    _NumberSelect1  = round _Number1;
    _NumberSelect2  = round _Number2; 
    _NumberSelect3  = round _Number3; 
    _NumberSelect4  = round _Number4; 
    _NumberSelect5  = round _Number5; 
    _NumberSelect6  = round _Number6; 
    _NumberSelect7  = round _Number7; 
    _NumberSelect8  = round _Number8; 
    _NumberSelect9  = round _Number9; 
    _NumberSelect10 = round _Number10; 
     
_numberArray = [_NumberSelect1,_NumberSelect2,_NumberSelect3,_NumberSelect4,_NumberSelect5,_NumberSelect6,_NumberSelect7,_NumberSelect8,_NumberSelect9,_NumberSelect10]; 
    for "_j" from 0 to ((count _numberArray) - 1) do 
    { 
        _testvar = _numberArray select _j; 
        if (_testvar == _number1) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number2) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number3) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number4) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number5) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number6) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number7) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number8) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number9) then {_CountCheckVal = _CountCheckVal + 1}; 
        if (_testvar == _number10) then {_CountCheckVal = _CountCheckVal + 1}; 
     
    }; 
    if (_CountCheckVal == 10) exitWith {}; 
 
 
}; 
 
 
 
_campPos1  = (FED_CampPos_Array select _number1); 
_campPos2  = (FED_CampPos_Array select _number2); 
_campPos3  = (FED_CampPos_Array select _number3); 
_campPos4  = (FED_CampPos_Array select _number4); 
_campPos5  = (FED_CampPos_Array select _number5); 
_campPos6  = (FED_CampPos_Array select _number6); 
_campPos7  = (FED_CampPos_Array select _number7); 
_campPos8  = (FED_CampPos_Array select _number8); 
_campPos9  = (FED_CampPos_Array select _number9); 
_campPos10 = (FED_CampPos_Array select _number10); 
 
 
    
 
_CampPosArray = [_campPos1,_campPos2,_campPos3,_campPos4,_campPos5,_campPos6,_campPos7,_campPos8,_campPos9,_campPos10];
 
hint format ["%1 : %2",_campPos1,FED_CampPos_Array];

if you copy this in to arma and execute it, then it will show that _campPos1 that will output "any" and the content of FED_CampPos_Array. In this example FED_CampPos_Array is already defined it will be possible to replicate without any problem.


Got something i will try something when i get back from work.

Share this post


Link to post
Share on other sites
50 minutes ago, Grumpy Old Man said:

Could you please sum up what you're actually trying to achieve? There might (most likely) be an easier approach to your problem.

 

@FederalRazer89 Try to not underestimate this request!

 

EDIT:

For sure! random, round, floor (and whatever else) are working as intended and described in wiki. Just test it with a simple script if u ve any doubts.

Share this post


Link to post
Share on other sites

Sorry forgot about that.

50 minutes ago, Grumpy Old Man said:

Could you please sum up what you're actually trying to achieve? There might (most likely) be an easier approach to your problem.


Trying to chose random elements from array FED_CampPos_Array which hold positions.

Problem is that selectrandom some time causes multiple markers to chose the same position, even when i try to compare with the this:

Spoiler

_TryAgain = 0;
    for "_i" from 0 to ((count _CampPosArray) -1) do
    {
    _PosCompare = _CampPosArray select _i;

    
    if ((_campPos1 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos2 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos3 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos4 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos5 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
                if (_checkvalue >= _sizevalue) then    
                {    
                    if ((_campPos6 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos7 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos8 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos9 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos10 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                };    
    
    
    };


if (_TryAgain != 10) exitWith {sleep 0.1;[] spawn fn_FED_CampControl};

That way it will restart the selections process if any of them are too close to each other.
So mabye if they have the same positions the distance command dont work that well, but i dont know. I am fairly new to scripting.

 

  • Like 1

Share this post


Link to post
Share on other sites

Could you go more in detail plz?

I think it would be better to write a new script than to correct ur current script.

1. You have a global positions array - understood

2. You need to select positions from it and they should be unique - how many positions should be selected?

3. You used the syntax for a weighted random in your script - why and is that necessary?

Share this post


Link to post
Share on other sites
1 minute ago, sarogahtyp said:

2. You need to select positions from it and they should be unique - how many positions should be selected?

10. But if i can use the metod that i am trying to use then, i will be able to be more flexible for me in the future.

 

 

4 minutes ago, sarogahtyp said:

3. You used the syntax for a weighted random in your script - why and is that necessary?

I want some level of control but its not necessary to be weighted, just that it needs to be random.

But i got some ideas i am going to try after work.

Share this post


Link to post
Share on other sites

I think u don't really like to have help at this point because you would not just mention that u like to have "more flexibility" but u would just describe what u mean...
Also I think everything which would help to get a much shorter solution is already told except the possibility of

BIS_fnc_selectRandomWeighted

which may help to archieve whatever u try.

Share this post


Link to post
Share on other sites

From what I see in this thread, OP is trying to randomly pick some elements from array without repetitions.

Probably the easiest and most effective way is to deleteAt from copy of input array. For array of heavy objects, better use indices.

Spoiler

pick_random_no_repetitions = {
	// Usage:
	// [ ARRAY, COUNT ] call pick_random_no_repetitions;
	//     ARRAY: array of items to select from
	//     COUNT: count of items to select
	// Returns: array of COUNT (or less, if there are not enough) items selected from input ARRAY, no repetitions
	// Complexity: linear on (COUNT min (count ARRAY))

	params [["_array", [], [[]]], ["_count", 0, [0]]];
	private _array_shallow_copy = [] + _array;
	private _count_avail = _count min (count _array_shallow_copy);
	private _count_remain = _count_avail;
	private _ret = [];
	for "_i" from 0 to (_count_avail-1) do {
		_ret pushBack (_array_shallow_copy deleteAt (floor random _count_remain));
		_count_remain = _count_remain - 1;
	}
	_ret
}

 

Some other considerations.

Whenever you feel the need to use lots of _varNameNUMBER variables, you're most likely on a wrong path.

Whenever you have to take enormous amount (usually indefinite) of tries to complete the task, you're most likely on a wrong path.

Best to reconsider your approach in general, e.g. try another algorithm.

 

Have a nice day.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, FederalRazer89 said:

Sorry forgot about that.


Trying to chose random elements from array FED_CampPos_Array which hold positions.

Problem is that selectrandom some time causes multiple markers to chose the same position, even when i try to compare with the this:

  Reveal hidden contents

_TryAgain = 0;
    for "_i" from 0 to ((count _CampPosArray) -1) do
    {
    _PosCompare = _CampPosArray select _i;

    
    if ((_campPos1 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos2 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos3 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos4 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
    if ((_campPos5 distance _PosCompare) <= _Dist) then 
        {
        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

        };
                if (_checkvalue >= _sizevalue) then    
                {    
                    if ((_campPos6 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos7 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos8 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos9 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                    if ((_campPos10 distance _PosCompare) <= _Dist) then 
                        {
                        if (_i == 0) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 1) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 2) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 3) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 4) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 5) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 6) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 7) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 8) exitWith {_TryAgain = _TryAgain + 1};
                        if (_i == 9) exitWith {_TryAgain = _TryAgain + 1};

                        };
                };    
    
    
    };


if (_TryAgain != 10) exitWith {sleep 0.1;[] spawn fn_FED_CampControl};

That way it will restart the selections process if any of them are too close to each other.
So mabye if they have the same positions the distance command dont work that well, but i dont know. I am fairly new to scripting.

 

 

 

Now I see, this is quite a desperate attempt, heh. :yay:

 

Doing something like this was causing headache for myself as well back in the days.

 

There was a similar request some time ago, asking to pick random positions from all roads within 10km, but only if these positions are at least 1000m from each other.

This was my solution, adjusted to use a positions array:

 

{deletemarker _x} foreach allMapMarkers; //for debug markers
_OutputPositions = [];
_positions = somethingsomething;//put your positions array here
systemchat str count _positions;

while {count _positions > 0} do {

	_rndPos = selectRandom _positions;
	_positions = _positions select {_x distance2d _rndPos >= 1000};//distance check, adjust the number to your liking
	_OutputPositions pushback _rndPos;

	_marker = createmarker [str _rndPos,_rndPos];//debug markers, if not wanted delete these 4 lines
	_marker setmarkertype "hd_dot";
	_marker setmarkercolor "ColorRed";
	_marker setmarkertext format ["Position No.%1",_OutputPositions find _rndPos];


};
systemchat format ["Valid positions found: %1",count _OutputPositions];

This will output positions that are at least 1000m from each other, using an input array of positions.

Not the most performant one since the original request was to be run at mission init, should work fine otherwise.

Feel free to adapt as you like.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I am not sure if some people misunderstood my intentions then i am sorry. Dont mean to offend anybody, but either way i got some ideas from this disscutions and made a bit better version of my previous script.


Will post it below for anyone intressted in this sort of script. Still a work in progress.


The new script:

Spoiler

if (FED_TestCycle >= 10) exitWith {hint "Not enough settlements"};
FED_CampPos_Array = [];
FED_TestCycle     = FED_TestCycle + 1;

_Center       = [(getNumber(configFile >> "CfgWorlds" >> worldName >> "mapsize"))*0.5,(getNumber(configFile >> "CfgWorlds" >> worldName >> "mapsize"))*0.5];
_mapsize      = (_Center select 0)*2;
_offsetCenter = [(_Center select 0)+(random [-_mapsize,0,_mapsize]),(_Center select 1)+(random [-_mapsize,0,_mapsize])];
_Giantlist    = nearestTerrainObjects [_offsetCenter ,["HOUSE","CHURCH","CHAPEL","FUELSTATION","HOSPITAL"], (_mapsize + 5000),false];
_NatoBasePos  = getMarkerPos "baseposWEST";
_checkradius  = 3000;
if (FED_TestCycle >= 2) then {_checkradius  = 2500};
if (FED_TestCycle >= 3) then {_checkradius  = 2000};
if (FED_TestCycle >= 4) then {_checkradius  = 1700};
if (FED_TestCycle >= 5) then {_checkradius  = 1500};
if (FED_TestCycle >= 6) then {_checkradius  = 1300};
if (FED_TestCycle >= 7) then {_checkradius  = 1000};


    
    for "_i" from 0 to ((count _Giantlist) - 1) do
    {
        _HouseComp    = _Giantlist select _i;
        _HouseCompPos = getpos _HouseComp;
        _houseposList = nearestTerrainObjects [_HouseCompPos ,["HOUSE","CHURCH","CHAPEL","FUELSTATION","HOSPITAL"], 100,false];
        _FlagCount    = nearestObjects [_HouseCompPos ,["Flag_CSAT_F"], 700,false];
        _HouseCount   = 0;
        _CloseValue   = 0;
        
    
        if ((count _houseposList) >= 3) then 
        {
            for "_j" from 0 to ((count _houseposList)- 1) do  
                {
                
                    _HouseComp2 = _houseposList select _j; 
                    if ((_HouseComp2 distance [0,0,0]) <= 100) exitWith {};
                    _HouseCount = _HouseCount + 1;

                        if ((count FED_CampPos_Array) != 0) then 
                            {
                                for "_k" from 0 to ((count FED_CampPos_Array) - 1) do 
                                {
                                    
                                    if (((FED_CampPos_Array select _k) distance _HouseComp2) <= _checkradius) then {_CloseValue = 1};
                                
                                };

                            };

                        if ((count FED_CampPos_Array) != 0) then 
                            {
                                for "_k" from 0 to ((count FED_CampPos_Array) - 1) do 
                                {
                                    
                                    if ((count _FlagCount) >= 1) then {_CloseValue = 1};
                                
                                };

                            };
                           

      
                if (_CloseValue == 1) exitWith {};    
                };
        }; 
        if (_HouseCount >= 8) then 
                {
                    _meanPosition = [];
                    _length       = count _houseposList;
                    for "_i" from 0 to 2 do {
                      _component = 0;
                      for "_j" from 0 to (_length - 1) do {
                        _component = _component + (((position (_houseposList select _j)) select _i) / _length);
                      };
                      _meanPosition pushBack _component;
                    };
                     
                    
                    
                    FED_CampPos_Array pushBack _meanPosition;
                    
                };

    
    };
hint format ["%1",count FED_CampPos_Array];
if ((count FED_CampPos_Array) >= 20) exitWith {[] spawn _FindCampPos};
if ((count FED_CampPos_Array) <= 11) exitWith {[] spawn _FindCampPos};


 

A bit slow but it will only be used once so its not problem for my type of mission.

 

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

×