Reserving inventory slots for special items

Started by Simonsez128, Wed 26/01/2005 14:27:28

Previous topic - Next topic

Simonsez128

Hello,

I have searched the forums, the BFAQ and the help files for any way to make an idea of mine work but i can't find any solution. I think it's a little more advanced problem. Sorry, if I am wrong about this.

I want - at a certain point of my game - add a few inventory objects to my character's inventory which represent certain special functions he can do then, like teleporting and the like. What I want to do then is reserve the first 4 or so inventory slots for these items, so they always appear there even if they are only added late in the game when the inventory already contains some items. I have been looking at the scripting functions for the inventory and the game overall but i couldn't find any function that would do this or help me with it.

If someone else has an idea or knows a thread which covers this, I'd be very thankful.  :)

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

RickJ

The 2.7 beta version now allows you to assign inventory windows to characters.  So you could create a dummy/invisible character to hold those four inventory items.  Then put the an extra inventory window assigned to your character in your gui.   


Simonsez128

Hey,

thanks for the quick reply.Ã,  ;D Fortunately, for the purpose I want, I don't have fiddle around with extra characters. AGS lists the items in the inventory in the order they are set up in the editor. That way I only have to set up the functions I want as the first items on my list and voilà  they'll always be the first items to be displayed.

Alternatively - and that's probably the way I will go - I will set up four new buttons in the inventory menu, which when clicked on will each trigger a new cursor mode I set up for the additional functions. I can make these buttons invisible while they're not yet available and control their function with a global variable which will be 0 as long as the new abilities are still disabled.

I could also change my code the way that cycling through the cursor modes skips these extra modes as long as the global variable is set to 0.Ã,  I prefer the other version though because always having to cycle through so many modes would probably irritate many players in the long run.

But thanks again for your input - i'll save this information in the back of my head, maybe I'll be able to use it for another problem :)

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

Rui 'Trovatore' Pires

Just a quick note - your first assumption,
QuoteAGS lists the items in the inventory in the order they are set up in the editor. That way I only have to set up the functions I want as the first items on my list and voilà  they'll always be the first items to be displayed.
is wrong. Only when you update the inventory window manually or change character (maybe not even when you update the inventory, maybe it's only when you change character) do the items in your INV revert to the order that they were made in AGS. And even this is (I hope ::) ) bound to disappear someday. Whatever items you pick up appear as the last one in the row.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Simonsez128

Hey Rui,

thanks for mentioning this. Apparently I just made this assumption based on the inventory system I use. I wanted all my inventory items to appear in a half circle. So I created a GUI with serveral buttons aligned that way and I am changing their ButtonPic when cycling through the inventory. (If anyone wants to see how I did the coding for this, reply to this thread and I'll post the script) Because of the way I have arranged this to be done, the items appear in the order of the list I set up in the editor.

Just one question: Since the order in the game does not reflect the order they are set up in the editor, is there maybe a variable I can access - like game.top_inv_item - which gives me the order the items appear in the inventory window?

Since I decided to set the additional options as new cursor modes I will have to do some more coding now but this seems like a much easier task to me :)

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

strazer

QuoteWhatever items you pick up appear as the last one in the row.

It would be neat if there was an optional parameter for Character.AddInventory (AGS v2.7) to specify the position of the inv item.

Pumaman

That's not a bad idea actually, I'll look into it.

Radiant

As a workaround, try this:
* move all inventory items carried by EGO to character #1
* AddInv the four special skills
* move all inventory items back to EGO

Now the special skills should appear at the top of the inv list.

Simonsez128

#8
That's a cool idea, Radiant, never thought of that...

I'm still working on how to set up the interface. I am thinking of something like in "Exile". Mouse options and inventory pop up at the same time. I know that some people don't like having to switch mouse modes like that but I definitely wanted the inventory to pop up with a right mouse click. That kind of disables the cycling of mouse modes since I can't just assign it to the left mouse button. It works but it virtually disables the walk mode since every click on a point that's not a hotspot, an object or a character will trigger a switch so that free walking is impossible. I can't think of a good workaround of this. A possible solution would be being able to switch mouse modes with the mouse wheel - if your mouse has one of course :)

EDIT:

I added a screenshot of a test-room I set up to try out the interface.



P.S.: The solution with the mouse wheels works perfect.

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

Radiant

Sounds very cool. But out of personal pet peevishness, please add some kind of keyboard support as well?

Simonsez128

#10
Sure I can add some keyboard support.Ã,  How do you feel about assigning the up and down keys to mode cycling and reserve the keys 1,2,3,4 for quick selecting the modes?
Any more suggestions, like inventory-wise and the like?

EDIT:

Opened up a seperate thread for taking this further....
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=18903.0

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

TheMagician

QuoteI wanted all my inventory items to appear in a half circle. So I created a GUI with serveral buttons aligned that way and I am changing their ButtonPic when cycling through the inventory. (If anyone wants to see how I did the coding for this, reply to this thread and I'll post the script)

Hi Simonsez.
I am really interested in your code for the inventory system because I am just trying to do the same thing.
I already managed to change the button pics if you rotate the gui.

However, every button now has to react diferrently according to the inv-item it holds. I am still looking for a convenient way of scripting that.

So I am very interested in having a look at your code!
Thanks in advance.Ã,  :)

Simonsez128

Hi there Magician :)

I'm glad you're interested in the code for this... took me a bit to get it right. You said you already had the cycling working. I'm still going to include the code for they way I managed it here since it's closely linked to the assigning of inventory items. I created a few extra functions to go with this.

Code: ags

// First define some global variables.
int currentitemoffset = 0;
int invbutton1 = 0;
int invbutton2 = 0;
int invbutton3 = 0;
int invbutton4 = 0;

// I use the following function to update the buttonpics and the itemnumbers the
// buttons stand for.

function checkandsetinv (int offset) {
int counter=0;
int counter2=0;
int counter3=0;
string itemname;

 // First off, I see which item is the first one the player already has.

 while (character[EGO].inv[counter] == 0) {counter = counter + 1;}

 counter = counter + offset;Ã,  // The offset is added so I can flip through the inventory.
 
 // I run a check, which of the items in the game the player is already carrying. Then I 
 // set the buttonpics accordingly. The inventory buttons are 2,3,4 and 5. 
 // I currently have 6 inventory items
 
 while (counter3Ã,  <= 3 && counter+counter2 <= 6) {

Ã,  if (character[EGO].inv[counter+counter2] == 1)
Ã,  Ã, {SetButtonPic (INVENTORY, 2 + counter3, 1, GetInvGraphic (counter+counter2));
Ã,  Ã,  GetInvName(counter+counter2, itemname);

// The invbutton-variables carry the values of the items assigned to the buttons.

Ã,  Ã,  if (counter3 == 0) invbutton1 = counter+counter2;
Ã,  Ã,  if (counter3 == 1) invbutton2 = counter+counter2;
Ã,  Ã,  if (counter3 == 2) invbutton3 = counter+counter2;
Ã,  Ã,  if (counter3 == 3) invbutton4 = counter+counter2;
Ã,  Ã,  counter3++;}
Ã,  Ã,  else SetButtonPic (INVENTORY, 2 + counter3, 1, 87); // pic 87 is a blank
Ã,  counter2++;
 }
}

// In the following function I defined a custom inventory-popup.

function show_inventory_window () {
int positionx;
int positiony;
Ã,  
Ã,  if (game.num_inv_items != 0) checkandsetinv (currentitemoffset); <--- Here I call the defined function checkandsetinv
// The currentitemoffset-variable stores the offset so you don't have to cycle through the whole inventory all the time.

Ã,  if (mouse.x - 20 > 240) {positionx = mouse.x - 100;} else {positionx = mouse.x - 20;}
Ã,  if (mouse.y - 20 > 120) {positiony = mouse.y - 100;} else {positiony = mouse.y - 20;}
Ã,  SetGUIPosition (INVENTORY, positionx, positiony);
Ã,  GUIOn (INVENTORY);
Ã,  SetCursorMode (MODE_USE);

}



Ok, after that, insert the following code into the interface_click function:

Code: ags

if (interface == INVENTORY) {

Ã,  Ã,  // They clicked a button on the Inventory GUI.
Ã,  Ã,  // Ok, so, buttons 2 to 5 stand for the inventory. Through the invbutton variables I know what items
Ã,  Ã,  // they are assigned to. Now all I gotta do is set the active inventory to them, set the respective 
Ã,  Ã,  // graphic as the mouse button and change to the USEINV mode.
Ã,  Ã,  
Ã,  Ã,  if (button == 2) {SetActiveInventory (invbutton1);SetMouseCursor (GetInvGraphic(invbutton1));SetCursorMode (MODE_USEINV);}
Ã,  Ã,  if (button == 3) {SetActiveInventory (invbutton2);SetMouseCursor (GetInvGraphic(invbutton2));SetCursorMode (MODE_USEINV);}
Ã,  Ã,  if (button == 4) {SetActiveInventory (invbutton3);SetMouseCursor (GetInvGraphic(invbutton3));SetCursorMode (MODE_USEINV);}
Ã,  Ã,  if (button == 5) {SetActiveInventory (invbutton4);SetMouseCursor (GetInvGraphic(invbutton4));SetCursorMode (MODE_USEINV);}

// The buttons 0 and 1 stand for the arrow keys to change the offset. Now all I gotta do is update the
// inventory items with my checkandsetinv-function.
Ã,  Ã,  
Ã,  Ã,  if (game.num_inv_items != 0) {
Ã,  Ã,  Ã,  if ((button == 0) && (currentitemoffset < game.num_inv_items - 4)) 
Ã,  Ã,  Ã,  Ã,  Ã, {currentitemoffset++; checkandsetinv (currentitemoffset);}Ã,  Ã,  Ã,  Ã, 
Ã,  Ã,  Ã,  if ((button == 1) && (currentitemoffset > 0)) 
Ã,  Ã,  Ã,  Ã,  Ã, {currentitemoffset--; checkandsetinv (currentitemoffset);} 
Ã,  Ã,  Ã,  }
Ã,  }


Hope this is halfway understandable. Looking back now, I sometimes have to think again twice about how I coded all this :D

So long.

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

Simonsez128

Sorry, forgot to mention something about the code:

So far, I have only set the buttons in the inventory to give you the specified item when clicked. However, for combining inventory items I still have to insert some other functions. I need to check whether there's already an active item and if the mode is set accordingly. Then you'd have to call the apropriate interaction for the item. Same thing goes for looking at and/or using the inventory items.

Gets a little complicated all this... Hmm. We'll see..


I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

TheMagician

Sorry for the delay Simonsez.
Thanks for posting your script. Looks really good to me!

QuoteI need to check whether there's already an active item and if the mode is set accordingly. Then you'd have to call the apropriate interaction for the item. Same thing goes for looking at and/or using the inventory items.

Seems complicated to me. I would be really interested in how you solve this issue. Even a simple thing like "looking at" an inventory item.
Every single button must have the script for all different inv items doesn't it?

Ashen

#15
Actually, I don't think it'd be that complicated. If I understand the script correctly, you just need to set the look at, use other inv on, etc commands for the items, then use the RunInventoryInteaction (item, mode) command, e.g.:

(I changed the formating slightly, to make it easier to read, but feel free to ignore that.)
Code: ags

if (button == 2) {
Ã,  if (GetCursorMode () == MODE_USE) {
Ã,  Ã,  SetActiveInventory (invbutton1);
Ã,  Ã,  SetMouseCursor (GetInvGraphic(invbutton1));
Ã,  Ã,  SetCursorMode (MODE_USEINV);
Ã,  }
Ã,  else RunInventoryInteraction(invbutton1, GetCursorMode());
}


In fact, depending on how you're handling inventory clicks (is 'Handle inventory clicks in script' checked or not?), RunInventoryInteraction(invbutton1, GetCursorMode()); might be all you need, but I'm not totally sure about that.
I know what you're thinking ... Don't think that.

Simonsez128

@ Ashen and TheMagician:

Thanks for your input. That idea of Ashen sounds excellent. Really the best way to sovle this I think... I'll try it out as soon as I have more time at my hand. Right now I need to study for a few exams and then I'll be away for about 2 weeks... We'll see how things go after this :) I am somewhat sad that I can't be spending more time on AGS.

So long!

I've given a million ladies a million footmassages - and they all meant something! - Vincent Vega

SMF spam blocked by CleanTalk