Jump to content
Sign in to follow this  
yoannis1995

Clear house script

Recommended Posts

Thanks, I had a look at the scripts but it doesn't allow the player to order IA to clear a building. And I couldn't find anything about an occupied position... :/

Is there any posibility to know wheter a position is occupied or not ?!

---------- Post added at 11:29 AM ---------- Previous post was at 10:15 AM ----------

I've added that to the script:

_listEnemy = [];
_listEnemy = (position _build) nearEntities ["Man",25];
{_unitL reveal [_x, 3.5];} forEach _listEnemy;

it helps to avoid that the IAs get killed too easily in the building. But is there any possibility to select only the units of one side (EAST) in the _listEnemy ?!

Share this post


Link to post
Share on other sites

Not tested but this might do the job, you could also create an array of just enemy or remove the enemy from the array

{if (side _x == east) then  {_unitL reveal [_x, 3.5]} foreach _listEnemy;

or

if (side _x != east) then  {_listEnemy = _listEnemy - [_x];}} forEach _listEnemy;

{_unitL reveal [_x, 3.5]} foreach _listEnemy;

from now on _listEnemy would only contain east units in the array.

Share this post


Link to post
Share on other sites

Yeah it seems to be working, thanks :)

Any ideas how to know if a position is occupied or not ?

I don't really know how we could do it but maybe combine the "if" and "forEach" commands to check if the position of each unit contained in the array _listEnemy is equal to one of the entries in the building positions array ?!

Share this post


Link to post
Share on other sites

If the enemy was placed in the building using a waypoint then you can use pos = waypointHousePosition [group red,1]; to return the position.

I'm not sure how you could implement that, also for some reason my units don't seem to be skipping rooms today so I can't really test anything.

Share this post


Link to post
Share on other sites

I tried to make the IA look around randomly at each positions but it doesn't seem to work. Also I deleted the reveal command because it makes the IA look at one enemy through the walls and then they don't look at any other targets on their way. So is it possible to use the reveal command only for the nearest enemy of the current position the IA are moving ?

Share this post


Link to post
Share on other sites

It only reveals AI units so you can't reveal items or objects.

Revealing the enemy AI will reveal it as a threat and will probably override other less important commands.

Share this post


Link to post
Share on other sites

No I mean reveal only the enemy IA near the position the IA is currently moving and not revealling all the IA of building to avoid the IA to look at enemies through the walls and missing enemies on their way. Also, the IA is often aiming an enemy but he takes a really long time to shoot. And by the way, it's the new script with the random thing:

_cnt = 0; 
_posarray = []; 
_listEnemy = [];
_unitL = _this select 0; // player
_unitS = _this select 1; // Units selected
_GroupLeader = leader (group _unitL);
_group = group _unitL;
_build = cursortarget; 

if (((_build buildingpos 0) select 0) != 0) then
{ 
   //as long as building position _cnt not equal to "[0,0,0]" keep looping 
  while {format ["%1", _build buildingpos _cnt] != "[0,0,0]" } do { 

       _pos = _build buildingpos _cnt;        //select building position _cnt 
       _posarray = _posarray + [_pos];        //add the position to the list 

       _cnt = _cnt + 1;        //increment counter 
       sleep 0.01; 
   }; 
_listEnemy = (position _build) nearEntities ["Man",25];
{if (side _x != east) then  {_listEnemy = _listEnemy - [_x]} forEach _listEnemy;};
player groupChat "Clear that building!";

{ 
 _temp_x = _x;
{ // adjust Unit Skills
   sleep 0.01; 
   _x setBehaviour "AWARE";
   _x setCombatMode "RED";
   _x setSpeedMode "LIMITED";
   _x setSkill ["aimingAccuracy",1];
   _x setSkill ["aimingShake",0];
   _x setSkill ["endurance",1];
   _x setSkill ["aimingSpeed",1];
   _x setSkill ["spotDistance",1];
   _x setSkill ["spotTime",1];
   _x setSkill ["courage",1];
   _x setSkill ["reloadSpeed",1];
   _x setSkill ["commanding",1];
   _x setSkill ["general",1];
 //////////////////////   

  _x  doMove   _temp_x; 
sleep 2;
// all units selected  
} foreach _units;
// this needs work as its only checking one unit 
waitUntil {sleep 1; (unitReady (_unitS select 0) || moveToCompleted (_unitS select 0)  || moveToFailed (_unitS select 0) || !alive (_unitS select 0))};

sleep 0.5; 
_cntUnit = count _unitS;
_cntUnit = _cntUnit - 1;
_select = random (_cntUnit);
(_unitS select _select) setDir (random 360);
sleep 5;
_group setFormDir (random 360);
} forEach _posarray; 

   sleep 2; 


if ({alive _x} count _unitS != 0) then {
(_unitS select 0)  groupChat "Building clear !"; 
};


{
sleep 1;
_x doFollow _GroupLeader;
}  foreach _unitS;  
} else {hint"The selected object is not available.";};
if (true) exitWith {};

That's the new part but I'm not sure it's right ?!

_cntUnit = count _unitS; 
_cntUnit = _cntUnit - 1; 
_select = random (_cntUnit); 
(_unitS select _select) setDir (random 360); 
sleep 5; 
_group setFormDir (random 360);

Share this post


Link to post
Share on other sites

How you have it won't work as random won't return whole numbers you need to use floor,round or ceil depending how you want the number formatting.

Also I removed the waituntil line so I could use the time to do other things.

while {_check} do {

if (moveToFailed (_unitS select 0)) then {hint "Fail";_check = false;};//never  activates even  it should

if (moveToCompleted (_unitS select 0)) then {hint "Comp";_check = false;};

if (unitready (_unitS select 0)) then {hint "Ready";_check = false;};

_select = floor random (count _unitS);
(_unitS select _select) dowatch [(getpos (_unitS select _select) select 0)+ random (360)-180,(getpos (_unitS select _select) select 0)+ random (360)-180,1];
hint format ["%1",name (_unitS select _select)]; 

_rnd = floor random 2;

hint format ["%1",_rnd];
sleep 1;
switch (_rnd) do {
case 0: { (_unitS select _select) setunitpos "up" };
case 1: { (_unitS select _select) setunitpos "middle" };
};
sleep 1; 
};

The real problem is still not being able to detect when the unit won't move to the next room position, I also notice that it's not just the occupied room but the one before that skips as well.

I've done a test and the AI doesn't know about the enemy so it has to be an occupation bug.

It's a bug because if you order a unit to move directly to the buildpos that's occupied it does so with hesitation and the same if you issue domove to unit name.

But in the script no matter how many times I issue the domove command it either halts or skips the rooms.

I then tried using a radio command and if you issue the move command several time it will move to the room.

Right now it's beating me.

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  

×