Translations of this page:

Triggering actions when actor is idle

Attach the following script to your actor to trigger some action when the actor is idle for some time (5 seconds in this case)

#include "scripts\base.inc" 
 
var IsIdle = false; 
var IdleStartTime = 0; 
 
while(true) // endless loop 
{ 
  if(actor.Ready) // is the actor doing something 
  { 
    if(!IsIdle) 
    { 
      // actor enters idle state 
      IsIdle = true; 
      IdleStartTime = Game.CurrentTime; 
    } 
    else if(Game.CurrentTime - IdleStartTime > 5000) // is the actor idle for 5 seconds 
    { 
      IdleStartTime = Game.CurrentTime;  
      actor.ApplyEvent("idle"); 
    } 
  } 
  else IsIdle = false; // actor is busy; set IsIdle to false 
  Sleep(100); // wait for 100 milliseconds 
} 
 
//////////////////////////////////////////////////////////////////////////////// 
on "idle" 
{ 
  // do some idle processing here 
  actor.Talk("Yawn!"); 
  actor.GoTo(Random(0, 1000), Random(0, 600)); 
}


 
resource/triggering_actions_when_actor_is_idle.txt · Last modified: 2008/11/24 19:58 by Jyujinkai
Recent changes RSS feed Creative Commons License Driven by DokuWiki