From The Strategy Gamer
Using conditions in Command Modern Air Naval Operations can be kind of tricky. Unlike triggers, which are pretty obvious, or actions, which can be dead simple, a condition is more complex. In a nutshell we use Lua to check something and return true or false. If true the action will execute, and if false nothing will happen. So lets walk through one.
For today’s mission we are going to simulate a recon run by an aircraft. We need to require the player to enter an area (the trigger), be below a certain altitude (the condition), be moving at a loiter (another condition), and then we’ll display a message.
Maybe we want to replicate a detailed intelligence survey of a target area. We could use clouds to force the player to drop, but what if it’s say, Mauritania in the dry season? This setup will do it.
First we set a trigger for a given area. Today we’ll set four corner Reference Points around Nouakchott Mauritania.
Next we’ll set the conditions. I’ll just show the Lua script for each.
1
2 3 4 5 6 7 8 9 |
local unit = ScenEdit_UnitX()
print(unit.altitude) local minAlt = 3000 if unit.altitude < minAlt then |
1
2 3 4 5 6 7 8 9 |
local unit = ScenEdit_UnitX()
print(unit.speed) local minSpeed = 350 if unit.speed <= minSpeed then |
Lets break it down a bit. First we are setting the variable “unit” to be equal to ScenEdit_UnitX. This is a special function that defines whatever unit triggered the trigger. Next we have a debug line, and props to MichaelM on the Matrix forums for this one. We don’t actually see that output, so we have to go to the CMANO Logs folder and find the LuaHistory file. Inside will be the stuff we print out (and maybe errors too!)
Next we’re setting a minAlt variable. We could avoid this step, but it makes for easily readable code. After that is an if statement comparing unit.altitude with the minAlt we set before. If the unit is below the minAlt, then it returns true. If not, it’s false. Same stuff happening for the unit speed.
Both of these must be true in order for our action to fire. The action is just a message box but you could add points for the score, have some SPAAG’s fire up radar, or even have the OPFOR respond with a counter air strike.
Once you’ve made your event, hit a few check boxes, mainly “Repeatable” and “Event is shown in log”. Otherwise the player will be spammed with an Event error saying a condition was not met. Good scenario design would have one trigger telling the player to reduce altitude/speed otherwise the player could be left wondering what to do to get the points.
The post Command Modern Air Naval Operations : Lua Repository #5 Conditions appeared first on The Strategy Gamer.
Original URL: http://thestrategygamer.com/2017/10/21/command-modern-air-naval-operations-lua-repository-5-conditions/