SphereCommunity
TestRun for NPC navgation - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Submissions (/Forum-Script-Submissions)
+--- Thread: TestRun for NPC navgation (/Thread-TestRun-for-NPC-navgation)

Pages: 1 2


TestRun for NPC navgation - Soulless - 09-16-2013 03:56 PM

Okay, so this script is just a concept for an idea im trying to bloom.
basically im in an attempt of making "bots" for my server. their eventual functionality will be hopefully rather in depth.

obviously the first part of a bot is making it move to a place it wants to get to. and not looking like it's too NPCish. so i've made this script that has been able to successfully move an NPC from the graveyard to the sweetdreams inn.

just add this to your scripts, add c_h_fighter, and type .testrun then target the fighter and watch him make his way.

im looking for feedback, ideas, brainstorms to make this better. its pretty basic, but i think this is the best way i could think of at the time.

let me know what you think, and feel free to help me with this project if you are ableWoot

Code:
//Created by Soulless
//this script is a concept to make npc's travel like regular players, to a location of your choice.
//you could make npcs that run to a mine, do some mining for 10 minutes, then run back to the bank
//currently this will take the npc to britain right out front of the SweetDreams Inn

//v.01
//Ive tested it several times, and he's made it from the graveyard, while it's not a beautiful journey, he does make it
//he also made it once from britain to minoc all on his own twice


//just go spawn an npc at the graveyard and type .testrun, then target your npc and follow him to see how it goes.

[defname testrun_settings]
running_control        2        //in tenths of a second how often to run (2 seems to be normal speed of running)
movement_attempts    10        //how many attempts failed in one direction till the npc diverts
diversion_tiles        10        //how many tiles will the npc divert in an attempt to get around obstacles
expected_eta        unused        //how many minutes until they just get teleported to their destination


[function testrun]
targetf testrun2
sysmessage who should testrun? npc only?

[function testrun2]
ref1=<argo.uid>
serv.newitem i_testrun
new.link <ref1>
new.p britain
new.update
new.timer=1
endif

[itemdef i_testrun]
id=i_shield_chaos
name=TestRun

on=@create
attr=090

on=@timer
timerd 2
if (<distance <link>> < 6)                //npc has reached his destination, remove the travelbit
remove
return 1
endif

if <more1>                        //this means he needs to divert his course, because he couldnt move in his targets direction
link.run <tag0.divert>
more1 -= 1
if <more1><1
tag0.divert=
endif
return 1
endif

link.face <uid>                        //face the target destination
if (<link.canmove <link.dir>>)                 //can run in the direction of his target
  if <more2>
  more2 -= 1                        //more2 keeps track of how many times he has ran into something, if he's moving without issue, remove a count on more2
  endif
link.run <link.dir>                    //so do it, run, bitch.
else    
more2 += 1                        //more2 keeps track of how many times he has ran into something, if he's running into things, add a count on more2
  if <more2>>=<def0.movement_attempts>            //he's been stuck 10 times in a row, divert his course
  more1=<def0.diversion_tiles>                //divert course by 10 tiles
  more2=                        //clear his obstruction count
//serv.log can't move <dir_convert <link.dir>>
   if !<tag0.divert>
   if <link.canmove <eval <link.dir>-1>>        //movecheck 45 degrees left
    tag0.divert=<eval <link.dir>-1>            //switch direction 45 degrees left
    elseif <link.canmove <eval <link.dir>+1>>        //movecheck 45 degrees right
    tag0.divert=<eval <link.dir>+1>            //switch direction 45 degrees right
    elseif <link.canmove <eval <link.dir>-2>>        //movecheck 90 degrees left
    tag0.divert=<eval <link.dir>-2>            //switch direction 90 degrees left
    elseif <link.canmove <eval <link.dir>+2>>        //movecheck 90 degrees right
    tag0.divert=<eval <link.dir>+2>            //swicth direciton 90 degrees right
   endif

  if (<tag0.divert> < 0 )                //0 is true north, if its less than 0
  // serv.log <eval <tag0.divert>>
   local.offset=<tag0.divert>
   tag0.divert=<eval (8 - <local.offset>)>
  elseif (<tag0.divert> > 7)
   tag0.divert -= 8
  endif
  // serv.log diverting <dir_convert <tag0.divert>>
   tag0.divert=<dir_convert <tag0.divert>>
   endif
  endif
endif

return 1

[function dir_convert]
doswitch <args>
  return n
  return ne
  return e
  return se
  return s
  return sw
  return w
  return nw
enddo



RE: TestRun for NPC navgation - XuN - 09-16-2013 09:38 PM

First of all, this is a great idea and a very nice adition for roleplaying purposes or some kind of events (LOL-Like minions, ie).

I've tried it with an skeleton from Britain Graveyard, making britain unguarded, you have to mess with homedist, it doesn't go so far after entering the city, wich is just easy to do.

But the real problem comes searching for a correct path, it will be a pain in the ass to make a pathfinding in scripts since you can calculate to move one tile, two, three, four... but the whole correct path it would be a very largue calculation when it may be possible that someone give us a function related to 'MoveToPos' from NPC_AI_ALWAYSINT or NPC_AI_PATH or somewhat/somehow/somewhere it's calculated?

Coming back to topic, it goes so nice with 1x1,2x2 obstacles, but it's hard to him to get out from graveyard now (wich I asume you already knew Tongue )


RE: TestRun for NPC navgation - Soulless - 09-17-2013 02:30 AM

well any enclosed area presents a serious problem for him. because there's no logic in the script in how to get out. but when he's outside of any trapping building anything that is a square shape, or anything thats small and can be re-routed by going 10 feet in either 45* or 90* along side it, can be handled decently.

hpoefully we could get some more information on pathfinding or possibley work some kind of a RUNTO function in ( i know a dev mentioned that being a possibility in IRC when i was bugging people about it Smile )

though i bet as a community we can all make this work seamlessly !
It's just a matter of getting it done and testing it out. the good news about bots is that they test themselves out Tongue


RE: TestRun for NPC navgation - Rattlehead - 09-18-2013 09:28 AM

well, one thing RunUO has that we dont, that we SHOULD have, are waypoint gems, no scripting required and they work (last time i checked 10 years ago) pretty well, i had one with 20 waypoints, all of which he flawlessly executed in a dungeon, so if the devs implemented something like this, we would be one step closer to having functionality on their level.


RE: TestRun for NPC navgation - Anarch Cassius - 09-18-2013 10:31 AM

I've seen a way point based caravan but then you just have a static route.

Ideally you'd have the waypoints form a nodemap and use an A* variant to navigate that. Possibly using square grid based A* for finer dynamic navigation at other times.

The question is how to do that most efficiently without bogging down the server.


RE: TestRun for NPC navgation - XuN - 09-18-2013 04:56 PM

GOD's have heard us ^^

Code:
small change to NPC_Act_Runto and NPC_Act_Goto to prevent invalid point errors.

bencro1028    r1629    18.09.13

-Added: Runto npc command. Accepts a point or region name as argument.
-Changed: Goto npc command to accept region name as argument.
-Added: NPC_AI_PERSISTENTPATH 0x0400 to the NPCAI setting in sphere.ini
-Updated: Sphere.ini and sphere_msg.scp with new settings

Can't wait for it to compile!


RE: TestRun for NPC navgation - Mordaunt - 09-18-2013 08:54 PM

Don't go calling him a god... it'll go to his head lol


RE: TestRun for NPC navgation - amonvangrell - 09-19-2013 07:12 AM

LOL >:]


RE: TestRun for NPC navgation - XuN - 09-19-2013 08:19 AM

I've been waiting for this nightly for testing this and at first view it does the same that Soulless script is doing atm, NPCs aren't moving like they will when chasing you in combat.


RE: TestRun for NPC navgation - Soulless - 09-19-2013 05:25 PM

i beleive new_positioning walkcheck diaganaol walkcheck and the persistent_path flags should all be on to get the most out of the runto command.