Help for Action Script

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
User avatar
Randomizer
Posts: 1535
Joined: Sat Jun 28, 2008 8:31 pm

Help for Action Script

Post 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

Attachments
VikrantgoestoWar.zip
(51.85 KiB) Downloaded 13 times
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Help for Action Script

Post 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.
Attachments
action.zip
(429 Bytes) Downloaded 20 times
Michael
User avatar
michaelm75au
Posts: 12464
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Help for Action Script

Post 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
Michael
User avatar
Randomizer
Posts: 1535
Joined: Sat Jun 28, 2008 8:31 pm

RE: Help for Action Script

Post 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
Post Reply

Return to “Lua Legion”