给大家分享一个幻想编辑器寻路的代码。 大家粘贴进高级编辑里就可以玩了。

1 大帅哥隋昊航 59分钟前 39次点击

首先,非常感谢梦月大神提供。

function 寻路(x,y,z,速度)

if not run then

task(function(_G,x,y,z,速度)

require("import")

_G.run=_G.run or true

local 速度=速度 or 100

local x=x or 0

local y=y or 0

local z=z or 0

if x<_G.横 then

fx=1

cx=1

elseif x>_G.横 then

fx=2

cx=2

else

fx=0

cx=0

end

if y<_G.竖 then

fy=1

cy=1

elseif y>_G.竖 then

fy=2

cy=2

else

fy=0

cy=0

end

while (_G.run) do

local x1,y1,z1=_G.横,_G.竖,_G.高

if _G.横==x and _G.竖==y and _G.高==z then

return

end

local moved=false

local canMoveX=false

local canMoveY=false

local canMoveZ=false

if _G.横

canMoveX=true

elseif _G.横>x and not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

canMoveX=true

end

if _G.竖

canMoveY=true

elseif _G.竖>y and not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==0 then

canMoveY=true

end

if _G.高

canMoveZ=true

elseif _G.高>z and not _G.沙河家园怪物地图(_G.横,_G.竖,_G.高-1) and _G.障碍物==0 then

canMoveZ=true

end

if canMoveX then

if _G.横

_G.横=_G.横+1

else

_G.横=_G.横-1

end

moved=true

elseif canMoveY then

if _G.竖

_G.竖=_G.竖+1

else

_G.竖=_G.竖-1

end

moved=true

elseif canMoveZ then

if _G.高

_G.高=_G.高+1

else

_G.高=_G.高-1

end

moved=true

end

if _G.横==x1 and _G.竖==y1 and _G.高==z1 then

if fx==1 and fy==2 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横-1

if not _G.沙河家园怪物地图(_G.横,_G.竖+1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖+1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==2 and fy==2 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横+1

if not _G.沙河家园怪物地图(_G.横,_G.竖+1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖+1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==2 and fy==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横+1

if not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖-1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

if fx==1 and fy==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横-1

if not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖-1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

end

if fx==0 and fy==2 and not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横+1

if not _G.沙河家园怪物地图(_G.横,_G.竖+1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖+1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==0 and fy==2 and not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横-1

if not _G.沙河家园怪物地图(_G.横,_G.竖+1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖+1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==0 and fy==1 and not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横+1

if not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖-1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==0 and fy==1 and not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横-1

if not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖-1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==1 and fy==0 and not _G.沙河家园怪物地图(_G.横,_G.竖+1,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖-1

if not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横-1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==1 and fy==0 and not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横,_G.竖+1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖+1

if not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横-1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==2 and fy==0 and not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横+1

if not _G.沙河家园怪物地图(_G.横,_G.竖+1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖+1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if fx==2 and fy==0 and not _G.沙河家园怪物地图(_G.横+1,_G.竖,_G.高) and _G.障碍物==1 then

while _G.run do

if not _G.沙河家园怪物地图(_G.横-1,_G.竖,_G.高) and _G.障碍物==0 then

_G.横=_G.横-1

if not _G.沙河家园怪物地图(_G.横,_G.竖-1,_G.高) and _G.障碍物==0 then

_G.竖=_G.竖-1

if x<_G.横 then

fx=1

elseif x>_G.横 then

fx=2

else

fx=0

end

if y<_G.竖 then

fy=1

elseif y>_G.竖 then

fy=2

else

fy=0

end

break

end

_G.沙河家园地图()

Thread.sleep(速度)

else

break

end

end

end

if _G.横==x1 and _G.竖==y1 and _G.高==z1 then

return

end

end

_G.沙河家园地图()

if _G.障碍物==1 then

_G.横,_G.竖,_G.高=x1,y1,z1

return

end

Thread.sleep(速度)

end

end,_G,x,y,z,速度,function()

end)

else

run=nil

local 速度=速度 or 100

task(速度+50,function()

寻路(x,y,z,速度)

end)

end

end

共 1 条评论
龙的传人 24分钟前
好家伙,这还挺长的