Unit Enter Area trigger not creating...

All discussions & material related to Command's Lua interface

Moderators: RoryAndersonCDT, michaelm75au, angster, MOD_Command

Post Reply
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

Unit Enter Area trigger not creating...

Post by jkgarner »

I am trying to create a trigger for my event to fire when a specific unit enters an area...

The code does not throw and error, other code after it executes, but this trigger is not being created...

I suspect that I did not code it correctly, the following code was my best guess after reading the documentation.

Code: Select all

local eName = 'some_unique_string_value'
 ScenEdit_SetEvent(eName, {mode='add', isRepeatable = false, isActive= active})
 																			
 --generate the trigger for the actual unit entering a small area defined around the destination.
 ScenEdit_SetTrigger({mode='add', type='UnitEnterArea', name=eName, 
                     targetFilter={SPECIFICUNIT=unit_name},
                     area={stepKeyValueName.."_RP_1", stepKeyValueName.."_RP_2", 
                     stepKeyValueName.."_RP_3", stepKeyValueName.."_RP_4"},
 	            exitarea=false})
 ScenEdit_SetEventTrigger( eName, {Mode='add', eName});
 	
 --create the script for the end EndfMove event...
 local script = ""	
 script = script.."myLibrary.FunctionName('"..strParam1.."', '"..strParam2.."',".."\r\n"
 script = script.."                       '"..strParam.."')"			
 ScenEdit_SetAction({Mode='add', name=eName, ScriptText=script })  
 ScenEdit_SetEventAction( eName, {Mode='add', name=eName})
any thoughts? What did I miss?


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

RE: Unit Enter Area trigger not creating...

Post by KnightHawk75 »

When using specific unit specify all the other required params for that level of specificity. On SetEventTrigger, use Description in association with ename, in your example it's just hanging there after mode. Below I use unit_guid instead of name, but you can use just the name...just make sure it's unique to at least the side, if not the whole scene if you do.

Sample

Code: Select all

local ename = "SomeEventName123"
 local unit_nameorguid = '4FH7PU-0HM6UPRN9G6HJ';
 local retval = ScenEdit_SetTrigger(
     {mode='add', Description=ename .."_trig",type='UnitEntersArea', 
                     TargetFilter = { 
                         TARGETSIDE = 'Blue',
                         TARGETTYPE = 'Aircraft',
                         TARGETSUBTYPE = '3001',
                         SPECIFICUNITCLASS = '4178',
                         SPECIFICUNITID = nameorguid},
                     AREA={"Blue_RP-1", "Blue_RP-2","Blue_RP-3","Blue_RP-4"}
     }
 )
 ScenEdit_SetEventTrigger( eName, {Description=eName .. "_trig", Mode='add'});
 
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Unit Enter Area trigger not creating...

Post by jkgarner »

thanks for the info.

The documentation says that the Side is required, but fails to mention that all the levels are required... (yeah I tried all the combinations.. all but including every level errors out)

Still getting an input error,
ERROR: Input string was not in a correct format.
which I've tracked down to the area object.

The documentation shows only putting the rp names, which is what I tried.

The ScenEditAddReferenecePoint function requires a side, and can be used to create areas and single points. So I tried adding the side... That did not work.

Any ideas?
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Unit Enter Area trigger not creating...

Post by jkgarner »

I found the problem with the input: it must be an (integer indexed) array of RP names!

Here is an example:

Code: Select all

area = { 
 [1] = 'Step_USA_73rd_Batallion_2nd_Company_1st_Platoon__op_M2A3_Bradley_AFV_x_4_cp__D1RP_1', 
 [2] = 'Step_USA_73rd_Batallion_2nd_Company_1st_Platoon__op_M2A3_Bradley_AFV_x_4_cp__D1RP_2', 
 [3] = 'Step_USA_73rd_Batallion_2nd_Company_1st_Platoon__op_M2A3_Bradley_AFV_x_4_cp__D1RP_3', 
 [4] = 'Step_USA_73rd_Batallion_2nd_Company_1st_Platoon__op_M2A3_Bradley_AFV_x_4_cp__D1RP_4' 
 }

Whisky Tango Foxtrot: that did not work.
I'm going bald here pulling out my hair trying to figure out what I am missing.[:@]
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Unit Enter Area trigger not creating...

Post by KnightHawk75 »

ORIGINAL: jkgarner

thanks for the info.

The documentation says that the Side is required, but fails to mention that all the levels are required... (yeah I tried all the combinations.. all but including every level errors out)

Still getting an input error,
ERROR: Input string was not in a correct format.
which I've tracked down to the area object.

The documentation shows only putting the rp names, which is what I tried.

The ScenEditAddReferenecePoint function requires a side, and can be used to create areas and single points. So I tried adding the side... That did not work.

Any ideas?

As you can see in the sample I provided, using the RP names does work, you should not be including anything but the names, I'd also make sure those named RP's are unique (don't have rp's on different sides with the same name as I think the lookup will just grab the first match) and that they exist prior to your call.

haha I feel bad now not explicitly mentioning what you found out via trial and error but alluded to in the sample, which is targetfilter entries should match the gui, such that each level of specificity requires the entries for the level above it to be present.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Unit Enter Area trigger not creating...

Post by jkgarner »

I've done that, just the names, and the names are unique, and the RP's exist, and it is still not working.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Unit Enter Area trigger not creating...

Post by jkgarner »

I'm using P.E. version 1.15.3, (released last summer) if that's an issue.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Unit Enter Area trigger not creating...

Post by KnightHawk75 »

ORIGINAL: jkgarner

I'm using P.E. version 1.15.3, (released last summer) if that's an issue.
idk what to tell you I tested the sample in 1147.16 worked without issue, and the code I copied out of a snippet in my lib I wrote at least 1/2 a year ago.

Try just a very simple test:
new scene..
add side Blue..
add a/x f-117 or whatever unit# 4178 is called.
add 4 rp's named Blue_RP-1...4
run the sample without the seteventtrigger line... you should get successful trigger generation, if you don't yeah maybe it's something to do with PE version not being the same and wanting it in some other format (perhaps it expects RP wrappers themselves? idk).
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Unit Enter Area trigger not creating...

Post by jkgarner »

Yeah, experimenting (printing objects)
input:

Code: Select all

print('testobj1')
 local testObj1 = {"str1","str2","str3","str4"}
 print(testObj1)
 print('')
 print('testobj2')
 local testObj2 = {[1]="str1",[2]="str2",[3]="str3",[4]="str4"}
 print(testObj2)
output

Code: Select all

 testobj1
 { [1] = 'str1', [2] = 'str2', [3] = 'str3', [4] = 'str4' }
 
 testobj2
 { [1] = 'str1', [2] = 'str2', [4] = 'str4', [3] = 'str3' }
shows that inserting or omitting the indices for tables of the same objects is irrelevant, so long as the indices are integers and start with 1.
KnightHawk75
Posts: 1850
Joined: Thu Nov 15, 2018 7:24 pm

RE: Unit Enter Area trigger not creating...

Post by KnightHawk75 »

As it shouldn't matter those two tables are functionally defined the same. see #8 though it go posted above your last for some reason.
jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Unit Enter Area trigger not creating...

Post by jkgarner »

I created a brand new scenario, and dropped the folloiwing code into the lua console and ran it:

Code: Select all

local myLat = 19.147022739293 
 local myLon = 110.18065528057
 local sizeScaler = 0.0008
 local mySide = 'Blue'
 local myUnit =  "my unit name"
 local myRPName = 'Blue_RP'
 ScenEdit_AddSide({name=mySide})	
 ScenEdit_AddUnit({side=mySide, type='Facility', name=myUnit, dbid=2784, latitude=19.004100276608, longitude=110.24596193077, }) 
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-1', lat=myLat-sizeScaler, lon=myLon-sizeScaler, highlighted=false})
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-2', lat=myLat+sizeScaler, lon=myLon-sizeScaler, highlighted=false})
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-3', lat=myLat+sizeScaler, lon=myLon+sizeScaler, highlighted=false})
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-4', lat=myLat-sizeScaler, lon=myLon+sizeScaler, highlighted=false})
 local ename = "SomeEventName123"
 local unit_nameorguid = myUnit;
 local retval = ScenEdit_SetTrigger(
     {mode='add', Description=ename .."_trig",type='UnitEntersArea', 
                     TargetFilter = { 
                         TARGETSIDE = 'Blue',
                         TARGETTYPE = 'Facility',
                         TARGETSUBTYPE = '5001',
                         SPECIFICUNITCLASS =  'Mech Inf Plt (M2A3 Bradley AFV x 4)',
                         SPECIFICUNITID = nameorguid},
                     AREA={"Blue_RP-1", "Blue_RP-2","Blue_RP-3","Blue_RP-4"}
     }
 )
 
and got the same error.

Code: Select all

ERROR: Input string was not in a correct format.
There seems to be a bug in this version (P.E. Student, 1.15.3).

Try the above cone in your, if you get a minute and let me know if it works.

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

RE: Unit Enter Area trigger not creating...

Post by KnightHawk75 »

SPECIFICUNITCLASS is supposed to be an dbid#.

Code: Select all

 local myLat = 19.147022739293 
 local myLon = 110.18065528057
 local sizeScaler = 0.0008
 local mySide = 'Blue'
 local myUnit =  "my unit name"
 local myRPName = 'Blue_RP'
 ScenEdit_AddSide({name=mySide})	
 local unitobj = ScenEdit_AddUnit({side=mySide, type='Facility', name=myUnit, dbid=2784, latitude=19.004100276608, longitude=110.24596193077}) 
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-1', lat=myLat-sizeScaler, lon=myLon-sizeScaler, highlighted=false})
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-2', lat=myLat+sizeScaler, lon=myLon-sizeScaler, highlighted=false})
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-3', lat=myLat+sizeScaler, lon=myLon+sizeScaler, highlighted=false})
 ScenEdit_AddReferencePoint( {side=mySide, name=myRPName..'-4', lat=myLat-sizeScaler, lon=myLon+sizeScaler, highlighted=false})
 local ename = "SomeEventName123"
 local unit_nameorguid = myUnit;
 local retval = ScenEdit_SetTrigger(
     {mode='add', Description=ename .."_trig",type='UnitEntersArea', 
                     TargetFilter = { 
                         TARGETSIDE = 'Blue',
                         TARGETTYPE = 'Facility',
                         TARGETSUBTYPE = '5001',
                         SPECIFICUNITCLASS =  '2784',
                         SPECIFICUNITID = unitobj.guid},
                     AREA={"Blue_RP-1", "Blue_RP-2","Blue_RP-3","Blue_RP-4"}
     }
 )
 

Produces the proper result and creation of the trigger without an error on my retail build 1147.16, "untouched" it produces the input error cause it's trying to convert an non numeric like string to a int on the specificunitclass.



jkgarner
Posts: 175
Joined: Thu Apr 30, 2020 12:42 pm

RE: Unit Enter Area trigger not creating...

Post by jkgarner »

Well, looks like I need to upgrade versions.
The code does not work on P.E.Student 1.15.3.

I've replaced the enter area trigger with a recurring time trigger and a condition on the unit.
I'm still fooling with it.

Thanks for the help.
Post Reply

Return to “Lua Legion”