Monti Posted December 5, 2019 Share Posted December 5, 2019 Hi Folks, i´ve started to implement Moose within my missions but get stucked regarding the following problem. I want to create a training-mission where a trigger starts to spawn (and respawn) infinite bandits. This was easy .. i think :-) the following code works fine for me: if trigger.misc.getUserFlag('1') == 1 then Spawn_Mig_29 = SPAWN:New("Mig-29"):InitKeepUnitNames(true) Spawn_Mig_29:InitLimit( 1, 0 ):SpawnScheduled( 60, 0 ) Spawn_Mig_29:InitRepeatOnEngineShutDown() Spawn_Su_27 = SPAWN:New("Su-27"):InitKeepUnitNames(true) Spawn_Su_27:InitLimit( 1, 0 ):SpawnScheduled( 60, 0 ) Spawn_Su_27:InitRepeatOnEngineShutDown() end But now - i want to be able to deactivate/stop the respawning of the bandits and .. after that ... be able to reactivate the respawning. So i added the following lines - and this doesn´t work so far: if trigger.misc.getUserFlag('1') == 2 then Spawn_Mig_29:SpawnScheduledStop() Spawn_Su_27:SpawnScheduledStop() end if trigger.misc.getUserFlag('1') == 3 then Spawn_Mig_29:SpawnScheduledStart() Spawn_Su_27:SpawnScheduledStart() end For your information. I´ve added radio-messages (switched condition) to the mission, which set the flag '1' to 1, 2 or 3. Question beside. For testing and debugging i´ve changed the lua-script a several times and added messages ToAll() to see if the triggers 2 an 3 are adressed. I´ve never seen a message. So i deleted the whole content of my lua script and restarted the mission ... nevertheless the bandits spawned, so i think the lua-script file wasn´t read again. So i restarted DCS and changed the name of the lua-file. That worked so far for lua-changes, but the code-lines above won´t work. Anyone got an idea, how to solve my concern ? Link to comment Share on other sites More sharing options...
Habu_69 Posted December 5, 2019 Share Posted December 5, 2019 A script is read by the mission only once, so if you need an action to start after the initial script read, those actions must be placed in a SCHEDULER function. Read about it in Moose docs. As an alternative, I suppose you could have a second independent script that is initiated by a trigger action when a trigger condition is met. Link to comment Share on other sites More sharing options...
Monti Posted December 5, 2019 Author Share Posted December 5, 2019 Thx4 your Reply. In your opinion - do u think my script would work, if i will put the lua code (for stopping and reactivating) in several files ? Because DCS reads a script-file just once, stopping and reactivating would also work just once, right ? Link to comment Share on other sites More sharing options...
A101Wayz Posted December 5, 2019 Share Posted December 5, 2019 One of the best and easiest ways I can think of to achieve your goal would be to use a Finite State Machine (FSM). It will allow for infinite starts and stops using any working trigger, requires only a single script file, and the script file only has to be called once. See Example Mission: FSM-100 Transition Explanation FSMs work great for the task you are describing. Wayz Out Intel Core i9 9900K | ASUS ROG Strix Z390E Gaming MB | G.Skill Ripjaws V 32gb DDR4-3200 | GeForce RTX 2080 Ti | Samsung 970 EVO Plus NVMe HTC Vive Pro VR | Logitech G x56 HOTAS | Logitech G PRO Pedals Link to comment Share on other sites More sharing options...
reiser Posted December 5, 2019 Share Posted December 5, 2019 if trigger.misc.getUserFlag('1') == 1 then Spawn_Mig_29 = SPAWN:New("Mig-29"):InitKeepUnitNames(true) Spawn_Mig_29:InitLimit( 1, 0 ):SpawnScheduled( 60, 0 ) Spawn_Mig_29:InitRepeatOnEngineShutDown() Spawn_Su_27 = SPAWN:New("Su-27"):InitKeepUnitNames(true) Spawn_Su_27:InitLimit( 1, 0 ):SpawnScheduled( 60, 0 ) Spawn_Su_27:InitRepeatOnEngineShutDown() end First off, your Init's need to be before ANY Spawn* functions. Second, you need to hook into the events system to start/stop the spawn schedule. You're on the right track with the triggers, but what you need is a SCHEDULE to continuously check those triggers. The triggers can be triggered via menu options or what not later. You can even then use MISSION to have the menu's to trigger the trigger to spawn. Link to comment Share on other sites More sharing options...
Monti Posted December 6, 2019 Author Share Posted December 6, 2019 Thx mates, @A101Wayz sent u a PM. Please have quick look. Link to comment Share on other sites More sharing options...
A101Wayz Posted December 6, 2019 Share Posted December 6, 2019 Having issues with responding to PM's for some reason. Got you msg. Will get back to you after I've tested... Wayz Out Intel Core i9 9900K | ASUS ROG Strix Z390E Gaming MB | G.Skill Ripjaws V 32gb DDR4-3200 | GeForce RTX 2080 Ti | Samsung 970 EVO Plus NVMe HTC Vive Pro VR | Logitech G x56 HOTAS | Logitech G PRO Pedals Link to comment Share on other sites More sharing options...
Pikey Posted December 7, 2019 Share Posted December 7, 2019 I believe the getUserFlag() needs checking. try if trigger.misc.getUserFlag('1') == '1' then also your Inits have to come before you spawn else they do nothing. ___________________________________________________________________________ SIMPLE SCENERY SAVING * SIMPLE GROUP SAVING * SIMPLE STATIC SAVING * Link to comment Share on other sites More sharing options...
A101Wayz Posted December 8, 2019 Share Posted December 8, 2019 Here's a sample mission that I used to test the script. If you don't have the F-18 module, you might want to change the F-18 at Kobaleti to an aircraft you do have, before you run the mission. FSM_BanditSpawnTest.miz Wayz Out Intel Core i9 9900K | ASUS ROG Strix Z390E Gaming MB | G.Skill Ripjaws V 32gb DDR4-3200 | GeForce RTX 2080 Ti | Samsung 970 EVO Plus NVMe HTC Vive Pro VR | Logitech G x56 HOTAS | Logitech G PRO Pedals Link to comment Share on other sites More sharing options...
Monti Posted December 9, 2019 Author Share Posted December 9, 2019 Thx for all your support, especially A101Wayz Link to comment Share on other sites More sharing options...
fargo007 Posted December 9, 2019 Share Posted December 9, 2019 The technique I use for this is to declare it all, and then create user functions that I can call from the ME when desired for starting/stopping. function stopSpawns() Object:SpawnScheduledStop() end So in the ME, all you would have to execute is a do_script that calls: stopSpawns() And the same technique for starts. But these need to be defined after the declarations and spawns of course. Have fun. Don't suck. Kill bad guys. https://discord.gg/blacksharkden/ Link to comment Share on other sites More sharing options...
Recommended Posts