Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Ophidic on Sun 12/03/2023 08:52:11

Title: Using an inventory item on a character (code format help)
Post by: Ophidic on Sun 12/03/2023 08:52:11
Hello. I'm trying to get a result when using an inventory item on a character in the 2 click template. I just finished making two items that combine into one item giving the new item and taking the other two away


So say I have cEgo and I want to 'give' iey that to cPerson, uhhh how do I express that?
I see the example cEgo.ActiveInventory = iKey; in the manual... and I understand how to do the rest of what I want for now, but the manual doesn't say how to use it and I don't know how to write the code from nothing just yet. Not sure where or how to start it sometimes, like in this case.

I can find a lot of stuff about inventory here but I can't find what I need. I found an old example of how to do it from 2004 but the topic is locked and the commands are obsolete.

Thanks

Edit: Here is a video of my practice so far, I've done some masks for the walk & walk behind areas.  Drew all the EGA backgrounds and that, but just using roger still.





Title: Re: Using an inventory item on a character (code format help)
Post by: tilapisha on Sun 12/03/2023 09:30:27
Characters > cPerson > ⚡Events > Use inventory on character / cPerson_UseInv

if (cEgo.ActiveInventory == iMartini){
    player.LoseInventory(iMartini);
    cPerson.Say("Thanks for this dirty martini!");

}

Title: Re: Using an inventory item on a character (code format help)
Post by: Ophidic on Sun 12/03/2023 15:57:21
Quote from: tilapisha on Sun 12/03/2023 09:30:27Awesome! that was exactly what I needed, thank you very much!

Title: Re: Using an inventory item on a character (code format help)
Post by: Snarky on Sun 12/03/2023 16:45:44
In many cases this won't be necessary, but if you need to keep track of the fact that the other character actually has the item, you can also add it to their inventory when you remove it from the player's:

Code (ags) Select
  cPerson.AddInventory(iMartini);
(Also, I would recommend being consistent in whether you use player or cEgo—or whatever the name of your player character is—at least within a single block of code. Code is easier to follow and debug if you use the same name to refer to the same thing.)