Difference between revisions of "DCS func scheduleFunction"
From DCS World Wiki - Hoggitworld.com
m (1 revision imported) |
|||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 16: | Line 16: | ||
The function that is called is expected to return nil or a number which will indicate the next time the function will be rescheduled. | The function that is called is expected to return nil or a number which will indicate the next time the function will be rescheduled. | ||
| − | Use the second argument in that function to retrieve the current time and add the desired amount of delay (expressed in seconds) | + | Use the second argument in that function to retrieve the current time and add the desired amount of delay (expressed in seconds). |
|rtnType= functionId | |rtnType= functionId | ||
| 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= | ||
}} | }} | ||
[[Category:Singleton Functions|scheduleFunction]] | [[Category:Singleton Functions|scheduleFunction]] | ||
| + | [[Category:Game Patch 1.2.0|scheduleFunction]] | ||
