Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: TD2345 on Wed 17/04/2024 21:51:33

Title: Is there a way to stop certain items in inventory becoming cursor? [Solved}
Post by: TD2345 on Wed 17/04/2024 21:51:33
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:

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:

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?
Title: Re: Is there a way to stop certain items in inventory becoming cursor?
Post by: Khris on Wed 17/04/2024 23:59:00
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:
  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))
Title: Re: Is there a way to stop certain items in inventory becoming cursor?
Post by: Cassiebsg on Thu 18/04/2024 17:25:15
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.
Title: Re: Is there a way to stop certain items in inventory becoming cursor?
Post by: Crimson Wizard on Thu 18/04/2024 18:35:05
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.
Title: Re: Is there a way to stop certain items in inventory becoming cursor?
Post by: TD2345 on Thu 18/04/2024 20:03:54
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.
Title: Re: Is there a way to stop certain items in inventory becoming cursor? [Solved}
Post by: Crimson Wizard on Fri 19/04/2024 12:39:04
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.
Title: Re: Is there a way to stop certain items in inventory becoming cursor? [Solved}
Post by: Cassiebsg on Sat 20/04/2024 13:50:40
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)?
Title: Re: Is there a way to stop certain items in inventory becoming cursor? [Solved}
Post by: Crimson Wizard on Sat 20/04/2024 13:54:23
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.