Jump to content

Recommended Posts

HI All,

 

I cannot get the AI to move to the top level waypoints of a tower.

 

The AI seems to stay on the ground level.

 

How can I get the AI to move to each building position on the top floor? for example:

 

player addAction ["<t color='#f44298' size='1' > BUILDING SEARCH</t>", {

	_posTestGrp = screenToWorld [0.5,0.5];	
	_building = "Land_Cargo_Tower_V1_No1_F" createVehicle _posTestGrp;
	sleep 1;
	
	_testgrp = createGroup WEST;
	_soldier = "B_Soldier_F";		
	_newUnit = _testgrp createUnit [_soldier, _posTestGrp   , [], 0, "NONE"]; 

	_buildingPositionsArray = [_building] call BIS_fnc_buildingPositions;	
	_buildingPositionsCount = count _buildingPositionsArray;
	
	for "_i" from 10 to _buildingPositionsCount - 1 do {	
		_wp = _testgrp addWaypoint [AGLToASL (_building buildingPos _i), 0];
		//_wp waypointAttachObject _building;
		_wp setWaypointHousePosition _i;
		_testgrp setCurrentWaypoint _wp; 
		//_wp setWaypointType "MOVE";
		_arrow = createSimpleObject ["Sign_Arrow_F", AGLToASL (_building buildingPos _i)];
		hint format ["moving to %1", getPosATL _arrow];
		waitUntil {
			sleep 1;
			hint format ["%1m to %2", round (AGLToASL getPos _newUnit distance AGLToASL (_building buildingPos _i)), AGLToASL(_building buildingPos _i)];
			((AGLToASL getPos _newUnit distance AGLToASL(_building buildingPos _i)) < 2)
		};	
		sleep 3;
		deleteVehicle _arrow; 
	};		
},"",2];

I also tried without waypoints and used ATL

 

player addAction ["<t color='#f44298' size='1' > BUILDING SEARCH</t>", {

	_posTestGrp = screenToWorld [0.5,0.5];
	
	_building = "Land_Cargo_Tower_V1_No1_F" createVehicle _posTestGrp; // Land_Cargo_HQ_V1_F  
	sleep 1;
	
	_testgrp = createGroup WEST;
	_soldier = "B_Soldier_F";		
	_newUnit = _testgrp createUnit [_soldier, _posTestGrp   , [], 0, "NONE"]; 

	_buildingPositionsArray = [_building] call BIS_fnc_buildingPositions; 
	_buildingPositionsCount = count _buildingPositionsArray;

	
	for "_i" from 0 to _buildingPositionsCount - 1 do {
		_buildingPos = [(_building buildingPos _i) select 0, (_building buildingPos _i) select 1,((_building buildingPos _i) select 2) + 5] ;
		_arrow = "VR_3DSelector_01_default_F" createVehicle _buildingPos; 
		_arrow setPosASL _buildingPos; 
		sleep 0.1;	
		/*
		_wp = _testgrp addWaypoint [[(getPosATL _arrow) select 0,(getPosATL _arrow) select 1, ((getPosATL _arrow) select 2) + 5], 0];
		_wp waypointAttachObject _building;
		_wp setWaypointHousePosition _i;
		_testgrp setCurrentWaypoint _wp; 
		_wp setWaypointType "MOVE";
		*/
		_newUnit move getPosATL _arrow;
		
		waitUntil {
			sleep 1;
			hint format ["%1m to %2", round (_newUnit distance getPosATL _arrow), getPosATL _arrow];
			(( _newUnit distance getPosATL _arrow) < 3)
		};	
		sleep 3;
		hint format ["I am here at %1", getPosATL _arrow];
		deleteVehicle _arrow; 
	};
},"",2];

But soldier does not climb up the stairs to get the first building waypoint!

Share this post


Link to post
Share on other sites

Have you tried removing the AGLToASL in your code? I think addwaypoint likes ATL positions more

 

Share this post


Link to post
Share on other sites

I tried without the AGLToASL, but still not working?

Share this post


Link to post
Share on other sites

I'm sorry but did you find a way to make it work ?

I'm trying the same thing in my mission with an object but i can't get the addwaypoint working too.

 

 

Share this post


Link to post
Share on other sites

Try to use the move command with the exact values that you get with BIS_fnc_buildingPositions. Don't do a getPosAtl of the arrow.

 

Works fine here.

 

EDIT : not working, I've just tested but I don't understand why because I already done that with that script :

_group = _this select 0;
_tower = _this select 1;
_side = side (leader _group);
_arrayPos = [14,11,16,7,4,2,8];
_arrayPos sort false;

hint "AI_CAPTURE START"; // TEST !!

// leader should not issue attack orders
_group enableAttack false;

_nameTower = format ["%1", _tower];
_units = [];
{if (_x getVariable _nameTower and alive _x) then {_units = _units + [_x]}} forEach allUnits; // list tower units
_towerGroup = group (_units select 0);


while {{alive _x} count units _group > 0} do {
	private ["_position"];

	_countUnits = {alive _x} count units _group; // count units group attack

	// CLEAR BUILDING
	//systemChat "AI_CLEARBUILDING";

	_units = [];
	{if (_x getVariable _nameTower and alive _x) then {_units = _units + [_x]}} forEach allUnits; // list tower units

	// get nearest ennemy unit
	_arrayEnnemyUnitsDist = [];
	for "_i" from 0 to (count _units)-1 do {

		_arrayEnnemyUnitsDist set [_i, [leader _group distance (_units select _i), _units select _i]];
	};
	_arrayEnnemyUnitsDist sort true;
	_unit = (_arrayEnnemyUnitsDist select 0) select 1;
	////

	_positions = [_tower] call BIS_fnc_buildingPositions; // list building positions

	// get the nearest pos of the nearest ennemy unit
	_arrayDistancePos = [];
	for "_i" from 0 to (count _positions)-1 do {

		_pos = _positions select _i;
		_dist = _pos distance _unit;

		_arrayDistancePos set [_i, [_dist,_pos]];
	};
	_arrayDistancePos sort true;


	// give units wps in building
	if ({alive _x} count units _group > 1) then {

		// get the nearest friendly unit from the pos
		_aliveUnits = [];
		{if (alive _x) then {_aliveUnits = _aliveUnits + [_x]}} forEach units _group - [leader _group];

		_arrayAliveUnitsDist = [];
		_position = (_arrayDistancePos select 0) select 1;
		systemChat str _position; // TEST !!!

		for "_i" from 0 to (count _aliveUnits)-1 do {

			_arrayAliveUnitsDist set [_i, [(_aliveUnits select _i) distance _position, _aliveUnits select _i]];
		};

		_arrayAliveUnitsDist sort true;
		////

		for "_i" from 0 to (count _aliveUnits)-1 do {

			((_arrayAliveUnitsDist select _i) select 1) doMove ((_arrayDistancePos select _i) select 1);

		};
	} else {
		
        _position = (_arrayDistancePos select 0) select 1;
		leader _group move _position;
	};

	{_group reveal _x} forEach _units;
	////

	_timer = [] spawn {
		sleep 180;
	};

	waitUntil {{alive _x} count units _group < 1 or {alive _x} count units _towerGroup < 1  or scriptDone _timer or !alive _unit};

	if ({alive _x} count units _group < 1 or {alive _x} count units _towerGroup < 1) exitWith {};

	if (!alive (leader _group)) then {

		_unitGroup = (units _group select {alive _x}) select 0;
		_group selectLeader _unitGroup;
		systemChat str (name _unitGroup); // TEST !!!
		playSound "event"; // TEST !!!
	};

	if (!isNil "timer") then {terminate _timer};
};

//systemChat "AI_CLEARBUILDING END";

// TEST

if ({alive _x} count units _group > 0) then {

	{_x doMove getPos _tower} forEach units _group;
	leader _group move getPos _tower;
};

while {{alive _x} count units _group > 0} do {
	systemChat "waiting for unitready";
	if ({alive _x} count units _group == {alive _x and unitReady _x} count units _group) exitWith {systemChat "ALL UNITS READY!"; playSOund "event"};
	sleep 1;
};

////

if ({alive _x} count units _group > 0) then {

	{
		_x setUnitPos "AUTO";
		_x doFollow leader _group;
	} forEach units _group;

};

_group setVariable ["capturing", false];
_group enableAttack true;

sleep 5;

hint "END AI_CAPTURE.SQF"; // TEST !!

 

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

×