St3v3f Posted August 27, 2013 Share Posted August 27, 2013 (edited) Baron's Tanker (and AWACS) Respawn Script; Version 2.1 If you have a long-running mission and want to have unlimited tanker support without having to place multiple tankers in the mission or are tired of being afraid of idiots killing the tanker, this is for you. The Tanker will respawn when one of three conditions is met: The Tanker is destroyed or damaged If it landed If it's fuel is low Steps: Add Mist to the mission. The script is working with DCS 1.5.2 and Mist 4.0.57 Place a tanker in the mission just like you always do. Give him waypoints and orbit instructions etc. It should have a RTB-Waypoint as well Create a MISSION START Trigger. For Action, select DO SCRIPT Paste the following code --RESPAWN SCRIPT; MISSION START -> DO SCRIPT local oldGroupRemovalTime = 2700 -- Time (seconds) after which old groups are removed barons_respawn_script = {} barons_respawn_script.predicate = function(groupName, lowFuelThreshold, lowHealthThreshold) if barons_respawn_script and barons_respawn_script[groupName] then groupName = groupName .. barons_respawn_script[groupName] end local group = Group.getByName(groupName) if not group then return true end group = group:getUnits()[1] if not group or Unit.inAir(group) == false then return true end if group:getFuel() < lowFuelThreshold or group:getLife() / group:getLife0() < lowHealthThreshold then return true end return false end barons_respawn_script.removeGroup = function(group) group = Group.getByName(group) if group then trigger.action.deactivateGroup(group) end end barons_respawn_script.action = function(groupName) local oldName = groupName if barons_respawn_script[groupName] == nil then barons_respawn_script[groupName] = 0 else oldName = groupName .. barons_respawn_script[groupName] end barons_respawn_script[groupName] = barons_respawn_script[groupName] + 1 local newName = groupName .. barons_respawn_script[groupName] mist.scheduleFunction(barons_respawn_script.removeGroup, {oldName}, timer.getTime() + oldGroupRemovalTime) local group = Group.getByName(oldName) if group then group = group:getController() Controller.setCommand(group, {id = 'DeactivateBeacon', params = {}}) Controller.setTask(group, {id = 'NoTask', params = {}}) end group = mist.getGroupData(groupName) group.route = { points = mist.getGroupRoute(groupName, true) } group.groupName = newName group.groupId = nil group.units[1].unitId = nil group.units[1].unitName = newName group.category = 'AIRPLANE' mist.dynAdd(group) group = Group.getByName(newName) group = group:getController() end barons_respawn_script.checkstate = function(groupName, lowFuelThreshold, lowHealthThreshold, oldresult) local newresult = barons_respawn_script.predicate(groupName, lowFuelThreshold, lowHealthThreshold) if oldresult == false and newresult == true then barons_respawn_script.action(groupName) end mist.scheduleFunction(barons_respawn_script.checkstate, {groupName, lowFuelThreshold, lowHealthThreshold, newresult}, timer.getTime() + 1) end Change the variable at the top as you desire Add another DO SCRIPT action to the trigger Paste the following code --RESPAWN SCRIPT; MISSION START -> DO SCRIPT local groupName = 'Tanker_Texaco' -- Name of the group in the ME local lowFuelThreshold = 0.08 -- RTB when less then this amount of fuel local lowHealthThreshold = 0.75 -- RTB when less then this amount of health barons_respawn_script.checkstate(groupName, lowFuelThreshold, lowHealthThreshold, true) Edit the first three lines to fit into your mission Repeat steps 5 - 7 for other tankers Edited January 1, 2016 by St3v3f Fixed and Updated for DCS 1.5.2 2 aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
St3v3f Posted August 27, 2013 Author Share Posted August 27, 2013 Reserved aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
104th_Maverick Posted August 27, 2013 Share Posted August 27, 2013 Big fat thumbs up from me on this! Will test this out on a new mission we are working on ... cheers! S! 1 [sIGPIC][/sIGPIC] 104th Phoenix Wing Commander / Total Poser / Elitist / Hero / Chad www.104thPhoenix.com www.facebook.com/104thPhoenix My YouTube Channel Link to comment Share on other sites More sharing options...
St3v3f Posted August 28, 2013 Author Share Posted August 28, 2013 I just had a thought. Originally I said the triggerzone is optional. You have to keep in mind though, that you should always place a triggerzone over the takeoff airfield, if the tanker does a ramp start. Reason: If it respawns and starts to taxi, it's speed goes above the 1 m/s threshold. If he then holds short of the runway or stops on the runway, the speed drops back below that threshold and it will respawn again. So either have a triggerzone over the airfield and/or increase the 'respawnSpeed' variable to above taxi speed aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
104th_Maverick Posted August 28, 2013 Share Posted August 28, 2013 Understood... with the current issues refueling online we have decided to keep the tankers out of this new mission for now. Once the refueling is fixed we'll get this added in and let you know how it goes! Thanks again S! [sIGPIC][/sIGPIC] 104th Phoenix Wing Commander / Total Poser / Elitist / Hero / Chad www.104thPhoenix.com www.facebook.com/104thPhoenix My YouTube Channel Link to comment Share on other sites More sharing options...
St3v3f Posted September 2, 2013 Author Share Posted September 2, 2013 Updated the script Thanks to Grimes giving us Mist 3.1, it's all working lovely now. When the respawn is triggered, a new tanker will appear while the old one remains existent and will RTB I also removed the issue with the speed and respawning when holding short by changing the condition from 'speed less than' to 'on ground' aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Ninja1959 Posted September 2, 2013 Share Posted September 2, 2013 Nice,thanks......... [sIGPIC] [/sIGPIC] Link to comment Share on other sites More sharing options...
verana_ss Posted September 3, 2013 Share Posted September 3, 2013 Great work St3v3f Are we allowed to edit and use your code to have a 24/7 fighter CAP? Link to comment Share on other sites More sharing options...
St3v3f Posted September 3, 2013 Author Share Posted September 3, 2013 Sure, go ahead 1 aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
verana_ss Posted September 3, 2013 Share Posted September 3, 2013 (edited) Sure, go ahead Thankyou! Please dont laugh, I know there is a professional way to achieve this one but this is my state of the art :P and dont hesitate to point out a problem this code may cause. Time based spawn (spawn group 5 minutes after it gets in the air) 1. Add following code in Condition if lock_the_time == nil then lock_the_time = 1 activation_time = timer.getTime() + 300 -- Change number accordingly to your mission routine elseif timer.getTime() >= activation_time then lock_the_time = nil return true end 2. Comment out the first controller section in "Do Action" to prevent the former group from RTBing after the spawn of the takeover. (do not comment out for tanker for obvious reason, overlapping TACAN and AR role) Edited September 4, 2013 by verana_ss small change Link to comment Share on other sites More sharing options...
St3v3f Posted September 6, 2013 Author Share Posted September 6, 2013 It's not going to work like that because the switched condition trigger only performs the action once when the condition changes. try wrapping the dynadd into mist.scheduleFunction instead aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
verana_ss Posted September 8, 2013 Share Posted September 8, 2013 It's not going to work like that because the switched condition trigger only performs the action once when the condition changes. try wrapping the dynadd into mist.scheduleFunction instead Hi, St3v3f Thank you for your advice. Do you mean I should pack all the dynadd code into switch condition section using mist.scheduleFunction? I'll try that way thanks again! :) Link to comment Share on other sites More sharing options...
St3v3f Posted September 8, 2013 Author Share Posted September 8, 2013 no just wrap the call of dynadd in the action into scheduleFunction aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
verana_ss Posted September 9, 2013 Share Posted September 9, 2013 no just wrap the call of dynadd in the action into scheduleFunction is this right? fucntion letspackthedynadd() dynadd codes end local lets-respawn-planes mist.scheduleFunction(letspackthedynadd, {}, timer.GetTimer() + 300)I could be totally wrong but wouldn't this take reservation of the next respawn when the original group lands or gets destroyed..? My explanation was poor that might fail to make myself understood, this is the video of outcome of the additional code that I posted to achieve following objective 1- 24/7 CAP over at AO, cloned group succeed to CAP role when original leaves the area. <-- main purpose of this additional code 2- Respawn CAP group when it gets wiped out for whatever reason <-- Already achieved by Baron's code 3- Easy to alter, add and maintainance flights in mission editor <-- Already achieved by Baron's code Link to comment Share on other sites More sharing options...
ENO Posted February 6, 2014 Share Posted February 6, 2014 (edited) bumping this amazing script with a question. St3v3- What I have happening with the script is I do have it set to respawn when it returns to a zone- but what's happening now is the tanker takes off, leaves the zone and then comes back in automatically... disregarding its route / waypoints... then lands or just flies around. In the meantime the next tanker in line takes off, returns... then flies around and respawns... each one does this. Any idea what I'm doing wrong? If I disable that "return zone" will it still respawn just by stopping? EDIT: I have resolved it by disabling the zone- however having a zone enabled may be causing some issues now in 1.2.7. Just a heads up for those of you who may encounter the same problem. Again- AWESOME script and thank you. Edited February 6, 2014 by ENO "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
St3v3f Posted February 6, 2014 Author Share Posted February 6, 2014 I will look into the issue when I get a chance, maybe tonight or during the weekend aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
ENO Posted February 6, 2014 Share Posted February 6, 2014 (edited) Basically to duplicate it all I've needed to do is set up a tanker on the ground, then a zone around it that it needs to leave and come back to (you know the script of course- I'm just saying that I understand the conditions). The waypoints essentially are set up to "switch waypoint" and the tanker shouldn't RTB until it's Bingo. But instead, it just turns quickly and either goes to land or doesn't. Amazingly, no matter how big the zone is it just seems to want to leave and reenter. As soon as I removed the "trigger zone" and just left it as '' it worked fine (though granted I haven't actually seen one respawn that way yet.) "Worked fine" as in the tanker went about its duties. EDIT: Actually- just noticed I haven't been running these in a "switched condition" and instead have been running them "run once" (not knowing any better.) It just occurred to me that I may need to do it in switched condition- and I went back to the first page and noticed the switched condition requirement. I'm not sure if that would affect performance or not- or just prevent a respawn... but it is a mistake I made that may be contributing. FYI Edited February 6, 2014 by ENO "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
St3v3f Posted February 6, 2014 Author Share Posted February 6, 2014 (edited) Got around to it earlier than I thought. local returnZone = 'Tanker_RTB' --Respawn if in this triggerzone. Set to '' if you don't want this --Make sure that the tanker does not exit and reenter this zone, especially during departure Are you absolutely positive about the second line? I could reproduce the effect you describe when it does that. Reason is that the script sets the task of the old tanker to 'No Task' in order to remove it from the radio list and that seems to have the side effect of making it RTB, even though it happens in the middle of the flight plan. Aside from that, I could not discover any issues with 1.2.7 and both Mist 3.1 and 3.2 On the note of the 'Once' trigger, you'll obviously need to use 'Switched Condition', otherwise it'll only run once and therefore spawn just one tanker and no more. I made a quick try with Once and it did something weird. A respawn occured immediately after mission start. For that, I don't have an explanation but didn't pursue the matter because it forfeits the sense of using this script anyways. I would regard the performance impact as negligible. I've been running scripts that are way more complex at intervals of 10ms and less without issues, running the lua predicate part once a second won't hurt the performance. Edited February 6, 2014 by St3v3f aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
ENO Posted February 6, 2014 Share Posted February 6, 2014 (edited) Sorry- by performance I wasn't concerned about "performance" as in speed or anything like that as much as "function" of the script. That must have seemed like an odd concern! Thanks for checking into it! About being certain about the second line... I'm not sure exactly what you mean- but when I was running it I did make sure the zone was spelled properly etc... Edited February 6, 2014 by ENO "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
St3v3f Posted February 6, 2014 Author Share Posted February 6, 2014 Well if you place the trigger zone over the airfield that the tanker takes off from and you don't make it large enough, it tends to depart the airfield and leave the zone. Then the flight plan kicks in, the tanker turns around and crosses over the airfield again to follow the route to the first waypoint. Doing that, it enters the zone again, making the script think it is RTBing, causing it to spawn a new tanker, set 'no task' for the old which makes that one land then. aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
ENO Posted February 7, 2014 Share Posted February 7, 2014 No I'm good on my end St3v3... I'd post my mission but I found the work around I needed thanks to your help. "ENO" Type in anger and you will make the greatest post you will ever regret. "Sweetest's" Military Aviation Art Link to comment Share on other sites More sharing options...
St3v3f Posted February 16, 2014 Author Share Posted February 16, 2014 Made a little update to make it compatible with IL-78M tankers aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
St3v3f Posted February 17, 2014 Author Share Posted February 17, 2014 Another update, removed the return zone entirely. Instead, it checks for the tanker's remaining fuel. If it is less than a defined value, it RTBs and a new one spawns in. aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
HiJack Posted February 18, 2014 Share Posted February 18, 2014 Thank's St3v3f, I will use the new script on the 138th server. I have the mission there just running 6 hours now but will extend this I think. Will there be a simmilar script for AWACS? Link to comment Share on other sites More sharing options...
St3v3f Posted February 18, 2014 Author Share Posted February 18, 2014 Actually it should work without modifications for an AWACS as well. The only thing you'd need is the correct number for the callsign: Overlord 1 Magic 2 Wizard 3 Focus 4 Darkstar 5 aka: Baron [sIGPIC][/sIGPIC] Link to comment Share on other sites More sharing options...
Recommended Posts