Can't Dynamically Assign Course (Full Version)

All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion



Message


Bashkire -> Can't Dynamically Assign Course (7/11/2020 2:22:35 PM)

Hello chaps,

I'm toying around with a piece of code to cause a stolen civilian aircraft to fly into the side of a warship to simulate a suicide attack,but for the life of me I can't see where this code is going wrong.

The below code was given to me by Apache85, who's help has been invaluable so far:

local NatoShip = ScenEdit_GetUnit({side='NATO',name='NatoShip'}) -- change as appropriate

local kamikazeAircraft = ScenEdit_GetUnit({side='Banzai',name='Sake #1'}) -- change as appropriate

local kamikazeCourse = {latitude=NatoShip.latitude, longitude=NatoShip.longitude}) --Desired speed only kicks in when you reach the waypoint, once you've got this segment working we can add more logic there

ScenEdit_SetUnit({guid=kamikazeAircraft.guid, course=kamikazeCourse})


Now I then edited it to my uses so it became the following:

local Albion = ScenEdit_GetUnit({side='NATO',name='[L 14] HMS Albion [LPD]'});

local LoSlo = ScenEdit_GetUnit({side='Civilian Air (Hijacked)',name='Lo-Slo'});

local terminalCourse = ({latitude=Albion.latitude, longitude=Albion.longitude});

ScenEdit_SetUnit({guid=LoSlo.guid, course=terminalCourse});




The problem is that running the code in the Lua editor to test before I put it into an event returns the error:
ERROR: Input string was not in a correct format.


Doing some messing about and commenting out lines, I believe that the problem lies in the last line where Lo-Slo gets given his waypoint. The Command Lua repository (here) mentions about a waypoint table with lots of possible inputs, but all I really need at the moment is the course to follow the ship and I can worry about speeds and altitudes later.

Can anyone see where this code is going wrong?



EDIT:

Just to keep people informed of progress, I now have this code which is seeming to work somewhat correctly, although I now need to loop it to continue updating the waypoint onto of the ship as it moves:

local Albion = ScenEdit_GetUnit({side='NATO',name='[L 14] HMS Albion [LPD]'});

local LoSlo = ScenEdit_GetUnit({side='Civilian Air.',name='Lo-Slo'});

local terminalCourse = LoSlo.course;

terminalCourse[1].latitude = Albion.latitude;
terminalCourse[1].longitude = Albion.longitude;

ScenEdit_SetUnit({side='Civilian Air.',name='Lo-Slo', course=terminalCourse, manualSpeed=170.0, manualAltitude=80.0});


Does anyone know how to loop this thing? I'm not seeing any syntax of while() loops on the documentation I linked above.




KnightHawk75 -> RE: Can't Dynamically Assign Course (7/11/2020 5:51:17 PM)

You wouldn't need to loop then, just run the code every so often to update the position inside an event say every 5 or 10 seconds.

  local terminalCourse = {};
  local Albion = ScenEdit_GetUnit({side='NATO',name='[L 14] HMS Albion [LPD]'});
  local LoSlo = ScenEdit_GetUnit({side='Civilian Air.',name='Lo-Slo'});
  if (LoSlo ~=nil and Albion ~=nil) then  --if both exist then do this
    table.insert(terminalCourse,{latitude=Albion.latitude,longitude=Albion.longitude,description='impact'})
    LoSlo.course = terminalCourse
    ScenEdit_SetUnit({side='Civilian Air.',name='Lo-Slo', manualSpeed=170.0, manualAltitude=80.0});
  else 
    --probably put code here to disable the event since one or both are gone or otherwise handle the situation.
    --ScenEdit_SetEvent ("myEventNameOrGuidofEvent", { isActive=false } )
  end

You can find all the standard for\while statement documentation in the lua documentation
https://www.lua.org/manual/5.3/contents.html#contents






Bashkire -> RE: Can't Dynamically Assign Course (7/11/2020 6:28:34 PM)

At first I don't think I understood what you mean, but I get it now. I didn't notice the Regular Time trigger. That's really handy and something that I didn't even consider existing!

But now I wonder how to delete the event so that the trigger doesn't continually fire once the plane has crashed.

I'll have a play about in that Lua documentation you posted and see if I can think of anything, otherwise I'll be looking at the Command stuff again to search for events.

Cheers!




KnightHawk75 -> RE: Can't Dynamically Assign Course (7/11/2020 7:29:17 PM)

The commented out line in the 'else ' clause above will disable the event when you no longer want it active.

If you do want to actually delete it you can do that too.
ScenEdit_SetEvent("EventNameOrGuidHere",{mode='remove'}) <-- I think, mode isn't included above because the default it 'update'.




Bashkire -> RE: Can't Dynamically Assign Course (7/11/2020 7:35:33 PM)

Thanks chap. I'll add that line in.

I hope I'm not imposing, but I've also sent you a PM (or rather I'm typing it now) to ask for some more advice regarding this.

Incidentally, for anyone that wants to help me out or see what I've done, here's a stripped down version of my mission with only the kamikaze element.




KnightHawk75 -> RE: Can't Dynamically Assign Course (7/11/2020 9:33:09 PM)

All good, sent you a reply and working example scene that highlights the basic enable and disable process.
Replied before I saw your attachment here, else I would have just used the real one. lol




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.921875