Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Disable Unit AI via LUA

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Disable Unit AI via LUA Page: [1]
Login
Message << Older Topic   Newer Topic >>
Disable Unit AI via LUA - 11/21/2019 3:42:11 AM   
KnightHawk75

 

Posts: 198
Joined: 11/15/2018
Status: offline
from http://www.warfaresims.com/?p=4990
quote:

Lua loco

The Lua API continues its expansion in CMO and offers additional hooks into the simulation engine as well as various methods for pulling the strings of the running scenario. One of the new hooks ties directly into the AI model: You can individually instruct units to, quite literally, not think for themselves (You in the back, quipping “you mean they do this now?” – SIT DOWN!). More specifically, you can set individual units to skip their AI routines for evaluating valid targets and picking out the primary one among them. This has two direct benefits:

It makes it easier to implement custom targeting AI routines in Lua, since an author not longer has to “compete” with the build-in AI for this.
As these routines are among the most CPU-expensive pieces of the simulation pipeline, disabling them can have a drastic effect on the speed & scalability of a large scenario. For example, if you disable the AI cycles of all static/inactive buildings, then only “active” units will use the CPU for this work (internally Command already does a lot of such optimizations, but since it cannot “intrinsically” know which units are static & inactive, it has to check them, which itself is not free).

Additionally, this ability can allow simulating “dormant” states for units (e.g. units begin a scenario in a “comatose” state, but later because of XYZ they become activated).


Can we get the commandlua.github.io docs updated to document whats involved in doing this or provide it here?

Post #: 1
RE: Disable Unit AI via LUA - 11/21/2019 7:02:23 AM   
Dimitris


Posts: 11697
Joined: 7/31/2005
Status: offline
Thanks for the heads up! There is also a bug in the current build about this, we'll need to resolve it on the next update.

_____________________________


(in reply to KnightHawk75)
Post #: 2
RE: Disable Unit AI via LUA - 11/21/2019 2:13:43 PM   
JPFisher55

 

Posts: 523
Joined: 11/22/2014
Status: online
Can someone post instructions on how to disable AI cycles of static or inactive units?

< Message edited by JPFisher55 -- 11/21/2019 9:16:27 PM >

(in reply to Dimitris)
Post #: 3
RE: Disable Unit AI via LUA - 11/21/2019 11:34:09 PM   
KnightHawk75

 

Posts: 198
Joined: 11/15/2018
Status: offline

quote:

ORIGINAL: Dimitris

Thanks for the heads up! There is also a bug in the current build about this, we'll need to resolve it on the next update.


Ah ok, thanks.

(in reply to Dimitris)
Post #: 4
RE: Disable Unit AI via LUA - 11/22/2019 9:16:14 PM   
apache85

 

Posts: 1631
Joined: 12/18/2014
From: Melbourne, Australia
Status: offline
Hey guys, sorry for the delay in getting these instructions out. Now that 1115.8 is out, here is a quick guide to using the C:MO 'disable AI' Lua functionality. You will need C:MO build 1115.8 or above to do this.

First we need to retrieve the unit wrapper and assign it to a variable. This example is from the Brother Against Brother standalone scenario:

quote:


unit = ScenEdit_GetUnit({name='S 31 Sabalo', guid='8813afed-2d28-4f14-ae3b-3e0c6bb3f780'})


Once we have the unit wrapper assigned to a variable, we can turn on the AI evaluation of targets by setting them to true (on) or false (off).

quote:


unit.AI_DeterminePrimaryTarget_enabled = false
unit.AI_EvaluateTargets_enabled = false


SPOILER for Brother Against Brother
If you open Brother Against Brother in the editor, switch to the Venezuelan side, select the S 31 Sabalo and clear its current target by pressing Ctrl+E. Run the scenario, and note that after a couple of seconds of game time the Sabalo automatically selects the nearest appropriate target and goes 'engaged offensive'.

Immediately pause the sim, delete any weapons that were fired, and again clear the target list for Sabalo by pressing Ctrl+E. Now run the code above in the console, which should look like this:

quote:


local unit = ScenEdit_GetUnit({name='S 31 Sabalo', guid='8813afed-2d28-4f14-ae3b-3e0c6bb3f780'})
unit.AI_DeterminePrimaryTarget_enabled = false
unit.AI_EvaluateTargets_enabled = false


Observe that the Sabalo no longer goes 'Engaged Offensive', nor does it fire any weapons despite being assigned to a mission that would otherwise have it do so.

_____________________________


(in reply to KnightHawk75)
Post #: 5
RE: Disable Unit AI via LUA - 11/22/2019 9:22:52 PM   
JPFisher55

 

Posts: 523
Joined: 11/22/2014
Status: online
Ok, now how do I disable static units? Can I do it by class, so I can disable thousands of units?

(in reply to apache85)
Post #: 6
RE: Disable Unit AI via LUA - 11/22/2019 10:24:35 PM   
apache85

 

Posts: 1631
Joined: 12/18/2014
From: Melbourne, Australia
Status: offline
I've written back to you via e-mail with a detailed explanation of the steps I took, as well as actually doing the work for you and providing you with the finished result and the script I used to get there.

For other's benefit, a quick and easy way of doing this is to get the GUIDs of the units you want to work with by using the VP_GetSide units table.

quote:


local listOfGUIDsForAllUnitsOnSide = VP_GetSide({side='USAF'}).units
local typeOfUnitIAmInterestedIn = 'Aircraft'
local listOfUnitsIWantToWorkWith = {}

for k,v in ipairs (listOfGUIDsForAllUnitsOnSide) do
local unit = ScenEdit_GetUnit({guid=v.guid})
if unit.type == typeOfUnitIAmInterestedIn then
table.insert(listOfUnitsIWantToWorkWith,unit)
print ("'"..unit.guid.."', --"..unit.name.." ("..unit.classname..") added to list of units to work with..")
end

end

print ('List complete! '..#listOfUnitsIWantToWorkWith..' units added to list.')

local counter = 0
for k,v in ipairs (listOfUnitsIWantToWorkWith) do
local unit = ScenEdit_GetUnit({guid=v.guid})
unit.AI_DeterminePrimaryTarget_enabled = false
unit.AI_EvaluateTargets_enabled = false
print (unit.name..' AI disabled!')
counter = counter + 1
end
print ('Run complete, AI disabled for '..counter..' units.')


The above example works in the Shamal standalone scenario.

This can be manipulated to be as broad or as specific as you like, using criteria in the unit wrapper.

_____________________________


(in reply to JPFisher55)
Post #: 7
RE: Disable Unit AI via LUA - 11/22/2019 10:34:05 PM   
KnightHawk75

 

Posts: 198
Joined: 11/15/2018
Status: offline
Nice. Thanks apache85 for the update and the info needed.

(in reply to apache85)
Post #: 8
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Disable Unit AI via LUA Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

0.109