Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Blondbraid on Tue 28/03/2017 22:25:09

Title: start a script when a npc cross an area
Post by: Blondbraid on Tue 28/03/2017 22:25:09
Hi!
What I'm trying to achieve is a scene where a character who is not the player walks from point A to B, and if they reach point B, the player loses the game,
so that the player has to be able to interact with the character before they reach that point.

But all scripts and functions I find are about the player character, so I wonder if it's possible
to have a script trigger when a specific non player character cross a region or walkable area?
Title: Re: start a script when a npc cross an area
Post by: Snarky on Tue 28/03/2017 22:36:05
Code (ags) Select
#define TRIGGER_REGION 3 // whatever number that region has

function repeatedly_execute()
{
  if(Region.GetAtRoomXY(walkingCharacter.X, walkingCharacter.Y) == region[TRIGGER_REGION] && Game.DoOnceOnly("Reached point B"))
  {
    // do stuff
  }
}
Title: Re: start a script when a npc cross an area
Post by: Blondbraid on Wed 29/03/2017 17:11:12
I tried the script, but I get the error message:
room2.asc(27): Error (line 27): undefined symbol 'walkingCharacter'

What shall I do?
Title: Re: start a script when a npc cross an area
Post by: dayowlron on Wed 29/03/2017 17:47:03
Where he put walkingcharacter you need to supply the character object such as cEgo

If your NPC character is named Charlie then use cCharlie.
Title: Re: start a script when a npc cross an area
Post by: Blondbraid on Wed 29/03/2017 18:12:58
Everything seems to be working, thank you both!