Game Development Community

New to scripting, inventory help please :)

by Brandon Coleman · in Torque Game Builder · 02/11/2010 (2:20 pm) · 3 replies

Hi guys :) I'm somewhat new to scripting so I'm a little confused as to what to do next.. I have a group project for a level designing class that I'm working on, and my job is to get a gas can object to add into the inventory. As I understand, there is an inventory system already built into Torque, so that one will work fine. How would I go about doing this? This is what I have so far:

//-----------------------------------------------------------------------------
//Gas Can Code
//-----------------------------------------------------------------------------
datablock ItemData( GasCan )
{
category = "Gas Can";
shapeFile = "~/data/shapes/GasCan/GasCan.dts";

respawnTime = 100000;
// Dynamic properties defined by the scripts
maxInventory = 1; // No pickup or throw
};

//-----------------------------------------------------------------------------
//Here is the function to call the gas can into the game
//-----------------------------------------------------------------------------
function ItemData::create( %data )
{
echo( "ItemData::create for GasCan called --------------------------" );

%obj = new Item()
{
dataBlock = %data;
rotate = false; // Gas Can will not rotate
static = true; // Gas Can will not move
};

return %obj;
}
function ItemData::onPickup(%this,%obj,%user,%amount)
{
// Add it to the inventory, this currently ignores the request
// amount, you get what you get. If the object doesn't have
// a count or the datablock doesn't have maxIventory set, the
// object cannot be picked up.
%count = %obj.count;
if (%count $= "")
if (%this.maxInventory !$= "") {
if (!(%count = %this.maxInventory))
return;
}
else
%count = 1;
%user.incInventory(%this,%count);

// Inform the client what they got.
if (%user.client)
messageClient(%user.client, 'MsgItemPickup', 'c0You picked up %1', %this.pickupName);

// If the item is a static respawn item, then go ahead and
// respawn it, otherwise remove it from the world.
// Anything not taken up by inventory is lost.
if (%obj.isStatic())
%obj.respawn();
else
%obj.delete();
return true;
}

Thanks for any help :)

Thread is locked
#1
02/11/2010 (3:44 pm)
Hey Brandon,

I thought because your account is linked to TGB that the project would be TGB but this code looks more like Torque Game Engine (TGE).

What engine are you using?
#2
02/11/2010 (4:27 pm)
I believe I'm using TGE. I didn't know there was a difference lol
#3
02/11/2010 (8:07 pm)
Please continue the discussion in this thread.