Give item from inventory to NPC

Started by Brex, Sun 22/03/2009 10:19:41

Previous topic - Next topic

Brex

Hi all, I'm trying to make a game where you can give an item to an NPC, and so far I'm up to here;

function cLewis_UseInv()
{
    Display("Wow thats all I needed!");
  }

But the Coffee that was just given is still there... is there a way to actually give the Coffee to an NPC, if it is in the manual, sorry I've searched it and couldn't find it anywhere

EDIT: After a bit more messing around I found the right command, sorry :)

Dualnames

Quote from: Brex on Sun 22/03/2009 10:19:41
Hi all, I'm trying to make a game where you can give an item to an NPC, and so far I'm up to here;

function cLewis_UseInv()
{
    Display("Wow thats all I needed!");
  }

But the Coffee that was just given is still there... is there a way to actually give the Coffee to an NPC, if it is in the manual, sorry I've searched it and couldn't find it anywhere

EDIT: After a bit more messing around I found the right command, sorry :)
function cLewis_UseInv(){
if (player.ActiveInventory==icoffee) {
    Display("Wow thats all I needed!");
  }
}

EDIT:
Ah..just saw that edit
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Shockbolt

And how would one go about, giving an NPC an item (losing it from one's inventory) based upon a choice in a dialog with the NPC?

The particular dialog with the NPC would only be started if the player actually has the item in his/hers inventory.

Let me be more specific:

Player has found the item that the NPC was asking him to find.
Player starts the dialog dFoundItem:

1. I found Your item 
2. Bye

When selecting 1. , the NPC would reply:

"Thank You!"

Then the NPCs viewloop would change to something other than the previous and the player will have lost the item from the inventory.

Back to the game.

Trent R

Am I getting your question right?
QuoteThen the NPCs viewloop would change to something other than the previous
cSomeDude.ChangeView(int);
Quoteand the player will have lost the item from the inventory.
player.LoseInventory(iItem);


Another thing that can be useful is to actually give the item to SomeDude (SomeDude.AddInventory(iItem);) You can then use this as a global variable, rather than creating a SomeDudeHasItem variable.
To check, simply use  SomeDude.HasInventory(iItem) in an if statement.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Shockbolt

#4
Quote from: Trent R on Mon 30/03/2009 19:26:42
Am I getting your question right?
QuoteThen the NPCs viewloop would change to something other than the previous
cSomeDude.ChangeView(int);
Quoteand the player will have lost the item from the inventory.
player.LoseInventory(iItem);


Another thing that can be useful is to actually give the item to SomeDude (SomeDude.AddInventory(iItem);) You can then use this as a global variable, rather than creating a SomeDudeHasItem variable.
To check, simply use  SomeDude.HasInventory(iItem) in an if statement.



~Trent

That's somewhat the way I ended up dealing with the "problem". What I wanted was to deal with it, as in the text below:

I was only wondering if it was able to achieve the same via the dDialog , where You choose what to ask/say, then the npc responds.
I mean, if You choose a line within the dDialog, then the item is lost from the inventory, and the npc changes viewloop or something else is triggered whilst still in the dDialog (when playing/testing)

*fixed* :-D

Trent R

One, you messed up the quote tags in the previous post. No biggie.

Two, normal scripting commands can now be used in dialog scripts as of AGS 3.something. You simply need to indent the line.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Shockbolt

Quote from: Trent R on Mon 30/03/2009 21:44:08
One, you messed up the quote tags in the previous post. No biggie.

Two, normal scripting commands can now be used in dialog scripts as of AGS 3.something. You simply need to indent the line.


~Trent

Hmm...I'll have to look into that and see what I can come up with.

Dualnames

I may suggest searching the forums on that, because it's really asked quite some times, so I think you'll find exactly what you're looking for, and maybe more cool stuff.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Shockbolt

I've spent alot of time looking around the forum, online manual, tutorials etc for help on what I'm coding.
I assume it'll get much easier with a few months of practice under the belt, but for now, all the various names  that are given
in the examples by the more experienced coders are kinda confusing to a rookie like myself. But I'm slowly getting the hang of it.

Here's how I got the job done, bu using an inventory item on a NPC:
When player has the correct item and is using that item on the npc, the npc should fall asleep, changing his animation loop.
This could also have been altered so that the npc would have gotten the item into his inventory as well.
(By adding the code cGromStart.AddInventory(iStinkyfruit001); )

Portion of the Globalscript.asc code:

Code: ags

function cGromStart_UseInv()
  {
    if (player.ActiveInventory != iStinkyfruit001)
   { cGromStart.Say("I don't want that.");
   }
    
   if (player.ActiveInventory == iStinkyfruit001)
   {
   player.LoseInventory(iStinkyfruit001);
   cGromStart.SayBackground("YUM YUM.");
   Wait(80);
   cGromStart.Say("I feel...dizzy...");
   Wait(80);
   cGromStart.Animate(6, 4, eRepeat, eNoBlock);
   myGromSleep += 1;
   }
   
  }



the Global variable myGromSleep is there to let the player trigger another cutscene that will only be done
if the first has been executed, and if the player has the correct items in the inventory.

So for my part, this problem has been solved :)

Khris

#9
Note that  a += b  is short for  a = a+b.
You're increasing myGromSleep by 1, not setting it to 1.

Edit:
The result is the same in this case, true, but since you were using += without obvious purpose, I thought I'd point out the difference.

Shockbolt

Quote from: KhrisMUC on Wed 01/04/2009 19:39:25
You're increasing myGromSleep by 1, not setting it to 1.

In this case, myGromSleep is 0 to begin with. It increases to 1 when the fruit is given to him :)
I could also use what You suggested, I see that now.

SMF spam blocked by CleanTalk