Is there a way to stop certain items in inventory becoming cursor? [Solved}

Started by TD2345, Wed 17/04/2024 21:51:33

Previous topic - Next topic

TD2345

Reading through the forums, I've not been able to find a solution for a specific issue I'm having, apologies if I've overlooked anything.

Essentially at the moment, when I left click on an item in the inventory, it becomes the mouse cursor so it can be used on other items. The code for this is as part of the BASS template:

Code: ags
function on_mouse_click(MouseButton button)
{
  if (action != null)
  {
    action.Text = "";
  }

  if (!IsGamePaused() && (button == eMouseLeft || button == eMouseRight))
  {
    do_room_action(button);
  }
  else if (button == eMouseLeftInv || button == eMouseRightInv)
  {
    do_inventory_action(button, inventory[game.inv_activated]);
  }
}

If I replace the else if so it's like so:

Code: ags
else if (button == eMouseLeftInv || button == eMouseRightInv)
  {
     inventory[game.inv_activated].RunInteraction(eModeInteract);
  }

Then that changes it so that whatever event is set to interact for all inventory item runs (and conversely I can no longer have the mouse cursor become the inventory item).

The basic concept is that I have a book which the player can pick up, which the player can then left click on in the inventory bar and it opens up a new room with an object on the screen that functions as a book they can read.

The question I have, is there to set the book inventory item so it's the only inventory item that will run emodeinteract whilst all others will stick to automatically becoming the cursor?

Khris

You can use a custom property for this.
https://adventuregamestudio.github.io/ags-manual/CustomProperties.html

Add a Boolean one to just inventory items, call it like "interact" and set its default value to 0 (false).
Then set it to 1 (true) for your book inventory item.

Now use this else if block:
Code: ags
  else if (button == eMouseLeftInv || button == eMouseRightInv)
  {
    InventoryItem* ii = inventory[game.inv_activated];
    if (ii.GetProperty("interact")) ii.RunInteraction(eModeInteract);
    else do_inventory_action(button, ii);
  }

(Also, if it's just the book, you can of course skip the property and simply do  if (ii == iBook))

Cassiebsg

I haven't looked at the new BASS template, but the old already had that coded in.
It's called InstantUse. Select the iBook and go to it's properties, if it's there just set it to True, no extra code needed. :)

If it's not there, I wonder why it was removed from the new template.
There are those who believe that life here began out there...

Crimson Wizard

This custom property is already in the BASS template, it's called "InstantUse". Click on "..." besides "Properties" property in Inventory item, and you'll see it.

TD2345

I'm an idiot, I had not idea you could do that in properties with BASS enabled. For what it's worth, Khris' way worked too. Thanks everybody for your help.

Crimson Wizard

I was wondering if this is documented somewhere. We have the page for BASS template in the manual, but it does not mention this custom property. That's definitely our oversight.

Cassiebsg

The old template had one of the inventory items (the pipe flutes) set to InstantUse, it would make the character play them , instead of picking it up from the inv. window. Maybe the new template should also have one item set in InstantUse ('m assuming it doesn'y now)?
There are those who believe that life here began out there...

Crimson Wizard

Quote from: Cassiebsg on Sat 20/04/2024 13:50:40The old template had one of the inventory items (the pipe flutes) set to InstantUse, it would make the character play them , instead of picking it up from the inv. window. Maybe the new template should also have one item set in InstantUse ('m assuming it doesn'y now)?

It does.

SMF spam blocked by CleanTalk