Advertisement
vossoft

Array extensions examples

Nov 22nd, 2013
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // easy examples with a numeric array
  2. _data = [1,2,3,4,5,6,7,8,9];
  3.  
  4. // filter
  5. _fnc = { _this >= 5 };
  6. [_data, _fnc] call AEX_filter; // [5,6,7,8,9]
  7. [_data, { _this < 4 }] call AEX_filter; // [1,2,3]
  8. [_data, { _this > 2 and _this < 8 }] call AEX_filter; // [3,4,5,6,7]
  9. [_data, { _this mod 2 == 0 }] call AEX_filter; // [2,4,6,8]
  10.  
  11. // map
  12. [_data, { _this * 2 }] call AEX_map; // [2,4,6,8,10,12,14,16,18]
  13. [_data, { str _this }] call AEX_map; // ["1","2","3","4","5","6","7","8","9"]
  14.  
  15. // reduce
  16. [_data, { (_this select 0) + (_this select 1) }] call AEX_reduce; // 45
  17.  
  18. // combination of filter and reduce
  19. [[_data, { _this <= 5 }] call AEX_filter, { (_this select 0) * (_this select 1) }] call AEX_reduce; // 120
  20.  
  21.  
  22. // real ArmA examples
  23.  
  24. // vehicles with at least 10% damage are mapped to an data array like [vehicle type, position, damage]
  25. _vehicles = [vehicles, { damage _this > .1 }] call AEX_filter;
  26. // [209f6080# 1056396: ah6x.p3d REMOTE,248de080# 1055939: hmmwv.p3d REMOTE]
  27. _vehicleData = [_vehicles, { [typeOf _this, position _this, damage _this] }] call AEX_map;
  28. // [["AH6X_DZ",[10473.1,8864.83,0.0306244],0.334646],["HMMWV_DZ",[11219.5,12499.5,-0.0309296],0.204724]]
  29.  
  30. // list of player names and distance within 100m of the player who own a toolbox
  31. _nearEntities = player nearEntities 100;
  32. _players = [_nearEntities, { isPlayer _this and "ItemToolbox" in items _this }] call AEX_filter;
  33. _playerData = [_players, { [name _this, player distance _this] }] call AEX_map;
  34. // [["Player 1",0],["Player 2",68.1549],["Player 3",13.565]]
  35.  
  36. // overall damage of all units
  37. [allUnits, { (_this select 0) + damage (_this select 1) }, 0] call AEX_reduce; // 2.457
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement