NPC changing room (solved)

Started by Zoolander, Sat 17/12/2005 05:30:31

Previous topic - Next topic

Zoolander

Here's something I'm hoping I can get help with.  I have a street scene where an NPC is repeatedly walking around and talking randomly in the background.  Then my player character goes into a building where the same NPC has also gone.  If I've talked to him, when I leave the building I want him to not be in the street (he's still in the building).  Then if I leave the street to go to another area, when I come back to that street the NPC should be back randomly walking and talking like before. 

I've tried many different variable variations, but nothing I try works.  Can anyone think of a way to do this?

By the way, here's how I've coded the NPC in the repeatedly execute script if it helps:
if (character[ORT].Moving==0) {
character[ORT].Walk(Random(225), Random(200)+130,eNoBlock);
}
  if (pause > 0 )   
pause--;

else if (speakline==Random(3)) {
  character[ORT].SayBackground("Sentence 1!");
  pause = 5*GetGameSpeed();
  speakline=2;
  }
else if (speakline==Random(3)) {
  character[ORT].SayBackground("Sentence 2!!");
  pause = 5*GetGameSpeed();
  speakline=3;
}
else if (speakline==Random(3)) {
  character[ORT].SayBackground("Sentence 3!!!");
  pause = 5*GetGameSpeed();
  speakline=1;
}
}

Akumayo

In your main game's repeatedly_execute:
Code: ags

if (character[player.ID].PreviousRoom == (building's room number)) {
Ã,  character[ORT].ChangeRoom(building's room number, whateverx, whatevery);
}
if (character[player.ID].PreviousRoom == (street room number)) {
Ã,  character[ORT].ChangeRoom(street room number, whateverx, whatevery);
}
"Power is not a means - it is an end."

Ashen

Actually, that'd be better going in the Player enters screen (before fade-in) interaction of the 'street' room.

You'll also probably want to add a variable to check if ORT has been spoken to, when coming out of the building (use GlobalInts, or create your on in the Global script and export/import it), e.g.:
Code: ags

 if (player.PreviousRoom != BUILDING && spoken_to_ort == 1) { // Not coming from BUILDING but have spoken to ORT
  cOrt.ChangeRoom(STREET, whateverx, whatevery);
}

NOTE: I haven't added anything to move ORT into the building - I figure you can do that when you need to, and it would've gone wrong if you've able to enter the building before ORT (Akumayo's code would've moved him everytime you left that room, whether you wanted to or not).
Also, you didn't say what should happen if you leave the building NOT having spoken to ORT. I've assumed nothing - he'll just stay there 'til you've spoken to him.
I know what you're thinking ... Don't think that.

Zoolander

I thought that would work.  But after talking to NPC (ORT) and going back outside, there he is.  The problem might be that because of the repeatedly execute stuff in the Street Room, if I don't move the NPC back there, I'll get an error because it wantes to move a character that isn't there.
What I tried to do is before fade-in:

character[ORT].ChangeRoom(7, 134, 140);
if (player.PreviousRoom != 15 && speak_to_ort == 1) {
  character[ORT].ChangeRoom(15, 10, 10);


(Street is room7, building is room15)
It should work but it doesn't.

Ashen

#4
Quoteif I don't move the NPC back there, I'll get an error because it wantes to move a character that isn't there.

Good point ... Just put all the rep_ex stuff relating to ORT in a condition to check he's in room 7 first, i.e.:
Code: ags

if (cOrt.Room == 7) {
  if (character[ORT].Moving==0) {
    character[ORT].Walk(Random(225), Random(200)+130,eNoBlock);
  }

  if (pause > 0 ) pause--;

  else if (speakline==Random(3)) {
    character[ORT].SayBackground("Sentence 1!");
    pause = 5*GetGameSpeed();
    speakline=2;
  }
  else if (speakline==Random(3)) {
    character[ORT].SayBackground("Sentence 2!!");
    pause = 5*GetGameSpeed();
    speakline=3;
  }
  else if (speakline==Random(3)) {
    character[ORT].SayBackground("Sentence 3!!!");
    pause = 5*GetGameSpeed();
    speakline=1;
  }
}

On a side note: does the speakline stuff actually work? Random(3) can also produce 0, and as far as I can see you don't have a condition for that - which could cause ORT to stop talking. The multiple instances mean it's unlikely, but still possible. Also (this isn't a problem, more for future reference), you could replace the pause countdown with a timer (SetTimer(), IsTimerExpired()).


Code: ags

character[ORT].ChangeRoom(7, 134, 140);
 if (player.PreviousRoom != 15 && speak_to_ort == 1) {
  character[ORT].ChangeRoom(15, 10, 10);
}  


You're moving ORT to room 7 whatever room the player is coming from, and only moving him out again if that room wasn't 15 (the building) - which is the opposite of what I thought you wanted. Try swapping the character[ORT].ChangeRoom(...) lines, so he's always placed in room 15, and only moved back if needed. In fact, you could probably do without sending him to room 15 to start with - if he's already in room 7 at the start of the game you don't want him being sent away before he's supposed to be (Since spoken_to_ort will presumably be 0 to start with, that condition would move him fout and keep him out from the get go. Then, once he's left room 7 he obviously doesn't need to be moved out again, only back in when necessary.)
I know what you're thinking ... Don't think that.

Zoolander

 I've got this solved.  I just want to make sure I make it clear what worked. 

In Room7, Player enters screen (before fade-in):
if (player.PreviousRoom == 8) {
  character[ORT].ChangeRoom(7, 134, 140);
}
if (player.PreviousRoom == 5) {
  character[ORT].ChangeRoom(7, 134, 140);
}
(Rooms 5 & 8 are where the player can go from room 7, besides room 15).

Repeatedly Execute:
if (character[ORT].Room==7) {
if (character[ORT].Moving==0) {
character[ORT].Walk(Random(225), Random(200)+130,eNoBlock);
}
}
  if (pause > 0 )   
pause--;
else if (speakline==Random(7) && character[ORT].Room==7) {
  character[ORT].SayBackground("Sentence 1!");
  pause = 5*GetGameSpeed();
  speakline=2;
  }
else if (speakline==Random(7) && character[ORT].Room==7) {
  character[ORT].SayBackground("Sentence 2!!");
  pause = 5*GetGameSpeed();
  speakline=3;
}
else if (speakline==Random(7) && character[ORT].Room==7) {
  character[ORT].SayBackground("Sentence 3!!!");
  pause = 5*GetGameSpeed();
  speakline=1;
}
}
Thanks to Ashen for getting me there!

SMF spam blocked by CleanTalk