How to make something happend, when npc is near enough?

Started by Rd27, Sat 05/03/2005 18:17:01

Previous topic - Next topic

Rd27

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  :)

Scorpiorus

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.");
}

YotamElal

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).

Rd27

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!

monkey0506

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).

Ashen

The + and - mean, well, + and -.  Suppose NPC's x was 160, that would be:
Code: ags

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:
Code: ags

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.
I know what you're thinking ... Don't think that.

Scorpiorus

#6
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>;
}


SMF spam blocked by CleanTalk