OnPickup
by Gary Blake · in Torque Game Engine · 06/22/2005 (4:56 am) · 11 replies
I can do a work aroun with onCollision but I would like to understand why onPickup fails to be called given the following :
datablock ItemData(Copper)
{
category = "Ammo";
className = "Ammo";
shapeFile = "~/data/shapes/items/kash1.dts";
mass = 0.7;
friction = 0.8;
elasticity = 0.3;
respawnTime = 30 * 60000;
salvageTime = 15 * 60000;
// Dynamic properties defined by the scripts
pickupName = "a copper coin";
value = 1;
maxInventory = 20;
};
function Copper::onPickup(%this,%obj,%user,%amount)
{
%count = %obj.count;
if (%count $= "")
if (%this.maxInventory !$= "") {
if (!(%count = %this.maxInventory))
return;
}
else
%count = 1;
%user.incInventory(%this,%count);
if (%user.client)
messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
%user.client.money += %this.value;
%scoreString = " $:" @ %client.money;
if (%user.client)
messageClient(%user.client, 'MsgItemPickup', %scoreString, %this.pickupName);
if (%obj.isStatic())
%obj.respawn();
else
%obj.delete();
return true;
}
datablock ItemData(Copper)
{
category = "Ammo";
className = "Ammo";
shapeFile = "~/data/shapes/items/kash1.dts";
mass = 0.7;
friction = 0.8;
elasticity = 0.3;
respawnTime = 30 * 60000;
salvageTime = 15 * 60000;
// Dynamic properties defined by the scripts
pickupName = "a copper coin";
value = 1;
maxInventory = 20;
};
function Copper::onPickup(%this,%obj,%user,%amount)
{
%count = %obj.count;
if (%count $= "")
if (%this.maxInventory !$= "") {
if (!(%count = %this.maxInventory))
return;
}
else
%count = 1;
%user.incInventory(%this,%count);
if (%user.client)
messageClient(%user.client, 'MsgItemPickup', '\c0You picked up %1', %this.pickupName);
%user.client.money += %this.value;
%scoreString = " $:" @ %client.money;
if (%user.client)
messageClient(%user.client, 'MsgItemPickup', %scoreString, %this.pickupName);
if (%obj.isStatic())
%obj.respawn();
else
%obj.delete();
return true;
}
About the author
#2
06/27/2005 (10:30 am)
I am wondering who defines the argument list since there is no "onpickup" in the C++ codes. How does the script know what each argument is for the callback.
#3
06/27/2005 (10:47 am)
OnPickup is script based on item.cs under server -> scriptsfunction 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;
}
#4
OnCollision works fine.
06/27/2005 (12:05 pm)
Any idea why it fails to trigger when the avatar runs over the objects I created ?OnCollision works fine.
#5
06/27/2005 (3:12 pm)
Gary make sure you make the necessary changes to the player object to make use of the inventory system. add a field to the player datablock called maxinv[name]=50; and add a field to the player object called inv[name]=0; where name is the name of the itemdata datablock.
#6
06/28/2005 (6:00 am)
Thanks................works perfectly !
#7
09/08/2005 (3:44 am)
From where i get kash1.dts
#9
09/08/2005 (9:34 pm)
Is this aviliable with torque engine or i have to create
#10
09/12/2005 (5:41 am)
Use coins.dts from the torque examples
#11
09/12/2005 (10:04 pm)
I have searched torque example but there is nothing like coin.dts can any one provide me that please
Torque 3D Owner Sean H.