Page 1 of 1

Help for Action Script

Posted: Fri Jan 24, 2020 1:17 pm
by Randomizer
Attached is a Lua Event Action script from a vestigial scenario being written for CMO. The aim of the action is to limit the availability of Player aircraft by applying a Reserve loadout with a Ready time of random duration of between ten-hours and 23-hours, 59-minutes.

The event fires at midnight local time and represents aircraft developing 'gripes' and being unavailable for much or all of the day's missions.

The script for the individual aircraft randomized ready times was easy enough and this works when triggered individually:

a=math.random(1,100)
if a <16 then
ScenEdit_SetLoadout({UnitName='300 #3', guid='61870050-cb82-4944-abb0-e2082871b87c', LoadoutID='3', TimeToReady_Minutes=math.random(600,1439)})
end

The Action script needs to do the following:

- Interrogate each aircraft in the air group and apply a 15% chance of the Reserve loadout for the random time

- Omit aircraft not present when triggered due to being on operations or lost so to avoid the Player receiving any error messages

Included is the scenario including the Action (but not the Trigger), the Action text on M$ Notepad and the scenario *.ini file. When run in the Consul the script returns a Consul error #1 and I have no idea what's wrong or how to fix.

If any of the Lua writers out there can sort this out I would be eternally grateful. Thanks in advance for any assistance.

-C


RE: Help for Action Script

Posted: Sat Jan 25, 2020 7:44 pm
by michaelm75au
You have created a function out of the script, but never call it.
Just remove the the 'Function' line and the the last 'end', and it should run

However, I have created a new tighter script for you.

RE: Help for Action Script

Posted: Sat Jan 25, 2020 9:05 pm
by michaelm75au
I just noticed
due to being on operations
You could add an additional test to see if it is flying ...
if unit ~= nil then -- not killed
if unit.airbornetime == '0' then -- not flying

RE: Help for Action Script

Posted: Sat Jan 25, 2020 9:28 pm
by Randomizer
Many thanks for the assist but I dug around a bit and found an aircraft maintenance script that somebody has written and modified it for my scenario. That said, I have added your input to my growing Lua script collection so I can experiment and continue to learn more.

Trying to write Lua is like trying to talk to Cat. I know what I am saying and precisely what I want yet his response never seems to fit...

-C