Help needed using "ScenEdit_AttackContact"

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
hivzigaming
Posts: 6
Joined: Sun Jun 18, 2023 7:13 pm

Help needed using "ScenEdit_AttackContact"

Post by hivzigaming »

Hello fellow gamers :)
I am pretty new to Command (and Lua scripting) and I have a problem using the automatic attack feature as described in the following website:
https://commandlua.github.io/assets/Fun ... ntact.html.

I have an EF2000 equipped with StormShadow cruise missiles and I want to attack an SA-10 Sam.
First I used the "F1" auto attack option from the GUI, which works perfectly as the EF gets into the required range to deploy the StormShadows and fires two of them as required.

Now, when I try to do the same via the event handling approach using a lua script code as an action, it does not work...
My code is

Code: Select all

attacker = UnitY().unit
target = UnitX()

print(attacker)
print(target)

ScenEdit_AttackContact(attacker.guid, target.guid , { mode='0'} )
with the corresponding output
>> attacker = UnitY().unit
target = UnitX()

print(attacker)
print(target)

ScenEdit_AttackContact(attacker.guid, target.guid, { mode='0'} )
unit {
type = 'Aircraft',
subtype = '2002',
name = 'EF2000 Eurofighter Typhoon Two-Seater [TF-2000A]',
side = 'B',
guid = 'UCX05P-0HMRG47SPONFV',
class = 'EF2000 Eurofighter Typhoon Two-Seater [TF-2000A]',
proficiency = 'Regular',
latitude = '52,2266238766894',
longitude = '14,5230216468008',
altitude = '10972,8',
heading = '110,7002',
speed = '350',
throttle = 'Loiter',
autodetectable = 'False',
mounts = '4',
magazines = '4',
unitstate = 'Unassigned',
fuelstate = 'None',
weaponstate = 'None',
AllowMultiMission = 'False',
AssignedMissionsQueue = 'table',
}
unit {
type = 'Facility',
subtype = '5001',
name = 'SAM Bn (SA-10a Grumble [S-300PT])',
side = 'R',
guid = 'UCX05P-0HMRG47SPNVVB',
class = 'SAM Bn (SA-10a Grumble [S-300PT])',
proficiency = 'Regular',
latitude = '52,2842667812602',
longitude = '16,2513846369828',
altitude = '102',
heading = '0',
speed = '0',
throttle = 'FullStop',
autodetectable = 'False',
mounts = '8',
magazines = '9',
unitstate = 'Unassigned',
fuelstate = 'None',
weaponstate = 'None',
AllowMultiMission = 'False',
AssignedMissionsQueue = 'table',
}
Am I missing something?

Thanks for your help...
hivzigaming
Posts: 6
Joined: Sun Jun 18, 2023 7:13 pm

Re: Help needed using "ScenEdit_AttackContact"

Post by hivzigaming »

Additional update:

After searching the forums, I've found a reply from "michaelm75au" in the thread at the following link
https://www.matrixgames.com/forums/view ... t#p4682335

Here "michaelm75au" writes a sample code to perform a BOL attack:
michaelm75au wrote: Fri Aug 07, 2020 11:47 pm Example using console: Adds unit, rp and fires BOL
local tbl = { type = 'Submarine', name = 'SSN-802 single', dbid = 554,
side = 'Usa',loadoutid = 0,heading = 0, Latitude="N12.12.00",
Longitude="E44.10.00", autodetectable="false",holdfire="true",
proficiency=4,speed=0,depth=0,altitude=0 };

local myunit = ScenEdit_AddUnit(tbl);
print(myunit.mounts)

local rp = ScenEdit_AddReferencePoint({side='USA',name='Target',latitude='11.5009269771411', longitude='44.557939718677',highlighted='true'})
print(rp)

local retval = ScenEdit_AttackContact(myunit.guid,'BOL', {latitude=rp.latitude,longitude=rp.longitude, mode=1,
mount=2532,
weapon=377,qty=1
--,course={{latitude='N 64.48.00',longitude='E 5.57.43'},{latitude='N 64.28.00',longitude='E 14.58.17'}, {latitude='N 65.15.46',longitude='E 17.58.23'}}
})
print(retval)
After starting a blank scenario and creating the "Usa" side, I inserted michaelm75au's code and saw that
  • the SSN 802 submarine is successfully deployed within the defined parameters.
  • the reference point named "Target" is successfully created
but unfortunately,
  • the printing command "print(retval)" only returns 'No'.
Is 'No' equivalent to boolean 'False' in this context?
Edit: found out that adding a "tostring()" command via "print(tostring(retval))" returns a "false" as expected.

What am I doing wrong that the ScenEdit_AttackContact() function doesn't work as expected and I am thus not able to start an attack via Lua?
Last edited by hivzigaming on Mon Jun 19, 2023 8:16 am, edited 1 time in total.
User avatar
blu3s
Posts: 1074
Joined: Fri Jul 08, 2022 9:45 am

Re: Help needed using "ScenEdit_AttackContact"

Post by blu3s »

Make sure to use the name or GUID of the contact, not the unit GUID, in order for this to work correctly. When a unit is detected by one side in Command, a contact object is created specifically for that side, and it is given a unique identifier called a GUID. This GUID is different from the one assigned to the unit itself. So, when using this method, remember to use the GUID or name of the contact, not the GUID/Name of the "unit" class.


In the next scen I rename the contact to "Target" and I'll be able to attack using:

Code: Select all

att = {name='EF2000 Eurofighter Typhoon [C.16A]', guid='N8SI1G-0HMRHB95SQSF7'}
ScenEdit_AttackContact(att.guid, "Target", {mode=0})
Attachments
Test ScenEdit_AttackUnit.zip
(10.32 KiB) Downloaded 9 times
hivzigaming
Posts: 6
Joined: Sun Jun 18, 2023 7:13 pm

Re: Help needed using "ScenEdit_AttackContact"

Post by hivzigaming »

blu3s wrote: Tue Jun 20, 2023 7:00 am Make sure to use the name or GUID of the contact, not the unit GUID, in order for this to work correctly. When a unit is detected by one side in Command, a contact object is created specifically for that side, and it is given a unique identifier called a GUID. This GUID is different from the one assigned to the unit itself. So, when using this method, remember to use the GUID or name of the contact, not the GUID/Name of the "unit" class.


In the next scen I rename the contact to "Target" and I'll be able to attack using:

Code: Select all

att = {name='EF2000 Eurofighter Typhoon [C.16A]', guid='N8SI1G-0HMRHB95SQSF7'}
ScenEdit_AttackContact(att.guid, "Target", {mode=0})
GREAT! Thanks a lot blu3s!
I was able to adapt my code accordingly and now everything works. The thread can now be closed.
Post Reply

Return to “Lua Legion”