Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rd27 on Sat 05/03/2005 18:17:01

Title: How to make something happend, when npc is near enough?
Post by: Rd27 on Sat 05/03/2005 18:17:01
Ok,I want this thing:

There is a sequence, where the player can't move the player character, he only can do something, but not move because NPC is coming to him. I want, that if the player does not do the right thing before the NPC is too close, there comes an death animation. Like the one in 5 days a stranger.

How can I do this so, that player can also move, but still NPC follows him? Same sequece, but player can move.

Hope somebody understand the question  :)
Title: Re: How to make something happend, when npc is near enough?
Post by: Scorpiorus on Sat 05/03/2005 18:56:06
Basically, if you want the player to retain control over the ego-character you should not use any blocking commands.

There is a special FollowCharacter(Ex) function you can use to make NPC follow the player:

enter room after fade-in:

int dist = 1;
int eagerness = 20;
FollowCharacterEx (NPC, GetPlayerCharacter(), dist, eagerness);


repeatedly execute:

if (AreCharactersColliding(NPC,Ã,  GetPlayerCharacter())
{
   Display("Here comes a death animation.");
}
Title: Re: How to make something happend, when npc is near enough?
Post by: YotamElal on Mon 07/03/2005 06:33:38
if you want something to happen when character NPC is close to you.

use this script in the rep_ex:

if (character[EGO].x < character[NPC].x + 50) {
   if (character[EGO].x > character[NPC].x - 50) {
      Display("Here comes a death animation.");
}
}

That's if you want EGO to dye when NPC is 50 pixels near EGO
(before the characters colide).
Title: Re: How to make something happend, when npc is near enough?
Post by: Rd27 on Mon 07/03/2005 19:32:19
Thanks for help. Both of you!

But that +50 and -50 is still a bit mystery to me. I know that it means that distance, right? But what are the exact meanings with - and +?

Thanks again!
Title: Re: How to make something happend, when npc is near enough?
Post by: on Mon 07/03/2005 19:35:04
mouse.x + 50 and mouse.x - 50 do exactly what they say.  They add/subtract (respectively) 50 from the x position of the mouse (mouse.x).
Title: Re: How to make something happend, when npc is near enough?
Post by: Ashen on Mon 07/03/2005 20:25:48
The + and - mean, well, + and -.  Suppose NPC's x was 160, that would be:

if (character[EGO].x < 210) { // 160 + 50 EGO is no more than 50 pixels right of NPC
  if (character[EGO].x > 110) { //160 - 50 and no more than 50 pixels left of NPC
...


Although, it could be condensed to a single line:

if (character[EGO].x < (character[NPC].x + 50) && character[EGO].x > (character[NPC].x - 50)) { // if EGO is within 50 pixels of NPC


It just allows NPC to be approaching EGO from ether side. You may also want to add a check on the y cordinates, depending on how the room is set up.
Title: Re: How to make something happend, when npc is near enough?
Post by: Scorpiorus on Tue 08/03/2005 18:58:55
Quote from: Rd27But that +50 and -50 is still a bit mystery to me. I know that it means that distance, right?
Yeah, they specify how close the NPC must walk up to the player character for the animation to start playing.

As Ashen suggested, you can as well add an y-coordinate check. Here is an example:


+---------> x
|
|
|
V y

Ã,  Ã,  Ã, \----50----|----50----/
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, (NPC)
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã, 20
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |
Ã,  Ã,  Ã, |--------(Plr)---------
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã, 20
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |
Ã,  Ã,  Ã, |Ã,  Ã,  Ã,  Ã,  Ã,  |Ã,  Ã,  Ã,  Ã,  Ã,  |
Ã,  Ã,  Ã, /----------|----------\

(Plr) - player character (EGO)
(NPC) - NPC is outside the bounding box


if ( (character[EGO].x < character[NPC].x + 50) &&
Ã,  Ã,  Ã, (character[EGO].x > character[NPC].x - 50) &&
Ã,  Ã,  Ã, (character[EGO].y < character[NPC].y + 20) &&
Ã,  Ã,  Ã, (character[EGO].y > character[NPC].y - 20)
Ã,  Ã, )
{
   // NPC is inside the bounding box:
   <animation code here>;
}


EDIT: Here is the exactly same piece of code but written in a slightly different manner to be consistent with the picture above:

if ( (character[NPC].x > character[EGO].x - 50) &&
Ã,  Ã,  Ã, (character[NPC].x < character[EGO].x + 50) &&
Ã,  Ã,  Ã, (character[NPC].y > character[EGO].y - 20) &&
Ã,  Ã,  Ã, (character[NPC].y < character[EGO].y + 20)
Ã,  Ã, )
{
   // NPC is inside the bounding box:
   <animation code here>;
}
Title: Re: How to make something happend, when npc is near enough?
Post by: Rd27 on Thu 10/03/2005 14:08:34
Thanks!