Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: AndreyMust19 on Sat 31/10/2015 18:37:32

Title: How to pick up item from inventory
Post by: AndreyMust19 on Sat 31/10/2015 18:37:32
Hello.

I have a problem with scripting.
I cannot pick up item from inventory gui when left-clicking on them. But in default demo game is worked.
Code (ags) Select
mouse.Mode = eModeInteract;, not helped me.

(http://s2.uploads.ru/d/QdDkx.png)

When i click on book in inventory-gui, cursor changed to 'pointer' and not change back to 'pick up' icon.

Global script is here (http://pastebin.com/UgkddX0g)(AGS 3.3.2.0).

In searching i find much deprecated code, what not work in my version AGS.
Title: Re: How to pick up item from inventory
Post by: Mandle on Sun 01/11/2015 01:15:17
You have to set the cursor image to the active inventory image, if I understand what it is you are trying to do...
Title: Re: How to pick up item from inventory
Post by: AndreyMust19 on Sun 01/11/2015 08:05:55
New morning, fresh head.

For found item under cursor (in 'repeatedly_execute()'):
Code (ags) Select

InventoryItem * item;

function repeatedly_execute()
{
    item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
}


Need setting 'Inventory: Override built-in inventory window click handling = True.
For pickup item from inventory (by left click) and release (by right click):
Code (ags) Select
function on_mouse_click(MouseButton button)
{
  if (button == eMouseLeftInv) {
    player.ActiveInventory = item;
    mouse.ChangeModeGraphic(eModeUseinv, item.CursorGraphic);
  }
  if (button == eMouseRight)
  {
    if (player.ActiveInventory != null) {
      mouse.Mode = eModePointer;
      player.ActiveInventory = null;
    }
  }
}


For using item on object in room-script:
Code (ags) Select
function UseBook()
{
  InventoryItem * item = player.ActiveInventory;
  Object * obj = Object.GetAtScreenXY(mouse.x, mouse.y);
  // compare item and object
  // ...
}
Title: Re: How to pick up item from inventory
Post by: Khris on Sun 01/11/2015 21:57:18
You don't need that global variable or the rep_exe code; you can access the clicked item using inventory[game.inv_activated] in your eMouseLeftInv block.
this:
    mouse.ChangeModeGraphic(eModeUseinv, item.CursorGraphic); should be the default behavior, you should not need that line. Try removing it.

Using an item on a room object is done using the "use inventory on" event, which creates a function named "oObject_Useinv". In there you don't compare item and object but player.ActiveInventory and item. (Since we already know which object was clicked.)
Title: Re: How to pick up item from inventory
Post by: Vincent on Mon 02/11/2015 11:38:27
I think you can do something like this indeed :smiley:
Code (ags) Select

function on_mouse_click(MouseButton button)
{
  InventoryItem*i = inventory[game.inv_activated];
 
  if (button == eMouseLeftInv)
  {
    if (mouse.Mode == eModeUseinv) i.RunInteraction(eModeUseinv);  // use current item with i
    else player.ActiveInventory = i; // select activated item
  }

  else if (button == eMouseRight)
  {
    if (mouse.Mode == eModeUseinv)
    {
      player.ActiveInventory = null; // deselect activated item
      mouse.Mode = eModePointer;
    }
  }
}


Then I think you can use to check the mouse mode over the inventory window in this way
Code (ags) Select

// rep_exe
GUIControl*theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
if (theControl == invCustomInv) // Mouse over inventory window ("invCustomInv" or the name you have replace in the editor)
{
  // Change mouse mode
}

else if (theControl == null) // The mouse is not over a control
{
  // Change mouse mode
}