Jump to content

serena

Member
  • Content Count

    335
  • Joined

  • Last visited

  • Medals

Everything posted by serena

  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. Because allMissionObjects command is tooooo slow, and entities does not work with static objects like "GroundWeaponHolder"
  10. serena

    Capture script

    This is an endless cycle that will never end (or never begin)
  11. player addAction ["Drop Item", { }, [], 1.5, true, true, "", "'Item_Class_Name' in items player"];
  12. 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.
  13. 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) };
  14. // 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"];
  15. // function call _settlements call function_now; // inside function_now private _settlements = _this; // _this variable always references arguments passed to function
  16. Improved grenade throwing and weapon switching actions script Version 1.2 Keys assigned to switch on primary/secondary/handgun weapon if corresponding weapon already in hands, allow to holster/move weapon on back Throwing distances of hand grenades can be controlled by holding throw key. After push and holding for short time, you hear the sound of pulled out grenade safety pin. At this moment, if you release the key, you just drop a grenade right under your feet. Holding button up to 1.5 seconds proportionally increases grenade initial speed and throwing distance. Version 1.2 Code refactored to release condition, removed early version restrictions, bugs and unwanted side effects. Demo mission updated. Download link.
  17. 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"]
  18. while {count _caches < _findCaches} do {_caches pushBack "Cache" + str count _caches};
  19. // select all settlement markers private _settlements = allMapMarkers select {_x find "Mark_" isEqualTo 0}; // result: ["Mark_1", "Mark_2", "Mark_3"] // select random settlement marker private _settlement = selectRandom _settlements; // result: "Mark_?" // get settlement markers count private _count = count _settlements; // result: 3 * code updated
  20. serena

    Hit Event Handler Effects

    Yeah, all the time I forget that the first argument of joinSilent is an array, not a unit. Blakestophen, if you want to do something with both, target and shooter units in your script: // in unit initialization field this allowDamage false; this addEventHandler ["HitPart", {_this execVM "switchside.sqf"}]; // in switchside.sqf params ["_target", "_shooter"]; // from this point and until end of this script // _target variable references target unit, and _shooter variable references shooter unit [_target] joinSilent hunters; [_shooter] joinSilent hiding;
  21. serena

    Hit Event Handler Effects

    // in unit initialization field this allowDamage false; this addEventHandler ["HitPart", {_this select 0 execVM "switchside.sqf"}]; // in switchside.sqf [_this] joinSilent hunters; * code fixed, thanks to killzone_kid The variable "this" has a meaning and value only inside object initialization field, but not in event handlers. The event handler or script receives its arguments in "_this" variable (starts with an underscore). Arguments of your handler are listed here: Event_Handlers#HitPart. The target character is the first argument. To get it use expression "_this select 0".
  22. Ehh, it's true. But my version is much shorter and twice as fast, although less universal :P
  23. Code: InAreaRandomPosition = {// parameters: [center, a, b, angle, isRectangle] - see inArea command alternative syntax params ["_pos", "_sza", "_szb", "_dir", "_rct"]; _pos params ["_psx", "_psy"]; if (_rct) then { private _dsx = random _sza * 2 - _sza; private _dsy = random _szb * 2 - _szb; [_psx + _dsx * cos -_dir - _dsy * sin -_dir, _psy + _dsx * sin -_dir + _dsy * cos -_dir] } else { private _ang = random 360; private _rad = sqrt random 1.0; private _dsx = _sza * _rad * sin _ang; private _dsy = _szb * _rad * cos _ang; [_psx + _dsx * cos -_dir - _dsy * sin -_dir, _psy + _dsx * sin -_dir + _dsy * cos -_dir] } }; Results (right column from a deliberately broken algorithm): Test mission (VR map, Test option in action menu) * ellipse distribution updated
  24. count allVariables missionNamespace // result for blank mission: 1308 Faster than light :) P.S. I like this: _x select [5] call {str parseNumber _this isEqualTo _this}
  25. Get all caches implicitly: AllCaches = { private _res = []; private _obj = nil; while {_obj = missionNamespace getVariable "Cache" + str (count _res + 1); not isNil {_obj}} do { _res pushBack _obj}; _res }; call AllCaches // Result: [Cache1,Cache2,Cache3,Cache4,Cache5,Cache6]
×