Inventory Questions

Started by Mantra of Doom, Sun 28/09/2008 17:32:19

Previous topic - Next topic

Mantra of Doom

I've read over the manual and the BFAQ and have a couple of questions about tweaking my own inventory. And "Handle Inventory Clicks in script" is set to False.

1.) I have a couple of items that the user has to combine to create a new item. The  items combine nicely, but the problem is that I can only do one at a time.. Item A is used on Item B to make Item C... but I can't use Item C on Item D unless I close the inventory window and reopen it. It makes the whole process a little bit frustrating if
you get stuck.

2.) Is it possible to code the item so that a click with the item not on a hotspot the
cursor changes back to the pointer and the item is reset?

3.) One more thing before I go, is it possible to set coordinates in such a way that if
the mouse goes outside of the inventory window, the window disappears? Like

if Mouse.X (coordinates){gInventory.Visible=false;}
I haven't been able to find which command I want to use for that yet, but I'm sure
that I missed something important.

Thanks for putting up with my questions... if the answer exists in a wiki or previous
post that I haven't come across yet, just point me in that direction.
"Imitation is the sincerest form of imitation."

Akatosh

1.) I believe this should be fixed by setting the mouse mode back to eModeInteract in the item's interaction script.

2.) Sure. All you'll need is the right script in the unhandled_event section in the global script. The manual knows the values you need to check for.

3.) You're on the right track there... all you'll need to do is put that script (with values and y-check filled in) in repeatedly_execute_always, and it will work like a charm.

Khris

2.) I don't think unhandled_event gets called when you click on nothing.
I'd do this in on_mouse_click, at the start of the eMouseLeft block:
Code: ags
  if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) {
    mouse.Mode = eModeInteract;   // or eModePointer, whatever you're using
    return;
  }


3.) You can do this inside rep_ex:
Code: ags
  if (gInventory.Visible && GUI.GetAtScreenXY(mouse.x, mouse.y) != gInventory)
    gInventory.Visible = false;

Mantra of Doom

#3
Haven't tried the solution to #1 yet, as I've been fiddling with 2 and 3 with Khris's suggestions above.

I tried copying the suggested code for question 2 into the on_mouse_click and it seems to have broken my interaction code. (I'm using a left click Interact and right click Looks system.) I can't seem to get it back to where it worked, though the right click still works alright. I'll play with it a bit more after I take a step back from it and see what's going on.

As for issue 3, I have a gui button at the bottom left of the screen that calls up the inventory, that code makes it so that the inventory flashes on, but then goes away as the mouse is already outside of that area, it goes away real fast. I think I might have to give up on this part.

Though I do think you guys have pointed me in a good direction.

EDIT: I fixed my interaction script and am back where I started from.
"Imitation is the sincerest form of imitation."

Khris

Regarding #2, I'll have to see the rest of the left-click code to help. (Always tell if you're using anything other than the default behavior.)

#3 can be easily solved by adding a variable.
Code: ags
// next line above rep_ex function
bool mhboi; // mouse has been over inventory

// following code inside rep_ex:
  if (GUI.GetAtScreenXY(mouse.x, mouse.y)) mhboi = true;
  else if (gInventory.Visible && mhboi) {
    gInventory.Visible = false;
    mhboi = false;
  }

Mantra of Doom

#5
This is my code for the interaction script. I know it's probably older, I got it from a post in here and changed the left and right behavior.

Code: ags
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
  // script fixed for non-popup modal inv guis
 
  int x = mouse.x;
  int y = mouse.y;
  if (button == eMouseLeftInv) {
    if (mouse.Mode == eModeLookat) {
      player.ActiveInventory = InventoryItem.GetAtScreenXY(x, y);
      mouse.Mode = eModeUseinv;
    }
    else if (mouse.Mode == eModeUseinv) {  // tries to combine something
      InventoryItem * item = InventoryItem.GetAtScreenXY(x, y);
      item.RunInteraction(eModeUseinv);
      mouse.Mode = eModeLookat;
    }
  }
  else if (button == eMouseRightInv) {
    InventoryItem * item = InventoryItem.GetAtScreenXY(x, y);
    item.RunInteraction(eModeLookat);
    if(mouse.Mode == eModeUseinv) {
      mouse.Mode = eModeLookat;
    } // re-setting mouse mode if it was useinv
  }
  else if (button == eMouseRight) 
  {
    if(GetLocationType(x, y) == eLocationNothing) {
      ProcessClick(x,y, eModeWalkto);
    }
    else {
      if (mouse.Mode == eModeLookat) {  // look
        ProcessClick(x, y, eModeLookat);
      }
      else if (mouse.Mode == eModeUseinv) {  // tries to useinv
        ProcessClick(x, y, eModeUseinv);
      }
    }
  }
  else if (button == eMouseLeft)
  {
    if (mouse.Mode == eModeUseinv) {
      mouse.Mode = eModeLookat; // kick off inventory
    }
    else if(GetLocationType(x, y) != eLocationNothing) {
      ProcessClick(x,y, eModeInteract);
      mouse.Mode = eModeLookat;
    }
  }
}


EDIT: I got issue #3 resolved with Khris's latest code and extending the bottom of the gui a bit. Works great now. I still can't figure out issues 1 and 2.

For 1, I tried putting this in the item interaction code as a shot in the dark

Code: ags
function iStrap_Interact()
{
player.ActiveInventory = iStrap;
if (GetLocationType(mouse.x,mouse.y) == eLocationNothing) {
    mouse.Mode = eModeInteract;
}
}


Not too sure where that will lead me, but it doesn't work. Am I at least in the ballpark?
"Imitation is the sincerest form of imitation."

Akatosh

That's not what I meant for #1... I meant that you need to put mouse.Mode = eModeInteract; right after whatever happens when the player combines the two items. As in,

Code: ags

if (player.ActiveInventory==inventory[2]) 
{
player.LoseInventory(inventory[2]); 
player.LoseInventory(inventory[3]); 
player.AddInventory(inventory[4]);
Display("There we go, a torch!");

mouse.Mode = eModeInteract;
}    


About unhandled event... There is this section in the manual...

WHAT  TYPE  Description
4         1        Look at nothing (ie. no hotspot)
4         2        Interact with nothing
4         3        Use inventory with nothing
4         4        Talk to nothing

... but it also states that "This function is not triggered if the player clicks on nothing (hotspot 0)." I have, however, used these checks in some games, and they seem to work just fine. Weird.

Mantra of Doom

D'oh! That makes much more sense and it works. Thanks Akatosh. Now things are running nicely.
"Imitation is the sincerest form of imitation."

SMF spam blocked by CleanTalk