Using an inventory item on a character (code format help)

Started by Ophidic, Sun 12/03/2023 08:52:11

Previous topic - Next topic

Ophidic

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.






tilapisha

Characters > cPerson > ⚡Events > Use inventory on character / cPerson_UseInv

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

}


Ophidic

Quote from: tilapisha on Sun 12/03/2023 09:30:27Awesome! that was exactly what I needed, thank you very much!


Snarky

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
  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.)

SMF spam blocked by CleanTalk