Inventory Help (Solved)

Started by Dropped Monocle Games, Sun 23/03/2014 12:38:15

Previous topic - Next topic

Dropped Monocle Games

I'm using this code for our games mouse and inventory to work like this

left click = interact
right click = look

with inventory item in hand
left click = use item on ... (walk or nothing if no hotspot)
right click = drop item back into inventory

most of it is working fine, but when I have an inventory item in hand and I left click somewhere on the background that has no hotspot more then once
or on a hotspots a second time, the cursor acts as if I have no inventory in my hand but the cursor still looks like its an inventory item,
and right clicking no longer drops the item :S

this has had me stumped, I guess I have something wrong with the way the 'invmode' is being called and changed, but I can't seem to work out how to fix it, I would really appreciate if anyone could help me
Thanks :D


Code: ags

//Mouse
 
bool invMode = false;
 
function on_mouse_click (MouseButton button) {
 
  int mX = mouse.x,  mY =  mouse.y;
 
  if (button == eMouseLeft) {
    
    if (invMode) {  // if in inventory mode
     ProcessClick (mX, mY, 4); // Run "Use Inventory on" action.
     invMode = false; // Turn off inventory mode
     
         }
    
    else if (GetLocationType(mX, mY) == eLocationNothing) // No hotspot, so walk
      player.Walk (GetViewportX () + mX, GetViewportY () + mY);
    
    else // Hotspot, so process click as "Interact"
      ProcessClick (mX, mY, 2);
 
  }
  
  else if (button == eMouseRight) {
    
    if (invMode) {// If "Use Inventory on", switch it off
    player.ActiveInventory = null;
    invMode = false;
    }
    else {
      
      if (GetLocationType(mX, mY) == eLocationNothing)  // No hotspot, so walk
        player.Walk(GetViewportX () + mX, GetViewportY () + mY);
      
      
      else // Process click as "Look at"
        ProcessClick(mX, mY, 1);
        
    }
  }
  
  
  // Inventory click handling:
    else if (button == eMouseLeftInv) {
    
    if (!invMode) {  // If not in "Use inventory mode"
      // Set the active inventory and switch inventory mode on
      player.ActiveInventory = inventory[game.inv_activated];
      invMode = true;
    }
    
    else { // The player is inventory mode, run "Use inventory on" interaction
     inventory[game.inv_activated].RunInteraction(4);
     invMode = false;
     player.ActiveInventory = null;
    }
  }
  
  else if (button == eMouseRightInv) // Else, look at the inventory item
    inventory[game.inv_activated].RunInteraction(1);
   
}

Dropped Monocle Games

#1
okay, got some help from a friend and everything seems to be working like it should!
here is the working code

Code: ags

bool invMode = false;
 
function on_mouse_click (MouseButton button) {
 
  int mX = mouse.x,  mY =  mouse.y;
 
  if (button == eMouseLeft) {
    
    if (GetLocationType(mX, mY) == eLocationNothing) // No hotspot, so walk
      player.Walk (GetViewportX () + mX, GetViewportY () + mY);
    
    
    
    
    else if (player.ActiveInventory != null) {  // if in inventory mode
     ProcessClick (mX, mY, 4); // Run "Use Inventory on" action.
     invMode = false; // Turn off inventory mode
    
     
     if(player.ActiveInventory == null)
    {
      invMode = false;
      }
    }
  
    else // Hotspot, so process click as "Interact"
      ProcessClick (mX, mY, 2);
 
  }
  
  else if (button == eMouseRight) {
    
    if (player.ActiveInventory != null) {// If "Use Inventory on", switch it off
    player.ActiveInventory = null;
    invMode = false;
    }
    else {
      
      if (GetLocationType(mX, mY) == eLocationNothing)  // No hotspot, so walk
        player.Walk(GetViewportX () + mX, GetViewportY () + mY);
      
      
      else // Process click as "Look at"
        ProcessClick(mX, mY, 1);
        
    }
  }
  
  
  // Inventory click handling:
    else if (button == eMouseLeftInv) {
    
    if (!invMode) {  // If not in "Use inventory mode"
      // Set the active inventory and switch inventory mode on
      player.ActiveInventory = inventory[game.inv_activated];
      invMode = true;
    }
    
    else { // The player is inventory mode, run "Use inventory on" interaction
     inventory[game.inv_activated].RunInteraction(4);
     invMode = false;
        }
  }
  
  else if (button == eMouseRightInv) // Else, look at the inventory item
    inventory[game.inv_activated].RunInteraction(1);
   
}

SMF spam blocked by CleanTalk