EasyEB Posted May 22, 2016 Posted May 22, 2016 Greetings! Is it possible to set a trigger to activate when a script spawned group is in a zone? I know the name of the group, but since it's not editor placed, I can not select it when making the trigger.
ESAc_matador Posted May 22, 2016 Posted May 22, 2016 Check in the mist functions and call the function via do script anytime needed.
Grimes Posted May 22, 2016 Posted May 22, 2016 If you are just wanting to set a flag you can use the mist.flagFunc.unitsInZones function. If you want to do other scripting its still a pretty simple check to write yourself. Just iterate each unit and get its position and do some math relative to the zone: if ((unitPos.x - zone.x)^2 + (unitPos.z - zone.z)^2)^0.5 <= zone.radius then -- unit is in the zone 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
EasyEB Posted May 22, 2016 Author Posted May 22, 2016 Interesting. I do not know the units names though, is it possible to use unitsinzone with the group name?
Grimes Posted May 23, 2016 Posted May 23, 2016 If you know the name of the group you can get the unit names from that. local units = Group.getByName('whatever'):getUnits() local unitNameTable = {} for i = 1, #units do unitNameTable[#unitNameTable+1] = Unit.getName(units) end mist has a function that generates this for you. local units = mist.makeUnitTable({'[g]whatever'}) 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
EasyEB Posted May 23, 2016 Author Posted May 23, 2016 Oh, cool! I'm at work now so can't test it out. But would mist.flagFunc.units_in_zones{units = mist.makeUnitTable({'[g]myGroup'}), zones = {'myZone'}, flag = 100, zone_type = 'sphere', toggle = true} make flag 100 true when myGroup is in the zone myZone, and false when they are out?
ESAc_matador Posted May 23, 2016 Posted May 23, 2016 Oh, cool! I'm at work now so can't test it out. But would make flag 100 true when myGroup is in the zone myZone, and false when they are out? should work
EasyEB Posted May 30, 2016 Author Posted May 30, 2016 I'm having trouble getting this to work with units that spawn into the mission. Is that expected or have I missed something?
Grimes Posted May 31, 2016 Posted May 31, 2016 I'm having trouble getting this to work with units that spawn into the mission. Is that expected or have I missed something? Possibly missed something. This actually took me a few minutes to test and realize what was going on. Both of the following examples work. The difference is how the function acts as new units are added to the mission via scripting. The first example will update the unit list as needed, while the second example is fixed to whichever units were on blue when the function was first called. I added this to the documentation on the PDF, but never did for the wiki. mist.flagFunc.units_in_zones({ units = {'[blue]'}, zones = {'zone'}, flag = '1' }) mist.flagFunc.units_in_zones({ units = mist.makeUnitTable({'[blue]'}), zones = {'zone'}, flag = '1' }) There is a slight bug with my code in that it will throw an error if you used the second example and units were spawned in. I am correcting this at the moment. Will also update documentation as needed. 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