Jump to content

serena

Member
  • Content Count

    335
  • Joined

  • Last visited

  • Medals

Posts 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. 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],
    //   ...
    // ]

     

    • Like 2

  3. 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)
    };

     

    • Like 1

  4. 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"];

     

    • Like 1

  5. 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; 

     


  6. // 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".

     


  7. 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):

    Areapos.png

     

    Test mission (VR map, Test option in action menu)

    * ellipse distribution updated

    • Like 1

  8. 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

     


  9. 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 :)

×