Jump to content
Sign in to follow this  
demonized

assignAsTurret moveInTurret workaround

Recommended Posts

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:

* 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:

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.

_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

/*
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.

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:

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:

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

/*
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:

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.

Edited by Demonized
added small code to find any turret array to be used with the script.

Share this post


Link to post
Share on other sites

nvm...........

Edit: just realised all commander seats is counted as a turret in cfg files i used.

then i can just check for emptypositions commander and remove 1 if there is from total guns, turrets count.

:)

New improved version soon to be released.

Edited by Demonized
added edit.

Share this post


Link to post
Share on other sites

I think that it is the best way for filling all turrets :)

_vehicleclass= _this select 0;
_spawnpos = _this select 1;
_spawnedcrewtype = _this select 2;
_vehicleDir = _this select 3;

_sides = [east, west, resistance, civilian, nil, enemy, friendly, nil];
_countx=0;

[color="Blue"]_turretsArray = [ [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] ];[/color]

private ["_vehicleType", "_position", "_group","_unit", "_crewType", "_vehicle"];

if ((isServer)or(isDedicated)) then 
{

    _vehicleType = _vehicleclass;
    _position = _spawnpos;
    _vehicle = createVehicle [_vehicleType, [_position select 0, _position select 1, 100000],[],0, "FORM"];
    _vehicle  setDir _vehicleDir;
    _vehicle setvelocity [0,0,0];
    _vehicle  setPos [_position select 0, _position select 1, 0.15];
    _siden= getNumber (configFile >> "CfgVehicles" >> _vehicleType >> "side");
    _group = createGroup (_sides select _siden);
    _crewType = _spawnedcrewtype;

    _npos = (_vehicle EmptyPositions "driver")+(_vehicle EmptyPositions "gunner")+(_vehicle EmptyPositions "Commander");

While {_countx < _npos} do
{
_countx = _countx+1;
_unit = _group createUnit [_crewType,[(_position select 0)-100*sin(getDir _vehicle), (_position select 1)-100*cos(getDir _vehicle),1000],[],50,"NONE"];

if ((_vehicle EmptyPositions "Driver") >0) then {_unit moveInDriver _vehicle; _unit setUnitRank "CORPORAL";};
if ((_vehicle EmptyPositions "Gunner") >0) then {_unit moveInGunner _vehicle; _unit setUnitRank "SERGEANT";};
if ((_vehicle EmptyPositions "Commander") >0)then {_unit moveInCommander _vehicle; _unit setUnitRank "LIEUTENANT";};
};

[color="Blue"]{
_unit = _group createUnit [_crewType,[(_position select 0)-100*sin(getDir _vehicle), (_position select 1)-100*cos(getDir _vehicle),1000],[],50,"NONE"];

_unit MoveInTurret [_vehicle,_x];
       sleep 1;
if (!(_unit in (crew _vehicle))) then {deleteVehicle _unit;};

}ForEach _turretsArray;[/color]

};

Share this post


Link to post
Share on other sites

yes that will work, but then you will get magic teleport and not AI boarding the turret wich is what i wanted to avoid doing.

I wanted workaorund for the missing assignAsTurret command.

if you simply want to fill a vehicle with magic teleport just use this:

_veh = _this select 0;
_grp = _this select 1;

_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] ];
{
if ((_veh emptyPositions "Gunner") != 0) exitWith {_x assignAsGunner _veh; _x moveInGunner _veh};
if ((_veh emptyPositions "Commander") != 0) exitWith {_x assignAsGunner _veh; _x moveInGunner _veh};
if ((_veh emptyPositions "Driver") != 0) exitWith {_x assignAsGunner _veh; _x moveInGunner _veh};
_x assignAsGunner _veh;
_unit = _x;
{
	if ((vehicle _unit) == _unit) then {_unit MoveInTurret [_veh,_x]};
} foreach _turretArray;
if ((vehicle _x) == _unit AND (_veh emptyPositions "Driver") != 0) exitWith {_x assignAsCargo _veh; _x moveInCargo _veh};
} foreach units _grp;

Edit: what is the purpose of all the position things in your script DAP?

does it give a correct boarding position?

Edited by Demonized

Share this post


Link to post
Share on other sites

First post updated with fully working workaround for missing assignAsTurret command on any vehicle.

Ai runs to correct position and mounts the specified turret correctly.

Share this post


Link to post
Share on other sites

My teleport to leader script only teleports players into the gunner seat if it is available, but it would be great if it was possible to teleport them into the other available turret positions. For instance, my mission uses Chinook HC4 that has three gunner/turret positions. Just yesterday my friend teleported to leader and wound up in the back of the Chinook and then he said, "Ahh man, this sucks, there are 2 empty gun seats and I'm stuck sitting back here". So I thought maybe you could help.

Flag Pole Init:

this addAction ["Teleport to Team Leader", "teleport_to_leader.sqf", [], 51, true, true, "", "player != s1"];

teleport_to_leader.sqf:

_unit = _this select 1;


if (!alive s1) then {
hint "The Team Leader is currently dead.";
} else {
if (vehicle s1 == s1) then {
	_unit setDir direction s1;
	_unit setPosATL [getPosATL s1 select 0,getPosATL s1 select 1,getPosATL s1 select 2];
	_unit setPos (s1 modelToWorld [+0.75,-1,((position s1) select 2)+0]);
} else {
	if (vehicle s1 != s1) then {
	_freePosGunner = (vehicle s1) emptyPositions "gunner";
	_freePosCommander = (vehicle s1) emptyPositions "commander";
	_freePosCargo = (vehicle s1) emptyPositions "cargo";
	_freePosDriver = (vehicle s1) emptyPositions "driver";
	if (_freePosGunner > 0) then {
		_unit moveInGunner (vehicle s1);
	} else {
		if (_freePosCommander > 0) then {
			_unit moveInCommander (vehicle s1);
		} else {
			if (_freePosCargo > 0) then {
				_unit moveInCargo (vehicle s1);
			} else {
				if (_freePosDriver > 0) then {
					_unit moveInDriver (vehicle s1);
				} else {
					hint "The Team Leader's vehicle currently has no empty seats to teleport to.";
				};
			};
		};
	};
};
};

Would it be possible to add a turret array and check for available turret positions and use moveInTurret instead of moveInGunner?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×