NPC walk, then wait, then walk again between two points

Started by Tenacious Stu, Tue 20/12/2011 11:18:30

Previous topic - Next topic

Tenacious Stu

I have this code for an NPC pacing an area. I want it so that when he reaches location 1 or 2, he waits for a few seconds before walking again. I tried to do this using timers, but failed miserably.

Code: ags

function room_RepExec()
{

  if (!cDog.Moving) //only check if the NPC isn't moving
  {
    if (characterLocation==1)
    {
      cDog.Walk(111, 183, eNoBlock, eAnywhere);
      characterLocation=2;
    }
    else
    if (characterLocation==2)
    {
      cDog.Walk(13, 181, eNoBlock, eAnywhere);
      characterLocation=1;
    }
  }
}

monkey0506

Based on the code you have now, it should be working fine except for the waiting part.

Code: ags
// room script
int dogDelay = 100; // change this to whatever wait duration you want

function room_RepExec()
{
  if (dogDelay) dogDelay--;
  else if (!cDog.Moving)
  {
    if (characterLocation == 1)
    {
      cDog.Walk(111, 183, eNoBlock, eAnywhere);
      characterLocation = 2;
    }
    else if (characterLocation == 2) // unless there's more than 2 locations, this is redundant and could just be 'else'
    {
      cDog.Walk(13, 181, eNoBlock, eAnywhere);
      characterLocation = 1;
    }
    dogDelay = 100; // again, change this as appropriate
  }
}

SMF spam blocked by CleanTalk