Browsed by
Month: October 2017

Scaling Forces To A Threat In CMANO Using Lua

Scaling Forces To A Threat In CMANO Using Lua

First a warning. This is using Lua code available with CMANO version 1.13 or greater. If you’re using something older all it does it make you wish you updated.

One of the bigger things I wanted to accomplish with CMANO and Lua was to devise a way to scale missions and/or mission assignments to the threat. The basic problem was that players could choose to overwhelm a patrol with greater numbers so needed a way for the static AI to evaluate a threat within an area and pick a better response to it based on some conditional logic. The responses could be adding units to the mission, adding new missions or deleting them all together. Thankfully the Lua team at CMANO came through and I’ve now got a way to do this.

My method is a two-event process. The first event which I call Air Defense Counter consists of an In Area Trigger and a Lua action with some code that runs a counter and runs some conditional logic that modifies missions based on the value of the counter. This is great but the detect trigger evaluates for everything regardless of where it is so we need to dictate an area which I do by creating a second event called Activate Air Defense Area which lets me modify an existing detect area trigger using a setter (Scenedit_SetTrigger) and some reference points as parameters. I then add some conditional logic statements to the counter code based on the current value.

Air Defense Counter Event:

Trigger: Type: Unit is detected Name: Red Unit Detected, Parameters: Aircraft, Detected By Myside, Minimum Classification Level: Unknown

Lua Action: Counter code and some conditional logic. Note the numeric value for b is a string (thus the ‘and’ around the numbers) because the CMANO Key Value Function only takes strings not numbers.

lastCount = ScenEdit_GetKeyValue(“AirdefCounter”);
lastCountN = tonumber(lastCount);
if lastCountN == nil then
lastCountN = 0;
end
lastCountN = lastCountN +1;
ScenEdit_SetKeyValue(“AirdefCounter”, tostring(lastCountN));
b=ScenEdit_GetKeyValue(“AirdefCounter”);
if b==’5′ then
ScenEdit_SetMission(‘Denmark’,’CAP 1′,{OnStation=8})
elseif b==’9′ then
ScenEdit_SetMission(‘Denmark’,’CAP 1′,{OnStation=12})
elseif b==’11’ then
ScenEdit_SetMission(‘Denmark’,’CAP 1′,{OnStation=16})
else
end

Activate Air Defense Area Event:

Trigger: Type: Scenario is Loaded. This fires everytime the scenario is loaded even if from a save.

Lua Action:

local a = ScenEdit_SetTrigger({name=’Red Unit Detected’,mode=update,area={‘rp-1154′,’rp-1155′,’rp-1156′,’rp-1157’}})
print(a)

So in summary here is what happens. Scenario loads and the Activate Air Defense Area fires which modifies the detect trigger to use four reference points (1154-1157) instead of evaluating for everything in sensor range. When an aircraft enters that zone the counter increases and if the value of the counter is 5 the Try to Keep value of the CAP 1 mission is increased to 8, if the value 9 the Try to Keep value of CAP 1 mission is set to 12 and so on and so forth. As you can see we’re scaling our air patrol to a threat.

I hope this helps. This is actually a huge add to being able to use lua to modify Command’s AI. Please let me know if you find any errors or smoother methods.  Hope to see some of it in your future scenarios.