Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Mon 15/12/2003 21:37:05

Title: Inventory GUI
Post by: on Mon 15/12/2003 21:37:05
How can I make my inventory GUI pop up when the player right clicks? Is there any way to do it without much scripting knowledge?
Title: Re:Inventory GUI
Post by: Scorpiorus on Mon 15/12/2003 21:54:53
Yes, it's not much scripting at all. Just open the global script and find the next function:

function on_mouse_click(int button) {
   // called when a mouse button is clicked. button is either LEFT or RIGHT
   if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
   }
   else if (button==LEFT) {
      ProcessClick(mouse.x, mouse.y, GetCursorMode() );
   }
   else {   // right-click, so cycle cursor
      SetNextCursorMode();
   }
}


next modify the right-click part:

function on_mouse_click(int button) {
   // called when a mouse button is clicked. button is either LEFT or RIGHT
   if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
   }
   else if (button==LEFT) {
      ProcessClick(mouse.x, mouse.y, GetCursorMode() );
   }
   else {   // right-click, so cycle cursor
      show_inventory_window (); //display inventory window
   }
}


I am assuming you use standart inventory window.

Does it work?
Title: Re:Inventory GUI
Post by: on Tue 16/12/2003 02:09:05
Thanks. But (and I feel really stupid right now, I'm very new to AGS) is there any way at all that I can now get rid of my icon bar and have just one single cursor, which causes all actions with left mouse clicks, and opens the inventory with right mouse clicks? If this requires alot of scripting, I'll do my best to understand. Thanks again.
Title: Re:Inventory GUI
Post by: Scorpiorus on Tue 16/12/2003 18:28:30
Quoteis there any way at all that I can now get rid of my icon bar
Inside the global script's game_start() function:

GUIOff(ICONBAR);

Quoteand have just one single cursor, which causes all actions with left mouse clicks
Well, here is an issue. What if an object, for example, have more than one interaction? It can be looked at, interacted, etc... If you mean interact than try the next modification of the on_mouse_click():

function on_mouse_click(int button) {
   // called when a mouse button is clicked. button is either LEFT or RIGHT
   if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
   }
   else if (button==LEFT) {
       ProcessClick(mouse.x, mouse.y, MODE_USE);
   }
   else { // right-click, so cycle cursor
      show_inventory_window ();
   }
}

~Cheers
Title: Re:Inventory GUI
Post by: on Tue 16/12/2003 20:14:29
Yeah, I meant interact. Thanks again for all your help.
Title: Re:Inventory GUI
Post by: on Wed 17/12/2003 13:30:25
Ahh. Sorry, I have to ask another question. Now my character won't walk, because the left mouse click is only set to interact. How do I make it so that when the player clicks on a hotspot, it causes an interaction, but when the player clicks somewhere else, the character walks there?
Thanks again.
Title: Re:Inventory GUI
Post by: Alynn on Wed 17/12/2003 13:43:13
Well if you have extra hotspots available you can set the walkable area as a hotspot with the interaction

MoveCharacter(CHARID, mouse.x, mouse.y);

Thats one way at least
Title: Re:Inventory GUI
Post by: on Wed 17/12/2003 13:52:53
Hm...isn't there some change I could make to the global script, under on_mouse_click?
Title: Re:Inventory GUI
Post by: Alynn on Wed 17/12/2003 14:25:25
if (GetHotspotAt (mouse.x, mouse.y)==0) {
 MoveCharacter(CHARID, mouse.x, mouse.y)
}
else {
 //interaction code here
}
Title: Re:Inventory GUI
Post by: on Wed 17/12/2003 14:40:31
Thanks! But now I'm getting this error message when I try to test it...

Error (line 51): read/write ax called with non-variable parameter ("int")

I know I'm getting annoying at this point, but more help would really be appreciated  :)
Title: Re:Inventory GUI
Post by: Scorpiorus on Wed 17/12/2003 15:17:01
QuoteError (line 51): read/write ax called with non-variable parameter ("int")
hmm, are you sure it's placed instead of ProcessClick(mouse.x, mouse.y, MODE_USE)?

Alternatively, you can put in use the IsInteractionAvailable() function:

function on_mouse_click(int button) {
   // called when a mouse button is clicked. button is either LEFT or RIGHT
   if (IsGamePaused() == 1) {
   // Game is paused, so do nothing (ie. don't allow mouse click)
   }
   else if (button==LEFT) {
      if (IsInteractionAvailable(mouse.x, mouse.y, MODE_USE))
         ProcessClick(mouse.x, mouse.y, MODE_USE);
      else
         MoveCharacter(GetPlayerCharacter(), GetViewportX()+mouse.x, GetViewportY()+mouse.y);
   }
   else { // right-click, so cycle cursor
      show_inventory_window ();
   }
}

Thus it will ensure reaction not only for the hotspots but for objects too, provided the interact interaction was assigned.

~Cheers
Title: Re:Inventory GUI
Post by: on Wed 17/12/2003 16:51:36
Alright, one final problem: in the game, when I try using inventory items on hotspots, the character just does what he would do if I had interacted with it. How do I set it up so inventory items have seperate effects from normal use?
Title: Re:Inventory GUI
Post by: Scorpiorus on Wed 17/12/2003 17:35:52
that should do the trick:

EDIT: Player walks instead of inv click if the use inv item on ... isn't defined.

....
else if (button==LEFT) {
   if (GetCursorMode() == MODE_USEINV && IsInteractionAvailable(mouse.x, mouse.y, MODE_USEINV))
      ProcessClick(mouse.x, mouse.y, MODE_USEINV);
   else
if (IsInteractionAvailable(mouse.x, mouse.y, MODE_USE))
      ProcessClick(mouse.x, mouse.y, MODE_USE);
   else
      MoveCharacter(GetPlayerCharacter(), GetViewportX()+mouse.x, GetViewportY()+mouse.y);
}
....

This way the use inv. on xxx interaction is run when player clicks with the inv cursor.