Total players online: 12



Take the Tour | Site Map

It is currently Wed Dec 19, 2018 3:25 am

All times are UTC - 8 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Pathfinding sub help
PostPosted: Sun Apr 02, 2017 11:56 pm 
Offline
Apprentice Scripter
Apprentice Scripter

Joined: 08/03/2016 00:49
Posts: 33
Hey all. I've written a pathfinding sub to follow a mob and dodge around mage field spells. The problem is that it only works sometimes when I'm sure that it could be made to work 100%. As you'll be able to see, the sub looks for fields and if it finds some it will pathfind up to it and try and determine a path around the field and then run around it. The key is that it has to be able to go around so it and not through and doesnt get stuck in a para field, trapped by an energy field, or get poisoned by a poison field. If it cannot find fields it just pathfinds straight to it's target as normal.

I really just need a second pair of eyes to look over it and see if there's anyway that it can be improved or done better. The aim is to avoid fields and find a clear path to what it's following as fast as possible. Any help would be greatly appreciated!

Here is what I have so far...

Code:
  1. set %fields VRV_QXV_KTV_GQV_PSV_VQV_GXV_QPV ;field types to avoid
  2. set #lpc 100
  3. set %mobtofollow ;ID of whatever it's pathfinding to
  4.  
  5. loop:
  6. finditem %mobtofollow
  7. gosub pathfinder
  8. goto loop
  9.  
  10. sub pathfinder
  11. set %runfree no
  12. set %reverse no
  13. set %fieldxlocs 0
  14. set %fieldylocs 0
  15. set %pathtox none
  16. set %pathtoy none
  17. set %pathfinderitemsave #findid
  18. set %repathno 0
  19. relooppath:
  20. repath:
  21. finditem %fields G_8
  22. {
  23.  runfree:
  24.  finditem %pathfinderitemsave
  25.  set %pathtox #findx
  26.  set %pathtoy #findy
  27.  set %repathno 0
  28.  set %relooppath no
  29.  set %runfree no
  30.  goto nofieldfoundskip
  31. }
  32. {
  33.  set %idx 0                ;<-- set index to 0
  34.  set %dist 100             ;<-- set dist to insanely far
  35.  for #findindex 1 #findcnt ;<-- loop through every found field
  36.  {
  37.   set %fieldxlocs %fieldxlocs , #spc , #findx
  38.   set %fieldylocs %fieldylocs , #spc , #findy
  39.   if #finddist <= %dist ;<-- if it's closer
  40.   {
  41.    set %idx #findindex   ;<-- if it's closer, then remember the index number
  42.    set %dist #finddist
  43.   }
  44.  }
  45.  ;set #findindex %idx       ;<-- go back to the closest one
  46.  if %dist < 3
  47.  {
  48.   set %pathdist 1
  49.   set %relooppath yes
  50.  }
  51.  {
  52.   set %pathdist 2
  53.   set %relooppath yes
  54.  }
  55.  if %dist > 3
  56.  {
  57.   set %pathdist 3
  58.  }
  59.  set %repathno %repathno + 1
  60.  finditem %pathfinderitemsave
  61.  set %pathtox #charposx + %pathdist
  62.  set %pathtox #charposx - %pathdist
  63.  set %pathtoy #charposy + %pathdist
  64.  set %pathtoy #charposy - %pathdist
  65.  set %pathtox #charposx
  66.  set %pathtoy #charposy
  67.  path2:
  68.  if %pathtox in %fieldxlocs && %pathtoy in %fieldylocs
  69.  {
  70.   if %pathtox > #charposx && %pathtoy > #charposy ;&& #findy > #charposy
  71.   {
  72.    replusxy:
  73.    if %repathno > 15
  74.    return
  75.    set %repathno %repathno + 1
  76.    set %pathtox #charposx
  77.    set %pathtoy #charposy
  78.    set %checkarea %pathtoy + 1
  79.    else
  80.    set %checkarea %pathtoy - 1
  81.    if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  82.    {
  83.     if %reverse <> yes
  84.     set %pathtox %pathtox + %repathno
  85.     else
  86.     set %pathtox %pathtox - %repathno
  87.     if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  88.     goto replusxy
  89.    }
  90.    else
  91.    {
  92.     set %pathtoy %checkarea
  93.     set %checkarea %checkarea + 1
  94.     else
  95.     set %checkarea %checkarea - 1
  96.     if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  97.     set %pathtoy %pathtoy
  98.     else
  99.     set %pathtoy %checkarea
  100.     set %runfree yes
  101.    }
  102.    goto finpath
  103.   }
  104.   if %pathtox > #charposx && %pathtoy < #charposy ;&& #findx > #charposx
  105.   {
  106.    replusxminusy:
  107.    if %repathno > 15
  108.    return
  109.    set %repathno %repathno + 1
  110.    set %pathtox #charposx
  111.    set %pathtoy #charposy
  112.    set %checkarea %pathtox + 1
  113.    else
  114.    set %checkarea %pathtox - 1
  115.    if %pathtoy in %fieldylocs && %checkarea in %fieldxlocs
  116.    {
  117.     if %reverse <> yes
  118.     set %pathtoy %pathtoy + %repathno
  119.     else
  120.     set %pathtoy %pathtoy - %repathno
  121.     if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  122.     goto replusxminusy
  123.    }
  124.    else
  125.    {
  126.     set %pathtox %checkarea
  127.     set %checkarea %checkarea + 1
  128.     else
  129.     set %checkarea %checkarea - 1
  130.     if %pathtoy in %fieldylocs && %checkarea in %fieldxlocs
  131.     set %pathtox %pathtox
  132.     else
  133.     set %pathtox %checkarea
  134.     set %runfree yes
  135.    }
  136.    goto finpath
  137.   }
  138.   if %pathtox < #charposx && %pathtoy < #charposy ;&& #findy < #charposy
  139.   {
  140.    reminusxminusy:
  141.    if %repathno > 15
  142.    return
  143.    set %repathno %repathno + 1
  144.    set %pathtox #charposx
  145.    set %pathtoy #charposy
  146.    set %checkarea %pathtoy - 1
  147.    else
  148.    set %checkarea %pathtoy + 1
  149.    if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  150.    {
  151.     if %reverse <> yes
  152.     set %pathtox %pathtox - %repathno
  153.     else
  154.     set %pathtox %pathtox + %repathno
  155.     if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  156.     goto reminusxminusy
  157.    }
  158.    else
  159.    {
  160.     set %pathtoy %checkarea
  161.     set %checkarea %checkarea - 1
  162.     else
  163.     set %checkarea %checkarea + 1
  164.     if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  165.     set %pathtoy %pathtoy
  166.     else
  167.     set %pathtoy %checkarea
  168.     set %runfree yes
  169.    }
  170.    goto finpath
  171.   }
  172.   if %pathtox < #charposx && %pathtoy > #charposy ;&& #findx < #charposx
  173.   {
  174.    reminusxplusy:
  175.    if %repathno > 15
  176.    return
  177.    set %repathno %repathno + 1
  178.    set %pathtox #charposx
  179.    set %pathtoy #charposy
  180.    set %checkarea %pathtox - 1
  181.    else
  182.    set %checkarea %pathtox + 1
  183.    if %pathtoy in %fieldylocs && %checkarea in %fieldxlocs
  184.    {
  185.     if %reverse <> yes
  186.     set %pathtoy %pathtoy - %repathno
  187.     else
  188.     set %pathtoy %pathtoy + %repathno
  189.     if %pathtoy in %fieldylocs && %checkarea in %fieldxlocs
  190.     goto reminusxplusy
  191.    }
  192.    else
  193.    {
  194.     set %pathtox %checkarea
  195.     set %checkarea %checkarea - 1
  196.     else
  197.     set %checkarea %checkarea + 1
  198.     if %pathtoy in %fieldylocs && %checkarea in %fieldxlocs
  199.     set %pathtox %pathtox
  200.     else
  201.     set %pathtox %checkarea
  202.     set %runfree yes
  203.    }
  204.    goto finpath
  205.   }
  206.   if %pathtox = #charposx ;&& #findx = #charposx;|| %pathtox > #charposx || %pathtox < #charposx
  207.   {
  208.    if %pathtoy > #charposy
  209.    {
  210.     replusy:
  211.     if %repathno > 15
  212.     return
  213.     set %repathno %repathno + 1
  214.     if %reverse <> yes
  215.     set %pathtox %pathtox + %repathno
  216.     else
  217.     set %pathtox %pathtox - %repathno
  218.     set %pathtoy #charposy
  219.     set %checkarea %pathtoy + 1
  220.     if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  221.     goto replusy
  222.    }
  223.    if %pathtoy < #charposy
  224.    {
  225.     reminusy:
  226.     if %repathno > 15
  227.     return
  228.     set %repathno %repathno + 1
  229.     if %reverse <> yes
  230.     set %pathtox %pathtox - %repathno
  231.     else
  232.     set %pathtox %pathtox + %repathno
  233.     set %pathtoy #charposy
  234.     set %checkarea %pathtoy - 1
  235.     if %pathtox in %fieldxlocs && %checkarea in %fieldylocs
  236.     goto reminusy
  237.     set %runfree yes
  238.    }
  239.    goto finpath
  240.   }
  241.   if %pathtoy = #charposy ;&& #findy = #charposy;|| %pathtoy > #charposy || %pathtoy < #charposy
  242.   {
  243.    if %pathtox > #charposx
  244.    {
  245.     replusx:
  246.     if %repathno > 15
  247.     return
  248.     set %repathno %repathno + 1
  249.     set %pathtox #charposx
  250.     if %reverse <> yes
  251.     set %pathtoy %pathtoy + %repathno
  252.     else
  253.     set %pathtoy %pathtoy - %repathno
  254.     set %checkarea %pathtox + 1
  255.     if %checkarea in %fieldxlocs && %pathtoy in %fieldylocs
  256.     goto replusx
  257.     set %runfree yes
  258.    }
  259.    if %pathtox < #charposx
  260.    {
  261.     reminusx:
  262.     if %repathno > 15
  263.     return
  264.     set %repathno %repathno + 1
  265.     set %pathtox #charposx
  266.     if %reverse <> yes
  267.     set %pathtoy %pathtoy - %repathno
  268.     else
  269.     set %pathtoy %pathtoy + %repathno
  270.     set %checkarea %pathtox - 1
  271.     if %checkarea in %fieldxlocs && %pathtoy in %fieldylocs
  272.     goto reminusx
  273.     set %runfree yes
  274.    }
  275.    goto finpath
  276.   }
  277.   finpath:
  278.  }
  279.  {
  280.   set %repathno 0
  281.  }
  282. }
  283. nofieldfoundskip:
  284. set %pathwaitx #charposx
  285. set %pathwaity #charposy
  286. event pathfind %pathtox %pathtoy #findz
  287. set %repathnowait %repathno * 3
  288. ;if #charposx = %pathwaitx && #charposy = %pathwaity
  289. wait %repathnowait
  290. if #charname in *getthere && %reverse <> yes
  291. {
  292.  if #charname in *getthere
  293.  set *getthere *getthere - #charname
  294.  set %repath yes
  295.  set %repathno 0
  296.  set %reverse yes
  297. }
  298. if %mage = yes && #finddist < 8
  299. if %relooppath = no || #hits < %magehealbelow || #hits < %chivhealbelow || C in #charstatus
  300. if %repath = yes
  301. {
  302.  set %repath no
  303.  goto repath
  304. }
  305. if %relooppath = yes
  306. goto relooppath
  307. ;if %runfree = yes
  308. ;goto runfree
  309.  


Top
  ProfileShow poster's scripts in the public script library 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Hosted by CalWeb Internet Services, Inc.