Speed Posted February 12, 2011 Posted February 12, 2011 (edited) Detect destroyed map object script, by 16th Speed Created during Beta 4 Tested and confirmed to be working in single and multiplayer. The host of the mission must be running Windows Vista or Windows 7; XP not supported. Only the host will see the batch file run. Description: -Will detect the destruction of a map object like a bridge, an airport's control tower, a building within a town, etc. -Will cause the game to minimize around the four second mark if game is run in full screen mode (just re-maximize it) -Utilizes a batch file- DO NOT CLOSE THIS BATCH FILE WHILE THE MISSION IS IN PROGRESS! -The "time since flag" trigger condition will NOT work on the flag set by this script- use a separate flag that is set true when this flag is set true in order to get a "time since flag" functionality. Instructions: 1)Place a unit in the far corner of the map, somewhere out of the way. FOR EACH MAP OBJECT YOU WANTO DETECT THE DEATH OF: 2)Create a triggered action for this out-of-the-way unit, of the type "run script". 3)Find the ID of the map object you want to detect, and then insert this code with the properly set variables (see below for additional information!). 4)In the trigger menu, create at "Continuous" trigger, with the condition being "random(100)", and the action being "AI Action(<run this script>). You're done! NOTE: This script COULD cause the mission to bog down if it is run on a lot of separate objects. You have two options in this case. First of all, the script only needs to be run continuously during the first ten seconds or so of the mission. After that, you can run it as infrequently as you like.Secondly, if that is not enough, send me a private message. I do know how to drastically improve the efficiency of this script, I just don't think it's necessary. HOW TO GET THE ID OF THE MAP OBJECT YOU WANT TO DETECT THE DESTRUCTION OF: Create a simple mission consisting of just your aircraft and the object you want to detect the destruction of. Bomb this object in that mission, then bring up the "debrief.log" file in your DCS A-10C/Temp folder. Find where it says: <something> "type='dead', initiatorID=<NUMBER>, initiator="Building", initiator_country=-1,}" That number after initiatorID= is the ID of the map object! Change the value of numbers after the mapobjectID variable to match this number. Questions: Why is the batch file necessary? And why only windows vista and 7? A: Because it appears that the lua input/output function library included with DCS does not have the capability, that I have found so far, to open and read a file that is already open with another process. In this case, the file is "debrief.log", and the process that is using it is another part of the DCS executable that is beyond the scope of the lua environment I know how to access. Windows has no such limitations, so I created a batch file that copies debrief.log to a new file. Unfortunately, batch file scripts are a little sparse on timing functions, and the only function I could find and make work, CHOICE, does not work on windows XP. Scripts only work on the host's computer, so windows XP clients can connect and fly a mission using this script over multiplayer just fine. CODE: --Detect destroyed map object script, by 16th Speed --created during Beta 4 --The host of the mission must be running Windows Vista or Windows 7; XP not supported --Description --Will detect the destruction of a map object like a bridge, an airport's control tower, etc. --Will cause the game to minimize around the four second mark if game is run in full screen mode. --Utilizes a batch file- DO NOT CLOSE THIS BATCH FILE WHILE THE MISSION IS IN PROGRESS! --The "time since flag" trigger condition will NOT work on the flag set by this script- use a --separate flag that is set true when this flag is set true in order to get a "time since flag" --functionality. --Instructions: --1)Place a unit in the far corner of the map, somewhere out of the way. --FOR EACH MAP OBJECT YOU WANTO DETECT THE DEATH OF: --2)Create a triggered action of this unit, and of the type "run script". --3)Find the ID of the map object you want to detect, and then insert this code with the properly --set variables (see below for additional information!). --4)In the trigger menu, create at "Continuous" trigger, with the condition being "random(100)", and --the action being "AI Action(<run this script>). --You're done! --NOTE: This script COULD cause the mission to bog down if it is run on a lot of separate objects. --You have two options in this case. First of all, the script only needs to be run continuously during the --first ten seconds or so of the mission. After that, you can run it as infrequently as you like. --Secondly, if that is not enough, you can email or private message me on the ED forums, my id is --"Speed". I have some more ideas that could further improve the efficiency of the code if necessary. --VARIABLES: --The ID of the map object you want to detect the destruction of: --To get this number, you need to create simple mission consisting of just your aircraft and the object --you want to detect the death of. Bomb this object in that mission, then bring up the "debrief.log" --file in your DCS A-10C/Temp folder. Find where it says: -- <something> "type='dead', initiatorID=<NUMBER>, initiator="Building", initiator_country=-1,}" --That number after initiatorID= is the ID of the map object! Change the value of numbers after --the equals sign below to this value, and you should be set! local mapobjectID = 269518197 --This is easy, just put in the flag you want to set true when the map object dies after the equals sign --below. local flag = 1 --DO NOT MODIFY ANYTHING BELOW THIS LINE!!!!!!!! ------------------------------------------------------------------------------------------------------ --ensure that batchstarted begins false at beginning of mission if timer.getTime() < 4 then batchstarted = false end --this code should only run once per mission if (timer.getTime() > 4) and (batchstarted ~= true) then local filename = 'debriefcopyloop.bat' print('Creating ' .. tostring(filename)) --Now, create a batch file that copies debrief.log to debriefcopy.log. For some reason, the lua io.open() will not --work on a file that is already open, even if you are just trying to read that open file. So I must --use a windows batch file to copy the file, and then read the copied file. file = io.open('./Temp/' .. tostring(filename), 'w') file:write(':1\n') file:write('CHOICE /T 1 /D N ' .. [[/M "DO NOT CLOSE THIS BATCH FILE UNTIL THE MISSION IS COMPLETE!" /N]] .. '\n') file:write('IF ERRORLEVEL 1 GOTO 2\n') file:write('IF ERRORLEVEL 2 GOTO 2\n') file:write(':2\n') file:write([[copy .\Temp\debrief.log .\Temp\debriefcopy.log /y]] .. '\n') file:write('GOTO 1\n') file:close() --start the batch file print('Starting debriefcopyloop.bat') os.execute[[sTART /MIN .\Temp\debriefcopyloop.bat]] --set batchstarted to true so the batch file only starts a single instance of itself. batchstarted = true end --This code should run every time the script is called. If I could make the lua io.open() read --an open file, then this script below would be all that was needed (with filename = debrief.log) if math.abs(timer.getTime()) > 15 then local filename = 'debriefcopy.log' print('Opening ' .. tostring(filename)) file = io.open('./Temp/' .. tostring(filename), 'r') local filestring = file:read('*all') --if "type='dead', initiatorID=<mapobjectID>" found, then set flag to true if string.find(tostring(filestring), [[type='dead', initiatorID=]] .. tostring(mapobjectID)) ~= nil then trigger.setUserFlag(flag, true) end file:close() end ATTACHED FILES: .zip file containing a lua file (you can copy from the code window above or from this file) and an example mission that uses this script. Edited February 13, 2011 by Speed 1 Intelligent discourse can only begin with the honest admission of your own fallibility. Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/ Lua scripts and mods: MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616 Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979 Now includes remote server administration tools for kicking, banning, loading missions, etc.
MadTommy Posted February 12, 2011 Posted February 12, 2011 Sounds excellent, great work, thanks for sharing. Very useful. First of all, the script only needs to be run continuously during the first ten seconds or so of the mission. After that, you can run it as infrequently as you like. But can you explain the above. Does it need to be continuous or not? And what is the relevance of the 1st 10 seconds or so of the mission? Just the bit quoted has me scratching my head, don't really understand what you are saying or the logic. Thanks i5-3570K @ 4.5 Ghz, Asus P8Z77-V, 8 GB DDR3, 1.5GB GTX 480 (EVGA, superclocked), SSD, 2 x 1680x1050, x-fi extreme music. TM Warthog, Saitek combat pro pedals, TrackIR 4
Speed Posted February 12, 2011 Author Posted February 12, 2011 (edited) Sounds excellent, great work, thanks for sharing. Very useful. But can you explain the above. Does it need to be continuous or not? And what is the relevance of the 1st 10 seconds or so of the mission? Just the bit quoted has me scratching my head, don't really understand what you are saying or the logic. Thanks You run scripts under the triggered actions of a unit. The only real requirement for this script is that it be run during the first 10 seconds of a mission, on a "Continuous" trigger- i.e., Contionus->Time Less(10)-> AI Action (run script). After that, if you are afraid that the mission has enough stuff in it that the scripts might be slowing down the game, you can run it as frequently or as infrequently as you like (such as on a minute long, Switched Condition and Time Since Flag based loop). I recommend running it continuously throughout the whole mission, but the only real requirements are that it be run continuously in the first 10 seconds or so. I hope that clears things up. You can look at the example mission if you are still confused. Edited February 13, 2011 by Speed Intelligent discourse can only begin with the honest admission of your own fallibility. Member of the Virtual Tactical Air Group: http://vtacticalairgroup.com/ Lua scripts and mods: MIssion Scripting Tools (Mist): http://forums.eagle.ru/showthread.php?t=98616 Slmod version 7.0 for DCS: World: http://forums.eagle.ru/showthread.php?t=80979 Now includes remote server administration tools for kicking, banning, loading missions, etc.
Grimes Posted February 13, 2011 Posted February 13, 2011 A quality replacement to the lone infantryman standing next to a bridge! The right man in the wrong place makes all the difference in the world. Current Projects: Grayflag Server, Scripting Wiki Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread) SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum
Recommended Posts