Do something interacting with item in inventory

Started by fratello Manu, Sat 26/12/2020 16:29:50

Previous topic - Next topic

fratello Manu

Hi everyone! I think this is a quite simple thing to do but I didn't find any answer.

I just want to make something happen (e.g.: playing a cutscene) when player "interacts" with an item which is already in inventory.

So I implemented the item's "interact inventory item" event:

Code: ags
function iMyItem_Interact()
{

    // do something;

}


...but instead of processing this code (I put a breakpoint and I see that code is not processed), it seems that the standard Use inventory mode is activated. Which would be correct, safe that for this item I want my code to be executed.

I'm missing something basic for sure... but what?

thanks!
bye
Manu


lafouine88

So what did you change? I faced the same issue and put it aside :p

Crimson Wizard

Inventory item interactions are usually performed in on_mouse_click function.

To check that mouse clicked on inventory item do
Code: ags
if (button == eMouseLeftInv)
and/or
Code: ags
if (button == eMouseRightInv)
. Then put the actions that you want under these.

Double check that you have "Override built-in inventory click handling" set to True in General Settings.

The rest depends on what exactly do you want to happen when you click on item.

Following is an example of code in on_mouse_click:
Code: ags

function on_mouse_click(MouseButton button)
{
     // ...
     // all the other actions
     // ...

     if (button == eMouseLeftInv)
     {
          // if clicked by left button - select this item
          InventoryItem* clicked_on = inventory[game.inv_activated];
          player.ActiveInventory = clicked_on;
     }
     else if (button == eMouseRightInv)
     {
          // if clicked by right button - run item interaction
          InventoryItem* clicked_on = inventory[game.inv_activated];
          clicked_on.RunInteraction(eModeInteract);
     }
}


Then adjust above to your liking.


SMF spam blocked by CleanTalk