How to Mount
by Jason Chadwick · in Torque Game Engine · 07/02/2009 (4:40 am) · 6 replies
I cant figure out how to mountmy object. All I am trying to do is walk into the object and auto mount it.
My object has a mountpoint and the character has a mount0 node.
My code snipet from the object cs file is:
My object has a mountpoint and the character has a mount0 node.
My code snipet from the object cs file is:
datablock ItemData( Machete_A )
{
category = "Weapon";
shapeFile = "~/data/shapes/swords/machete_a.dts";
PickUpName = "Machete";
};
function ItemData::create( %data )
{
echo( "ItemData::create for Machete_A called --------------------------" );
%obj = new Item()
{
dataBlock = %data;
rotate = false;
static = false;
};
return %obj;
}
function Machete_A::onCollision( %this, %obj, %col )
{
echo( "Machete_A::onCollision called ----------------------------------" );
echo ( %this.getName() );
echo ( %obj.getClassName() );
echo ( %col.getClassName() );
%col.mountObject ( %obj , 0 );
// TO DO: Add code here to have the player react to touching the power-up!
}About the author
#2
Yes Its a weapon but I will also be doing the same for armour etc.
So weapons should be an image type mount, but can armour be simply shape?
Can the image mounts still take damage etc? Also I have always been unsure about how to use the inventory system
07/02/2009 (10:28 am)
nothing happens but the echo messages.Yes Its a weapon but I will also be doing the same for armour etc.
So weapons should be an image type mount, but can armour be simply shape?
Can the image mounts still take damage etc? Also I have always been unsure about how to use the inventory system
#3
This will mount an object directly upon pickup if there is no weapon currently equipped.
Where " Weapon:: " is simply the class name you pass into for the datablocks of your weapons.
So in your weapon's datablock you should have.
Armor can be a shape but you will still need to mount it. Although Images might be less expensive in the long run since they don't posses collision meshes and thus do not take a toll on the engine for calculations. However shapes mounted to other shapes do retain their collision meshes. So the Images do not take damage directly from projectiles as they lack a collision mesh.
And .../server/Inventory.cs shows the functions relating to the inventory. Most important to remember is %this is the player handle being passed through and the " ShapeBase:: " simply is inheriting these functions to that namespace. The rest is kind of more self explanatory but if you have any questions feel free to ask.
Hope this helped.
07/04/2009 (1:21 am)
You can find this directly in the starter.fps/server/scripts/weapon.cs file.function Weapon::onPickup(%this, %obj, %shape, %amount)
{
// The parent Item method performs the actual pickup.
// For player's we automatically use the weapon if the
// player does not already have one in hand.
if (Parent::onPickup(%this, %obj, %shape, %amount)) {
serverPlay3D(WeaponPickupSound,%obj.getTransform());
if (%shape.getClassName() $= "Player" &&
%shape.getMountedImage($WeaponSlot) == 0) {
%shape.use(%this);
}
}
}This will mount an object directly upon pickup if there is no weapon currently equipped.
Where " Weapon:: " is simply the class name you pass into for the datablocks of your weapons.
So in your weapon's datablock you should have.
datablock ItemData( Machete_A )
{
//...blah blah blah
// Hook into Item Weapon class hierarchy. The weapon namespace
// provides common weapon handling functions in addition to hooks
// into the inventory system.
className = "Weapon";
//...blah blah blahCheck out weapon.cs it will provide you most of what you need.Armor can be a shape but you will still need to mount it. Although Images might be less expensive in the long run since they don't posses collision meshes and thus do not take a toll on the engine for calculations. However shapes mounted to other shapes do retain their collision meshes. So the Images do not take damage directly from projectiles as they lack a collision mesh.
And .../server/Inventory.cs shows the functions relating to the inventory. Most important to remember is %this is the player handle being passed through and the " ShapeBase:: " simply is inheriting these functions to that namespace. The rest is kind of more self explanatory but if you have any questions feel free to ask.
Hope this helped.
#4
I feel this might set it up right now, but I might be mistaken and it could possibly be the %col where %this is now. Try either and see if that helps. But I would look into the above scripts as well. They will be more useful later on if you make more guns.
07/04/2009 (1:35 am)
Oh but your current script could probably work if you simply switch %col and %obj. Those are in the Incorrect spots I'm assuming. The first parameter is the datablock calling the function. The second parameter of a ::onCollision event is suppose to be the object that collided with the object, and that is the shape that needs to have the mounting applied to it. And the third is the shape we actually hit.echo ( %col.getClassName() );
%obj.mountObject ( %this , 0 );
// TO DO: Add code here to have the player react to touching the power-up!I feel this might set it up right now, but I might be mistaken and it could possibly be the %col where %this is now. Try either and see if that helps. But I would look into the above scripts as well. They will be more useful later on if you make more guns.
#5
I'd try echoing %obj and %col, and checking that these are correct by looking at the object numbers in the editor.
Images are useful for mounting weapons, but have a lot of stuff you don't need for armour and other bits of equipment. Also, while it's fine to use the existing scripts as an inventory system, it's quite simplified, and you can always learn more if you jump into scripting and make your own.
07/04/2009 (5:15 am)
Shane, I thought the second argument was the object that got collided with. %this is of course the datablock (so your script won't work - you can't mount a datablock!) and I thought %obj would be the machete object, and %col is the object that collided with the machete, in this case the Player.I'd try echoing %obj and %col, and checking that these are correct by looking at the object numbers in the editor.
Images are useful for mounting weapons, but have a lot of stuff you don't need for armour and other bits of equipment. Also, while it's fine to use the existing scripts as an inventory system, it's quite simplified, and you can always learn more if you jump into scripting and make your own.
#6
07/05/2009 (7:07 pm)
You're right Daniel, the this is the datablock, I confused my self. But the second parameter is the player handle, and the third is the handle of the object we collided with, that is why I suggested that you should actually switch the %this that I had put in the code with the %col variable instead. Thanks for the catch.
Associate Michael Hall
Distracted...
What does happen when you "collide" with your item? Do you get the echo messages? Is this intended to be a weapon or some sort of accessory such as a backpack?
If you are trying to mount a weapon, then no that will not work. You would need to mount the image instead: