MODULE: Grid-Based Inventory v1.1

Started by Besh, Mon 04/09/2006 15:43:21

Previous topic - Next topic

Besh

Grid-Based Inventory script module

This module is coded to realize the ideas posted in Coding Contest .


*** requires AGS 2.71 or later ***

Download GridInventory 1.1
Simple demo (requires AGS 2.71 or later)

Code: ags

// 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.
"Spread our codes to the stars,
You can rescue us all"
- Muse

jasonjkay

Sounds good, i'll have to give it a try. I'll add it to my site soon.
http://www.americangirlscouts.org/agsresources/ - Mods, plugins and templates.

Joe

WOW!!!!!! Like Diablo inventory!!!!! I never thought it could be possible!!!!! Thankyou!!!!
Copinstar © Oficial Site

R4L

Wow thats awesome! Nice Sigon set  :D!

Fabiano

Yeah, yeah, It happens. A lot.

monkey0506

Heh...now that I actually realize what this is it's pretty neat. Nice work.

Besh

Yeah, Grid-Based is not self-explanatory but that is the name given in the coding constest.

Thanks to all to appreciate my work!!!
"Spread our codes to the stars,
You can rescue us all"
- Muse

riseryn

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

riseryn


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.

LUniqueDan

Have you tried adding the item to Your Gridinventory instead of the character?

Code: ags

GridInventory.AddItem(iBarreau);
"I've... seen things you people wouldn't believe. Destroyed pigeon nests on the roof of the toolshed. I watched dead mice glitter in the dark, near the rain gutter trap.
All those moments... will be lost... in time, like tears... in... rain."

riseryn

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

riseryn

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

Caracal

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!


SMF spam blocked by CleanTalk