Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Tue 01/03/2011 16:51:58

Title: Solved-Check if the character has walked onto a region.
Post by: on Tue 01/03/2011 16:51:58
I know how to do this with player character, and it's really easy...
But how do I do that with some other character. If he walks onto a region ...
If anyone can help me I would be very grateful.
Thanks in forward! :)
Title: Re: Check if the character has walked onto a region.
Post by: Khris on Tue 01/03/2011 17:24:31
Add the room's repeatedly_execute event. In there, use something like this:

// above function

int npc_prev_region;

// inside function

  if (cNpc.Room == player.Room) {

    Region*re = Region.GetAtRoomXY(cNpc.x, cNpc.y);
    if (re.ID != npc_prev_region) {  // Npc changed current region

      if (npc_prev_region > 0) {

        // Npc walked off region npc_prev_region
      }
      if (re.ID > 0) {

        // Npc walked onto region re.ID
      }
     
      npc_prev_region = re.ID;
  }
Title: Re: Check if the character has walked onto a region.
Post by: on Tue 01/03/2011 18:11:51
It's kinda complicated, and It'll take time for me to understand that code but...
It will probably work so...
thanks !!! ;D
guess my problem is solved.
thank you khris
Title: Re: Solved-Check if the character has walked onto a region.
Post by: Khris on Tue 01/03/2011 18:19:35
It's not that complicated really, all that does is check if the NPC is in the current room and if they are, constantly keep track of the region they're on.
For that, the current region is checked against the previous one 40 times per second, and if they aren't the same any longer, the NPC must have just changed regions.
Both events are handled, then the previous region variable is updated.
Title: Re: Solved-Check if the character has walked onto a region.
Post by: on Tue 01/03/2011 19:24:33
Yes... I think I understand it now.
It works. :)