Jump to content
Sign in to follow this  
RonnieJ

Incorporate while loop how to

Recommended Posts

hey guys... ive got this piece of code that checks if s1-s10 players have been found by enemyUnit:

_unitArray = [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10];

if ({enemyUnit knowsAbout _x > 3} count _unitArray > 0) then {

hint "player spotted by enemyUnit";

} else {

hint "enemyUnit hasn't spotted a player yet";

};

But im not sure how to incorporate this code... if I place it in a units init then its only run once and I surpose this should be turned into a while loop insted then? Or should it be a trigger... im really not sure... any one who can help me?:confused:

Edited by RonnieJ

Share this post


Link to post
Share on other sites

Put it in a file called init.sqf in your mission folder.

Share this post


Link to post
Share on other sites

But will that make the code run all the time? As I understand this... this code will only be run once... but I need it to look all the time... or at least every 5 seconds or something

Share this post


Link to post
Share on other sites

call it with nul=[] execVM "Knows.sqf"; placed in a unit's init.

Save code as "knows.sqf"

_unitArray = [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10];

While {true} do
{

if ({enemyunit  knowsAbout _x > 3} count _unitArray > 0) then {
hint "player spotted by enemyUnit";
} else {
hint "enemyUnit hasn't spotted a player yet";
};
sleep 5;
};

Share this post


Link to post
Share on other sites

Works perfectly... theres just one last question... how do I know what player he have seen? I need him to target that one... tried with _x with no luck

---------- Post added at 08:06 PM ---------- Previous post was at 07:52 PM ----------

_unit dotarget _x;

---------- Post added at 08:55 PM ---------- Previous post was at 08:06 PM ----------

Strange... I try:

_unit disableAI "MOVE";

_unit selectWeapon "Laserdesignator";

_unit dotarget _x;

_unit dofire _x;

The movement is disabled but the unit dosent select the laser designator and target me?? If I kill the target the laser designator is on with batteries...

---------- Post added at 09:02 PM ---------- Previous post was at 08:55 PM ----------

Seems to have something to do with the group he is in... the unit apparently get commands from the leader... is there any way to "disable" the group commands so he cant act according to the commands he get from the script?

Share this post


Link to post
Share on other sites

Okay I made a work around but I still need to know how to target what ever unit it is he have seen...

Share this post


Link to post
Share on other sites

I think the problem is _x If you use a hint to display the value it won't report the unit.

_unitArray = [s1, s2, s3, s4, s5, s6, s7, s8, s9, s10];

While {true} do
{
_i=0;
while {_i < (count _unitarray)} do
{
if ( enemyunit knowsabout (_unitarray select _i) >3) then  {
  hint "player spotted by enemyUnit";
 sleep 2;
hint format ["name %1",(_unitarray select _i)];
enemyunit disableAI "MOVE";
enemyunit selectWeapon "Laserdesignator";
sleep 6;
enemyunit dotarget (_unitarray select _i);
enemyunit dofire (_unitarray select _i);

} else {
 hint "enemyUnit hasn't spotted a player yet";
};
_i = _i +1;
};
};

that will now display who the unit knowsabout, so instead of _x try _unitarray select _i

He will get the laser designator out but then puts it away. I don't know how to take it further sorry.

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I don't think the AI like the laserdesignator. i tried a few things to force them to use it and they always resorted back drawing their rifle. Even when i removed all other weapons the AI spazzed tryign to get a weapon that wasn't there. An issue you will run in to with that script is if you get it to work what the Ai will do is switch through all the targets he knwos about as fast as the script cycles. So say he knowsabout s1,s2, and s3, he will aim at one then the other and then the other each time the loop cycles.

Are you trying to get the Ai to do a coordinated airstrike or something? Might have to use a workaround, like just create the lasertarget on the unit and have it track the units movement.

Share this post


Link to post
Share on other sites

Things like that always seem to be hit and miss, (old OFPEC thread) though I think the AI are only built to use the designator on armored targets.

Maybe you could keep the whole selectWeapon thing there just for show, and simulate the entire airstrike, or whatever it was you're after. You could createVehicle a "LaserTarget" on the spotted player's position, then use doTarget with an air unit to fire on the position.

As far as I know the AI are usually pretty accurate when it comes to firing at laser targets, if not, you could always just createVehicle the bomb in the correct position.

Share this post


Link to post
Share on other sites

Thx for the answers guys...

F2k Sel> Ill try the script later since I havent got the time now - But it looks perfect and im looking forward to it! :)

And yes this is a part of a random script where I put a FAC into an excisting enemy group... this unit and only this unit may call in an enemy airstrike on the players when he sees them...

I made a workaround conserning the laserdesignator and he now stops up and uses it correctly... this have only been testet on a car (succesfully airstrike) so I have to try on some infantry to see if it is possible.

If not I might have to script the airstrike so I can avoid the laserdesignator...

Jonescrusher> did you have any ideas concerning an enemy airstrike?

And again thx guys for the help so far :)

Edited by RonnieJ

Share this post


Link to post
Share on other sites

Yeah, the AI seem to treat the laser designator as some kind of an AT weapon, and draw it naturally when facing appropriate targets. Changing that would most likely require an addon that tells them it's ok to use it on infantry (but then don't be surprised when they don't shoot you, as they will draw out their laser whether or not there is an aircraft around to use it).

Share this post


Link to post
Share on other sites

I have tried making the AI attack the unit its self without the laserdesignator but everytime the bombs dosent hit its target....

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  

×