Author Topic: TrailMyx's Pathfind sub for OEUO  (Read 5286 times)

0 Members and 1 Guest are viewing this topic.

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
TrailMyx's Pathfind sub for OEUO
« on: August 31, 2010, 07:40:47 PM »
0
Here's a port of the pathfinding sub used in my rail engine.  It's always been pretty basic, but very functional for getting out of blocked conditions in Fel.

Code: [Select]
dofile("tm_subs_collection5.lua")
function TM_Pathfind(xdest, ydest, zdest)
  local max_retry = 3
  local retry = 0
  if UO.CursKind == 0 then
    max_retry = 8
  end
  local complete = false
  while not complete do
    UO.Pathfind(xdest,ydest,zdest)
    local timer = TM_SecondTimer:New{duration = 8}
    local move_again = false
    while not move_again and not complete do
      repeat
        local tempx = math.abs(xdest - UO.CharPosX)
        local tempy = math.abs(ydest - UO.CharPosY)
        local tempz = math.abs(zdest - UO.CharPosZ)
        if (tempx > 1 or tempy > 1 or tempz > 1) and (timer:Check() == false) then
          break
        end
        if (tempx == 1 or tempy == 1) and UO.CursKind == 0 and UO.Stamina ~= UO.MaxStam then
          UO.Move(xdest, ydest, 2, 1000)
          break
        end
        if timer:Check() == true then
          retry = retry + 1
          if retry <= max_retry then
            move_again = true
            break
          end
          return true
        else
          complete = true
          break
        end
      until false
    end
  end
  return false
end
---------------------------------------------------------------
---------------------------------------------------------------
---------------------------------------------------------------
TM_Pathfind(1006,430,-63)
TM_Pathfind(1006,436,-63)
TM_Pathfind(1013,436,-63)
TM_Pathfind(1013,430,-63)
pause()

Note: requires tm_subs_collection5.lua and you need to save this file to a lua file before you run it.  I've also attached the file.

There are 1 attachment(s) in this post. You must register and post an acceptable introduction to download
tm_pathfind10.lua
« Last Edit: August 31, 2010, 07:58:49 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: TrailMyx's Pathfind sub for OEUO
« Reply #1 on: August 31, 2010, 07:57:03 PM »
0
Reserved
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline TrailMyxTopic starter

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: TrailMyx's Pathfind sub for OEUO
« Reply #2 on: August 31, 2010, 08:09:01 PM »
0
You might wonder why I'm using a nested while and repeat?  One of the annoying things about Lua is there is no "continue" command.  In other languages, you have a "break" that breaks you out of the present loop, and also a "continue" that will start the loop over again without running the rest of the code.  In this example, I've nested a "repeat/until" which I can "break" out of so from the point of view of the enclosing "while" statement the loop starts over again...  

Broken down:

Code: [Select]
   while not move_again and not complete do
      repeat
...
        if something then
          break -- breaks out of the repeat/until, while continues
        end
        if something_else then
          break -- breaks out of the repeat/until, while continues
        end
        if timer:Check() == true then
          return true
        else
          complete = true
          break -- breaks out of the repeat/until, while continues (stops because complete is true)
        end
      until false
    end
« Last Edit: August 31, 2010, 08:14:30 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: