Matrix Games Forums

Forums  Register  Login  Photo Gallery  Member List  Search  Calendars  FAQ 

My Profile  Inbox  Address Book  My Subscription  My Forums  Log Out

Can't Dynamically Assign Course

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
  Printable Version
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Can't Dynamically Assign Course Page: [1]
Login
Message << Older Topic   Newer Topic >>
Can't Dynamically Assign Course - 7/11/2020 2:22:35 PM   
Bashkire

 

Posts: 38
Joined: 2/23/2015
Status: offline
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.

< Message edited by Bashkire -- 7/11/2020 3:11:24 PM >
Post #: 1
RE: Can't Dynamically Assign Course - 7/11/2020 5:51:17 PM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
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




< Message edited by KnightHawk75 -- 7/11/2020 6:09:13 PM >

(in reply to Bashkire)
Post #: 2
RE: Can't Dynamically Assign Course - 7/11/2020 6:28:34 PM   
Bashkire

 

Posts: 38
Joined: 2/23/2015
Status: offline
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!

(in reply to KnightHawk75)
Post #: 3
RE: Can't Dynamically Assign Course - 7/11/2020 7:29:17 PM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
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'.

(in reply to Bashkire)
Post #: 4
RE: Can't Dynamically Assign Course - 7/11/2020 7:35:33 PM   
Bashkire

 

Posts: 38
Joined: 2/23/2015
Status: offline
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.

Attachment (1)

< Message edited by Bashkire -- 7/11/2020 8:28:59 PM >

(in reply to KnightHawk75)
Post #: 5
RE: Can't Dynamically Assign Course - 7/11/2020 9:33:09 PM   
KnightHawk75

 

Posts: 1450
Joined: 11/15/2018
Status: offline
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

(in reply to Bashkire)
Post #: 6
Page:   [1]
All Forums >> [New Releases from Matrix Games] >> Command: Modern Operations series >> Mods and Scenarios >> Lua Legion >> Can't Dynamically Assign Course Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts


Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI

1.266