RPG Resource 4 AKA Invertory/Store
by Kevin Mitchell · 10/05/2009 (12:15 am) · 8 comments
File Front:
Click Here
This is a little store demo of the inventory system i made. I do believe you might need a global variable got the money since its something i have in a separate file for global.
Note: This is used using the previous resources.



For those who just want the inventory system:
Font you may need for the store:
Note: Sell is 'not' coded :P
Back To Blog:
RPG_Blog AKA New Resources
Click Here
This is a little store demo of the inventory system i made. I do believe you might need a global variable got the money since its something i have in a separate file for global.
Note: This is used using the previous resources.



For those who just want the inventory system:
$InventoryObject::MyInventory="";
$InventoryObject::InventoryCount=0;
$InventoryObject::ITEM_ENUM=1;
$InventoryObject::ARMOR_ENUM=2;
$InventoryObject::EVENTITEM_ENUM=3;
new ScriptObject(Inventory){
Name="";
ID="";
Type="";
TypeID="";
Quantity="";
MaxQuantity="";
Cost="";
Description="";
Image="";
};
function InitalizeInventory(){
%sqlite = new SQLiteObject(sqlite);
if (%sqlite == 0)
{
echo("ERROR: Failed to create SQLiteObject. sqliteTest aborted.");
return;
}
// open database
if (sqlite.openDatabase("Database.db") == 0)
{
echo("ERROR: Failed to open database: " @ %dbname);
echo(" Ensure that the disk is not full or write protected. sqliteTest aborted.");
sqlite.delete();
return;
}
%query = "Select ItemID, ArmorID, EventItemID FROM InventoryInit;";
%result = sqlite.query(%query, 0);
if (%result == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
// attempt to retrieve result data
%i=0;
while (!sqlite.endOfResult(%result))
{
%ItemID = sqlite.getColumn(%result, "ItemID");
%ArmorID = sqlite.getColumn(%result, "ArmorID");
%EventItemID = sqlite.getColumn(%result, "EventItemID");
$InventoryObject::MyInventory[%i] = new ScriptObject(){
class=Inventory;
};
$InventoryObject::InventoryCount=%i;
%i++;
sqlite.nextRow(%result);
}
}
sqlite.clearResult(%result);
sqlite.closeDatabase();
sqlite.delete();
PopulateInventory();
}
function PopulateInventory(){
%sqlite = new SQLiteObject(sqlite);
if (%sqlite == 0)
{
echo("ERROR: Failed to create SQLiteObject. sqliteTest aborted.");
return;
}
// open database
if (sqlite.openDatabase("Database.db") == 0)
{
echo("ERROR: Failed to open database: " @ %dbname);
echo(" Ensure that the disk is not full or write protected. sqliteTest aborted.");
sqlite.delete();
return;
}
%query = "Select ItemID, ArmorID, EventItemID, Quantity FROM InventoryInit;";
%result = sqlite.query(%query, 0);
if (%result == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
// attempt to retrieve result data
%i=0;
while (!sqlite.endOfResult(%result))
{
%ItemID = sqlite.getColumn(%result, "ItemID");
%ArmorID = sqlite.getColumn(%result, "ArmorID");
%EventItemID = sqlite.getColumn(%result, "EventItemID");
%Quantity = sqlite.getColumn(%result, "Quantity");
if(%ItemID != 0){
$InventoryObject::MyInventory[%i].setID(%ItemID);
$InventoryObject::MyInventory[%i].setType($InventoryObject::ITEM_ENUM);
$InventoryObject::MyInventory[%i].setQuantity(%Quantity);
}else if(%ArmorID != 0){
$InventoryObject::MyInventory[%i].setID(%ArmorID);
$InventoryObject::MyInventory[%i].setType($InventoryObject::ARMOR_ENUM);
$InventoryObject::MyInventory[%i].setQuantity(%Quantity);
}else if(%EventItemID != 0){
$InventoryObject::MyInventory[%i].setID(%EventItemID);
$InventoryObject::MyInventory[%i].setType($InventoryObject::EVENTITEM_ENUM);
$InventoryObject::MyInventory[%i].setQuantity(%Quantity);
}
%i++;
sqlite.nextRow(%result);
}
}
sqlite.clearResult(%result);
sqlite.closeDatabase();
sqlite.delete();
PopulateInventoryNames();
}
function PopulateInventoryNames(){
%sqlite = new SQLiteObject(sqlite);
if (%sqlite == 0)
{
echo("ERROR: Failed to create SQLiteObject. sqliteTest aborted.");
return;
}
// open database
if (sqlite.openDatabase("Database.db") == 0)
{
echo("ERROR: Failed to open database: " @ %dbname);
echo(" Ensure that the disk is not full or write protected. sqliteTest aborted.");
sqlite.delete();
return;
}
for(%i=0;%i<$InventoryObject::InventoryCount;%i++){
if($InventoryObject::MyInventory[%i].getType()==1){
%query2 = "Select Name, ItemTypeID, MaxQuantity, Cost, Description, Image FROM Items where ItemID="@$InventoryObject::MyInventory[%i].getID()@";";
%result2 = sqlite.query(%query2, 0);
if (%result2 == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
$InventoryObject::MyInventory[%i].setName(sqlite.getColumn(%result2, "Name"));
$InventoryObject::MyInventory[%i].setTypeID(sqlite.getColumn(%result2, "ItemTypeID"));
$InventoryObject::MyInventory[%i].setMaxQuantity(sqlite.getColumn(%result2, "MaxQuantity"));
$InventoryObject::MyInventory[%i].setCost(sqlite.getColumn(%result2, "Cost"));
$InventoryObject::MyInventory[%i].setDescription(sqlite.getColumn(%result2, "Description"));
$InventoryObject::MyInventory[%i].setImage(sqlite.getColumn(%result2, "Image"));
sqlite.clearResult(%result2);
}
}else if($InventoryObject::MyInventory[%i].getType()==2){
%query2 = "Select Name, ArmorTypeID, MaxQuantities, Cost, Description, Image FROM Armors where ArmorID="@$InventoryObject::MyInventory[%i].getID()@";";
%result2 = sqlite.query(%query2, 0);
if (%result2 == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
$InventoryObject::MyInventory[%i].setName(sqlite.getColumn(%result2, "Name"));
$InventoryObject::MyInventory[%i].setTypeID(sqlite.getColumn(%result2, "ArmorTypeID"));
$InventoryObject::MyInventory[%i].setMaxQuantity(sqlite.getColumn(%result2, "MaxQuantities"));
$InventoryObject::MyInventory[%i].setCost(sqlite.getColumn(%result2, "Cost"));
$InventoryObject::MyInventory[%i].setDescription(sqlite.getColumn(%result2, "Description"));
$InventoryObject::MyInventory[%i].setImage(sqlite.getColumn(%result2, "Image"));
sqlite.clearResult(%result2);
}
}else if($InventoryObject::MyInventory[%i].getType()==3){
%query2 = "Select Name, Quantity FROM Items where ItemID="@$InventoryObject::MyInventory[%i].getID()@";";
%result2 = sqlite.query(%query2, 0);
if (%result2 == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
$InventoryObject::MyInventory[%i].setName(sqlite.getColumn(%result2, "Name"));
}
}
}
//sqlite.clearResult(%result);
sqlite.closeDatabase();
sqlite.delete();
}
function Inventory::getID(%this){
return %this.ID;
}
function Inventory::getName(%this){
return %this.Name;
}
function Inventory::getType(%this){
return %this.Type;
}
function Inventory::getTypeID(%this){
return %this.TypeID;
}
function Inventory::getQuantity(%this){
return %this.Quantity;
}
function Inventory::setID(%this, %value){
%this.ID=%value;
}
function Inventory::setName(%this, %value){
%this.Name=%value;
}
function Inventory::setType(%this, %value){
%this.Type=%value;
}
function Inventory::setTypeID(%this, %value){
%this.TypeID=%value;
}
function Inventory::setQuantity(%this, %value){
%this.Quantity=%value;
}
function Inventory::getMaxQuantity(%this){
return %this.MaxQuantity;
}
function Inventory::setMaxQuantity(%this, %value){
%this.MaxQuantity=%value;
}
function Inventory::getCost(%this){
return %this.Cost;
}
function Inventory::setCost(%this, %value){
%this.Cost=%value;
}
function Inventory::getDescription(%this){
return %this.Description;
}
function Inventory::setDescription(%this, %value){
%this.Description=%value;
}
function Inventory::getImage(%this){
return %this.Image;
}
function Inventory::setImage(%this, %value){
%this.Image=%value;
}
function CheckInventory(%Name){
%hasItem=false;
for(%i=0;%i<$InventoryObject::InventoryCount;%i++){
if(%Name $= $InventoryObject::MyInventory[%i].getName()){
%hasItem=true;
return $InventoryObject::MyInventory[%i].getQuantity();
}
}
return -1;
}
function AddInventory(%Type,%Name, %Quantity){
for(%i=0;%i<$InventoryObject::InventoryCount;%i++){
if(%Name $= $InventoryObject::MyInventory[%i].getName()){
$InventoryObject::MyInventory[%i].setQuantity($InventoryObject::MyInventory[%i].getQuantity()+%Quantity);
return;
}
}
InsertInventoryName(%Type,%Name,%Quantity);
}
function InsertInventoryName(%Type,%Name,%Quantity){
%sqlite = new SQLiteObject(sqlite);
if (%sqlite == 0)
{
echo("ERROR: Failed to create SQLiteObject. sqliteTest aborted.");
return;
}
// open database
if (sqlite.openDatabase("Database.db") == 0)
{
echo("ERROR: Failed to open database: " @ %dbname);
echo(" Ensure that the disk is not full or write protected. sqliteTest aborted.");
sqlite.delete();
return;
}
%i=$InventoryObject::InventoryCount;
if(%Type==1){
%query2 = "Select Name,ItemID,ItemTypeID,MaxQuantity,Cost, Description, Image FROM Items where Name=""@%Name@"";";
%result2 = sqlite.query(%query2, 0);
if (%result2 == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
$InventoryObject::MyInventory[%i].setName(sqlite.getColumn(%result2, "Name"));
$InventoryObject::MyInventory[%i].setID(sqlite.getColumn(%result2, "ItemID"));
$InventoryObject::MyInventory[%i].setType(1);
$InventoryObject::MyInventory[%i].setTypeID(sqlite.getColumn(%result2, "ItemTypeID"));
$InventoryObject::MyInventory[%i].setMaxQuantity(sqlite.getColumn(%result2, "MaxQuantity"));
$InventoryObject::MyInventory[%i].setCost(sqlite.getColumn(%result2, "Cost"));
$InventoryObject::MyInventory[%i].setDescription(sqlite.getColumn(%result2, "Description"));
$InventoryObject::MyInventory[%i].setImage(sqlite.getColumn(%result2, "Image"));
$InventoryObject::MyInventory[%i].setQuantity(%Quantity);
$InventoryObject::InventoryCount++;
}
}else if(%Type==2){
%query2 = "Select Name, ArmorID, ArmorTypeID, MaxQuantities,Cost, Description, Image FROM Armors where %Name="@%Name@";";
%result2 = sqlite.query(%query2, 0);
if (%result2 == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
$InventoryObject::MyInventory[%i].setName(sqlite.getColumn(%result2, "Name"));
$InventoryObject::MyInventory[%i].setID(sqlite.getColumn(%result2, "ArmorID"));
$InventoryObject::MyInventory[%i].setType(2);
$InventoryObject::MyInventory[%i].setTypeID(sqlite.getColumn(%result2, "ItemTypeID"));
$InventoryObject::MyInventory[%i].setMaxQuantity(sqlite.getColumn(%result2, "MaxQuantities"));
$InventoryObject::MyInventory[%i].setCost(sqlite.getColumn(%result2, "Cost"));
$InventoryObject::MyInventory[%i].setDescription(sqlite.getColumn(%result2, "Description"));
$InventoryObject::MyInventory[%i].setImage(sqlite.getColumn(%result2, "Image"));
$InventoryObject::MyInventory[%i].setQuantity(%Quantity);
$InventoryObject::InventoryCount++;
}
}else if(%Type==3){
%query2 = "Select Name, Quantity FROM Items where ItemID="@%Name@";";
%result2 = sqlite.query(%query2, 0);
if (%result2 == 0)
{
echo("ERROR: Failed to SELECT from users table.");
}else{
$InventoryObject::MyInventory[%i].setName(sqlite.getColumn(%result, "Name"));
}
}
for(%h=0;%h<$InventoryObject::InventoryCount;%h++){
echo("Echo ItemNumber "@%h@": "@$InventoryObject::MyInventory[%h].getName() @" - "@ $InventoryObject::MyInventory[%h].getTypeID() @" - "@ $InventoryObject::MyInventory[%h].getQuantity());
}
}
function RemoveInventory(%Name, %Quantity){
for(%i=0;%i<$InventoryObject::InventoryCount;%i++){
if(%Name $= $InventoryObject::MyInventory[%i].getName()){
$InventoryObject::MyInventory[%i].setQuantity($InventoryObject::MyInventory[%i].getQuantity()-%Quantity);
}
}
}
InitalizeInventory();Font you may need for the store:
if(!isObject(WhiteTextLeft)) new GuiControlProfile(WhiteTextLeft)
{
fontType = "Arial Bold";
fontSize = 20;
fontColor = "255 255 255";
justify = "left";
};
if(!isObject(BlackTextLeft))new GuiControlProfile(BlackTextLeft)
{
fontType = "Arial Bold";
fontSize = 25;
fontColor = "0 0 0";
justify = "left";
};
if(!isObject(BlackTextCenter))new GuiControlProfile(BlackTextCenter)
{
fontType = "Arial Bold";
fontSize = 30;
fontColor = "0 0 0";
justify = "center";
};
if(!isObject(BlackTextRight))new GuiControlProfile(BlackTextRight)
{
fontType = "Arial Bold";
fontSize = 30;
fontColor = "0 0 0";
justify = "right";
};
if(!isObject(MapTextProfile))new GuiControlProfile(MapTextProfile)
{
opaque = false;
fontType = "Arial Bold";
fontSize = 20;
fontColor = "237 201 0";
fontColorHL = "237 201 0";
justify = "center";
//canKeyFocus = true;
};
if(!isObject(StoreLightTextRight))new GuiControlProfile(StoreLightTextRight)
{
fontType = "Arial Bold";
fontSize = 30;
fontColor = "253 254 191";
justify = "right";
};
if(!isObject(StoreLightTextCenter))new GuiControlProfile(StoreLightTextCenter)
{
fontType = "Arial Bold";
fontSize = 30;
fontColor = "253 254 191";
justify = "center";
};
if(!isObject(StoreLightTextLeft))new GuiControlProfile(StoreLightTextLeft)
{
fontType = "Arial Bold";
fontSize = 25;
fontColor = "253 254 191";
justify = "left";
};
if(!isObject(StoreItemTextLeft))new GuiControlProfile(StoreItemTextLeft)
{
fontType = "Arial Bold";
fontSize = 25;
fontColor = "0 0 0";
justify = "left";
};Note: Sell is 'not' coded :P
Back To Blog:
RPG_Blog AKA New Resources
About the author
Riding Solo since 2005. Current Project: Fated World 2005-Present "... because Torque3D is not just for Tribes style First Person Shooters - but anything which you have the will to create" ~ Steve Acaster
#2
10/05/2009 (8:58 pm)
Please explain I don't understand
#3
10/07/2009 (7:16 am)
Please let me know if anyone is having problems. I'll see if I can help.
#4
11/01/2009 (11:10 pm)
You didnt, put any instructions, where and what to put. Im trying implement your inv into Torque SDK 3D 1.0.1. U have some folders "main frame" which dosent explain where to put them. Please if you can make clear, for this version of Torque, how to install inv.
#5
11/01/2009 (11:30 pm)
You can place it any where client side you want just make sure the init string is cslll
#6
11/01/2009 (11:38 pm)
How u initialize ur inv, while running game? Which button did u assign to do that? I found buttons how to navigate through the inv, but not how to turn its on. Pls help.
#7
If you are using the store interface, when you call the setCanvas to load the GUI you will init the onwake which pushes you current movemap and uses the keymap for the GUI these keys to navigate the GUI can be found in the store.cs file you can change it to what ever you want.
11/02/2009 (5:08 am)
Wow sorry about the last comment wrote it when I was half sleep. Basicly you want to drop the folder into your project's client directory. If you are using just the invetory code you must make sure to add the othe resources for sqlite,you must call the main.cs in the mainframe ddirectory to get things working. This can be added in the init section for the client side code. From there you can read through the code answer the init inventory functions this will load a list of inventory that is set up for the inital start of the game. To see which you can do some queries on the sqlite database,also you can use the database mod resource to edit the content of the inventory.If you are using the store interface, when you call the setCanvas to load the GUI you will init the onwake which pushes you current movemap and uses the keymap for the GUI these keys to navigate the GUI can be found in the store.cs file you can change it to what ever you want.
#8
12/04/2010 (6:53 pm)
Have you thought about using Canvas.setCursor("DefaultCursor"); and using it to make the interface a point and click?
Torque 3D Owner Edward