pierremgi 4475 Posted August 27, 2018 Hi all, Trying to make an automatic reload for the S-750 Rhea, i discovered a strange Arma engine behavior. I placed via editor one player, one S-750 and R-750 (sensors are active by default). Then a black Wasp as enemy, disabled damage and a loiter waypoint around the SAM system in order to make it fire again and again. So, when out of missile, you need to reload the SAM. I placed in init field of the launcher: this addEventHandler ["fired",{ params ["_unit"]; if (magazinesAmmo _unit select 0 select 1 == 1) then { _unit addMagazineTurret ["magazine_Missile_s750_x4",[0],4] } }]; That works, but there is no delay to reload the SAM and I'd like to add a decent one for more realism. So I tried, as test, to spawn a code: this addEventHandler ["fired",{ params ["_unit"]; if (magazinesAmmo _unit select 0 select 1 == 1) then { _unit spawn { params ["_unit"]; waitUntil {magazinesAmmo _unit isEqualTo []}; sleep 5; _unit addMagazineTurret ["magazine_Missile_s750_x4",[0],4] } } }]; This last code doesn't work. Not a script question. The magazines are added but the launcher remains empty and don't fire. I added a loadMagazine with no more success. The strange thing: If I remove the simple line: sleep 5; the code works again (but missiles are loaded with no delay.) Any clue? Share this post Link to post Share on other sites
HazJ 1287 Posted August 27, 2018 Odd. Why not put all code inside? Like so: this addEventHandler ["Fired", { _this spawn { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; if (((magazinesAmmo _unit select 0) select 1) isEqualTo 1) then { waitUntil {magazinesAmmo _unit isEqualTo []}; sleep 5; _unit addMagazineTurret ["magazine_Missile_s750_x4", [0], 4]; }; }; }]; Also... Try using the magazinesTurret command instead. Have you tried debugging to see if magazinesAmmo returns an actual empty array, etc? Share this post Link to post Share on other sites
pierremgi 4475 Posted August 27, 2018 3 hours ago, HazJ said: Odd. Why not put all code inside? Like so: this addEventHandler ["Fired", { _this spawn { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; if (((magazinesAmmo _unit select 0) select 1) isEqualTo 1) then { waitUntil {magazinesAmmo _unit isEqualTo []}; sleep 5; _unit addMagazineTurret ["magazine_Missile_s750_x4", [0], 4]; }; }; }]; Also... Try using the magazinesTurret command instead. Have you tried debugging to see if magazinesAmmo returns an actual empty array, etc? As I wrote, it's not a script question. It's easy to reproduce that. The condition works fine. The only thing which breaks the reloading is the sleep command (in a scheduled scopre...) So, there is something weird with the SAM. Just try that. Share this post Link to post Share on other sites
davidoss 548 Posted August 27, 2018 Hi. Maybe you just need make them to reload, after your sleep where they set no ammo left. Anyway the time how long weapon reload take place you can set by setWeaponReloadingTime. Try always put sleep inside waituntil scope, if you want one just after or for slown down evaluation. 0 = this setWeaponReloadingTime [gunner this, "magazine_Missile_s750_x4", 1]; this addEventHandler ["fired",{ params ["_unit"]; if (magazinesAmmo _unit select 0 select 1 == 1) then { _unit addMagazineTurret ["magazine_Missile_s750_x4",[0],4] }; }]; 1 Share this post Link to post Share on other sites
pierremgi 4475 Posted August 27, 2018 5 hours ago, davidoss said: Hi. Maybe you just need make them to reload, after your sleep where they set no ammo left. Anyway the time how long weapon reload take place you can set by setWeaponReloadingTime. Try always put sleep inside waituntil scope, if you want one just after or for slown down evaluation. That doesn't work (anywhere i write the setWeaponReloadingTime in the script). In all cases: - the SAM can fire each loaded missile every ~ 5 or 6 sec; - can reload (with unscheduled/scheduled with small* delay code). Then, the animation is instantaneous but the next first missile of 4 can't be fired sooner as ~13 sec. The setWeaponReloadingTime doesn't have any effect. (I failed in all cases). * I did some tests and I can confirm that SAM is reloaded if the delay (sleep) is up to 3 sec. The reload fails with 4 sec or more. I didn't chase for the exact limit. So, there is a little slot in the SAM macro to reload it. If overshot, you have an empty SAM. The question is: how to reload it each 10 minutes? Share this post Link to post Share on other sites
HazJ 1287 Posted August 27, 2018 The sleep shouldn't break it... You could try uiSleep though. Share this post Link to post Share on other sites
pierremgi 4475 Posted August 27, 2018 1 hour ago, HazJ said: The sleep shouldn't break it... You could try uiSleep though. uiSleep or sleep doesn't make difference. As I said, it's not a script question. It's something related with the time spent after the SAM is totally empty. It seems to me the engine (SAM macro: _generalMacro = "StaticMGWeapon"; is same as MG static by the way) probably continues to run for some animation or else, during less than 4 sec. The reload is possible within this slot, but no more after, with the same code. No clue why. I checked also the weapon: "weapon_s750Launcher" is supposed to autoreload: autoReload = 1; and the reloadTime = 4; (between 2 missiles) Thank you for your suggestion. It's easy to reproduce what I get (see first post). If anyone has a workaround (one more in Arma!)... Share this post Link to post Share on other sites
HazJ 1287 Posted August 27, 2018 No idea then. Is this the SAM from RHS or some other mod? Maybe ask in the official thread as they might be able to help you further. Share this post Link to post Share on other sites
pierremgi 4475 Posted August 27, 2018 6 minutes ago, HazJ said: No idea then. Is this the SAM from RHS or some other mod? Maybe ask in the official thread as they might be able to help you further. No, the vanilla one (since Encore update). Share this post Link to post Share on other sites
HazJ 1287 Posted August 27, 2018 Ah. That one. Not messed with it too much, I'll do some testing / messing around with later on. Share this post Link to post Share on other sites
Grumpy Old Man 3512 Posted August 28, 2018 BI naming convention strikes again, setWeaponReloadingTime doesn't do what the name implies at a first glance, same for playerViewChanged EH (which still confuses the heck out of me how BI came up with that name considering the functionality of the EH, go figure). Spoiler setWeaponReloadingTime only affects reloading single rounds, not magazines. Check the comments on the page for further info. Cheers 1 Share this post Link to post Share on other sites
friendlyfyre 2 Posted March 12, 2019 @pierremgi Try this. Worked for me. this addEventHandler ["fired",{ params ["_unit"]; _unit spawn { params ["_unit"]; if (count (magazinesAmmo _unit) == 0) then { sleep 20; _unit addMagazineTurret ["magazine_Missile_mim145_x4",[0],4]; }; }; }]; Note that's the NATO SAM. Not the CSAT one. I think your issue is that by the time 4 seconds has passed your SAM has fired its last missile. Meaning magazinesAmmo _unit select 0 select 1 == 1 evaluates false. Either that or BI fixed it since you posted. On a related note, the SAM fires off all its missiles ridiculously fast. Which may or may not be realistic but it does mean the turret wastes 4 missiles on 1 plane. And 4 turrets wasted 16 missiles on 1 plane. Which looks even sillier. So I wrote this: this addEventHandler ["fired",{ params ["_unit"]; _unit spawn { params ["_unit"]; (group _unit) setCombatMode "BLUE"; sleep 20; (group _unit) setCombatMode "RED"; if (count (magazinesAmmo _unit) == 0) then { _unit addMagazineTurret ["magazine_Missile_mim145_x4",[0],4]; }; }; }]; 1 Share this post Link to post Share on other sites
dave_beastttt 135 Posted March 12, 2019 _thisIsMySAMToReload addEventHandler ["Fired",{_this spawn {uiSleep 30; (_this select 0) setVehicleAmmo 1}}]; Share this post Link to post Share on other sites