Starting the interactive dialogues after giving an inventory item to a character

Started by Adeel, Sun 10/03/2013 15:59:15

Previous topic - Next topic

Adeel

Hello All Members.
I am new to A.G.S. & its community. Now I am facing a problem. I would like you all to help me.
I have two characters. I want my player character to give (use) an inventory item to the NPC. I have done it all right. Player gives the item. Item also disappears from the inventory. BUT the REAL PROBLEM starts when I want to add the interactive dialogues. I have read in forums to use 'character.say' command, but N.P.C. only speaks.
    I, on the other hand want N.P.C. to ask (such as:) "Which item would you like to have?" and then player would choose from the three items, such as (book, journal or pen). And then he may receive his chosen item. How can I do it? Also, please be kind enough to upload the code because I am not too good in scripting.
[/size]
    (P.S: Moderators, I hope you do not lock this. Since I am new & as per my knowledge, I am posting it in the write section.)

geork

Hello Adeel, welcome to the forums :)

If you go through the tutorial, you'll find what you want with dialogues. In the editor, go to Help -> Contents -> Tutorial.

Also if you're new, I'd check out densming's video series - that should get you set up with a lot of the basic scripting you'll want.

Have you read the *Read First *Before* Posting thread? It's a good idea if you haven't.

Also, it's very likely that your question has already been answered, so it's a good idea to use the search bar on this site before opening a new thread

Hope you enjoy AGS!

Adeel

Before starting, I would like to thank "geork" for giving reply. I would also like to thank "Cerno" for giving me a suggestion about Dialog.DisplayOptions(). I haven't tried it yet (lazy me) but I'll post about it whenever I check it out.
    NOTE: This post is long since it is a tutorial. Please be patient and read it. If anyone of you gets benefit from it, that would be the worth of hard work I have done to write this.
    If you have played point-and-click adventure games, you would have surely come across that you give an inventory item to a NPC (Non Player Character) and then the dialog starts. But the question for beginners (such as myself) is, how to initiate the dialogs after giving (using) an inventory item on a NPC?
    To better understand what I'm saying, consider the following example.
    Suppose your player would have to find a free coupon in your game. That coupon would allow player to get anyone of the three items for free from a NPC in your game. Those free items are: Key, Shovel and Dagger. Now you will naturally give the player choice as to which item he may choose. Normally, these are followed by the dialogs such as:
PLAYER:Here is the free coupon for which you asked.
NPC:Why, sure that is. Now, which item would you like to have.

(And then, the player gets the options, such as):

PLAYER: I want the master key of which you told me earlier about.
OR
PLAYER: I would like to have that shovel.
OR
PLAYER: I think that sharp dagger would suit me the most.

    (To which the NPC responds and gives you the item you chose. i.e.)

NPC: Here is the key you that you wanted.
OR
NPC: A free shovel for you then.
OR
NPC: The sharp dagger is yours. Be careful, do not injure yourself.
       
    (Now you would surely have idea of what I were talking about. But the question again persists that HOW TO INITIATE DIALOGS AFTER USING / GIVING an inventory item to a NPC? So, here is my worked out solution for you:)
Code: AGS
function cNPC_UseInv()
{
if (player.ActiveInventory == iCoupon)
{
  dCoupon.Start();
}
else 
{
  cNPC.Say("This is not the free coupon..");
  player.Say("I'll try to find it A.S.A.P.");
  cNPC.Say("Best of Luck.");
}
}

    As you can see. I have just inserted the simple code i.e. when player gives coupon to the NPC then the dialogs will start. Else, NPC would not accept it. In the above code:

  • cNPC = NPC Character.
  • iCoupon = Script Name for Coupon.
  • dCoupon = The Script Name of Dialog

For Dialogs (dCoupon):
Code: AGS

// Dialog script file
@S  // Dialog startup entry point
HERO: Here is the free coupon for which you asked.
NPC: Why, sure that is. Now, which item would you like to have?
    player.LoseInventory(iCoupon);
return
@1
HERO: I want the master key of which you told me earlier about.
NPC: Here is the key you that you wanted.
    player.AddInventory(iKey);
stop
@2
HERO: I would like to have that shovel.
NPC: A free shovel for you then.
    player.AddInventory(iShovel);
stop
@3
HERO: I think that sharp dagger would suit me the most
NPC: The sharp dagger is yours. Be careful, do not injure yourself.
    player.AddInventory(iDagger);
stop


    So, whatever item player would demand, he would get it. Afterwards, the dialogs will stop.
In the above code:

  • HERO = cHERO (Script Name for player. Remember, do not use 'c' in dialogs.)
  • iKey = Script Name for the master key.
  • iShovel = Script Name for the shovel.
  • iDagger = Script Name for the dagger.
    Noticed the indent (space) between the usual dialogs and scripts? This is the way you can directly insert the normal scripting command in your dialogs.
    There you go. It works for me and will definitely work for you. I know that the post has become too long and moderators would not be happy (I am sorry, moderators). But I have written it with explanation so that anyone beginner to scripting would easily understand it (such as myself).
    So, don't be sad just because you are a rookie. Since every expert was at some point a rookie.
    Cheers, 8-)
    Adeel S. Ahmed

EDIT: Khris pointed out a mistake which has been rectified.
   

Khris

In cNPC_UseInv, you're using if (player.HasInventory(iCoupon)).
That's a check for whether the player has at least one iCoupon in their inventory. What you need is
Code: ags
  if (player.ActiveInventory == iCoupon)


Also, this is extremely basic and obvious stuff. There's isn't any trick in there, or elegant shortcut; it's just what you're supposed to do anyway. However, we used to get the "how to run commands after dialogs" question a lot, so maybe some people will find it useful.

Slasher

Drat, beaten by Khris  (laugh)

Without looking further at your code:

Code: AGS
function cNPC_UseInv()
{
if (player.HasInventory(iCoupon)) // THIS PART SHOULD BE: 

if (player.ActiveInventory==iCoupon)// ------as if giving iCoupon inventory to NPC otherwise Dialog options will start because you put if player HAS iCoupon.
{
  dCoupon.Start();
}
else 
{
  cNPC.Say("This is not the free coupon..");
  player.Say("I'll try to find it A.S.A.P.");
  cNPC.Say("Best of Luck.");
}
}




Adeel

Khris, I didn't say it was 'extremely difficult' or I discovered a 'shortcut'. I said it 'simple'. With all due respect, I would say that surely you are mistaken there.
    By the way, thanks for pointing me out. I am sure gonna edit that.
    Hey slasher, you can't compare me with Khris, yet.  ;) He is very experienced scriptor, so its good of him to point out the mistake. I am just a beginner as I said. By the way, thanks for explaining the correction done by Khris.
    So guys, thanks for reading the code and correcting it.
    Cheers, :)
    Adeel S. Ahmed

SMF spam blocked by CleanTalk