Jump to content

serena

Member
  • Content Count

    335
  • Joined

  • Last visited

  • Medals

Community Reputation

140 Excellent

3 Followers

About serena

  • Rank
    Staff Sergeant

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. I use such rather flexible and convenient approach: // Abc.sqf Abc_FuncX = {...}; Abc_FuncY = {...}; Abc_FuncZ = {...}; // Def.sqf Def_FuncX = {...}; Def_FuncY = {...}; Def_FuncZ = {...}; // init.sqf call compile preprocessFileLineNumbers "Abc.sqf"; call compile preprocessFileLineNumbers "Def.sqf"; // Somewhere in mission: ... call Abc_FuncX; ... call Def_FuncZ;
  2. It looks cool, but ... Allocate in memory an array with a removed element -> compare elements of two arrays -> allocate new array to storing result -> partially copy elements of source array into resulting. Isn't too expensive?
  3. My code above does not solve your problem completely, only demonstrates how to get names and other useful attributes of locations.
  4. // For example, we have in our mission: // - marker we want to shift, named MyMarker // - number of markers with predefined positions named SpawnLocation_01, SpawnLocation_02, ..., SpawnLocation_XX // Execute somewhere after mission initialization: "MyMarker" setMarkerPos getMarkerPos selectRandom (allMapMarkers select { _x find "SpawnLocation_" == 0});
  5. private _result = allGroups apply {private _acc = 0; {_acc = _acc + skill _x} forEach units _x; _acc / count units _x} // Result: [0.4375,0.4375,1] private _result = allGroups apply {private _acc = 0; {_acc = _acc + skill _x} forEach units _x; [_x, _acc / count units _x]} // Result: [[B Alpha 1-1,0.4375],[B Alpha 1-2,0.4375],[B Alpha 1-3,1]]
  6. GetAttributesForGivenLocationTypes = { private _lcs = []; { private _lct = _forEachIndex; { _lcs pushBack [text _x, _lct, locationPosition _x, direction _x, size _x, rectangular _x]; } forEach nearestLocations [getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition"), [_x], worldSize]; } forEach _this; _lcs }; // Usage: private _result = ["NameLocal", "NameVillage", "NameCity", "NameCityCapital"] call GetAttributesForGivenLocationTypes; // Result: // [ // ["airfield",0,[1697.19,5554.18,-5.5],0,[295.45,220.91],false], // ["military range",0,[3338.44,5744.44,-4.88803],0,[254.81,199.25],false], // ["Old Outpost",0,[4318.72,4398.14,-179.132],0,[121.02,90.49],false], // ["Kill Farm",0,[4449.56,6845.08,-91.6142],0,[236.36,176.73],false], // ["Xiros",0,[3712.09,7940.36,0.000755993],0,[236.36,176.73],false], // ... // ]
  7. Any syntax is allowed. You can use syntax that suits you best. Keyword effects and usage cases described here. Also good approach is to minimize allocation of variables where possible: private _idx = floor random count _pos_jose; _jose setPosAtl (_pos_jose select _idx); _jose setDir (_dir_jose select _idx);
  8. private _idx = floor random count _pos_jose; private _pos = _pos_jose select _idx; private _dir = _dir_jose select _idx; Because searching array in array of arrays operation is too slow
  9. serena

    Capture script

    This is an endless cycle that will never end (or never begin)
  10. player addAction ["Drop Item", { }, [], 1.5, true, true, "", "'Item_Class_Name' in items player"];
  11. https://community.bistudio.com/wiki/params https://community.bistudio.com/wiki/param My personal opinion: optional parameters impair the quality of the code, it is better to avoid using them if possible.
  12. Yes private _last = _array param [count _array - 1]; Note, if array is empty you got nil value attempt to use which will cause an error. So, if you not sure array is not empty then use syntax with default value or check result before use: if (not isNil "_last") then { // code here executed only if _last variable contains value (array not empty) };
  13. // last element if array contains something, otherwise nothing: private _last = if (count _array < 1) then {nil} else {_array select (count _array - 1)}; // if you want to get default value when array empty - just replace nil constant: private _last = if (count _array < 1) then {"This is default value - array is empty"} else {_array select (count _array - 1)}; Another way is to use the param command: private _last = _array param [count _array - 1]; private _last = _array param [count _array - 1, "Default value - when array empty"];
  14. // function call _settlements call function_now; // inside function_now private _settlements = _this; // _this variable always references arguments passed to function
  15. private _all = ["A", "B", "C", "D", "E"]; private _evn = []; private _odd = []; { if (_forEachIndex % 2 > 0) then {_evn pushBack _x} else {_odd pushBack _x} } forEach _all; // Result: // _evn = ["B","D"] // _odd = ["A","C","E"]
×