assignAsTurret workaround
Updated - 18 July 2011.
As you all may already know, there is no assignAsTurret command wich makes AI run to a vehicle and mount a turret wich is not gunner or commander.
use this script to make any AI run to any vehicle and enter the specified turret from the correct position.
Notes:
Spoiler:
* obviously you need to know what the turret position is. many posts with correct turret arrays for any vehicle, and there is also config files that can be dynamically used. so i leave that to you.
to find what turret number you want of any vehicle:
Spoiler:
place a empty vehicle of your choise.
create a alpha radio trigger and set it to repeated and place this code in the on act field:
you will get a hint with the complete seating array, and you can use ctrl V to paste the turret arra if you are in a turret after the hint, it will also tell you if you are in a gunner or commander seat(those are turrets too), for those just use assignAsGunner and assignAsCommander as normal.
Code:_null = [] spawn { _seat = assignedVehicleRole player; hint format["you are in %1",_seat]; if ("Turret" in _seat) then { copyToClipboard format["%1",(_seat select 2)]; if ((commander (vehicle player)) == player) then {player sideChat "this is also the commander position"}; if ((gunner (vehicle player)) == player) then {player sideChat "this is also the commander position"}; }; };
* you can also automate the filling this way by filling a vehicle get their assigned positions and run the code.
* you should have all the tools here to make a group run to a vehicle and mount ALL the positions including any turret with no magic teleporting.
save as turret.sqf
Spoiler:
Code:/* assignAsTurret workaround by Demonized. run this on a unit you wish to run to correct entry position of any turret in a vehicle and mount. _null = [unitname,vehiclename,turret array] execVM "turret.sqf"; _null = [this,tusk1,[0,1]] execVM "turret.sqf"; */ _unit = _this select 0; _arr = ["getInTurret", (_this select 1), (_this select 2)]; // make unit run towards vehicle while we gather info. _unit doMove (getPos _veh); // create a invicible and captive temp unit. _tempGrp = createGroup (side _unit); _tempUnit = _tempGrp createUnit [(typeOf _unit), [0,0,200], [], 0, "NONE"]; _tempUnit setCaptive true; hideObject _tempUnit; // make the hidden unit teleport and board from correct position. _tempUnit action _arr; // track the position of the temp unit. _pos = getPos _tempUnit; while {(vehicle _tempUnit) != _tempUnit} do { _pos = getPos _tempUnit; sleep 0.01; }; // remove the temp unit from the vehicle and delete him and his group. unAssignVehicle _tempUnit; [_tempUnit] orderGetIn false; _tempUnit setPos [0,0,0]; deleteVehicle _tempUnit; waitUntil {isNull _tempUnit}; deleteGroup _tempGrp; // make your unit run to the last "outside vehicle" position and board when ready. _unit doMove _pos; waitUntil {unitReady _unit OR !canMove _veh}; if (alive _unit AND canMove _veh) then {_unit action _arr};
this below is what this thread contained before. its for filling an entire group into a vehicle, not just 1 single unit.
Spoiler:
Workaround for AssignAsTurret
Current Version is 1.1
Works with any type vehicle land, air or sea.
Purpose of script is to move AI units into all positions of a vehicle including turrets without using moveInTurret etc.. (magic teleport to vehicle)
Units will approach vehicle and enter as gunner, then check if there are any turrets available and switch to that and next unit will move to enter etc... until all positions is filled in vehicle.
Only available positions in vehicle will be filled, rest of group that has no place available in vehicle will follow in formation as normal.
Changelog:Spoiler:
version 1.1
Added workaround for 3 bugged helis, info in bugs/notes, tnx to Raphael for noticing.
added some checks for damaged vehicle, dead members etc.
small tweaks.
version 1.0 - first release.
Bugs/Notes: Spoiler:
1: gunner and turret selection must be completed before any others enter vehicle (driver, commander, cargo).
This is why gunners get in first.
2: When group is waiting for turrets and guns to be manned, they sometimes sprint away from the vehicle, but returns and enters correctly once turrets and guns have been sorted.
This does not happen when not using doMove on group towards vehicle in script.
This is because group is returning to formation on leader in vehicle and is very visible on big helis as chinook, not so much on vehicles.
3: If using assignAsCommander on the final commander/leader switch the commander will get out of vehicle and enter commanderseat and thus resulting in 1 less turret occupied.
Unknow effect of commander being in commander seat with a assignAsGunner command combined with moveToCommander.
Seems fully able/functioning and fighting ok.
4: due to gunners and turrets being occupied first driver, carg, commander waits until all gunner/turret psoitions is filled.
5: when used with boats on water its recomended to not use the doMove line in script or script something to work with this as water is not very AI friendly on their equipment if they get deep in water.
6: when using this on either of the 3 helis, uh1-y, mi-171sh [ACR] and same rockets version, then observer in uh1 or 1 turret in the mi´s wont get in, ive failed to locate the error, since all other vehicles, land air with 3 turrets work perfectly.
Only thing i can see is that when a unit is inside any of these vehicles and switches to the seat he is in, not a new one, the commands read it as he is no longer in his gunner seat but in a turret seat, even tho he never moved when switching.
Ive added a workaround to these 3 helis, until i get the hang of modelToWorld commands.
Many vehicles was tested, should not be anymore issues.
getin.sqf
Spoiler:
PHP Code:/*
GetinTurrets v.1.1
by Demonized
Execute with _null = [vehicleName,group] execVM "getin.sqf";
*/
if (!isServer) exitWith {};
_veh = _this select 0;
_grp = _this select 1;
_debugMode = true; // set to false to disable debug messages.
// all possible turrets.
_turretArray = [ [0],[1],[2],[3],[4],[5],[0,1],[0,2],[0,3],[0,4],[0,5],[1,1],[1,2],[1,3],[1,4],[1,5],[2,1],[2,2],[2,3],[2,4],[2,5] ];
_getInTurret = {
if (!isServer) exitWith {};
_veh = _this select 0;
_unit = _this select 1;
_turretArray = _this select 2;
_debugMode = _this select 3;
_newArr = [];
_seat = [];
_selector = 0;
if ((count (crew _veh)) != 3 AND ((typeOf _veh) == "Mi171Sh_CZ_EP1" OR (typeOf _veh) == "Mi171Sh_rockets_CZ_EP1" OR (typeOf _veh) == "UH1Y")) then {
if ((count (crew _veh)) == 1) then {_seat = [0]};
if ((count (crew _veh)) == 2) then {_seat = [2]};
if ((typeOf _veh) == "UH1Y") then {
if ((count (crew _veh)) == 1) then {_seat = [1]};
if ((count (crew _veh)) == 2) then {_seat = [2]};
_unit action ["moveToTurret",_veh,_seat];
} else {
_unit setPos [0,0,1000];
waitUntil {!(_unit in _veh)};
_unit moveInTurret [_veh, _seat];
};
if (_debugMode) then {player sidechat format["bug workaround seat is %1",_seat]};
} else {
{
if ((gunner _veh) == _unit) then {
if (_debugMode) then {player sideChat format["checking turret %1",_x]};
_unit action ["moveToTurret",_veh,_x];
while {_selector != ((count _turretArray)-1)} do {
_newArrVar = _turretArray select _selector;
if (str(_newArrVar) != str(_x)) then {
_newArr = _newArr + [_newArrVar];
};
_selector = _selector + 1;
};
};
} foreach _turretArray;
};
_freeGunner = _veh emptyPositions "Gunner";
if (_debugMode) then {player sideChat format["gunner positions available is %1",_freeGunner]};
_newArr
};
// move units towards vehicle.
{_x doMove [(getPos _veh select 0)+(random 3), (getPos _veh select 1)+(random 3),0]} foreach units _grp; // note read bugs/notes in BI forums on this script.
// have units stop and not run away to get in far formation with helis. note this makes units stand like idiots, need some sort of formation or similar.
/*
{
[_x,_veh] spawn {
if (!isServer) exitWith {};
_unit = _this select 0;
_veh = _this select 1;
waitUntil {unitReady _unit};
dostop _unit;
waitUntil {{(_veh emptyPositions _x) == 0} foreach ["Driver","Commander","Gunner","Cargo"] OR !alive _unit OR !canMove _veh OR _unit in _veh};
_unit doFollow (leader (group _unit));
};
} foreach units _grp;
*/
// count all various free positions.
_freeDriver = _veh emptyPositions "Driver";
_freeCommander = _veh emptyPositions "Commander";
_freeGunner = _veh emptyPositions "Gunner";
_freeCargo = _veh emptyPositions "Cargo";
_commPos = _freeCommander;
sleep 2;
if (_debugMode) then {player sideChat format["commander %1 driver %2 gunner %3 cargo %4",_freeCommander,_freeDriver,_freeGunner,_freeCargo]};
_commAssigned = false;
_drivAssigned = false;
_gunnAssigned = false;
{
_notMounted = true;
if ((_veh emptyPositions "Gunner") != 0 AND (vehicle _x) == _x AND alive _x AND !_gunnAssigned AND _notMounted) then {
_x assignAsGunner _veh;
[_x] orderGetIn true;
waitUntil {_x in _veh OR !alive _x};
if (alive _x) then {
_turretArrayMod = [_veh, _x, _turretArray, _debugMode] call _getInTurret;
_turretArray = [];
_turretArray = _turretArray + _turretArrayMod;
_freeGunner = _veh emptyPositions "Gunner";
if (_freeGunner == 0) then {
if (_debugMode) then {player sideChat "gunner assigned"};
_gunnAssigned = true;
} else {
if (_debugMode) then {player sideChat "turret assigned"};
};
};
_notMounted = false;
};
if ( _freeCommander != 0 AND (vehicle _x) == _x AND alive _x AND !_commAssigned AND _notMounted) then {
_x assignAsCommander _veh;
[_x] orderGetIn true;
_freeCommander = _freeCommander - 1;
if (_debugMode) then {player sideChat "commander assigned"};
_notMounted = false;
_commAssigned = true;
};
if (_freeDriver != 0 AND (vehicle _x) == _x AND alive _x AND !_drivAssigned AND _notMounted) then {
_x assignAsDriver _veh;
[_x] orderGetIn true;
_freeDriver = _freeDriver - 1;
if (_debugMode) then {player sideChat "driver assigned"};
_notMounted = false;
_drivAssigned = true;
};
if (_freeCargo != 0 AND (vehicle _x) == _x AND alive _x AND _notMounted) then {
_x assignAsCargo _veh;
[_x] orderGetIn true;
_freeCargo = _freeCargo - 1;
if (_debugMode) then {player sideChat "cargo assigned"};
_notMounted = false;
};
} foreach units _grp;
// finally make sure leader is in commander seat if its present in vehicle.
if (_commPos != 0 AND (leader _grp) in _veh) then {
waitUntil {(_veh emptyPositions "Commander") == 0};
(leader _grp) action ["moveToCommander", _veh];
//(leader _grp) assignAsCommander _veh; // note read bugs/notes in BI forums on this script.
if (_debugMode) then {player sideChat "leader was in vehicle and switched place with unit in commander seat"};
};
Creation notes:
Spoiler:
script has basic alive checks, but need more update on this, will be included in updates of this script.
Arma 2 CO (A2 + OA) and full BAF and PMC + official patch 1.57 was used in creation and testing.
HOME
Reply With Quote
