Forum Jump :

Author Message

Posts: 23

Level: Member

Country: us
Location: Charleston, SC
Age: 37
In-game name:

#145521 Posted at 2013-06-15 19:20        
# Skippy : Do you call this script in a single file or is it split into two?
First the errors I can see :
forEach allUnits misses its opening "{"
There is an infinite loop (while{true}) which, in this case, is not what you'd like I guess.
Even if this loop weren't infinite you'd be setting (_bomberGroup = [];) to an empty array each times, you'd better do it only once (before entering the loop).

Now I can think of an easier way to do that just see if it suits your style :)
What I would do is to give a name (in the editor) to each unit that might be a bomber.
Then you'd simply select one of them and give him the package.
Could look like that:
_bomberGroup = [myBomber1, myBomber2, ..., myBomberN];
_rnd = floor(random(count _bomberGroup));
bomber = _bomberGroup select _rnd;
bomber addBackpack "B_AssaultPack_khk";
bomber addMagazine  "DemoCharge_Remote_Mag";
Where myBomberi are the names you gave to your bombers. Of course you'd have to make sure to call this only once (call it only on the server maybe).

I can't use already named units because this is a multiplayer mission and it needs to be able to work rather you have 2 players or full server.

Added 1 minute later:

# Br. : I need more details to help you(when/where/who do you call this script?)
Is it 2 separated script files? It's the complete code?
_bomberGroup = [];
{//u missed this one
if (!isServer || !isDedicated) then {
waitUntil {!isNull player};
waitUntil {(getPlayerUID player) != ""};
while {true} do {//infinite loop???
_uid = getPlayerUID player;
// _bomberGroup = [] scope local in the loop
_bomberGroup set [ count _bomberGroup, [_uid]];
//_bomberGroup = _bomberGroup + [_uid];
//use set instead of operator "+" _bomberGroup set [ count _bomberGroup, [_uid]];
} forEach allUnits;

if (isServer || isDedicated) then {//server exec
_rnd = floor (random (count _bomberGroup));
bomber = _bomberGroup select _rnd;//bomber is a global variable?
bomber addBackpack "B_AssaultPack_khk";
bomber addMagazine  "DemoCharge_Remote_Mag";
 _bombHint = "You have the bomb";//i'm not sure but the hint won't be displayed for the player but check
if (bomber == player) then {
 hint _bombHint;

Use set instead of the operator "+" :
  • _bomberGroup set [ count _bomberGroup, [_uid]];

  • Be careful with the scopes of the variables(see as below, the link)

    I will give these changes a try.