Making an NPC constantly patrol?

Post » Thu Dec 24, 2009 11:06 am

I would like an NPC to constantly move in a predetermined path back and forth on patrol, however the NPC does not do this. He will stop periodically and stand, how can a avoid this? Is there an AI package setting I can use?
User avatar
kelly thomson
 
Posts: 3380
Joined: Thu Jun 22, 2006 12:18 pm

Post » Thu Dec 24, 2009 7:31 am

http://planetelderscrolls.gamespy.com/View.php?view=Tutorials.Detail&id=55#ArtificialIntelligence (specifically the path-grid editing part, obviously)

Ive never done it myself, but..

Goodluck :thumbsup:

Edit: I believe Fargoth has some pathgrid-ding assigned to him for *that* mission of his in Seyda Neen. Might wana check that out.

Keep in mind that (say your trying to get the NPC to walk down a corridor) setting its walk range really high and 'constant' (basically) he'll probably walk the path you want him to anyway :D But youve probably got something more elaborate in mind hey.. :hubbahubba:
User avatar
Andrea P
 
Posts: 3400
Joined: Mon Feb 12, 2007 7:45 am

Post » Thu Dec 24, 2009 6:53 am

I would like an NPC to constantly move in a predetermined path back and forth on patrol, however the NPC does not do this. He will stop periodically and stand, how can a avoid this? Is there an AI package setting I can use?

You may not require a pathgrid, but it will make travel more reliable. Find the coordinates of each end of the patrol and use AITravel to move the NPC from one end to the other and back again. I think a brief pause at each end is appropriate, but of course it is your call.

Begin PatrolScript; Attached to patrolling NPCshort stateSetHello 0 ; prevent idle greetings as player approachesif ( state == 0 )    SetHello 0 ; prevents idle greetings as player approaches    set state to 10    AITravel x1 y1 z1 ; coordinates of one endelseif ( state == 10 )    if ( GetAIPackageDone == 1 ) ; arrived at end of patrol        set state to 20    endifelseif ( state == 20 )    set state to 30    AITravel x2 y2 z2 ; coordinates of other endelseif ( state == 30 )    if ( GetAIPackageDone == 1 ) ; arrived at other end of patrol        set state to 0    endifendifEnd

There is nothing in this code to reset the script if the NPC's travel is disrupted by the player resting for fast traveling in the cell with the NPC. It is possible such actions by the player could suspend travel. If the patrol distance is too great or interrupted by obstacles, a pathgrid will help or you may require multiple waypoints.
User avatar
Enie van Bied
 
Posts: 3350
Joined: Sun Apr 22, 2007 11:47 pm

Post » Thu Dec 24, 2009 2:57 pm

Double post
User avatar
xx_Jess_xx
 
Posts: 3371
Joined: Thu Nov 30, 2006 12:01 pm

Post » Thu Dec 24, 2009 12:26 pm

Oh yea.. dont know why i didnt even think about scripting it :facepalm:
User avatar
Damian Parsons
 
Posts: 3375
Joined: Wed Nov 07, 2007 6:48 am

Post » Thu Dec 24, 2009 5:04 am

Just a word of warning: The entire patroll path must be in one cell. I the start and end point of any segement of the patrol path cross an exterior cells boundry the AITravel command will not work. It's easy to add multiple way points along the route with the same framework in cyranO's example.
User avatar
Ronald
 
Posts: 3319
Joined: Sun Aug 05, 2007 12:16 am

Post » Thu Dec 24, 2009 6:56 am

You may not require a pathgrid, but it will make travel more reliable. Find the coordinates of each end of the patrol and use AITravel to move the NPC from one end to the other and back again. I think a brief pause at each end is appropriate, but of course it is your call.

Begin PatrolScript; Attached to patrolling NPCshort stateSetHello 0 ; prevent idle greetings as player approachesif ( state == 0 )    SetHello 0 ; prevents idle greetings as player approaches    set state to 10    AITravel x1 y1 z1 ; coordinates of one endelseif ( state == 10 )    if ( GetAIPackageDone == 1 ) ; arrived at end of patrol        set state to 20    endifelseif ( state == 20 )    set state to 30    AITravel x2 y2 z2 ; coordinates of other endelseif ( state == 30 )    if ( GetAIPackageDone == 1 ) ; arrived at other end of patrol        set state to 0    endifendifEnd

There is nothing in this code to reset the script if the NPC's travel is disrupted by the player resting for fast traveling in the cell with the NPC. It is possible such actions by the player could suspend travel. If the patrol distance is too great or interrupted by obstacles, a pathgrid will help or you may require multiple waypoints.

Hmm, that will work wonders, I just want my NPC to move from one end of a field to another, how would I find the coordinates?
User avatar
roxxii lenaghan
 
Posts: 3388
Joined: Wed Jul 05, 2006 11:53 am

Post » Thu Dec 24, 2009 7:03 am

I prefer to get them in-game, but you could find them in the construction set as well. When in-game I move the player to the desired position and use the console to grab the player's coordinates: player->GetPos x and repeat for 'y' and 'z'. For the latter approach, place your NPC at the desired position and the coordinates of the object will be displayed in the lower left corner of the construction set window.

Nicholaithan is correct: pathgrids cannot cross cell boundaries, however AITravel can. If you have to hop from one path grid to that in an adjacent cell it might require separate AITravel instructions. I remember having to get creative for a quest in LGNPC Khuul.
User avatar
DarkGypsy
 
Posts: 3309
Joined: Tue Jan 23, 2007 11:32 am

Post » Thu Dec 24, 2009 2:50 am

To get coordinates in the CS, you can just put a placeholder NPC at the point, and select it. The coordinates are shown in the status bar of the CS (bottom of the screen).
User avatar
JUan Martinez
 
Posts: 3552
Joined: Tue Oct 16, 2007 7:12 am

Post » Thu Dec 24, 2009 4:42 pm

To get coordinates in the CS, you can just put a placeholder NPC at the point, and select it. The coordinates are shown in the status bar of the CS (bottom of the screen).


For some reason, I have found that the coordinates gotten from the CS are sometimes not reliable. I've found the easiest way is to go to the spot in game, open the console, select the PC, and enter a beta comment. This automatically gets you all the co-ordinates.
User avatar
Enny Labinjo
 
Posts: 3480
Joined: Tue Aug 01, 2006 3:04 pm


Return to III - Morrowind