Public Macros Autopilot include for macros using MQ2Nav
Reply
Autopilot include for macros using MQ2Nav
Imade this include for my own macro.
It uses MQ2Nav and MQ2Nav waypoints to create routes to a named destination.
You can then trigger an autopilot to run to this location through this include.
The zone shortnames in the ini file can be in any order, and you dont have to start the autopilot in the furthest away zone, it will work from any zone between A and B. I havent tested any wierd scenarios, but if you keep it simple stupid it should work ok.

You need to tweak your mq2nav waypoints a bit to make sure mq2nav zones you to the next zone you want to go too.
My repostory has some added here:
https://github.com/projecteon/MacroQuest/blob/master-mqemu-beta/macros/data/mq2nav_waypoints.ini

Ill keep updateing as a I add more. Disclaimer: They are made for Firiona Vie Project server which is a classic one, so old zones.

Code it currently branched here (will go to main branch once MQEmulator Beta build is released):
https://github.com/projecteon/MacroQuest/blob/master-mqemu-beta/macros/includes/commonAutopilot.inc

Setup:

  • Add the include in your macro
  • Add /call InitAutopilot to any setup sub you have
  • Add /call DoAutoPilotEvents to any event runner you have


Autopilot ini
Must be in a folder
Macros/data/Autopilot Routes.ini

Syntax is as follows
[nameofroute]
zoneshortname=waypoint1/waypoint2 etc where waypoint1 and 2 are name of waypoints in mq2nav

Ex
[solb]
ecommons=ectunnel/nektulos
nektulos=lavastorm
lavastorm=soldungb

Macro
More +

Sub IniKeyToArray(string iniFile, string section, string keyName, arrayName)
    /if (${Debug}) /echo |- IniKeyToArray ==>

    /declare values     string  local
    /declare k          int     local
    /declare key        string  local

    /varset values ${Ini[${iniFile},${section},${keyName}]}

    /if (${values.Equal[NULL]}) {
        /if (${Debug}) /echo <values> is NULL, exiting.
        /goto :endIniKeyToArray
    }

    /declare numberOfValues int local ${Math.Calc[${values.Count[/]}+1]}

    /if (${Defined[${arrayName}]}) /deletevar ${arrayName}
    /declare ${arrayName}[${numberOfValues}] string outer

    /for k 1 to ${numberOfValues}
        /varset key ${values.Arg[${k},|]}
        /if (${Debug}) /echo |- ${key} > [${k}] > ${values.Token[${k},/]}
        /varset ${arrayName}[${k}] ${values.Token[${k},/]}
    /next k

    :endIniKeyToArray
    /if (${Debug}) /echo <== IniKeyToArray
/return

Sub DoAutoPilot(string route)
  /if (${Debug} || ${Debug_AutoPilot}) /echo |- DoAutoPilot ==>

  /declare zones string local ${Ini[${autoPilotIniFileName},${route}]}
  /if (${zones.Equal[NULL]}) {
    /echo Route <${route}> has no config in <${autoPilotIniFileName}>, exiting.
    /goto :endAutoPilot
  }

  /declare currentZone    string  local ${Zone.ShortName}
  /declare zoneWayPoints  string  local

  :doAutopilot
  /varset zoneWayPoints ${Ini[${autoPilotIniFileName},${route},${currentZone}]}
  /if (${Debug} || ${Debug_AutoPilot}) /echo zoneWayPoints <${zoneWayPoints}>
  /if (${zoneWayPoints.Equal[NULL]}) {
    /echo No waypoints for <${currentZone}>, exiting.
    /goto :endAutoPilot
  } else {
    /if (${Defined[waypoints]}) /deletevar waypoints
    /call IniKeyToArray ${autoPilotIniFileName} ${route} ${currentZone} waypoints
    /call NavigateZoneWaypoints

    /if (${Zone.ShortName.NotEqual[${currentZone}]}) {
      /varset currentZone ${Zone.ShortName}
      /goto :doAutopilot
    }
  }
 
  :endAutoPilot
  /if (${Debug} || ${Debug_AutoPilot}) /echo <== DoAutoPilot -|
/return

Sub NavigateZoneWaypoints
  /if (${Debug} || ${Debug_AutoPilot}) /echo number of waypoints <${waypoints.Size}>
  /declare k  int local
  /for k 1 to ${waypoints.Size}
    /if (!${Navigation.PathExists[wp ${waypoints[${k}]}]}) {
      /bc Could not find nav path to waypoint ${waypoints[${k}]}
      /return
    }

    /nav wp ${waypoints[${k}]}
    :doNaviate
    /delay 5
    /if (${Navigation.Active}) /goto :doNaviate
  /next k
/return

Sub InitAutopilot(string iniFile)
  /declare autoPilotIniFileName string  outer "data/Autopilot Routes.ini"
  /declare Debug_AutoPilot          bool        outer TRUE

 
    /squelch /alias /autopilot /bc autopilot too
/return

| ################################################################################
| # Autopilot to navpoint
| ################################################################################
#Event AutoPilot "<#*#> autopilot too #1#"
#Event AutoPilot "#*#[MQ2] autopilot too #1#"
Sub Event_AutoPilot(eventText, route)
  /if (${Debug} || ${Debug_AutoPilot}) /echo |- Event_AutoPilot ==>

  /if (!${Defined[route]}) {
    /bc You must supply a route param.
  } else {
    /call DoAutoPilot ${route}
  }

  /if (${Debug} || ${Debug_AutoPilot}) /echo <== Event_AutoPilot -|
/return

Sub DoAutoPilotEvents
  /doevents AutoPilot
/return
Wed Sep 15, 2021 12:29 pm
Public Macros Autopilot include for macros using MQ2Nav
Reply