New Inventory "Tutorial"
by Tim Newell · in Torque Game Engine · 11/01/2002 (2:02 am) · 8 replies
I was too lazy to actually integrate and write a tutorial to use this, so I'll just go ahead and post it.
Then simple put in the create player in game.cs in createPlayer (add the part in bold)
// Create the player object
%player = new Player() {
dataBlock = LightMaleHumanArmor;
client = %this;
inventory = new ScriptObject() {
class = Inventory;
};
};
then you can simple call in a function where you can access the player,
%player.inventory.addItemField(0, "Name", "Rifle");
%player.inventory.addItemField(0, "Desc", "You shoot things with it");
etc.
I hope you enjoy it. If you have any questions about using it feel free to ask.
-Tim aka Spock
//////////////////////////////////////////////////////////////////////////////////////////
function Inventory::getItemField(%this, %num, %type)
{
return %this.inv[%type,%num];
}
//////////////////////////////////////////////////////////////////////////////////////////
function Inventory::getCurItemField(%this, %type) {
return %this.getItemField(%type, %this.current);
}
//////////////////////////////////////////////////////////////////////////////////////////
function Inventory::getFirstItemField(%this, %type) {
return %this.getItemField(%type, %this.first);
}
//////////////////////////////////////////////////////////////////////////////////////////
function Inventory::getLastItemField(%this, %type) {
return %this.getItemField(%type, %this.last);
}
//////////////////////////////////////////////////////////////////////////////////////////
function Inventory::moveCurrent(%this, %amount) {
%this.current += %amount;
}
//////////////////////////////////////////////////////////////////////////////////////////
function Inventory::addItemField(%this, %num, %type, %data) {
%this.inv[%type,%num] = %data;
if (%num > %this.max) {
%this.max++;
%this.last = %num;
}
if (%this.first $= "") {
%this.first = %num;
}
}
//////////////////////////////////////////////////////////////////////////////////////////
function Inventory::getMaxItems(%this) {
return %this.max;
}Then simple put in the create player in game.cs in createPlayer (add the part in bold)
// Create the player object
%player = new Player() {
dataBlock = LightMaleHumanArmor;
client = %this;
inventory = new ScriptObject() {
class = Inventory;
};
};
then you can simple call in a function where you can access the player,
%player.inventory.addItemField(0, "Name", "Rifle");
%player.inventory.addItemField(0, "Desc", "You shoot things with it");
etc.
I hope you enjoy it. If you have any questions about using it feel free to ask.
-Tim aka Spock
#2
03/24/2005 (2:27 pm)
Does this still work?
#3
03/25/2005 (6:39 am)
3 years old, alot has changed.
#4
04/01/2005 (6:22 am)
I don't see any reason why it wouldn't
#5
02/23/2006 (7:01 pm)
Stefan do you still have your tutorial?
#7
My name is Lucus and I go to school at lane. A group of students and I are doing a project using your the torque engine.
I just purchased the engine. Will we still need to do the inventory tutorials to update our engine?
02/16/2008 (9:43 am)
Hey tim,My name is Lucus and I go to school at lane. A group of students and I are doing a project using your the torque engine.
I just purchased the engine. Will we still need to do the inventory tutorials to update our engine?
#8
04/05/2008 (12:43 pm)
I don't know about Stefan's code, but Tim's should still work with your version of the engine. it is a basic system, but you will probably want to extend on this some to provide better management of the inventory. Some additional helper methods are needed to make Inventory management easier with this code. However, it's still a good place to start.
Associate Stefan Beffy Moises