Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Blade on Thu 30/09/2004 11:52:37

Title: NPC leaves room
Post by: Blade on Thu 30/09/2004 11:52:37
I have such a problem:
Player goes to room A, talks with the NPC (I'll call him Boss).
Some time later Player talks with NPC in room B - this triggers a diferent dialog with Boss from room A than the first one, which leads to an animation of Boss leaving room A (so the Player can search the room)

How do I script this change?
I hope I describe it understandably.
Title: Re: NPC leaves room
Post by: jetxl on Thu 30/09/2004 12:16:34
Reading the manual and looking at the tutorials will let you learn AGS.
From the top of my head.

When you talk to the boss and tell him to leave, SetGlobalInt(1,1). This is the "boss will leave" flag.

Function Repeatly_Execute(){ //boss room
Ã,  If (getGlobalInt(1)==1){Ã,  //Converation mode is blocking(?).after you have ended the conversation this will be triggered (I think)
Ã,  Ã,  // animation
Ã,  Ã,  MoveCharacterBlocking(BOSS,-20,160,1);Ã,  //Boss is walking of screen
Ã,  Ã,  character[BOSS].room=-1;Ã,  //
Ã,  Ã,  SetGlobalInt(1,2);Ã,  //sets boss flag to 2 so this equasion isn't run again
Ã,  }


To search the room you have to make eqasions with if(getGlobalInt(1)==2 to check if the boss is gone or not. Otherwise you can open the drawer when the boss is still there.
Title: Re: NPC leaves room
Post by: Blade on Thu 30/09/2004 12:20:24
Thanks. I'm completely new to scripting, so I suppose I'll have more questions when I check on that one.
Title: Re: NPC leaves room
Post by: Ashen on Thu 30/09/2004 13:09:20
Alternatively, you could use the run-script and dialog_request commands. It's a little more complicated than jetxl's way, though.

Firsly, create your dialog with BOSS. Have an option, the one that will make the boss leave, that isn't visible at first (uncheck the 'Show' box next to it). After the conversation with NPC, use SetDialogOption to turn it on.
The dialog script for it should look something like:

@4  // option 4
boss: Well, I'd better go check that out.
run-script 1


Then check your global script for 'dialog request' - it's one of the shortcuts on the 'Script' menu, but by default it isn't in the script. Create the function if you have to (just copy&paste this code), and add the if (xvalue == 1) condition:

   function dialog_request (int xvalue) {
    if (xvalue == 1) {
      StopDialog ();
      MoveCharacterBlocking (BOSS, 100, 100, 0);
      character[NAB].room = -1;
    }// end of condition
  }// end of dialog_request

If you already have an '== 1' condition, just change the number, but be sure to change the run-script as well.

Lastly, in the hotspots/objects you want to search, use Run script and:

  if (character[BOSS].room == A) { // BOSS is still in the room (replace A with room number)
    DisplaySpeech (EGO, "I can't, not with Boss here.");
  }
  else { // BOSS has left the room, so
    // Whatever you want to happen
  }