Page 1 of 1

Using ChatGPT to create capture script

Posted: Wed Dec 03, 2025 4:54 am
by merlinark
Hello everyone,

I'm trying to create a module to capture an airbase. ChatGPT helped with some of the lua coding for a simple one unit capture as a test of capture.

-- ============== SIDES ==============
ScenEdit_AddSide({name='Blue', awareness='Aware'})
ScenEdit_AddSide({name='Red', awareness='Aware'})


-- Create a visible reference point circle around Puerto Cabezas airport
ScenEdit_AddReferencePoint{
side='Red',
name='CAPTURE_ZONE',
lat=14.0460, -- Puerto Cabezas Airport approximate center
lon=-83.3867,
highlighted=true
}

-- Set as a circular zone with 10 km radius
ScenEdit_SetZone{ <--------------------------------------------------------Line 16
zone='CAPTURE_ZONE',
isactive=true,
arenaradius=10000 -- 10,000 meters
}
-- Add the USMC Mech Inf Platoon (DBID 4594)
ScenEdit_AddUnit{
side='Blue',
type='Facility',
dbid=4594,
name='USMC Mech Inf Platoon',
lat=14.0465,
lon=-83.3855
}
-- Create the event
ScenEdit_AddEvent{
name='Capture Puerto Cabezas',
isActive=true
}

-- Create the trigger: Blue unit inside zone for 1 minute
ScenEdit_AddTrigger{
event='Capture Puerto Cabezas',
type='UnitRemainsInArea',
name='BlueInZone1min',
unitname='USMC Mech Inf Platoon',
side='Blue',
area={'CAPTURE_ZONE'},
time=60 -- 1 minute
}

-- Action: Change Puerto Cabezas airfield to Blue
ScenEdit_AddAction{
event='Capture Puerto Cabezas',
type='ChangeUnitSide',
name='FlipAirfield',
newside='Blue',
unitname='Puerto Cabezas Airport'
}
-- Add message popup when the airfield is captured
ScenEdit_AddAction{
event='Capture Puerto Cabezas',
type='Message',
name='AirfieldSecuredMsg',
description='Airfield secured!'
}


Getting this error
ERROR: [string "Console"]:16: Invalid arguments to method call

Line 16 indicated above.

Any suggestions?

Thanks in advance,

Re: Using ChatGPT to create capture script

Posted: Wed Dec 03, 2025 5:44 am
by merlinark
Quick update:
I manually created the Event/Triggers/Actions.
There wasn't an option to flip unit so I pasted in the LUA section on action

-- Action: Change Puerto Cabezas airfield to Blue
ScenEdit_AddAction{
event='Capture Puerto Cabezas',
type='ChangeUnitSide',
name='FlipAirfield',
newside='Blue',
unitname='Puerto Cabezas Airport'

I ran the scenario, unit arrived in box and 60 seconds later the Airfield Secured! message appeared.
The airfield was still green and wasn't able to access Aircraft Operations.

Some progress, missing something on the changing sides.

Re: Using ChatGPT to create capture script

Posted: Wed Dec 03, 2025 8:22 am
by Nikel
I do not know lua code, but I know the AI is very imaginative, inventing functions and stuff.

Not sure it will be useful, but in a scenario designed by Transient, there is an event to capture a Chinese Ro-Ro vessel, the scenario is Operation Ardent Shield (included in the CSP).

This is the line for the event:
ScenEdit_SetUnitSide({side='China', guid='LK465H-0HN7TERUINFMT', newside='Singapore'})

Re: Using ChatGPT to create capture script

Posted: Wed Dec 03, 2025 6:21 pm
by SunlitZelkova
The AI is indeed making up functions that don't exist. There is no "ScenEdit_SetZone."

Check out this thread for the challenges of using AI to write Lua scripts- https://forums.matrixgames.com/viewtopic.php?t=413668

Re: Using ChatGPT to create capture script

Posted: Wed Dec 03, 2025 6:28 pm
by thewood1
I'll state the obvious...generative AI can be a great productivity tool for experienced coders. But note I said experienced coders. People who are novices in any type of coding will most likely not get good coding outcomes from ChatGPT or other tools. You can engage in a basic conversation to have gAI fetch information and frame in an understandable format. But to generate useful code, you have to already know how to ask the question, know what kind of answer you'll need, and be able to sniff out AI slop.

Re: Using ChatGPT to create capture script

Posted: Thu Dec 04, 2025 1:33 am
by merlinark
Yeah, I started noticing that.
AI got me in the ballpark of what I needed.

I'll give the new code line a try.

Thanks guys,

Re: Using ChatGPT to create capture script

Posted: Thu Dec 04, 2025 4:02 am
by merlinark
Got it working.

Used this command in lua console to get ID:
print( ScenEdit_GetUnit({ name='Puerto Cabezas Airport' }).guid )
MTJZF8-0HNHDQAEUNN6C

Then I substituted the ID into the string Nikel provided from Operation Ardent
ScenEdit_SetUnitSide({side='China', guid='LK465H-0HN7TERUINFMT', newside='Singapore'})

and created
ScenEdit_SetUnitSide({side='Red', guid='MTJZF8-0HNHDQAEUNN6C', newside='Blue'})

Re-run the scenario and it changed on the timer. I was able to access Aircraft Operations.

Appreciate the assistance everyone.
I'll be reading the thread that SunlitZelkova provided.

Re: Using ChatGPT to create capture script

Posted: Thu Dec 04, 2025 8:06 am
by Nikel
Yes, Transient's event worked :)

You may also get the ID of the unit this way.

ID.png
ID.png (10.51 KiB) Viewed 517 times

Re: Using ChatGPT to create capture script

Posted: Thu Dec 04, 2025 8:27 am
by merlinark
I was successful in inserting that info into different scenario and was able to capture the airfield.
I had fighters divert if low on fuel. Nothing big. May try a few helicopters.

It's a great start!

Re: Using ChatGPT to create capture script

Posted: Mon Dec 08, 2025 7:46 pm
by merlinark
Small update:
While testing capture script on Nicaragua Missile Crisis, I discovered that the ID isn't correct when using copy ID to clipboard.


>> print( ScenEdit_GetUnit({ name='Santa Clara Air Base ' }).guid )
XMJRWB-0HMA38CN79JA4
ScenEdit_SetUnitSide({side='China', guid='XMJRWB-0HMA38CN79JA4', newside='United States'})

---------------------------------------
Copy ID to clipboard
{name='Santa Clara Air Base ', guid='XMJRWB-0HMAD0FIGAPPI'}
>> ScenEdit_SetUnitSide({side='China', guid='XMJRWB-0HMAD0FIGAPPI', newside='United States'})
ScenEdit_SetUnitSide 0 : ,Can't find guid XMJRWB-0HMAD0FIGAPPI


The print command produced the working ID.

>> print( ScenEdit_GetUnit({ name='Santa Clara Air Base' }).guid )
ERROR: [string "Console"]:1: attempt to index a nil value
If there's a missing space in the name, it won't work either.

I also found it will a duplicate the Airfield with an A under it.

A note on the aircraft on the captured airfield, you do not control them.
On my first run, remaining aircraft that preparing to take off, took off and departed the airfield.