Grizzle 0 Posted November 24, 2009 (edited) Ok, so the situation is I need one AI to kill an entire AI squad and I've tried using the following code to do that but the attacker seems to stop after the first kill. So basically I'm trying to use forEach to iterate the units and fire on each one in turn until they are dead then move to the next unit in the squad. Should be simple right? If I change the attacker doFire statement to a setDamage 1 statement they all fall down, presumably dead. So... what gives? { while {alive _x} do {attacker doFire _x;}; } forEach units group Squad1; Any suggestions would be greatly appreciated. Edited November 24, 2009 by Grizzle Share this post Link to post Share on other sites
f2k sel 164 Posted November 24, 2009 This seems to work for me // nul=[squad,attacker] execVM "squad.sqf"; _squad = _this select 0; _attacker = _this select 1; { while {alive _x} do {_attacker doFire _x; sleep 5; }; } forEach units _squad; I tried using just a trigger and did get it to work but it did cause a the game to lag. Share this post Link to post Share on other sites
Grizzle 0 Posted November 25, 2009 This seems to work for meI tried using just a trigger and did get it to work but it did cause a the game to lag. Hmmm. I was using it directly within the trigger as opposed to an SQF file, but it does work when executed as a script file. I'm guessing it's good practice to use scripts as opposed to coding directly within the editor UI? Share this post Link to post Share on other sites
mattxr 9 Posted November 25, 2009 Scripts dont harm anyone when coded right :) some say they make the mission perform less well but thats all BS lol the whole game is scripted. :) Share this post Link to post Share on other sites
f2k sel 164 Posted November 25, 2009 (edited) It could be the while command looping continuously causing the lag. I couldn't get the sleep delay to work in the trigger, increasing the delay will reduce the amount of loops so the larger the delay reduces the strain on the cpu. It may be better to replace sleep with something like waituntil {!alive _x }; but I haven't tested it. Also it would be a good idea to check the alive status of the attacker, if he gets killed while the script is running I don't think it will ever finish until the whole squad is dead. Update.. I did test it using waituntil and it does work better as the attacker is less prone to changing positions but for some reason halfway through killing the squad he changes weapons to pistol and won't fire anymore. Edited November 25, 2009 by F2k Sel Share this post Link to post Share on other sites
Grizzle 0 Posted November 25, 2009 ^^^ Thanks for the feedback. It's not actually for a mission, it's for a movie so performance and the attacker dying isn't much of an issue. I had tried the sleep before in the trigger but it seemed to lock up. In any event moving it to a file was the key to better success. I'm new to ARMA scripting (but not coding in general) and I wasn't aware of the waituntil command so I might give that a go as well. Thanks! Share this post Link to post Share on other sites