Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: rorschach on Wed 01/02/2006 01:31:12

Title: Selecting inv items with right mouse click (SOLVED)
Post by: rorschach on Wed 01/02/2006 01:31:12
I'm using a BASS inventory system and I want to be able to activate the inventory objects with a right mouse click.

I've tried several diffrent approches to this and everyone has been insuccessful.
Title: Re: using inventory with custom GUI
Post by: Khris on Wed 01/02/2006 08:54:19
function on_mouse_click(MouseButton button) {
Ã,  ...
Ã,  else if (button==eMouseRightInv) {
Ã,  Ã,  player.ActiveInventory=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
Ã,  Ã,  Mouse.Mode=eModeUseinv;
Ã,  }
}
Title: Re: using inventory with custom GUI
Post by: rorschach on Wed 01/02/2006 12:05:18
I've tried this one. The reason I couldn't use this on_mouse_click functions on the inv GUI was that I had Popup Modal activated. I changed it to normal but my main problem still remains..

How do I make the invThingie dissapear after any click and how can I use an object

used this on 'use inventory on hotspot'
if (cEgo.ActiveInventory==iobject) {
Ã,  cEgo.Say("Used object on hotspot");
}

tnx
Title: Re: using inventory with custom GUI
Post by: Ashen on Wed 01/02/2006 12:38:06
Have you checked the 'Handle inventory clicks in script' option? You need to, to be able to use the eMouseRightInv button option khrismuc showed. I think you'll also need to check that there IS an inventory item at the mouse coords, before setting the active inv, e.g.

if (button == eMouseRightInv) {
  InventoryItem *item = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  if (item != null) {
    player.ActiveInventory = item;
    mouse.Mode = eModeUseinv;
    // Although, I think this is automatically set when you change active inventory
  }
}


By invThingie, do you mean the inventory GUI? gGuiname.Visible = false; will turn it off, added to the proper condition(s) of on_mouse_click (and/or possibly the eEventGUIMouseUp/Down conditions of on_event).
That 'use object' code should be fine. Does it not work, or haven't you tried it?
Title: Re: using inventory with custom GUI
Post by: rorschach on Wed 01/02/2006 14:36:17
Yes it's checked.
By invThingie i mean the inventory object. The GUI works fine but when it comes to using the inventory objects I get nada. Once I've selected the inventory obj all it does is changing the cursor graphic and it stays that way... all clicks are responding as the 'normal' cursors

I use this code for the standard mouse clicks

if (button == eMouseLeft) {
String buffer = Game.GetLocationName(mouse.x, mouse.y);
if (StrComp(buffer, "") == 0) ProcessClick(mouse.x, mouse.y, eModeWalkto);
else ProcessClick(mouse.x, mouse.y, eModeLookat);
}
else if (button == eMouseRight) {
  ProcessClick(mouse.x, mouse.y, eModeInteract);
  }
Title: Re: using inventory with custom GUI
Post by: Scorpiorus on Wed 01/02/2006 22:31:47
You see, use inventory item on hotspot/object/character is triggered by eModeUseinv rather than eModeInteract, so you code becomes:

...
else if (button == eMouseRight) {
Ã, 
   if (player.ActiveInventory == null)
   {
      // normal clicks (no active inventory item)
      ProcessClick(mouse.x, mouse.y, eModeInteract);
   }
   else
   {
      // active inventory clicks
      ProcessClick(mouse.x, mouse.y, eModeUseinv);
   }
Ã, 
}
Title: Re: using inventory with custom GUI
Post by: rorschach on Thu 02/02/2006 17:22:05
thanks I finally got it to work.

But how do I use an invobj with another?
Title: Re: using inventory with custom GUI
Post by: strazer on Thu 02/02/2006 18:27:11
"Inventory items" pane -> Select inventory item that you want to use something on -> "Interaction..." button -> Right-click "Use inventory on this item" -> "New Run Script action" (in older AGS versions "New action..." -> Select "Run script" -> "Edit script...") ->

  // script for Inventory item: Use inventory on this item
  // (This event is triggered by the "eModeUseinv" mouse mode)

  if (player.ActiveInventory == iKey) { // if key used
    // do stuff
  }
  else if (player.ActiveInventory == iPoster) { // if poster used
    // do some other stuff
  }
Title: Re: Selecting inv items with right mouse click (SOLVED)
Post by: Scorpiorus on Thu 02/02/2006 18:40:37
...and to trigger such active item on inv item events modify your on_mouse_click function code as follows:

if (button == eMouseRightInv) {

   if (player.ActiveInventory == null)
   {
      player.ActiveInventory = inventory[ game.inv_activated ];
   }
   else
   {
      inventory[ game.inv_activated ].RunInteraction( eModeUseinv );
   }

}

Should run interaction on right click (if there is an active inventory item to use).

Make sure Handle inventory clicks in script is checked.

See if it works.