Kydoimos 916 Posted June 7, 2015 Hi all! I'm just trying to optimise a very, very simple ambient firing script. It works fine, but it's a bit crude. Essentially, I just want to have a selection of units fire their weapons (preferably with some small, split second delays) for a short period of time, before having them stop. They don't really need to be aiming properly! Here's what I've been using: _FIA_A fire "arifle_MX_SW_Black_F"; _FIA_B fire "hgun_PDW2000_F"; _FIA_C fire "arifle_MK20_MRCO_F"; Sleep 0.15; _FIA_A fire "arifle_MX_SW_Black_F"; etc... etc... Any thoughts? Obviously, 30 seconds worth of shooting with a layout like the above would lead to a very long sqf! :D I was thinking maybe something involving a while loop? Thanks for any help in advance! Share this post Link to post Share on other sites
Jona33 51 Posted June 7, 2015 _t=time; while {time-_t < 30} do { {_x fire (currentWeapon _x)} forEach [_FIA_A,_FIA_B,_FIA_C]; sleep 0.15; }; Share this post Link to post Share on other sites
Kydoimos 916 Posted June 7, 2015 @Jona33 - so beautiful in its simplicity! :D Thank you mate! That's wonderful! Share this post Link to post Share on other sites
rübe 127 Posted June 7, 2015 (edited) _endtime = time + 30; _units = [_FIA_A, _FIA_B, _FIA_C]; while {true} do { { _x fire (primaryWeapon _x); sleep (random 0.33); } forEach _units; sleep (3 + (random 5)); // larger delay inbetween maybe if (_endtime < time) exitWith {}; // break out of while loop }; Something along those lines maybe? There is a small delay between each unit's shot; maybe you indeed want to have them shoot pretty much at the same time? If not, maybe you want to add a minimum/guaranteed amount of delay, for "random 0.33" could as well return next to 0 (I think you have at least 1 frame of delay no matter what...). You could also randomize the "_endtime" a little; note how the _endtime is independent of those short random delays (but can be too long by max. delay; well, non-issue...). You might want to setup some faketargets first and make those guys target 'em, in order to have them shoot in a general direction. You can, of course displace those targets a bit after each shot or something. Then clean up (watch objNull) after exiting the main loop. While this is still nice and easy in script form, I'd rather do such stuff with some FSM - especially once more complex stuff (in terms of cases/conditions and what not...) is going on. But it doesn't really matter. EDIT: P.S. I like to write "while{true} do ..." to then use "exitWith"-clauses out of habbit, since it's much nicer this way once there are multiple different exit clauses - maybe at different steps in the while-block too. For example we could have: while {true} do { { _x fire (primaryWeapon _x); sleep (random 0.33); } forEach _units; if (_endtime < time) exitWith {}; // break out of while loop if (!(alive _FIA_A)) exitWith {}; // different reason to exit the while loop // maybe some other code inbetween... if ((player distance _FIA_A) > 500) exitWith {}; // yet another one... }; :cool: Edited June 7, 2015 by ruebe Share this post Link to post Share on other sites
Kydoimos 916 Posted June 7, 2015 @Ruebe - wow! Fantastic stuff! That's just brill, cheers! You wouldn't believe how much you've helped me downsize my scripts! Think I'm getting the idea now! :P Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted June 8, 2015 _target = "O_TargetSoldier" createvehicle _targetpos; {_x dofire _target} foreach _units; sleep 30; deletvehicle _target; No loops or similar needed, it's as if they were firing at a hostile unit, switching firemodes according to distance etc... Cheers Share this post Link to post Share on other sites
rübe 127 Posted June 8, 2015 Ahh, so that's how it's done properly. Cool beans :cool:, thanks for tuning in Grumpy. Nothing beats comprehensive knowledge of all the gimmicks the engine offers (and how they're supposed to be put together...) - otherwise you end up with overly complicated and overengineered scripts like mine. ...guess I should read some of the classic guides for OFP/Arma/... (Murphie's or what not...) again some time, in order to (re-)discover all the "old school" patterns of doing things. There are so many cool things one can achieve with just a bunch of simple tricks, yet I tend to forget that stuff after some time away from the game... :( Share this post Link to post Share on other sites
Grumpy Old Man 3547 Posted June 8, 2015 Yeah, there's a few bits and pieces in the engine that still work fine. How to figure them out is an entirely different matter, heh. About proper solutions, as long as it gets the job done its proper enough. Cheers Share this post Link to post Share on other sites