Jump to content

Patrol AI


Recommended Posts

Yes. You can use AITravel. Script the NPC to travel to one point, and check for when the NPC arrives using GetAIPackageDone. When the latter returns true, issue AITravel to the next check point. Once the cycle is completed you can set it up to repeat. You can script pauses and idles at each checkpoint before the NPC continues.

 

Another approach is to create a pathgrid for the NPC and use AIWander. That creates a more random patrol, since the NPC may pause and sometimes reverse direction before completing the journey to a checkpoint. Such a pathgrid needs to be distinct from any existing pathgrid. The NPC will leave the grid to engage in combat, and it's problematic to restore the patrol afterward.

Link to comment
Share on other sites

Thanks.

 

I'm confused about what you mean with "Creating a pathgrid" since I'm only seeing an option for a radius.

 

(Also I haven't begun Morrowind scripting so the first option is great but a week away from me)

Link to comment
Share on other sites

Pathgrids are perhaps the least documented aspect of modding for Morrowind - I haven't done it years. I can describe the process if you are interested, but the scripted approach gives more control and easily allows you to cross cell boundaries outside (pathgrids are confined to a single cell).

 

In answering the questions raised in your other thread, Morrowind Scripting for Dummies (MSFD) is the best scripting reference available to modders. The original author Ghan Buri Ghan was extremely knowledgeable about scripted movement of NPCs, so his examples will be very much to the point. If you get frustrated writing a working script, post the coordinates for the waypoints you want, and I can give you the basic structure of the script for you to amend as you please.

Link to comment
Share on other sites

So I created this script on my Test NPC (VPImperialPatrolMF6). He should only patrol a bit in Balmora

However he won't start travelling

Begin VPGuard1Scr

short state 
float timer 
float timeout




 
if ( menumode == 1 ) ; if menu is open don't process 
 return 
endif 



;start walking 
if ( state == 0 ) 
 if ( player->GetDistance VPImperialPatrolMF6 < 5000 ) 
set state to 5 
 endif 

elseif ( state == 5 ) 
 SetHello 0 
AiTravel, -25615, -12061, 1193
 set state to 10 

elseif ( state == 10 ) 
 if ( GetAIPackageDone == 1 ) ;he's reached point 1 
 set state to 20
 endif 
 
elseif ( State == 20 ) 
AITravel -22941, -12546, 622
 set State to 30

elseif ( state == 30 ) 
 if ( GetAIPackageDone == 1 ) ;he's reached the point 2 
 set state to 0 
 endif  
Endif

If ( Player->GetDistance, VPImperialPatrolMF6 < 5000 )
if ( GetCurrentAIPackage == -1 ) ; check for idleness
set timeout to ( timeout + GetSecondsPassed )
if ( timeout >= 3 ) ; wait some time.
; Short instances of idleness always occur
set state to ( state - 10 ) ; stall will occur at
; AIPAckageDone - jump to "wander" again.
set timeout to 0
endif
else
set timeout to 0
endif
endif


End VPGuard1Scr
Link to comment
Share on other sites

Structurally, it looks fine. The float timer isn't being used. I assume the script compiles and you have it attached to the guard. The game engine can be finicky - sometimes you have to chew its food for it. Try:

 

if ( ( player->GetDistance "VPImperialPatrolMF6" ) < 5000 )

 

It is inefficient to include two identical distance checks every frame. You can combine the travel code with the recover code under the same umbrella. Alternately, you could place the following block after the menu check:

 

if ( ( player->GetDistance "VPImperialPatrolMF6" ) >= 5000 )

return

endif

 

It seems like the script is stalling at state == 0, but it could be at state == 5. If the coordinates of AITravel are not attainable (too far, not in line-of-sight, etc.) the NPC might be paralyzed by indecision. I can see that the distance between point 1 and point 2 is over 2500 units. That's on the long side, but it may work if there are no obstacles. Otherwise introduce intermediate waypoints to make the route navigable. You can introduce messageboxes that display at each step to find out how far the script processes before there is a problem.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...