Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: Besh on Mon 04/09/2006 15:43:21

Title: MODULE: Grid-Based Inventory v1.1
Post by: Besh on Mon 04/09/2006 15:43:21
Grid-Based Inventory script module

This module is coded to realize the ideas posted in  Coding Contest  (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27384.0).


*** requires AGS 2.71 or later ***

Download GridInventory 1.1 (http://www.webalice.it/besh81/GridInventory_v1.1.rar)
Simple demo (http://www.webalice.it/besh81/Grid_demo.rar) (requires AGS 2.71 or later)


// Script header for module 'GridInventory'
//
// Author: Gabriel Ferri (Besh)
//  Please contact me about problems with this module.
//
// Abstract: manage Grid-Based Inventory.
//
// Dependencies:
//
// AGS 2.71 or later
//
// Functions:
//
// void GridInventory.InitInv(InvWindow *iWindow, InventoryItem *blankItem)
//    Link the GridInventory to the InvWindow. Moreover, sets the blankItem, that is
//    a normal InventoryItem with no name and a blank image.
//
//  static void GridInventory.SetItem(InventoryItem *item, int width, int height)
//    Sets item's width and height in number of grid-boxes.
//
//  static void GridInventory.GetItemWidth(InventoryItem *item)
//    Returns item's width in number of grid-boxes.
//
//  static void GridInventory.GetItemHeight(InventoryItem *item)
//    Returns item's height in number of grid-boxes.
//
//  bool GridInventory.AddItem(InventoryItem *item, optional int pos)
//    Adds the item to the GridInventory at the given (optional) position. If position
//    is not specified adds the item at the first free position. Postion are numbered
//    from 0.
//    Returns true if the item is added or false if not.
//     
//  bool GridInventory.AddItemAtScreenXY(InventoryItem *item, int x, int y)
//    As for GridInventory.AddItem but adds the item at the given screen position.
//
//  InventoryItem* GridInventory.LoseItem(InventoryItem *item)
//    Removes the specified item from the GridInventory. If there are multiple items
//    removes the first one.
//    Returns the removed item if the item is removed or null if not.
//
//  InventoryItem* GridInventory.LoseItemAt(int pos)
//    Removes the item at the given position.
//    Returns the removed item if the item is removed or null if not.
//
//  InventoryItem* GridInventory.LoseItemAtScreenXY(int x, int y)
//    As for GridInventory.LoseItemAt but removes the item at the given screen position.
//
//  InventoryItem* GridInventory.LoseArea(int pos, int width, int height)
//    If in the selected area (pos is the upper-left corner) there is ONLY ONE item
//    removes it.
//    Returns the removed item if the item is removed or null if not.
//
//  InventoryItem* GridInventory.LoseAreaAtScreenXY(int x, int y, int width, int height)
//    As for GridInventory.LoseArea.
//
//
// Example:
//
// See the DEMO.
//
// Caveats:
//
//  - In "general setting" panel make sure that "HANDLE INVENTORY CLICKS IN SCRIPT" and
//    "DISPLAY MULTIPLE INVENTORY ITEMS MULTIPLE TIMES" are checked.
//  - ATTENTION: The normal AGS inventory functions become unusable. Don't use them.
//  - ATTENTION: Don't use UpdateInventory() function.
//
// Revision History:
//
// 04 Sep 06: v1.0  First release
// 05 Sep 06: v1.1  Fixed bug in LoseItem
//                  Fixed bug _function_AtScreenXY
//                  Added functions: LoseArea, LoseAreaAtScreenXY, GetItemWidth and
//                                   GetItemHeight
//
// Licence:
//
//   GridInventory AGS script module
//   Copyright (C) 2006 Gabriel Ferri
//
// This module is licenced under the Creative Commons Attribution Share-alike
// licence, (see http://creativecommons.org/licenses/by-sa/2.5/scotland/ )
// which basically means do what you like as long as you credit me and don't
// start selling modified copies of this module.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.



What do you think? Let me know.
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: jasonjkay on Tue 05/09/2006 13:10:07
Sounds good, i'll have to give it a try. I'll add it to my site soon.
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: Joe on Tue 05/09/2006 15:06:46
WOW!!!!!! Like Diablo inventory!!!!! I never thought it could be possible!!!!! Thankyou!!!!
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: R4L on Tue 05/09/2006 15:37:50
Wow thats awesome! Nice Sigon set  :D!
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: Fabiano on Tue 05/09/2006 16:15:24
amazing. Nice job, Besh!

Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: monkey0506 on Tue 05/09/2006 16:53:18
Heh...now that I actually realize what this is it's pretty neat. Nice work.
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: Besh on Fri 08/09/2006 16:11:15
Yeah, Grid-Based is not self-explanatory but that is the name given in the coding constest.

Thanks to all to appreciate my work!!!
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: riseryn on Wed 16/04/2008 17:16:13
sorry to pop up this old thread but Im triyng to use this module wits AGS 3.01 and I have this error
Quote
An error has occurred. Please contact the game author for support, as this
is likely to be a scripting error and not a bug in AGS.
(ACI version 3.01.1017)

in "GridInventory.asc", line 397
from "GlobalScript.asc", line 360

Error: String.Substring: invalid index


line 397 is

id = this.itemId.Substring(pos * 3, 3);

I dont understand what this code mean ant to what its related.

any clue or suggestion?

Maybe its because I'm using the verbcoin template but not the inventory from it?

when I load the demo game in 3.01 there is no problem so I certainly miss an important point in the configuration but cant figure which one.

EDIT
problem solved it was just itemheight anditemweight which were not correctly setted
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: riseryn on Mon 21/04/2008 23:18:16

I have this error
---------------------------
Adventure Game Studio
---------------------------
An internal error has occurred. Please note down the following information.
If the problem persists, contact Chris Jones.
(ACI version 3.01.1018)

Error: run_text_script1: error -6 running function 'oBarreau_Interact':
Error: Null pointer referenced
in "GridInventory.asc", line 159
from "room19.asc", line 56


---------------------------
OK   
---------------------------


line 56 is :  janeInv.AddItem(iBarreaucoupe);

I can add item to inventory only in game_start.
This is not very usefull for a game not being able to add inventory item in room.
So i guess i have miss something on the use of this module.
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: LUniqueDan on Thu 24/04/2008 13:38:29
Have you tried adding the item to Your Gridinventory instead of the character?


GridInventory.AddItem(iBarreau);
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: riseryn on Thu 24/04/2008 20:33:13
Thats not possible to do that, it must be an instance of the structure.
Problem is i cant use the instance ouside game_start.
I tryed to add in room script

GridInventory janeInv;

but it give me the error above.

so if someone as any clue ;)
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: riseryn on Fri 25/04/2008 22:29:18
I have finally solved my problem

i had to export and import the definition of my character inventory.

in global script

export  janeInv;

in global script header

import GridInventory janeInv;

now it works :)
Title: Re: MODULE: Grid-Based Inventory v1.1
Post by: Caracal on Sat 07/12/2013 11:57:20
The idea for such a module is amazing! I love it so much! Thank you for creating it, Besh!
Not only Diablo I and II work with this kind of inventory, it is also used in epic games such as Arcanum and Resident Evil 4! Therefore the need of such an inventory is unquestionable. Once I finish my current game I will start going into this one by using it!

For now I have discovered 2 issues about your module.
The first problem is that when the player selects an item (the mouse cursor changes) and then selects the “return to select button” on the bottom of the inventory (next to ok). The mouse cursor returns to normal without returning the picked item into its original inventory position. Thus the item is lost! (I just imagine that to happen in the real Diablo II after finally finding a good weapon)

Secondly there is another thing that diminishes its use, as discussed in this forum: http://www.adventuregamestudio.co.uk/forums/index.php?topic=8119.0
One can't drop Inventory Items at the moment!