[SOLVED] Give NPC inventory item and get another in return.

Started by Rocky_Johan, Tue 06/07/2021 14:58:18

Previous topic - Next topic

Rocky_Johan

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!


Cassiebsg

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

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) )
There are those who believe that life here began out there...

Chomba

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

Rocky_Johan

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

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:

Rocky_Johan

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!

Cassiebsg

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)
There are those who believe that life here began out there...

Rocky_Johan

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!

Rocky_Johan

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

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

Crimson Wizard

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.

Rocky_Johan

Finally got it to work!
There was a semicolon missing apparently.
Thanks again for the help!

Rocky_Johan

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.

Khris

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

  • Set up a UseInv interaction with a character (can be extrapolated from any generic interaction, plus player.ActiveInventory check)
  • Approach a character i.e. walk to a specific spot blocking, i.e. find out another character's coordinates
  • How to lose/gain inventory items
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

SMF spam blocked by CleanTalk