Random Lua Elements-How, When, and Why (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series



Message


RoryAndersonCDT -> Random Lua Elements-How, When, and Why (5/22/2015 4:09:58 PM)

Coiler12 examines using Lua to provide random elements in Command scenarios, and how to manage how much of a scenario should be set up randomly.

Random Lua Elements-How, When, and Why by Coiler12



quote:

When I saw the Lua tutorial video showing how it could be used to make random elements in Command, I was excited. My excitement diminished as I started making an overambitious scenario involving random Lua and recognized both the limitations and difficulty. But with that lesson in mind, I continued using random Lua.

While still frustrating at times, in part due to me not being a programmer, I found the benefits to be worth it. (Ckfinite, who is a programmer, has been a great help in getting my Lua efforts to work, and has provided many necessary technical corrections to this post. )

Event Editor vs. Lua.
So, in layman’s terms, the existing event editor allowed for an “either or” option. Operation Square Peg: Syrian MiG-29s are sitting at Damascus International, and a probability event fires to see if they’re dumb enough to mess with F-22s. The “attempted intercept” mission switches from inactive to active, and that’s all it can do.

Lua would allow that same group of MiG-29s to either all take off, none of them take off, have a portion of them take off, or have them take off to fly to another airbase rather than engaging the attackers.




Read more on baloogancampaign.com




tjhkkr -> RE: Random Lua Elements-How, When, and Why (5/22/2015 8:09:04 PM)

It is very good, but there are ways to streamline the code such that if you had 30 aircraft you wanted to add, it would not take 30 if/then/else platforms to make it work...[8D]




snowburn -> RE: Random Lua Elements-How, When, and Why (5/22/2015 10:08:50 PM)

Thanks for the article!

Can a lua script LUA set random skill values to units? i need something like:


function SetSkill(side_name,unit_name, min, max)
local unit = ScenEdit_GetUnit({side=side_name,name=unit_name})
if unit ~= nil then
unit.skill= math.random(min,max)
end
end

math.randomseed( os.time() )
SetSkill('Soviet Union', 'Jet #1', '1', '3')
SetSkill('Soviet Union', 'Jet #2', '1', '3')
SetSkill('Soviet Union', 'Jet #3', '3', '4')




ckfinite -> RE: Random Lua Elements-How, When, and Why (5/23/2015 5:01:07 AM)

Yes, you can use Lua to set proficiency. See my documentation here. The field is called "proficiency", and you can access it through ScenEdit_GetUnit.




snowburn -> RE: Random Lua Elements-How, When, and Why (5/26/2015 5:57:51 PM)

Thanks ckfinite!




snowburn -> RE: Random Lua Elements-How, When, and Why (5/26/2015 11:07:50 PM)

How to set random skill levels for units:

Event: Scenario Start

Trigger: Scenario is loaded

Action: Lua Script:

function SetSkill(side_name,unit_name, min, max)
local unit = ScenEdit_GetUnit({side=side_name,name=unit_name})
if unit ~= nil then
local unit_id=unit.guid
ScenEdit_SetUnit({guid=unit_id, proficiency = math.random(min,max) })
end
end

math.randomseed(os.time())
SetSkill('Irak', 'Fishbed #1', 2, 4)
SetSkill('Irak', 'Fishbed #2', 2, 3)
SetSkill('Irak', 'Fishbed #3', 1, 3)
SetSkill('Irak', 'Fishbed #4', 0, 2)
SetSkill('Irak', 'Fishbed #5', 0, 2)
SetSkill('Irak', 'Fishbed #6', 0, 2)




solidgeoff -> RE: Random Lua Elements-How, When, and Why (5/27/2015 12:42:27 PM)

Thanks for posting. Randomizing elements in a scenario is a great way to improve replayability.




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
2.859375