How to pick up an NPC like an object?

Started by khalilsajadi, Sat 02/04/2011 22:56:03

Previous topic - Next topic

khalilsajadi

In my game I have a ham that the character can talk to. I created the ham as a character so it could speak. At the end of the dialogue, I want my character to be able to pick up the ham, bring him to another room, and set him down again. To experiment with this, I tried creating an object that was the ham, and coded it so that when I use the interact option on oHam, it disappears and is then in my inventory. Looks like this:

function oHam_Interact()
{
  oHam.Visible = false;
  player.AddInventory(iHam);
}

So, obviously, now there are two hams on the screen. XD

Is there a way I can either:
a. have dialogue with an object, or
b. make cHam invisible (after the dialogue) and still have iHam show up in my inventory, and then just make the NPC reappear in another room after I drop the inventory item?

TomatoesInTheHead

a. will not work, only characters have a Say function.

But b. will: you can make characters invisible by setting their room to 0.
Either you do it like you intended, making them invisible when you pick them up with
Code: ags
cHam.ChangeRoom(0);

and visible again later with something like
Code: ags
cHam.ChangeRoom(player.Room,x,y);


Or you use an object which you hide and show, and use a character that is always in room 0 to say something, like
Code: ags

function oHam_Interact()
{
  oHam.Visible = false;
  cHam.Say("Help! I get abducted!"); //cHam is not in this room, but his speech appears
  player.AddInventory(iHam);
}


(the inventory item iHam is not affected by anything of this)

khalilsajadi

Firstly, thanks for the speedy reply. I've decided to go with your second option, where he is always in room 0. However, if I have an entire scripted dialogue rather than just one phrase, can I say dHam.Start(); instead of cHam.Say("..."); ? I tried that, and AGS wouldn't let me add oHam.Visible = false; afterwards. o:

What I'm understanding the whole script should look like is:

  function oHam_Interact()
{
  dHam.Start();
  oHam.Visible = false;
  player.AddInventory(iHam);
}

But it won't allow the oHam line?

khalilsajadi

Nevermind; I went back to your first option and it worked splendidly. thank you! :)

SMF spam blocked by CleanTalk