Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Random Lua Elements-How, When, and Why

 
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 >> Random Lua Elements-How, When, and Why Page: [1]
Login
Message << Older Topic   Newer Topic >>
Random Lua Elements-How, When, and Why - 5/22/2015 4:09:58 PM   
RoryAndersonCDT

 

Posts: 1830
Joined: 6/16/2009
Status: offline
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


_____________________________

Command Dev Team
Technical Lead
Post #: 1
RE: Random Lua Elements-How, When, and Why - 5/22/2015 8:09:04 PM   
tjhkkr


Posts: 2428
Joined: 6/3/2010
Status: offline
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...

_____________________________

Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.

(in reply to RoryAndersonCDT)
Post #: 2
RE: Random Lua Elements-How, When, and Why - 5/22/2015 10:08:50 PM   
snowburn


Posts: 188
Joined: 9/24/2013
From: Bovril, Argentina
Status: offline
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')

(in reply to tjhkkr)
Post #: 3
RE: Random Lua Elements-How, When, and Why - 5/23/2015 5:01:07 AM   
ckfinite

 

Posts: 377
Joined: 7/20/2013
Status: offline
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.

(in reply to snowburn)
Post #: 4
RE: Random Lua Elements-How, When, and Why - 5/26/2015 5:57:51 PM   
snowburn


Posts: 188
Joined: 9/24/2013
From: Bovril, Argentina
Status: offline
Thanks ckfinite!

(in reply to ckfinite)
Post #: 5
RE: Random Lua Elements-How, When, and Why - 5/26/2015 11:07:50 PM   
snowburn


Posts: 188
Joined: 9/24/2013
From: Bovril, Argentina
Status: offline
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)

(in reply to snowburn)
Post #: 6
RE: Random Lua Elements-How, When, and Why - 5/27/2015 12:42:27 PM   
solidgeoff

 

Posts: 11
Joined: 2/19/2015
Status: offline
Thanks for posting. Randomizing elements in a scenario is a great way to improve replayability.

(in reply to snowburn)
Post #: 7
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Random Lua Elements-How, When, and Why 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

1.063