Jump to content
Sign in to follow this  
IcyDennis

Group laying mines

Recommended Posts

I have a small problem with a script which make a group laying mines and just cant figure how to get it done the way I want it...

What I want to achieve is this:

player as group leader of 6 engineers has an actionmenu entry making all 5 units in his group lay mines at once

Each of the units has 6 mines, 3 in inventory plus 3 in backpack

When the 3 mines in inventory are placed, each unit gets 3 new ones and the backpack is cleared

When these 3 mines are also placed, the actionmenu entry is removed

Here is the script I wrote (probably without knowing exactly what I'm doing lol)

_aunits = units grp_hammer;
_i = 0;
_j = count _aunits;
_mines = 6;

player groupChat "Everyone lay a mine!";

while {true} do
{
 (_aunits select _i) fire ["MineMuzzle","MineMuzzle","Mine"];
 _i = _i + 1;
 _mines = _mines - 1;
 if (_mines == 0) then {player removeAction 0;};
 if (_mines == 3) then {{_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6]; {_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6]; {_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6];};
};

grp_hammer : group name

s2 - s5 : the units in the players group

Depending on what I change, I either can place mines forever or only some units place mines, or none at all... so I fear I need professional help with this. :)

Share this post


Link to post
Share on other sites
... I either can place mines forever ...

Use the value of _i as your condition (or exit the loop upon reaching the desired value. That way the loop will not be infinite.

Condition

while {_i < myNumber} do {
    //The stuff
};

exitWith

while {true} do {
    //The stuff
    if (_i == myNumber) exitWith {};
};

Share this post


Link to post
Share on other sites

Thanks! Almost there, at least no errors anymore. But:

_aunits = units grp_hammer;
_i = 0;
_j = count _aunits;

player groupChat "Everyone lay a mine!";

while {true} do
{
 (_aunits select _i) fire ["MineMuzzle","MineMuzzle","Mine"];
 _i = _i + 1;
 if (_i == 3) then {{_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6]; {_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6]; {_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6];};
 if (_i == 6) exitWith {player removeAction 0;};
};

The action gets removed after the first batch of mines are laid.

With:

_aunits = units grp_hammer;
_i = 0;
_j = count _aunits;

player groupChat "Everyone lay a mine!";

while {_i < 6} do
{
 (_aunits select _i) fire ["MineMuzzle","MineMuzzle","Mine"];
 _i = _i + 1;
 if (_i == 3) then {{_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6]; {_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6]; {_x addMagazine "Mine"} forEach [s2,s3,s4,s5,s6];};
};

I can lay mines forever. With above code, the variable _i is set to 6 when the action was used the first time. Changing it to 36 (6x6 mines) doesn't do anything.

Guess this more complicated than I thought, that or my math skills just suck :(

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  

×