One mouse cursor control method

Started by Helixeagle, Tue 31/07/2012 16:03:19

Previous topic - Next topic

Helixeagle

Most of what I currently have is by trial and error, I'm new to AGS and stubbornly have started from scratch learning along the way. I have looked over the internet and forums over the week and have finally decided to post as I have found bits and pieces of what I need/want but am failing to understand how I am going to work around specific issues I am discovering along the way.

What I essentially want is a method of left clicking for eModeInteract + eModeWalkto and right click as eModeLookat, which I have done simple enough by editing the on_mouse_click and Process Click coding, I have also recently created a custom Inv GUI which is always available (not sure if this ties into my issues) on screen and used a player.ActiveInventory = inventory[game.inv_activated] command to help me select inventory items with my new mouse (if that makes sense) so a bit like Brokensword or The Dig.

But say I wanted to do the following on a door hotspot:

function door_UseInv()
{
  if (player.ActiveInventory == IKey) {
  cChar.Say ("Hello!");
  }
else
{
  cChar.Say ("Goodbye!");
}



This will work fine but because interact, useinv, talk etc are all mashed into left click, it executes the actions one after another (which I guess is pretty obvious), so it will run the hotspot interact script and then the use inv script etc etc, the issue is that I stubbornly refuse to accept defeat on my single cursor idea, my coding is pretty messy since I'm using trial and error most of the time.

Is there a way to possible avert the interact and walkto clicks when I have an active inventory item? I'm not entirely sure on what's possible, I've tried a couple of things to no avail, I may have to ditch the idea completely since it's starting to drive me mad, here's the mess of code regardless:

function on_mouse_click(MouseButton button)
{
  if (IsGamePaused() == 1)
{
}
  else if (button == eMouseLeft)
  {
    ProcessClick(mouse.x,mouse.y, eModeInteract);
    ProcessClick(mouse.x,mouse.y, eModeWalkto);
    ProcessClick(mouse.x,mouse.y, eModeUseinv);
  }
      else if (button == eMouseRight)// right-click, so Lookat
  {   
    ProcessClick(mouse.x,mouse.y, eModeLookat);
    mouse.Mode = eModeWalkto; 
  }
 
if (button == eMouseLeftInv)
  {
   player.ActiveInventory = inventory[game.inv_activated];
  }
  else if (button == eMouseRightInv)
  {
    inventory[game.inv_activated].RunInteraction(eModeLookat);
  }
 
 
 
 
   

Crimson Wizard

#1
You should not do anything like that:
Code: ags

ProcessClick(mouse.x,mouse.y, eModeInteract);
ProcessClick(mouse.x,mouse.y, eModeWalkto);
ProcessClick(mouse.x,mouse.y, eModeUseinv);


Instead make a check, find what lies under the mouse and process appropriate command.
For example:
Code: ags

// 1. Find any usable object under the cursor:
Hotspot *h = Hotspot.GetAtScreenXY(mouse.x,mouse.y);
Object *o = Object.GetAtScreenXY(mouse.x,mouse.y);
Character *c = Character.GetAtScreenXY(mouse.x,mouse.y);
// 2. If there's an object, then...
if (h != null || o != null || c != null)
{
  // 2.1. If player is holding an inventory item, then use it on object
  if (player.ActiveInventory != null)
  {
     ProcessClick(mouse.x,mouse.y, eModeUseinv);
  }
  // 2.2 else interact with object
  else
  {
     ProcessClick(mouse.x,mouse.y, eModeInteract);
  }
}
// 3. If no object found, then simply walk
else
{
  ProcessClick(mouse.x,mouse.y, eModeWalk);
}

Khris

Just use GetLocationType. Here's the entire click handling:

Code: ags
  int lt = GetLocationType(mouse.x, mouse.y);
  InventoryItem*ai = player.ActiveInventory, ia = inventory[game.inv_activated];

  if (button == eMouseLeft) {
    if (lt == eLocationNothing) ProcessClick(mouse.x, mouse.y, eModeWalkto);
    else if (ai) ProcessClick(mouse.x, mouse.y, eModeUseinv);
    else ProcessClick(mouse.x, mouse.y, eModeInteract);
  }
  else if (button == eMouseRight) {
    if (ai) player.ActiveInventory = null;
    else ProcessClick(mouse.x, mouse.y, eModeLookat);
  }
  else if (button == eMouseLeftInv) {
    if (ai) ia.RunInteraction(eModeUseinv);
    else player.ActiveInventory = ia;
  }
  else if (button == eMouseRightInv) {
    if (ai) player.ActiveInventory = null;
    else ia.RunInteraction(eModeLookat);
  }

Not tested!

Helixeagle

Well I clearly have a lot to learn, thank you so much! this worked perfectly, maybe I can actually advance my game now :)

SMF spam blocked by CleanTalk