Forum Jump :

Author Message


Posts: 43

Level: Member

Country: fr
In-game name: Br.

#145512 Posted at 2013-06-15 13:42        
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)
    Scope If a local variable is initialized within a Control Structures (i.e. if, for, switch, while) its scope will stay within this structure (i.e. outside of the structure it will still be seen as undefined). This does not apply to global or public variables. if (alive player) then {_living=true}; hint format["%1",_living]; Returns "scalar bool array string 0xe0ffffef", since the local variable was not initialized before being used within a control structure.

    _dead=true; if (alive player) then {_dead=false}; hint format["%1",_dead]; Returns "false", since the variable was initialized before the if...then.
    To initialize local variables, so that they are available throughout the whole script (including any control structures), either initialize it via the private command (e.g. private ["_varname"];), or by assigning a default value to it (e.g. varname=0;).

    If knowledge can create problems, it's not through ignorance that we can solve them.
    I. Asimov