×
Меню
Индекс

MSFD Checking whether an NPC has performed his movement

 
GetAIPackageDone     (returns Boolean/short)
 
if ( GetAIPackageDone == 1 )         
          [do something]
endif
 
To check whether an NPC has arrived at his location you can use the GetAIPackageDone function. This function returns 1 for one frame when the current AI package has finished.
 
Use this to perform a check whether a movement has been finished. The following script is an example of how to link several AITravel commands within one script, using a state variable and an if-elseif structure:
 
Begin TravelLoop
 
short state
float timer
 
if ( menumode == 1 ) ; if menu is open don't process
     return
endif
 
;start walking
if ( state == 0 )
     if ( player->GetDistance HB_adros_darani < 5000 )
          set state to 5
     endif
 
;******************* He begins his trip
elseif ( state == 5 )
     SetHello 0
     AITravel -8144, -19409, 728 ;new co-ords point 1
     set state to 10
 
elseif ( state == 10 )
 
     if ( GetAIPackageDone == 1 )          ;he's reached point 1
          set state to 40
     endif
 
elseif ( State == 40 )
 
     AITravel -9147, -19459, 720 ; new co-ords point 2
     set State to 50
    
elseif ( state == 50 )
 
     if ( GetAIPackageDone == 1 )          ;he's reached the point 2
          set state to 60        
     endif
 
elseif ( state == 60 )
     AITravel -8144, -19409, 728 ;new co-ords point 1
     set state to 70
 
elseif ( state == 70 )
 
     if ( GetAIPackageDone == 1 )          ;he's reached point 1
          set state to 80
     endif
 
elseif ( state == 80 )
     AITravel -6640, -18496, 1040 ;new co-ords point 0
     set state to 90
 
elseif ( state == 90 )
     if ( GetAIPackageDone == 1 )          ;he's reached point 0
          set state to 0
     endif
 
endif
 
End TravelLoop
 
Good examples of scripting using AITravel are also found in the “lookoutscript” (Fargoth hiding his treasure) and the CharGenWalkNPC script (The guard that walks you through the ship at the beginning of the game). Or look at my "Traveling Merchants" plugin for true AITravel madness  !
If you plan on using this function extensively you should be aware of the following problems: When you leave a cell with an Actor that is just performing its AITravel command, or if you rest, the script will never detect the GetAIPackageDone signal, meaning your NPC gets stuck on its path once you return or finish sleeping. The following simple code can be used to get the script going again (this is for the above script)
 
 
; *************** Stalled Script rescue - recovers script after leaving a cell or resting
If ( Player->GetDistance, HB_adros_darani < 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