Special Action and Lua

Take command of air and naval assets from post-WW2 to the near future in tactical and operational scale, complete with historical and hypothetical scenarios and an integrated scenario editor.

Moderator: MOD_Command

Post Reply
DWReese
Posts: 2312
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

Special Action and Lua

Post by DWReese »

I have a Special Action for a scenario that I am building that I only want to offer to the game player BEFORE the START button is actually hit to begin the game. In other words, if you would like, you can spend a few Victory Points (putting you in the negative to begin the game) now by keeping something else from happening. It's simply a choice, and it works well.

Can anyone tell me how to disable the option if it wasn't originally selected AFTER the game player has pressed the START button? In other words, after you hit START it is no longer an option. Could Lua do that, or is there another way, or is there no way?

Thanks in advance.

Doug
Cik
Posts: 671
Joined: Wed Oct 05, 2016 3:22 am

RE: Special Action and Lua

Post by Cik »

set up an event that fires at an exact time (say 10 seconds after the scenario starts)
use ScenEdit_SetSpecialAction({ActionNameorID= "event", IsActive= "False"})

this should work 100% of the time (99% sure)
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Special Action and Lua

Post by KnightHawk75 »

Cik is right.
If I understand correctly you either want the Special Action to disappear once it's either used\chosen OR after the user has selected a side and started playing to no longer have access to the choice.

You can't trap the 'Start\Begin Scenario' button, and 'load scenario' fires after side selection, so I think your just best doing a time-in-game check.

In SP Action itself at the end of it upon success add:
--disable myself if run
ScenEdit_SetSpecialAction({ActionNameOrID="someNameOfSpecialAction", IsActive = false,IsRepeatable = false,}); --disable the action, will disappear in SA menu.

Then in a 'non-repeatable' marked event set to run the following action script at say every 5 seconds (remember it'll only run the 1 time.) or at exact time:

local constStartTimeOfScenarioSince1970 = 1548855506 --Just a sample, adjust to start-date of your scenario.
if ScenEdit_CurrentTime() > constStartTimeOfScenarioSince1970) then
ScenEdit_SetSpecialAction({ActionNameOrID="someNameOfSpecialAction", IsActive = false,IsRepeatable = false,}); --disable the action, will disappear in SA menu.
end

Just remember to reset these correctly in 'editor mode' before testing in 'player mode' since they're fire-once and forget.
DWReese
Posts: 2312
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Special Action and Lua

Post by DWReese »

Thank you so much.

Doug
DWReese
Posts: 2312
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Special Action and Lua

Post by DWReese »

Thanks for the very detailed explanation.

I will go and try them out right now.

Doug
DWReese
Posts: 2312
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Special Action and Lua

Post by DWReese »

ScenEdit_SetSpecialAction({ActionNameOrID="someNameOfSpecialAction", IsActive = false,IsRepeatable = false,})

Okay, I'm a dummy. I'm getting an error message. (I'm not surprised.) I'm not sure that I completely understand. If my Special Action is titled "Hello 123" (it isn't), should that go first? Can you give me an example using that action name? It keeps telling me that it is expecting a "}" near something.

Doug
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Special Action and Lua

Post by KnightHawk75 »

Code: Select all

 ScenEdit_SetSpecialAction({ActionNameOrID="Hello 123",IsActive=false})
 ScenEdit_SetSpecialAction({ActionNameOrID="Hello 123",IsActive=false,IsRepeatable = false})
 

Problem in post #6\#3 was the extra comma 'false,' my sample was off the cuff typing, not a cut and paste. my bad.

Most error messages like that involve extra comma, or missing quote sort of thing. :)
DWReese
Posts: 2312
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Special Action and Lua

Post by DWReese »

Thanks again for responding.

Since I don't ACTUALLY KNOW anything about Lua, I rely completely on the effort of others for these things. I just kind of change the names to make it work, as you can see. I had no idea that a comma was missing, or that anything else was even potentially wrong. I just knew that it didn't work.

Thanks again for your help. I'll go and try it out now.

Doug
DWReese
Posts: 2312
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Special Action and Lua

Post by DWReese »

It works perfectly. Thanks again.

Doug
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Special Action and Lua

Post by KnightHawk75 »

ORIGINAL: DWReese

It works perfectly. Thanks again.

Doug

You quite welcome, I didn't know Lua 3-4mo ago, it's a pretty simple language to pickup the basics of, particularly if you've ever done any scripting or programming before, even if you haven't it's fairly easy. If you have questions the Lua Legion section of 'Mods and Scenarios' forum is good place to eyeball for useful scripts or examples you can make minor changes too for your own purposes. Copy, paste, change is definitely part of the learning process and a time saver. ;)

BTW forum user Whicker recently has done a couple intro videos to Lua and CMANO if your interested, I think they're helpful for anyone just starting out who wants to learn the basics. Here is the YT link.
https://www.youtube.com/user/ephotopros/videos

DWReese
Posts: 2312
Joined: Fri Mar 21, 2014 11:40 am
Location: Miami, Florida

RE: Special Action and Lua

Post by DWReese »

Knighthawk75,

Thanks again.

Yes, I did check out the link. Unfortunately, I didn't see anything remotely close to editing any Lua code associated with making a Special Action disappear. That was pretty cool. It appears that you can likely do anything with the game (and Lua), if you know how. <g>

Doug

Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Special Action and Lua

Post by Whicker »

I knew nothing about Lua a year ago, and I am just a hobbyist level programmer. Lua is the easiest language to work with I have used.

Mostly I make mistakes, my skills seems to be patience and persistence. And of course curiosity.

copy, paste, change, that's where it all starts for sure.
rmunie0613
Posts: 202
Joined: Tue Jan 02, 2018 7:41 pm

RE: Special Action and Lua

Post by rmunie0613 »

Doug (and others) I have certainly begun with no knowledge of LUA either...the guys here are amazing though and I have learned A LOT (though still am a Lua Rookie) now through experimenting, AND through following others' such as your own questions and answers here
Thank you all... This was something I have been trying to incorporate also.
Ron
User avatar
daveoreno
Posts: 65
Joined: Sat Aug 27, 2016 10:10 am
Location: Toronto, Canada

RE: Special Action and Lua

Post by daveoreno »

Wow, Whicker doing CMANO tutorials on YouTube!! Count me in! SUBSCRIBED

Dave
Rory Noonan
Posts: 2418
Joined: Thu Dec 18, 2014 1:53 am
Location: Brooklyn, NY

RE: Special Action and Lua

Post by Rory Noonan »

ORIGINAL: Whicker

I knew nothing about Lua a year ago, and I am just a hobbyist level programmer. Lua is the easiest language to work with I have used.

Mostly I make mistakes, my skills seems to be patience and persistence. And of course curiosity.

copy, paste, change, that's where it all starts for sure.
Like Whicker I had no previous scripting or programming experience and knew absolutely nothing about Lua when it came out as a feature with (I think) CMANO 1.06. It's very easy to learn and the more you practice the better you'll get.
Image
Post Reply

Return to “Command: Modern Operations series”