Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: undergroundling on Sun 08/06/2003 05:02:29

Title: multiple inventories
Post by: undergroundling on Sun 08/06/2003 05:02:29
would it be possible to create two separate inventories for the same character which could both be accessed by separate icons on the GUI.  i would use this to create both a standard inventory and a "spellbook" which could store spells like those in zork:grand inquisitor and other games of the sort.  if anyone has any ideas or would be willing to help me with some interface design, that would be really appreciated.

thanks.

- bryan
Title: Re:multiple inventories
Post by: Rui 'Trovatore' Pires on Sun 08/06/2003 06:14:05
Yeah, I thought about it too, but I was wondering about having containers - you know, a box that had a separate inventory. Here's how I'd figure it'd work (it's off-da-wall, but that's what you gotta do when it's something AGS doesn't support)

- Make 2 main characters, both with the same views and animations and whatnots. One of them is the player, and has the player's inventory; the other one is the, say, spellbook inventory, or what the box contains.

- When the player opens the spellbook, set player character to the 2nd char, and MAKE SURE to change it's view to the main character's (up until now, it should have been on a transparent view).

- And now, to open the spellbook(or box) change character. The inventory will be changed/refreshed with the items the other character had. Change back (if you want to) after you're done.

- To ensure the player doesn't magically transport, you have to make sure both characters are always in the same X,Y and facing the same direction. You can go to repeteadly execute and have them character[X].x=character[Y].x , or maybe make your own walk function which might look like,

 function walk() {
   if (IsGamePaused()==0) {
      MoveCharacter(X,mouse.x,mouse.y);
      MoveCharacter(Y,mouse.x,mouse.y);
  }
 }

Of course, multiple views (wearing a robe/a cloak/nothing at all) means extra work, but not significantly.

As I've said, it's off-da-wall, and I haven't even tested it yet, but it should work, I don't see why not. See, it's actually harder to do if while the book is available you can still see the background - that's the case in which you need both characters. Of course, if somehow the book always covers your main character, you don't have to juggle so much with a second character, just make sure it's in the same room and open it's inventory.
Title: Re:multiple inventories
Post by: MrColossal on Sun 08/06/2003 06:40:10
why do you have to do all that business with the swapping characters? if you switch characters the character you just were doesn't disappear, and if i read you right you're just gonna pause the game anyway so why not just switch to the invisible character who can be anywhere on the screen and display that inventory

i've never mucked about with multiple characters but if you switch characters is that just like going to a new room? if an animation runs everytime you entire a room and you switch characters will that animation run?

eric
Title: Re:multiple inventories
Post by: Rui 'Trovatore' Pires on Sun 08/06/2003 06:58:22
As I've said, I've never even tested it. This code is actually for a kind of inventory that's always on display, LSL6 type. I envision it like -


--------------------------------------------------
  <HANDS>         <POCKET>       <BOX>|
--------------------------------------------------
                                                      |         (inv)                                                 |
--------------------------------------------------

Where the <> things are buttons to be made available as the situation needs. Since it's always visible, it's necessary to make sure the 2nd character is in the right place, so you keep on playing with that character. You constantly switch back and forth, but the player can't know it.

But I do realize it's a bit overboard for that spellbook thing, undergroundling. As Mr. Colossal pointed out, the second way to do things might be much better.

Realize, however, that it'll only work as long as the spellbar and invbar (talking ZORK G. INQ.) are not active at the same time. Only one inventory can be displayed at any given time. But you already knew that, right? :)
Title: Re:multiple inventories
Post by: undergroundling on Sun 08/06/2003 16:31:40
hmm, thanks for the ideas.  i think im going to try mr.colossal's idea of the invisible second character.  it just looks easier than attempting redrum's idea.  but i guess i can always try that out if the other doesnt work.  thanks for your input.

- bryan

edit: well, ive been thinking, and if i have an invisible second player character who is set to follow the main character, then this just might work.  i still have to decide if i want a separate function on the GUI or have the spellbook inventory accessible from an icon in the main inventory.

of course, there is also the problem of when to switch back to the main player character.  but i guess ill have to get that sorted out.  <sigh>  if anyone has any major scripting experiences with stuff like this, i could sure use a hand.
Title: Re:multiple inventories
Post by: Pumaman on Sun 08/06/2003 18:14:33
Yep, as eric says all you need is an invisible second character. Don't worry about what's happening with that character, but when the player asks for the spellbook, just do something like:

character[SPELLS].room = character[EGO].room;
SetPlayerCharacter (SPELLS);
GUIOn (SPELLBOOK);

and then, once they select the spell, you can do
GUIOff (SPELLBOOK);
SetPlayerCharacter(EGO);
character[SPELLS].room = -1;

to restore everything back to normal.
Title: Re:multiple inventories
Post by: Spyros on Sun 08/06/2003 21:25:41
One question :
If you change to character SPELL and chose an inv item (lets say 10 that represents a spell), then when you change to the normal character is inv 10 still the active inv?
Because the normal character doesn't own inv 10, how can it be his active inv?
Title: Re:multiple inventories
Post by: undergroundling on Sun 08/06/2003 21:35:30
yeah, spyros, that was the problem i was thinking would come up.  ill try it out tonight and see if it works and post back here when i figure out what happens.

- bryan
Title: Re:multiple inventories
Post by: undergroundling on Mon 09/06/2003 01:47:19
ok, apparently im too retarded to figure this out.  i need some people to help me script this thing.

- bryan
Title: Re:multiple inventories
Post by: Scorpiorus on Mon 09/06/2003 19:46:38
QuoteOne question :
If you change to character SPELL and chose an inv item (lets say 10 that represents a spell), then when you change to the normal character is inv 10 still the active inv?
Because the normal character doesn't own inv 10, how can it be his active inv?
Yes, the active inventory is still the same then. That's because when you select an item from the inventory AGS sets up Use inv mode to use that item as the active one. Next the character is changed but the mode isn't therefore we can click around with that cursor mode. But there are some obstacles:
- if we start to cycle modes then that item will never be selected again as the current character hasn't it as active. So either AGS selects another item which the current char has as active or it just skips Use inv mode.

- if we want some actions to be run when we click with that loan item on hotspot for example then we shouldn't use character[GetPlayerCharacter()].activeinv variable but game.inv_ictivated instead. Because otherwise there are no actions will be run as the current player hasn't this item as the active (actually he maybe hasn't it at all).

EDIT: here we could set the active item (for the current char) to be the same manually:
character[EGO].activeinv = character[SPELL].activeinv;
Even if the character hasn't an item that doesn't mean we can't set it to be the active one. :)


btw each character struct has it's own active inventory (character[].activeinv) which is used, as I said above, when AGS sets the Use inv mode.




Quote--------------------------------------------------
<HANDS> <POCKET> <BOX>|
--------------------------------------------------
| (inv) |
--------------------------------------------------
If you need to have the inventory/spell window to be active all the time you do not need to make all these views, double move characters etc.
Instead create two additional characters (apart from the main one). Call them: CHARINVENTORY and CHARSPELLS respectively.

So we have:
- EGO (player character)
- CHARINVENTORY (this is EGO's inventory) yes we have a separate inv.
- CHARSPELLS (this is EGO's spells)
- .... (maybe something else btw)

There is also the function comes in handy:

function CopyInventory(int CharID1, int CharID2) {
int INV_MAX = 300;
int i=1;
while (i<INV_MAX) {
character[CharID1].inv[ i ] = character[CharID2].inv[ i ];
i++;
}
}

that copy all the inventory items from CharID2 to CharID1.


ok. now when we choose inventory screen:

CopyInventory(EGO, CHARINVENTORY); //copy inventory
UpdateInventory();
GUIOn(...); //close spells, open inv


and when we choose spells:

CopyInventory(EGO, CHARSPELLS); //copy spells
UpdateInventory();
GUIOn(...); //close inv, open spells


The principle is that we overwrite current char's inventory with any we want.

Of course when you add a spell or an inv item you should use the appropriate char (not the current one):
character[CHARINVENTORY].inv[2] = 1;
character[CHARSPELLS].inv[2] = 3;
etc.

Note, however, all these chars can be in room -1 all the time.


-Cheers

Edit by strazer

Since AGS v2.7 you can specify which character's inventory a GUI InvWindow should display, so you don't need to copy inv items around anymore.
Title: Re:multiple inventories
Post by: Rui 'Trovatore' Pires on Mon 09/06/2003 20:59:10
Scorpiorus, you're a lifesaver! I wonder why I have this tendency to always do stuff the hard way...
Title: Re:multiple inventories
Post by: Pumaman on Mon 09/06/2003 21:26:28
Hmm good point, there's a bug there - if you SetPlayerCharacter when an inventory item is selected, it should change the cursor mode back to Walk or something. I'll look into it.
Title: Re:multiple inventories
Post by: Scorpiorus on Mon 09/06/2003 22:34:09
QuoteHmm good point, there's a bug there - if you SetPlayerCharacter when an inventory item is selected, it should change the cursor mode back to Walk or something. I'll look into it.
Btw I thought it was by-design. :)

What if another char has an active inv too? Will it just replace the current active inv? ..or

... Does it mean we'll have to add a line for that kind of script...

character[SPELLS].room = character[EGO].room;
SetPlayerCharacter (SPELLS);
GUIOn (SPELLBOOK);

and then, once they select the spell, you can do
GUIOff (SPELLBOOK);
SetPlayerCharacter(EGO);
character[SPELLS].room = -1;
SetActiveInventory(game.inv_activated);

to be sure the cursor was set up properly?

EDIT: I tested SetActiveInventory() thingy but it doesn't allow to set an active item if it's not in the current inventory. Therefore the next lines instead:
...
and then, once they select the spell, you can do
GUIOff (SPELLBOOK);
SetPlayerCharacter(EGO);
character[SPELLS].room = -1;
SetActiveInventory(game.inv_activated);
character[EGO].activeinv = game.inv_activated;
SetCursorMode(MODE_USEINV);


:P


QuoteScorpiorus, you're a lifesaver! I wonder why I have this tendency to always do stuff the hard way...
It happens to me too. Then I state to myself that there must be a more common way and sometimes it works. ;D


-Cheers
Title: Re:multiple inventories
Post by: undergroundling on Tue 10/06/2003 00:58:15
if anyone can write up a GUI script and send me the compiled script file, that would be AMAZING.  and of course, you'd get programming credit for my game.

- bryan

edit: and PLEASE test it first to make sure it works.  wow, if anyone does this, they will be my best friend forever.
Title: Re:multiple inventories
Post by: Scorpiorus on Tue 10/06/2003 15:16:53
No problem mate. Here is a template demonstrating the multi-inventory (multibox.zip (http://geocities.com/scorpiorus82/mbox11.zip) [right click/save as] AGS 2.55 required)


Some notes

- to add the items the player starts with you have to place something  like this into game_start() function:

miAddItem(INVBOX, 1);
miAddItem(SPELLBOX, 2);

I mean do not use player starts with this item checkbox. It doesn't help.

- if you need to use miAddItem/miLoseItem functions in other rooms place this code into the Script header:

import function miAddItem(int, int);
import function miLoseItem(int, int);



if any problems/questions then tell me and I'll help. ;)

-Cheers

[edited to correct the link]
Title: Re:multiple inventories
Post by: Pumaman on Tue 10/06/2003 22:10:11
Quote from: Scorpiorus on Mon 09/06/2003 22:34:09
What if another char has an active inv too? Will it just replace the current active inv? ..or

... Does it mean we'll have to add a line for that kind of script...


Ah I see your point, you can actually use the bug to your advantage to select an inventory item that the player doesn't have (ie. a spell). hmm, I don't know whether to fix it or not now.
Title: Re:multiple inventories
Post by: Scorpiorus on Tue 10/06/2003 23:08:09
Yep, I think maybe leave it as is. And so the designer could decide for himself what exactly mode to set when the character has been changed. :P

-Cheers
Title: Re:multiple inventories
Post by: on Wed 11/06/2003 00:10:33
what about an option in ags that a particular inv box shows only sertain inv items. example- setup one box to show only even numbered inv items and another one could show odd numbred items.

even numbers can be spell items and odd canbe regular items. dis way you can add too boxes and make iit work like to seperate inv for the character.

hows bout that for a feature chris?
Title: Re:multiple inventories
Post by: undergroundling on Wed 11/06/2003 03:04:58
Scorpiorus -

Thank you!  That's amazing!  Now, just a few questions...

Is there any way you could make it so the default inventory button doesnt exist and only the spell and inv ones are there, or would that cause some problem?  I tried to see if I could fix it, but only ended up making things weird.  Is this harder than it looks or am I just retarded at GUI scripting?

Actually, that's about the only question I had.

Thanks a lot, let's see if we can get that one issue sorted out and I may have quite the game on my hands.  

- Bryan

oh, and you will, of course, get programming credit for my game when its completed.
Title: Re:multiple inventories
Post by: Scorpiorus on Wed 11/06/2003 15:33:03
Quotewhat about an option in ags that a particular inv box shows only sertain inv items. example- setup one box to show only even numbered inv items and another one could show odd numbred items.
I think there should be a more general solution because it doesn't help much if you want to have three and more different-type boxes. :P
I would suggest to have a function SetInvInterval(int low_item_index, int top_item_index) which sets the index interval for the inventory. So if the item's index in that range then it's displayed otherwise not. Thereby we could have a number of groups of items to be displayed separately. ...I would suggest but... the problem is it would be impossible to add a new item into a group located between two other groups...


QuoteIs there any way you could make it so the default inventory button doesnt exist and only the spell and inv ones are there, or would that cause some problem? I tried to see if I could fix it, but only ended up making things weird. Is this harder than it looks or am I just retarded at GUI scripting?
That's simple enough. Just open the global script, find interface_click() function and look for the next line inside it:

if (interface == ICONBAR) {
   if (button == 4) {  // show inventory
     show_inventory_window();
   }

It is show_inventory_window() function that opens standart inventory screen therefore just comment it out:

if (interface == ICONBAR) {
   if (button == 4) {  // show inventory
     // show_inventory_window();
   }

Also you can goto GUI editor and remove the appropriate button (maybe replace it's image, it's up to you)

-Cheers
Title: Re:multiple inventories
Post by: undergroundling on Thu 12/06/2003 22:50:16
Great!  ;D

I've managed to fix it so the GUI has both the save/load buttons and the spell/inv buttons.  Couldn't have done this without your help Scorpiorus!  Thanks!

Oh, and let me know via private message how you want to be credited when I finish my game ;)

- Bryan
Title: Re:multiple inventories
Post by: SSH on Wed 19/11/2003 11:00:21
Some thoughts I had on this recently:

1. This is a prime candidate for the Tech Archive
2. You could implement an always-on-screen inventory (normal or a second one) by using characters as inv items. Then you would have a thing in the rep_ex to make sure that they were always in the same room as the player, and also you would need to organise their screen postiition yourself, ditto removeing them, so on.
Title: Re:multiple inventories
Post by: Superman95 on Fri 21/11/2003 04:31:16
I think I would recommend opening up the interface to the inventory controls.  For instance, right now, you only have the inventory control box but there's not really a way to change the way it behaves.  Made if you could have more control of the box itself, not just the items it displays.  I wish I had a better recommendation on how to do this.  Just a thought.  :)

Oh, I know.  Maybe make the listbox (or add a new list box control) that lets you add graphics to it.  Then, you pretty much draw anything you want there.
Title: Re:multiple inventories
Post by: Scorpiorus on Fri 21/11/2003 16:06:22
QuoteOh, I know. Maybe make the listbox (or add a new list box control) that lets you add graphics to it. Then, you pretty much draw anything you want there.
Today AGS GUI control becomes pretty flexible. You can adjust it's object size, position. So, you could make each button representing a certain inventory slot and set it's graphics accordingly. It does invole some scripting though.  :P

PS I've realized I forgot to upload an undated version of multibox which enables different gui support for the different kind of inventory: multibox v1.1 (18kb) (http://www.geocities.com/scorpiorus82/mbox11.zip) (right click/ save as)

[edited to correct the link]

~Cheers
Title: Re:multiple inventories
Post by: Akumayo on Mon 19/01/2004 01:48:02
EDIT:  my my, my earliest posts were childish and stupid.  I'm editing this one away, it was terrible.
Title: Re:multiple inventories
Post by: Scorpiorus on Mon 19/01/2004 09:04:23
Quote from: Akumayo on Mon 19/01/2004 01:48:02and doing those two things will make two different inventories for the same character.
Unfortunately, no. In fact, it will make two different GUIs showing the same inventory.

On adding an inventory item you do not specify which inventory it would go to. Thus, you can't distinguish between the various inventories.

~Cheers