Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Rocky_Johan on Tue 06/07/2021 14:58:18

Title: [SOLVED] Give NPC inventory item and get another in return.
Post by: Rocky_Johan on Tue 06/07/2021 14:58:18
Hi! Just starting out. This seems really simple so apologizing beforehand but i canät find the answer anywhere(Sorry sorry sorry).

I want to give an inventory object to an NPC and get another object in return.
Point & Click 101. Can't figue out the coding and every tutorial just skips it.

Please help
(Sorry again)

Cheers!
Title: Re: Give NPC inventory item and get another in return.
Post by: Chomba on Tue 06/07/2021 17:53:29
Hi, you need to see this commands

Character.Loseinventory
https://adventuregamestudio.github.io/ags-manual/Character.html#characterloseinventory (https://adventuregamestudio.github.io/ags-manual/Character.html#characterloseinventory)

Character.Addinventory
https://adventuregamestudio.github.io/ags-manual/Character.html#characteraddinventory (https://adventuregamestudio.github.io/ags-manual/Character.html#characteraddinventory)
Title: Re: Give NPC inventory item and get another in return.
Post by: Cassiebsg on Tue 06/07/2021 17:58:43
Not too long I posted this:


Basically the code goes in interact with the character instead of an object.
What you need is Character.AddInventory and Character.LoseInventory, check them out in the manual.  :)

But the code could look something like this:
Code (ags) Select

player.Say("Here's your money");
player.LoseInventory(iMoney);
cOther.Say("Looks good. Here's your key!");
player.AddInventory(iKey);
player.Say("Goodbye.");


PS - (Chomba ninja...  (laugh) )
Title: Re: Give NPC inventory item and get another in return.
Post by: Chomba on Tue 06/07/2021 18:12:26
Ah yes,

if you're totally new to AGS, the tutorials from densming (after following the basic tutorial in the manual) are very helpful and some of the best stuff out there!



QuotePS - (Chomba ninja...  (laugh) )
*insert Bruce Lee sound
Title: Re: Give NPC inventory item and get another in return.
Post by: Rocky_Johan on Tue 06/07/2021 20:55:45
Quote from: Cassiebsg on Tue 06/07/2021 17:58:43
Not too long I posted this:


Basically the code goes in interact with the character instead of an object.
What you need is Character.AddInventory and Character.LoseInventory, check them out in the manual.  :)

But the code could look something like this:
Code (ags) Select

player.Say("Here's your money");
player.LoseInventory(iMoney);
cOther.Say("Looks good. Here's your key!");
player.AddInventory(iKey);
player.Say("Goodbye.");


PS - (Chomba ninja...  (laugh) )

Thanks!
I was actually going trough all of your videos trying to solve this but still couldn't figure it out.   :smiley:
Title: Re: Give NPC inventory item and get another in return.
Post by: Rocky_Johan on Tue 06/07/2021 20:58:14
Quote from: Chomba on Tue 06/07/2021 18:12:26
Ah yes,

if you're totally new to AGS, the tutorials from densming (after following the basic tutorial in the manual) are very helpful and some of the best stuff out there!



QuotePS - (Chomba ninja...  (laugh) )
*insert Bruce Lee sound

I was looking trough the videos and the manuals but still couldnt figure out the solution.
Maybe 16 hours of coding whitout sleep was starting to mess with my brain.  :smiley:

Anyway, thank you both!
Title: Re: Give NPC inventory item and get another in return.
Post by: Cassiebsg on Tue 06/07/2021 22:03:03
They're not my videos, they are densming's videos. I learned my AGS ABC from them.  ;)
I just meant, that I posted that exact video on another thread last week...  (laugh)
Title: Re: Give NPC inventory item and get another in return.
Post by: Rocky_Johan on Wed 07/07/2021 00:04:33
Quote from: Cassiebsg on Tue 06/07/2021 22:03:03
They're not my videos, they are densming's videos. I learned my AGS ABC from them.  ;)
I just meant, that I posted that exact video on another thread last week...  (laugh)

Ah ok!
Those videos have been a great help.

I went trought like 50 pages of threads but couldn't find the answer i was looking for before sucking it up and posting this total newbie question :)
Thanks for being so nice and helpful!
Title: Re: Give NPC inventory item and get another in return.
Post by: Rocky_Johan on Wed 07/07/2021 00:18:15
Quote from: Cassiebsg on Tue 06/07/2021 17:58:43
Not too long I posted this:


Basically the code goes in interact with the character instead of an object.
What you need is Character.AddInventory and Character.LoseInventory, check them out in the manual.  :)

But the code could look something like this:
Code (ags) Select

player.Say("Here's your money");
player.LoseInventory(iMoney);
cOther.Say("Looks good. Here's your key!");
player.AddInventory(iKey);
player.Say("Goodbye.");


PS - (Chomba ninja...  (laugh) )

Sadly i can't get the script to work.

Ok so here is what i wanna do:
I wanna bring out an object from my inventory and use it on an npc
this should trigger the player to walk to the npc and giving him the object.
Some dialogue should occur where the npc says thanks or something and the player respons.
The NPC gives te player another object in exchange.

Iv'e been trying all sorts of solutions but either it doesn't work or there is an error in the code.
Please help. I'm totally stuck :P
Title: Re: Give NPC inventory item and get another in return.
Post by: Crimson Wizard on Wed 07/07/2021 00:31:27
Quote from: Rocky_Johan on Wed 07/07/2021 00:18:15
Sadly i can't get the script to work.

Please, never just say "it does not work", explain what you did, show the script you wrote, tell what happens instead. This will make it much easier to find out what was wrong.
Title: Re: Give NPC inventory item and get another in return.
Post by: Rocky_Johan on Wed 07/07/2021 00:36:41
Finally got it to work!
There was a semicolon missing apparently.
Thanks again for the help!
Title: Re: Give NPC inventory item and get another in return.
Post by: Rocky_Johan on Wed 07/07/2021 00:38:15
Quote from: Crimson Wizard on Wed 07/07/2021 00:31:27
Quote from: Rocky_Johan on Wed 07/07/2021 00:18:15
Sadly i can't get the script to work.

Please, never just say "it does not work", explain what you did, show the script you wrote, tell what happens instead. This will make it much easier to find out what was wrong.

I was about to post a longer explanation but then i finally managed to fix it by myself.
Title: Re: Give NPC inventory item and get another in return.
Post by: Khris on Wed 07/07/2021 08:32:57
Hi,

note that it is often much easier to find an existing solution if you break down your problem into its parts.
Here it's
Each of those has lots of existing answers, especially the player.ActiveInventory check part, which is asked on a monthly basis because the manual's tutorial isn't covering it (afaik) :P