fnc_droidDispenserPFH.sqf 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "function_macros.hpp"
  2. params ["_args", "_handle"];
  3. _args params ["_target"];
  4. LOGF_1("Evaluating PFH %1",_handle);
  5. if(isNil "_target") exitWith {
  6. LOGF_1("Removing PFH %1, Reason: Null Target",_handle);
  7. [_handle] call CBA_fnc_removePerFrameHandler;
  8. };
  9. if(!isServer) exitWith {
  10. LOGF_1("Removing PFH %1, Reason: Not Server",_handle);
  11. [_handle] call CBA_fnc_removePerFrameHandler;
  12. };
  13. if(!alive _target) exitWith {
  14. LOGF_1("Removing PFH %1, Reason: Droid Dispenser Dead",_handle);
  15. [_handle] call CBA_fnc_removePerFrameHandler;
  16. };
  17. _group = _target getVariable QGVAR(group);
  18. if(isNil "_group") then
  19. {
  20. LOGF_1("PFH %1 Group empty, creating new",_handle);
  21. _target setVariable [QGVAR(group), createGroup [opfor, true]];
  22. _group = _target getVariable QGVAR(group);
  23. };
  24. _aliveUnits = ({alive _x} count (units _group));
  25. LOGF_2("Alive units for Droid Dispenser %1 :: %2",_target,_aliveUnits);
  26. if(_aliveUnits < _target getVariable QGVAR(maxUnits)) exitWith
  27. {
  28. _possibleUnits = _target getVariable QGVAR(possibleUnits);
  29. _selectedUnit = selectRandom _possibleUnits;
  30. if(_selectedUnit == _possibleUnits select 0) then {
  31. _selectedUnit = selectRandom _possibleUnits; // if its a b2, (first be default atm) random again (requires 2 rolls on b2 to spawn one)
  32. };
  33. LOGF_2("%1 spawning in %2",_target,_selectedUnit);
  34. _unit = _group createUnit [_selectedUnit, position _target, [], 0, "NONE"];
  35. [{
  36. params["_unit"];
  37. _unit call ace_common_fnc_fixPosition;
  38. _group = group _unit;
  39. _group setBehaviour "SAFE";
  40. _group1 setCombatMode "RED";
  41. _unit commandMove (_unit getPos [5, 0]);
  42. {
  43. _x addCuratorEditableObjects [[_unit], true];
  44. } forEach allCurators;
  45. }, _unit] call CBA_fnc_execNextFrame;
  46. };
  47. LOGF_1("%1 not spawning anything",_target);