Advertisement
IssyPutchy

Watchmaker Directions API main script

Feb 1st, 2021
1,655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. function update_table()
  2.  stepslat=wm_tag("{tmapsteplat()}")
  3.  stepslon=wm_tag("{tmapsteplon()}")
  4.  var_s_stepslat={}
  5.  var_s_stepslon={}
  6.     for lat in string.gfind(stepslat, "[-]?%d*[\.][-]?%d*")
  7.      do
  8.       table.insert(var_s_stepslat, lat)
  9.     end
  10.     for lon in string.gfind(stepslon, "[-]?%d*[\.][-]?%d*")
  11.      do
  12.       table.insert(var_s_stepslon, lon)
  13.     end
  14. end
  15.  
  16. update_table()
  17.  
  18. function setmapvars()
  19.  distance = wm_tag("{tmapdistance}")
  20.  eta = wm_tag("{tmapeta}")
  21.  startloc = wm_tag("{tmapstartloc}")
  22.  endloc = wm_tag("{tmapendloc}")
  23.  startadd = wm_tag("{tmapstartadd}")
  24.  endadd = wm_tag("{tmapendadd}")
  25.  steps = wm_tag("{tmapsteps}")
  26.   var_s_distance = tostring(distance)
  27.   var_s_eta = tostring(eta)
  28.   var_s_startloc = tostring(startloc)
  29.   var_s_endloc = tostring(endloc)
  30.   var_s_startadd = tostring(startadd)
  31.   var_s_endadd = tostring(endadd)
  32.   var_s_steps = tonumber(steps)
  33. end
  34.  
  35.  
  36. end_loc = {}
  37. start_loc = {}
  38.  
  39. function mapcoords()
  40.  for endloc in string.gfind(var_s_endloc, "[-]?%d*[\.][-]?%d*")
  41.   do
  42.    table.insert(end_loc, endloc)
  43.  end
  44.  for startloc in string.gfind(var_s_startloc, "[-]?%d*[\.][-]?%d*")
  45.   do
  46.    table.insert(start_loc, startloc)
  47. var_start_lat = start_loc[1]
  48. var_start_lon = start_loc[2]
  49. var_end_lat = end_loc[1]
  50. var_end_lon = end_loc[2]
  51.  end
  52. end
  53.  
  54. setmapvars()
  55. mapcoords()
  56.  
  57. tweens.map_lat = var_start_lat
  58. tweens.map_lon = var_start_lon
  59. length = 1
  60.  
  61. var_run = 0
  62.  
  63. function tweenmap()
  64.  
  65.  if var_run == 0 then
  66.   wm_schedule
  67.    { action='tween', tween='map_lat', from=var_start_lat, to= var_s_stepslat[var_run+1], duration=length, easing=linear }
  68.   wm_schedule
  69.    { action='tween', tween='map_lon', from=var_start_lon, to= var_s_stepslon[var_run+1], duration=length, easing=linear }
  70.   var_run =  var_run + 1
  71.  
  72.    elseif var_run <= var_s_steps then
  73.  
  74.   wm_schedule
  75.    { action='tween', tween='map_lat', from=var_s_stepslat[var_run], to= var_s_stepslat[var_run+1], duration=length, easing=linear }
  76.   wm_schedule
  77.    { action='tween', tween='map_lon', from=var_s_stepslon[var_run], to= var_s_stepslon[var_run+1], duration=length, easing=linear }
  78.   var_run = var_run + 1
  79.  
  80.    elseif var_run > var_s_steps then
  81.  
  82.   wm_schedule
  83.    { action='tween', tween='map_lat', from=var_s_stepslat[var_run], to=var_end_lat, duration=length, easing=linear }
  84.   wm_schedule
  85.    { action='tween', tween='map_lon', from=var_s_stepslon[var_run], to=var_end_lon, duration=length, easing=linear }
  86.   var_run = 0
  87.  
  88.  end
  89.  
  90. end
  91.  
  92. function new_directions()
  93. -- This can be ignored, it's a lazy formula to auto update steps and doesn't work LOL
  94.  if math.floor((math.rad(var_s_stepslon[1]))*1000)/1000 == math.floor((math.rad({alon}))*1000)/1000 and math.floor((math.rad(var_s_stepslat[1]))*1000)/1000 == math.floor((math.rad({alat}))*1000)/1000 then
  95.   wm_action('m_task:WMDirections')
  96.   wm_vibrate(100,3)
  97.  end
  98. end
  99.  
  100. function on_second(h,m,s)
  101.  if {abright} then
  102.   setmapvars()
  103.    if var_run == 0 then
  104.     tweens.map_lat = {alat}
  105.     tweens.map_lon = {alon}
  106.    end
  107.  end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement