Difference between revisions of "DCS func scheduleFunction"
From DCS World Wiki - Hoggitworld.com
| Line 63: | Line 63: | ||
end | end | ||
timer.scheduleFunction(CheckStatus, 53, timer.getTime() + 5) | timer.scheduleFunction(CheckStatus, 53, timer.getTime() + 5) | ||
| + | |||
| + | |||
| + | This function will check if any red coalition units are in a trigger zone named "anyReds" and will set the flag "zoneOccupied" to true. This function will schedule itself to run every 60 seconds. | ||
| + | |||
| + | local function checkZone(zoneName) | ||
| + | timer.scheduleFunction(checkZone, zoneName, timer.getTime() + 60) | ||
| + | local zone = trigger.misc.getZone(zoneName) | ||
| + | local groups = coalition.getGroups(1) | ||
| + | local count = 0 | ||
| + | for i = 1, #groups do | ||
| + | local units = groups[i]:getUnits() | ||
| + | for j = 1, #units do | ||
| + | local unitPos = units[j]:getpoint() | ||
| + | if math.sqrt((zone.point.x - unitPos.x)^2 + (zone.point.z - unitPos.z)^2) < zone.radius then | ||
| + | count = count + 1 | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | if count > 0 then | ||
| + | trigger.action.setUserFlag("zoneOccupied", true) | ||
| + | else | ||
| + | trigger.action.setUserFlag("zoneOccupied", false) | ||
| + | end | ||
| + | end | ||
| + | checkZone("anyReds") | ||
|notes= | |notes= | ||
