Page 1 of 1

Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 2:25 pm
by rmunie0613
I am just...asking for a friend[:D] lol.. I know there IS a way to use LUA to change weather, but the entire LUA process is a mystery to me, and most of the "help" I have seen in various posts is really aimed towards people who already apparently are familiar with the concept, and just need to know how to "tweak" it.
I, on the other hand, see it as an entirely foreign language. So I see the edit place for the LUA , and even see the "Change weather" choice there...but the Lua script "change weather" opens up, and I really have ZERO ideas on how to edit the script, while I know enough about the event editor to make it run- I think- once I edit it, but the LUA portion remains a mystery.
Is there any way to have- for the average player who likely does not work with LUA or programming... just some type of step-by-step guide for using a VERY cool feature that makes some really amazing abilities for the game... a guide that does not assume we already know how to use it, and that the advice given should have been obvious to those asking?

For the record, I would even pay extra for a step-by-step manual type of documentation for that feature.

Thank you.

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 2:45 pm
by thewood1
Just did quick search on weather and lua...got this.

tm.asp?m=3975992&mpage=1&key=weather%2Clua&#3975992

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 2:47 pm
by thewood1
As to documenting lua and how to use it. There are numerous websites around that provide training and lessons on lua. Lua is not a command-specific function. Its a common scripting tool used by millions of people. I would start by learning lua in general, then transition into Command-specific capabilities.

In other words, what you are asking for already exists. Just not in the Command ecosystem.

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 4:46 pm
by rmunie0613
Hello "thewood" (sorry, it feels rather strange to call you that [:)] )

First, thank you for the reply.
I, too, saw that, but again, it was written for someone who already knows the basics..to myself it is the same as if it were written in another language- which, technically, it is. It is a discussion between someone who knew enough to write a LUA script, and someone else who is providing insight into what may or may not be wrong with it. There is no point of reference of what the various "foreign words" mean.

My point largely is that many of the players *could* make some amazing scenarios if there was a way to document its application to Command... somewhere there are details on the various command-specific scripts in LUA, somewhere there are details of how to use it, I am sure...but largely it is an intimidating process- and I am rarely intimidated lol...but find myself instead of messing with it, simply going back into Scenario Edit mode every 10-12 hours to change weather as one example, but that is a serious cheat that I dislike doing...not to mention that some things would be nice to be surprised with- sometimes the weather forecast is wrong and you end up with high winds and poor visibility for example...or using LUA to bring in "reinforcements"...I tried, failed...so again go into editor, at random time, and bring a squadron of aircraft from a base far in the north, for example, of Iran..to a forward operating base close to Hormuz...a workaround I can play with, but can not "deploy" my scenario lol, because I will not include a message to the players "at noon, go to Scenario Editor and ferry the aircraft from Base A to Base C"... so none of it bothers me greatly except that I put a lot of otherwise work into some of these scenarios, and really would love to see how others like them...and myself would like to even occasionally be surprised by a runway I had "destroyed" suddenly being operational enough to send a F-14A able to down my mine-hunting helos, etc.

Anyway...thank you for the help though, there well may be some "non-Command specific" things I can learn about it that help me here.

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 6:13 pm
by AlGrant
As a fellow Lua Dunce I feel your pain! [:'(]

I have tried a number of web-based 'learn lua' guides and whilst I could follow the basic tutorials without too much trouble, I struggled in making the jump from printing 'Hello World' to applying it in any useful function in Command.

Where I did get an idea on how to use some Lua was by looking at how it is used in other scenarios and then adapting that to what I want to achieve.
And also copy bits from these forums .... as long as you know it works!
In most cases, I have managed to get where I need ..... even if it takes me a bit of time to get there.

What I find helps is to use something like Notepad++ and copy any Lua snippets into that and select the Lua language.
That colour codes the script and makes it quite readable (even for a total numpty like me!)

I also make sure that I include a reference to the source if it's from the forum as there are occasional updates or better ways of doing the same thing that gets posted.

Below is a Lua script snippet from the forum that might be of help.
It's used to create random weather and generate a message with the weather state.
Obviously you would need to tweak the side name in the special message. If you don't need the message - guess which bit you of the code you don't need!
*(full credit for the following to those people in the original thread)
=============================================================================================
- Source http://www.matrixgames.com/forums/tm.asp?m=4116381
-- Action to trigger random weather & player message

--Random weather

local temp= math.random(22,28)
local rain= math.random(0,5)
local cloud= math.random(0,5)/10.0
local sea= math.random(1,4)
ScenEdit_SetWeather(temp,rain, cloud, sea)
ScenEdit_SpecialMessage('South Asian Allied Forces (SAAF)', '<P><FONT size=2 face="Courier New">COMMANDER,</P><P>NEW WX REPORT,</P> TEMPERATURE: ' .. temp .. ' DEGREES CELSIUS, RAIN STATE: ' .. rain .. ' CLOUD LEVEL: ' .. cloud .. ' AND SEA STATE: ' .. sea)
=============================================================================================
* disclaimer ... I've never used this other than a quick test

I can only suggest reading the original thread, loading up Command and pasting this into the Lua Console and maybe have it open in Notepad++

Once you get it to work save it in Notepad++ so you can keep your own mini-lua-library of script snippets that you can call on at a later date.

Using this method and no small amount of help from those who actually know Lua, I managed to get a functioning lua script that counts the number of aircraft a carrier has lost, once it reaches a certain number the carrier withdraws to a fall back mission area and some of her escorts detach from the group, form a new group and are assigned a new mission. <----- For a total lua numpty this was as close to performing black magic as I will ever get[:D]

Basically .... keep plugging away at it. If there is something you want to achieve in Lua, there is a good chance somebody has already done it.

Good luck


RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 6:23 pm
by thewood1
"Where I did get an idea on how to use some Lua was by looking at how it is used in other scenarios and then adapting that to what I want to achieve. "

That is how I learned 90% of what I use Lua for. I tend to use Lua mostly in events and in the console. I have written very few full scripts. My main advice is start simple and resue a lot of other code.

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 6:48 pm
by stilesw
This works well for me. I trigger it every 60 minutes:

------- Temperature Range = 22C to 42C (71.6F to 107.6F)
local temp= math.random( 31, 42 )

------- Rain Range = 0 to 50
local rain= math.random( 0, 1 )

------- Cloud Range = 0.0 to1.0
local cloud= math.random( 0.0, 2.5 ) / 10.0

------- Sea State Range = 0 to 9
local sea= math.random( 0, 1 )

------- Set Ranges
ScenEdit_SetWeather( temp, rain, cloud, sea )

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 6:57 pm
by Rory Noonan
Hi rmunie0613,

I know where you're coming from. I learnt Lua from trial and error, also the book 'Beginning Lua Programming' really helped although the most recent edition is getting a bit dated now (some say it's old enough that you can find PDF files of it...).

While there's resources out there, thewood1 is quite right in saying that there's not much in the Command ecosystem. That's something I'd like to rectify; I have thought for a while about making some simple explanatory videos about Lua in Command. I'm at sea for the moment but when I get home I think I'll go ahead and do this.

In the mean time, I'd be happy to help with your question about weather. Incidentally modifying weather for Good Morning Malvinas was how I started learning Lua.

This ended up being really long, but I've written it to explain everything with absolutely no expectation of any prior knowledge. Hope it helps!

Edit:
Hi guys, I see I've been ninja'd but I wrote a quick guide to Lua in Command for the absolute beginner here:

tm.asp?m=4435326

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 7:01 pm
by Randomizer
I go through scenarios, particularly the DLC and Command:Live scenarios and copy/paste useful Lua scripts into M$ Notepad files named for that scenario including explanatory notes written by me for me. Then, as needed I will copy/paste a script into the Lua consul and edit as necessary. Run the script, observe the result and if it works as desired, it gets an entry into the Lua script file for the scenario in progress.

An example entry from the Lua notes from my "Sanitising NORLANT" scenario is:
///////////////////////////////////////////////////////////////////////////////////

Set Doctrine for air operations:

ScenEdit_SetDoctrine({side="WESTLANT"}, {quick_turnaround_for_aircraft="1"})
ScenEdit_SetDoctrine({side="WESTLANT"}, {air_operations_tempo="0"})

Doing this I have built up a pretty extensive and growing Lua script library. There are people here who will help but the best way to learn Lua is to use Lua, try assorted scripts and conduct extensive testing on your own.

The last thing is credit where due; if you use a third-party's script you should give them credit somewhere in the scenario documentation.

-C

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 7:41 pm
by rmunie0613
The people in this Forum are awesome, thanks guys.
Yes, I will learn by experimenting.

The weather is a particularly interesting "toy" as many of the 1990s era, especially (but even a few of todays) "smart weapons" work amazingly well when there is LOS for the aircraft...but cloudy skies make a very interesting difference... and likely will even more at the point when night and weather are increasingly modeled in future iterations of this game with regard to their impact on air operations.

RE: Lua Help appreciated, thank you

Posted: Mon Feb 12, 2018 7:44 pm
by rmunie0613
It actually becomes feasible to drop in an observer in order to laser targets with the new cargo operations also.
I cannot stress how much I am loving this game...Devs I used to chat with back in the H3 days... this "baby" has really grown up, I am SO impressed with what you all have done here.