-
Content Count
335 -
Joined
-
Last visited
-
Medals
Posts posted by serena
-
-
5 hours ago, Tajin said:... _crateSpawns = _crateSpawns - [_rndCrate];
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?
-
5 hours ago, Cerbium said:I'm not very familiar with scripting, where exactly would I put this?
My code above does not solve your problem completely, only demonstrates how to get names and other useful attributes of locations.
-
// 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});
- 1
-
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]]
- 2
-
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], // ... // ]
- 2
-
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);
-
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
- 2
-
20 hours ago, TheDusty01 said:_game_active = varHolder getVariable "game_active"; while {_game_active} do { sleep 4; };
This is an endless cycle that will never end (or never begin)
-
player addAction ["Drop Item", { }, [], 1.5, true, true, "", "'Item_Class_Name' in items player"];
-
- 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.
-
26 minutes ago, Godis_1 said:So it doesn't need an extra check to verify if the array is empty?
Yes
26 minutes ago, Godis_1 said:How would that be used to keep it empty in case nothing was stored inside?
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) };
- 1
-
3 hours ago, Godis_1 said:Well, then it must be:
// 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"];
- 1
-
// function call _settlements call function_now; // inside function_now private _settlements = _this; // _this variable always references arguments passed to function
- 1
-
12 hours ago, Godis_1 said:Can I "split" the result of "_settlements" into even and odd numbers and put them into a new array?
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"]
- 1
-
while {count _caches < _findCaches} do {_caches pushBack "Cache" + str count _caches};
-
// 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
- 2
-
21 minutes ago, killzone_kid said:_this select 0 is array, alright, but not the kind of array you want to pass to joinSilent
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;
-
// 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".
-
Ehh, it's true. But my version is much shorter and twice as fast, although less universal :P
-
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
- 1
-
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}
- 1
-
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]
-
36 minutes ago, killzone_kid said:Depends on how many spawned scripts there and how busy is script engine. If overloaded could be minutes over
Checking trigger conditions and unscheduled environment in which it is running apparently gives some strong guarantees of timely execution :/
It is a pity that we can not do something like this: setThreadPriority "REALTIME" :)
P.S. Another funny moment: when the game performance falls so much that the scripts stop working, the last thing you think about is: "why is the sleeping script that is supposed to launch the spawn of the super-invasion force, fires 5 seconds later?" XDD
-
15 minutes ago, killzone_kid said:Nope. As I said it will only be guaranteed to sleep given amount at least, but usually sleeps longer especially when engine is loaded, so you might just oversleep
Technically this can happen. The question is, how likely is it practically and how much will the gap be. I regularly use this approach and it always works perfectly. Maybe you're right, and I'll once face such a problem :)
Modifying function location issues
in ARMA 3 - MISSION EDITING & SCRIPTING
Posted
I use such rather flexible and convenient approach: