Inventory GUI

Started by , Mon 15/12/2003 21:37:05

Previous topic - Next topic

jimnorris

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?

Scorpiorus

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?

jimnorris

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.

Scorpiorus

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

jimnorris

Yeah, I meant interact. Thanks again for all your help.

jimnorris

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.

Alynn

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

jimnorris

Hm...isn't there some change I could make to the global script, under on_mouse_click?

Alynn

if (GetHotspotAt (mouse.x, mouse.y)==0) {
 MoveCharacter(CHARID, mouse.x, mouse.y)
}
else {
 //interaction code here
}

jimnorris

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  :)

Scorpiorus

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

jimnorris

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?

Scorpiorus

#12
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.

SMF spam blocked by CleanTalk