How to pick up item from inventory

Started by AndreyMust19, Sat 31/10/2015 18:37:32

Previous topic - Next topic

AndreyMust19

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
mouse.Mode = eModeInteract;
, not helped me.



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

Global script is here(AGS 3.3.2.0).

In searching i find much deprecated code, what not work in my version AGS.

Mandle

You have to set the cursor image to the active inventory image, if I understand what it is you are trying to do...

AndreyMust19

#2
New morning, fresh head.

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

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
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
function UseBook()
{
  InventoryItem * item = player.ActiveInventory;
  Object * obj = Object.GetAtScreenXY(mouse.x, mouse.y);
  // compare item and object
  // ...
}

Khris

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:
Code: ags
    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.)

Vincent

#4
I think you can do something like this indeed :smiley:
Code: ags

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

// 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
}

SMF spam blocked by CleanTalk