Bimbac Posted April 23, 2019 Posted April 23, 2019 (edited) Hello everyone! I'm asking all the mission scripting community for help because I'm getting quite desperate. Here's the question: I have several groups of enemy AI fighters as training targets to be spawned (by MIST group.Respawn function) on user's command via the F10 menu. The group respawns without any problem, but here is the catch. When all friendly players leave the training zone or if the AI fighters stray away from the training zone, the AI groups should deactivate, but no matter what I try, they don't. I'm using the following script in Do Script trigger action: if Group.getByName('M29C') then trigger.action.deactivateGroup(Group.getByName('M29C')) endI'm also using the same script for the SAM units in the other training zone, and it works perfectly. Is there a problem with the sim not detecting the respawned fighter groups in the training zone or when they leave it? Any help appreciated. Thanks! Edited April 23, 2019 by Bimbac
Knives Posted April 25, 2019 Posted April 25, 2019 Try Group.getByName('M29C'):destroy() instead of deactivate.
Bimbac Posted April 25, 2019 Author Posted April 25, 2019 (edited) Unfortunately, that doesn't work. Is the trigger setting correct? Edited April 25, 2019 by Bimbac
Hardcard Posted April 26, 2019 Posted April 26, 2019 I don't know how MIST handles spawns, but if it works like MOOSE, you might have a problem with the group name. In MOOSE, every time you spawn a late activated group you're actually creating a copy of it (the original ME group is never spawned, it only acts as template). As you know, when you make copies of units/groups in ME, a #number is added to the unit/group name. In your case, perhaps this is what's going on: [color="Blue"]-- 'M29C' group is spawned as 'M29C#001' the first time around[/color] if Group.getByName('M29C') then [color="blue"]-- Group can't be found [/color] trigger.action.deactivateGroup(Group.getByName('M29C')) [color="blue"]-- Group can't be found[/color] end Run this script right after M29C group spawns for the first time to see whether it spawns as a copy or not: if Group.getByName('M29C') == nil then trigger.action.outText("Original M29C group can't be found!", 10) else trigger.action.outText("Original M29C group found!", 10) end if Group.getByName('M29C#001') == nil then trigger.action.outText("M29C#001 group copy can't be found!", 10) else trigger.action.outText("M29C#001 group copy found!", 10) end [sIGPIC][/sIGPIC]
Bimbac Posted April 26, 2019 Author Posted April 26, 2019 Thanks for your help. I have tried two consecutive respawns of the first group (in the same session), and the group gets respawned by its original name. As I stated before, I use the same original script for the SAM units, and it works without any problems. Check the screenshots. The blurred lines report various events in the mission and are irrelevant to the issue.
Knives Posted April 27, 2019 Posted April 27, 2019 mist function mist.respawnGroup('groupName) Would return the new respawned group name. Use the returned name instead of the original in global variable. For examaple: respawnedM29C = mist.respawnGroup('M29C') And the check if Group.getByName(respawnedM29C) then trigger.action.deactivateGroup(Group.getByName(respawnedM29C)) end
Hardcard Posted April 27, 2019 Posted April 27, 2019 (edited) According to mist_4_3_74.lua, this is what happens when respawnGroup() is called: function mist.respawnGroup(gpName, task) local vars = {} vars.gpName = gpName vars.action = 'respawn' if task and type(task) ~= 'number' then vars.route = mist.getGroupRoute(gpName, 'task') end local newGroup = mist.teleportToPoint(vars) if task and type(task) == 'number' then local newRoute = mist.getGroupRoute(gpName, 'task') mist.scheduleFunction(mist.goRoute, {newGroup, newRoute}, timer.getTime() + task) end return newGroup -- Perhaps I'm mistaken, but this seems to be giving the return of teleportToPoint(), not the group name end Anyway, I've no idea of what the problem might be, see if you can reach Grimes, he'll be able to help. Edited April 27, 2019 by Hardcard [sIGPIC][/sIGPIC]
Grimes Posted April 28, 2019 Posted April 28, 2019 mist.respwnGroup() doesn't change the group name at all, so it should be exactly the same. I can't think of a reason why it wouldn't work other than the code isn't executed. That message you have in the same trigger action is being display correct? Try putting it in the doScript actions that destroy the ground groups to see if the process gets interrupted or has an error maybe? Attached a demo of it working for aircraft.group_destroy_sample.miz 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
Bimbac Posted April 28, 2019 Author Posted April 28, 2019 Thanks, Grimes! I have tested the script you used in the demo mission, but I had to modify it for my mission. I use this condition: if Group.getByName('M29C') then Group.getByName('M29C'):destroy() endMy question is, can the script (or the trigger action) have multiple conditions or just one? When I set a separate trigger for each group, it works. I'll try to describe what result I want to get in pseudocode: If selected friendly units leave the training zone, then all AI fighter groups deactivate. (This is a safety measure for new pilots if they get overwhelmed) If any member of any AI fighter group leaves the training zone, then all AI fighter groups deactivate. (This is a safety measure for other friendly units in the area not to get engaged by the rogue AI fighter) How do I properly set the trigger that when the AI group is destroyed, a message shows to the units within the training zone?
Grimes Posted April 29, 2019 Posted April 29, 2019 Yes triggers can have multiple conditions and actions. With the conditions you just gotta be aware that all of their conditions have to be met for it to execute the actions. Might be easier to move as much as you can to use scripting for some of that stuff. At least from my experience there is certainly a crossover point where it is better to use scripting over a bunch of triggers. For instance with the trigger highlighted from an earlier post you could change that to lua a be something like this in a single lua predicate condition: local u = mist.getUnitsInZones({'test 1', 'test 2', 'test 3'}, {'TRA A', 'TRA B', 'TRA C', 'TRA D'}) if #u > 0 then return false else return true end It checks the location of unit 1, unit 2, and unit 3 to see if any of them are in any of the zones TRA A, TRA B, TRA C, and TRA D. If the size of the table returned is greater than 0 then at least 1 unit is in at least 1 zone. If it is 0 then it will execute the action, which could be to despawn a group and display a message. To display a message to units in a given training zone you'd need to do the same sort of thing to get which units are in the zone, iterate each unit, get the group ID, then send a message to the group Id. Something like this: local u = mist.getUnitsInZones({'test 1', 'test 2', 'test 3'}, {'TRA A'}) local msgTo = {} if #u > 0 then for i = 1, #u do msgTo[mist.DBs.unitsById[unit.getID(u[i])].groupId] = true end for id, blank in pairs(msgTo) do trigger.action.outTextToGroup(id, 'TRA A Zone Empty, despawning units', 20) end end 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
Bimbac Posted April 30, 2019 Author Posted April 30, 2019 Thanks again! I hope that soon I'll be able to fully comprehend the scripting engine so I can do all the stuff myself. Grimes, I have sent you a PM. Big Thanks to you all guys!
Bimbac Posted January 1, 2020 Author Posted January 1, 2020 Yes triggers can have multiple conditions and actions. With the conditions you just gotta be aware that all of their conditions have to be met for it to execute the actions. Might be easier to move as much as you can to use scripting for some of that stuff. At least from my experience there is certainly a crossover point where it is better to use scripting over a bunch of triggers. For instance with the trigger highlighted from an earlier post you could change that to lua a be something like this in a single lua predicate condition: local u = mist.getUnitsInZones({'test 1', 'test 2', 'test 3'}, {'TRA A', 'TRA B', 'TRA C', 'TRA D'}) if #u > 0 then return false else return true end It checks the location of unit 1, unit 2, and unit 3 to see if any of them are in any of the zones TRA A, TRA B, TRA C, and TRA D. If the size of the table returned is greater than 0 then at least 1 unit is in at least 1 zone. If it is 0 then it will execute the action, which could be to despawn a group and display a message. To display a message to units in a given training zone you'd need to do the same sort of thing to get which units are in the zone, iterate each unit, get the group ID, then send a message to the group Id. Something like this: local u = mist.getUnitsInZones({'test 1', 'test 2', 'test 3'}, {'TRA A'}) local msgTo = {} if #u > 0 then for i = 1, #u do msgTo[mist.DBs.unitsById[unit.getID(u[i])].groupId] = true end for id, blank in pairs(msgTo) do trigger.action.outTextToGroup(id, 'TRA A Zone Empty, despawning units', 20) end end Hello again, I've been fighting with the scripts quite hard, and still unable to get the desirable results. Here is a "Code" for a trigger action which should do the following: If the group is active (within a zone) and that particular group flies out of the zone, the group shall be destroyed and a message to coalition appears. Please check it out: if Group.isActive('M29C') and Group.outOfZone({'M29C'}, {'TRA A'}) then Group.getByName('M29C'):destroy() trigger.action.outTextForCoalition(blue, 'M29C group out of zone, deactivated for safety reasons', 10) end It's a pseudocode basically, but getting it right would help me a lot. Thanks!
Grimes Posted January 5, 2020 Posted January 5, 2020 Assuming you replace the Group.outOfZone() with something that checks if the entire group is out of the zone because outOfZone is not a group class function. Then yes that should be working. The non-pseudo-code version would be helpful to see where you might be going wrong. 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
C525 Posted February 19, 2023 Posted February 19, 2023 Sorry to bring this thread up again, but I did not get a reply on my posted thread and it is pretty much the same direction. How would the code have to be, in order to destroy/deactivate the selected Units? And also, is it possible to destroy different Groups (all starting with "Bandit-x") at once? I'm sure it's less a MIST problem than my general limited knowledge with scripting. I can also PM or Upload the Script I'm working with, if that helps. Thanks Alex
Recommended Posts