Can I modify this to place items here and there
by Charlie Higdon · in Torque Game Engine · 06/28/2008 (1:14 pm) · 12 replies
I played Starsiege Tribes for a number of years. I started back playing it a few weeks ago once I discovered a new masterserver IP hosted by the community.
I am having no end of trouble trying to create an item I can place where ever I so happen to desire. I noticed the camera item in Tribes can be placed on walls, terrain, ceilings, floors, etc. It has collision, which the item I want to place also has. It can be stood upon, if you place enough of them in the doorway they can block a player til you destroy them, all kinds of uses. This is the script from item.cs in Tribes
ItemImageData CameraPackImage
{
shapeFile = "camera";
mountPoint = 2;
mountOffset = { 0, -0.1, -0.06 };
mountRotation = { 0, 0, 0 };
firstPerson = false;
};
ItemData CameraPack
{
description = "Camera";
shapeFile = "camera";
className = "Backpack";
heading = "dDeployables";
imageType = CameraPackImage;
shadowDetailMask = 4;
mass = 2.0;
elasticity = 0.2;
price = 100;
hudIcon = "deployable";
showWeaponBar = true;
hiliteOnActive = true;
validateShape = true;
validateMaterials = true;
};
function CameraPack::onUse(%player,%item)
{
if (Player::getMountedItem(%player,$BackpackSlot) != %item) {
Player::mountItem(%player,%item,$BackpackSlot);
}
else {
Player::deployItem(%player,%item);
}
}
function CameraPack::onDeploy(%player,%item,%pos)
{
if (CameraPack::deployShape(%player,%item)) {
Player::decItemCount(%player,%item);
}
}
function CameraPack::deployShape(%player,%item)
{
%client = Player::getClient(%player);
if($TeamItemCount[GameBase::getTeam(%player) @ %item] < $TeamItemMax[%item]) {
if (GameBase::getLOSInfo(%player,3)) {
// GetLOSInfo sets the following globals:
// los::position
// los::normal
// los::object
%obj = getObjectType($los::object);
if (%obj == "SimTerrain" || %obj == "InteriorShape") {
// Try to stick it straight up or down, otherwise
// just use the surface normal
%prot = GameBase::getRotation(%player);
%zRot = getWord(%prot,2);
if (Vector::dot($los::normal,"0 0 1") > 0.6) {
%rot = "0 0 " @ %zRot;
}
else {
if (Vector::dot($los::normal,"0 0 -1") > 0.6) {
%rot = "3.14159 0 " @ %zRot;
}
else {
%rot = Vector::getRotation($los::normal);
}
}
if(checkDeployArea(%client,$los::position)) {
%camera = newObject("Camera","Turret",CameraTurret,true);
addToSet("MissionCleanup", %camera);
GameBase::setTeam(%camera,GameBase::getTeam(%player));
GameBase::setRotation(%camera,%rot);
GameBase::setPosition(%camera,$los::position);
Gamebase::setMapName(%camera,"Camera#"@ $totalNumCameras++ @ " " @ Client::getName(%client));
Client::sendMessage(%client,0,"Camera deployed");
playSound(SoundPickupBackpack,$los::position);
$TeamItemCount[GameBase::getTeam(%camera) @ "CameraPack"]++;
echo("MSG: ",%client," deployed a Camera");
return true;
}
}
else {
Client::sendMessage(%client,0,"Can only deploy on terrain or buildings");
}
}
else {
Client::sendMessage(%client,0,"Deploy position out of range");
}
}
else
Client::sendMessage(%client,0,"Deployable Item limit reached for " @ %item.description @ "s");
return false;
}
Besides renaming the "camera" to whatever my item name is, and changing the shapefile, would anyone have any idea what else I would need to change?
I am having no end of trouble trying to create an item I can place where ever I so happen to desire. I noticed the camera item in Tribes can be placed on walls, terrain, ceilings, floors, etc. It has collision, which the item I want to place also has. It can be stood upon, if you place enough of them in the doorway they can block a player til you destroy them, all kinds of uses. This is the script from item.cs in Tribes
ItemImageData CameraPackImage
{
shapeFile = "camera";
mountPoint = 2;
mountOffset = { 0, -0.1, -0.06 };
mountRotation = { 0, 0, 0 };
firstPerson = false;
};
ItemData CameraPack
{
description = "Camera";
shapeFile = "camera";
className = "Backpack";
heading = "dDeployables";
imageType = CameraPackImage;
shadowDetailMask = 4;
mass = 2.0;
elasticity = 0.2;
price = 100;
hudIcon = "deployable";
showWeaponBar = true;
hiliteOnActive = true;
validateShape = true;
validateMaterials = true;
};
function CameraPack::onUse(%player,%item)
{
if (Player::getMountedItem(%player,$BackpackSlot) != %item) {
Player::mountItem(%player,%item,$BackpackSlot);
}
else {
Player::deployItem(%player,%item);
}
}
function CameraPack::onDeploy(%player,%item,%pos)
{
if (CameraPack::deployShape(%player,%item)) {
Player::decItemCount(%player,%item);
}
}
function CameraPack::deployShape(%player,%item)
{
%client = Player::getClient(%player);
if($TeamItemCount[GameBase::getTeam(%player) @ %item] < $TeamItemMax[%item]) {
if (GameBase::getLOSInfo(%player,3)) {
// GetLOSInfo sets the following globals:
// los::position
// los::normal
// los::object
%obj = getObjectType($los::object);
if (%obj == "SimTerrain" || %obj == "InteriorShape") {
// Try to stick it straight up or down, otherwise
// just use the surface normal
%prot = GameBase::getRotation(%player);
%zRot = getWord(%prot,2);
if (Vector::dot($los::normal,"0 0 1") > 0.6) {
%rot = "0 0 " @ %zRot;
}
else {
if (Vector::dot($los::normal,"0 0 -1") > 0.6) {
%rot = "3.14159 0 " @ %zRot;
}
else {
%rot = Vector::getRotation($los::normal);
}
}
if(checkDeployArea(%client,$los::position)) {
%camera = newObject("Camera","Turret",CameraTurret,true);
addToSet("MissionCleanup", %camera);
GameBase::setTeam(%camera,GameBase::getTeam(%player));
GameBase::setRotation(%camera,%rot);
GameBase::setPosition(%camera,$los::position);
Gamebase::setMapName(%camera,"Camera#"@ $totalNumCameras++ @ " " @ Client::getName(%client));
Client::sendMessage(%client,0,"Camera deployed");
playSound(SoundPickupBackpack,$los::position);
$TeamItemCount[GameBase::getTeam(%camera) @ "CameraPack"]++;
echo("MSG: ",%client," deployed a Camera");
return true;
}
}
else {
Client::sendMessage(%client,0,"Can only deploy on terrain or buildings");
}
}
else {
Client::sendMessage(%client,0,"Deploy position out of range");
}
}
else
Client::sendMessage(%client,0,"Deployable Item limit reached for " @ %item.description @ "s");
return false;
}
Besides renaming the "camera" to whatever my item name is, and changing the shapefile, would anyone have any idea what else I would need to change?
About the author
#2
I just picked a shape at random from the dts files in starter.fps. I decided to use boulder just simply for the sheer size of it. This is what I had.
//named it test just for testing purposes
datablock ItemData(test)
{
description = "testitem";
shapeFile = "~/data/shapes/rocks/boulder.dts";
category = "Test";
mass = 2.0;
elasticity = 0.2;
};
// commented out a lot on the $backpackslot because i was unsure what to substitute that with,
//using starter.fps
function Test::onUse(%player,%item)
{
// if (Player::getMountedItem(%player,$BackpackSlot) != %item) {
// Player::mountItem(%player,%item,$BackpackSlot);
// }
// else {
%user.decInventory(%this,1);
Player::deployItem(%player,%item);
// }
}
function Test::onDeploy(%player,%item,%pos)
{
if (Test::deployShape(%player,%item)) {
Player::decItemCount(%player,%item);
}
}
function Test::deployShape(%player,%item)
{
%client = Player::getClient(%player);
if($TeamItemCount[GameBase::getTeam(%player) @ %item] < $TeamItemMax[%item]) {
if (GameBase::getLOSInfo(%player,3)) {
// GetLOSInfo sets the following globals:
// los::position
// los::normal
// los::object
%obj = getObjectType($los::object);
if (%obj == "SimTerrain" || %obj == "InteriorShape") {
// Try to stick it straight up or down, otherwise
// just use the surface normal
%prot = GameBase::getRotation(%player);
%zRot = getWord(%prot,2);
if (Vector::dot($los::normal,"0 0 1") > 0.6) {
%rot = "0 0 " @ %zRot;
}
else {
if (Vector::dot($los::normal,"0 0 -1") > 0.6) {
%rot = "3.14159 0 " @ %zRot;
}
else {
%rot = Vector::getRotation($los::normal);
}
}
if(checkDeployArea(%client,$los::position)) {
%camera = newObject("Test", CameraTurret,true);
addToSet("MissionCleanup", %camera);
GameBase::setTeam(%camera,GameBase::getTeam(%player));
GameBase::setRotation(%camera,%rot);
GameBase::setPosition(%camera,$los::position);
Gamebase::setMapName(%camera,"Camera#"@ $totalNumTests++ @ " " @ Client::getName(%client));
Client::sendMessage(%client,0,"Test deployed");
playSound(SoundPickupBackpack,$los::position);
$TeamItemCount[GameBase::getTeam(%camera) @ "CameraPack"]++;
echo("MSG: ",%client," deployed a Camera");
return true;
}
}
else {
Client::sendMessage(%client,0,"Can only deploy on terrain or buildings");
}
}
else {
Client::sendMessage(%client,0,"Deploy position out of range");
}
}
else
Client::sendMessage(%client,0,"Deployable Item limit reached for " @ %item.description @ "s");
return false;
}
That's how my script looks so far. The item shows up under the "shapes" category in world editor, I can spawn it, and it is the boulder. I can pick it up. When I try to use it, (just sat "B" as the use in default.bind.cs), it says unable to find "function Test::deployItem" in the console. I am sure there is alot at the bottom I need to change as well. Had a lot of trouble, my company went out of business, having to sue them for months of pay. Having a hard time concentrating on this at the moment.
06/28/2008 (2:15 pm)
I'm having trouble with the whole thing sadly.I just picked a shape at random from the dts files in starter.fps. I decided to use boulder just simply for the sheer size of it. This is what I had.
//named it test just for testing purposes
datablock ItemData(test)
{
description = "testitem";
shapeFile = "~/data/shapes/rocks/boulder.dts";
category = "Test";
mass = 2.0;
elasticity = 0.2;
};
// commented out a lot on the $backpackslot because i was unsure what to substitute that with,
//using starter.fps
function Test::onUse(%player,%item)
{
// if (Player::getMountedItem(%player,$BackpackSlot) != %item) {
// Player::mountItem(%player,%item,$BackpackSlot);
// }
// else {
%user.decInventory(%this,1);
Player::deployItem(%player,%item);
// }
}
function Test::onDeploy(%player,%item,%pos)
{
if (Test::deployShape(%player,%item)) {
Player::decItemCount(%player,%item);
}
}
function Test::deployShape(%player,%item)
{
%client = Player::getClient(%player);
if($TeamItemCount[GameBase::getTeam(%player) @ %item] < $TeamItemMax[%item]) {
if (GameBase::getLOSInfo(%player,3)) {
// GetLOSInfo sets the following globals:
// los::position
// los::normal
// los::object
%obj = getObjectType($los::object);
if (%obj == "SimTerrain" || %obj == "InteriorShape") {
// Try to stick it straight up or down, otherwise
// just use the surface normal
%prot = GameBase::getRotation(%player);
%zRot = getWord(%prot,2);
if (Vector::dot($los::normal,"0 0 1") > 0.6) {
%rot = "0 0 " @ %zRot;
}
else {
if (Vector::dot($los::normal,"0 0 -1") > 0.6) {
%rot = "3.14159 0 " @ %zRot;
}
else {
%rot = Vector::getRotation($los::normal);
}
}
if(checkDeployArea(%client,$los::position)) {
%camera = newObject("Test", CameraTurret,true);
addToSet("MissionCleanup", %camera);
GameBase::setTeam(%camera,GameBase::getTeam(%player));
GameBase::setRotation(%camera,%rot);
GameBase::setPosition(%camera,$los::position);
Gamebase::setMapName(%camera,"Camera#"@ $totalNumTests++ @ " " @ Client::getName(%client));
Client::sendMessage(%client,0,"Test deployed");
playSound(SoundPickupBackpack,$los::position);
$TeamItemCount[GameBase::getTeam(%camera) @ "CameraPack"]++;
echo("MSG: ",%client," deployed a Camera");
return true;
}
}
else {
Client::sendMessage(%client,0,"Can only deploy on terrain or buildings");
}
}
else {
Client::sendMessage(%client,0,"Deploy position out of range");
}
}
else
Client::sendMessage(%client,0,"Deployable Item limit reached for " @ %item.description @ "s");
return false;
}
That's how my script looks so far. The item shows up under the "shapes" category in world editor, I can spawn it, and it is the boulder. I can pick it up. When I try to use it, (just sat "B" as the use in default.bind.cs), it says unable to find "function Test::deployItem" in the console. I am sure there is alot at the bottom I need to change as well. Had a lot of trouble, my company went out of business, having to sue them for months of pay. Having a hard time concentrating on this at the moment.
#3
function Test::deployItem
and you script has a function called
function Test::deployShape
I'll check for more...
(sorry, I'm doing this on a cell phone, not a computer, so it takes a little time...)
Tony
06/29/2008 (11:19 am)
Well, the first thing I see is that the console is looking for a function calledfunction Test::deployItem
and you script has a function called
function Test::deployShape
I'll check for more...
(sorry, I'm doing this on a cell phone, not a computer, so it takes a little time...)
Tony
#4
As it stands the basic idea will still carry over. However you will need to make some of those calls conform to Torque specific standards.
A few will have to be written in to have that functionality.
But don't give! It can be done. You'll need to look at how other items, itemData, itemImages, and static shapes are defined. Look at how the "new" method works. Cameras in tribes were technically treated as turrets that didn't shoot so also check out the turret resources located Here and Here.
06/29/2008 (12:05 pm)
Infinitum caught the first major error as far as the functionTest::deployItem call versus the actual function named funtionTest::deployShape. As it stands the basic idea will still carry over. However you will need to make some of those calls conform to Torque specific standards.
decItemCount getObjectType addToSet GameBase::setRotation GameBase::setPosition playSoundNone of those will work as worded but most of them have similar functions in Torque.
A few will have to be written in to have that functionality.
GameBase::getLOSInfo checkDeployArea GameBase::getTeam GameBase::setTeam Gamebase::setMapName Client::sendMessage
But don't give! It can be done. You'll need to look at how other items, itemData, itemImages, and static shapes are defined. Look at how the "new" method works. Cameras in tribes were technically treated as turrets that didn't shoot so also check out the turret resources located Here and Here.
#5
datablock ItemData(Test)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Test";
// Basic Item properties
shapeFile = "~/data/shapes/rocks/boulder.dts";
mass = 2.0;
elasticity = 0.2;
// Dynamic properties defined by the scripts
pickUpName = "test item";
};
function Test::onUse(%this,%user)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Test Used');
}
That works, as far as picking up an item that I placed using the in game editor. It shows up in a category named test, with an item named test. It rotates just like all the other items. I pick it up and it adds to inventory. I press the key I randomly chose to be the "USE" key, and the item disappears from inventory.
I capped maxinventory at 1. I have 2 of them on the map, and I am unable to pick up the second til I use the first. Of course using it at the moment does nothing but remove it from inventory.
I am still learning this, new to all of it. My thinking is, I should add a command in the "function Test::onUse(%this,%user)" function telling it to place the item where my cursor is, if within a certain distance.
This is what is confusing me, I was trying to pull that particular part of the script from the camera script in Tribes. I suppose I could have chosen an inventory station and what not, it was just that they don't mount to ceilings and walls. I feel so stupid, I've been at this for weeks.
06/29/2008 (12:52 pm)
I'm not wanting to make a camera exactly, or really any kind of controllable object. This is what I've done so far. I tried starting over.datablock ItemData(Test)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Test";
// Basic Item properties
shapeFile = "~/data/shapes/rocks/boulder.dts";
mass = 2.0;
elasticity = 0.2;
// Dynamic properties defined by the scripts
pickUpName = "test item";
};
function Test::onUse(%this,%user)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Test Used');
}
That works, as far as picking up an item that I placed using the in game editor. It shows up in a category named test, with an item named test. It rotates just like all the other items. I pick it up and it adds to inventory. I press the key I randomly chose to be the "USE" key, and the item disappears from inventory.
I capped maxinventory at 1. I have 2 of them on the map, and I am unable to pick up the second til I use the first. Of course using it at the moment does nothing but remove it from inventory.
I am still learning this, new to all of it. My thinking is, I should add a command in the "function Test::onUse(%this,%user)" function telling it to place the item where my cursor is, if within a certain distance.
This is what is confusing me, I was trying to pull that particular part of the script from the camera script in Tribes. I suppose I could have chosen an inventory station and what not, it was just that they don't mount to ceilings and walls. I feel so stupid, I've been at this for weeks.
#6
datablock ItemData(Test)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Test";
// Basic Item properties
shapeFile = "~/data/shapes/rocks/boulder.dts";
mass = 2.0;
elasticity = 0.2;
// Dynamic properties defined by the scripts
pickUpName = "a test";
};
datablock StaticShapeData(Test2)
{
shapeFile = "~/data/shapes/rocks/boulder.dts";
};
function Test::onUse(%this,%user)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
new Staticshape(Test) {
datablock = "Test2";
position = LocalClientConnection.camera.getPosition();
};
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Test Used');
}
This places the item in game, it's a solid item just like I had hoped. The only problem I have now is...it ONLY places them at my spawn point, and about a foot off the ground. If I pick up another, it'll place it inside the one I just placed, over and over each time.
Feel so silly, but excited I got that far.
06/29/2008 (1:25 pm)
WOW!! Ok, I made a little progress.datablock ItemData(Test)
{
// Mission editor category, this datablock will show up in the
// specified category under the "shapes" root category.
category = "Test";
// Basic Item properties
shapeFile = "~/data/shapes/rocks/boulder.dts";
mass = 2.0;
elasticity = 0.2;
// Dynamic properties defined by the scripts
pickUpName = "a test";
};
datablock StaticShapeData(Test2)
{
shapeFile = "~/data/shapes/rocks/boulder.dts";
};
function Test::onUse(%this,%user)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
new Staticshape(Test) {
datablock = "Test2";
position = LocalClientConnection.camera.getPosition();
};
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Test Used');
}
This places the item in game, it's a solid item just like I had hoped. The only problem I have now is...it ONLY places them at my spawn point, and about a foot off the ground. If I pick up another, it'll place it inside the one I just placed, over and over each time.
Feel so silly, but excited I got that far.
#7
You're using camera.getPosition. The camera is still at your spawn point (Alt-C)
You need to use something like
player.getPosition (maybe???)
Thanks for this. I plan on using it :)
Tony
06/29/2008 (2:23 pm)
Charlie,You're using camera.getPosition. The camera is still at your spawn point (Alt-C)
You need to use something like
player.getPosition (maybe???)
Thanks for this. I plan on using it :)
Tony
#8
"position = LocalClientConnection.camera.getPosition();" line from
http://tdn.garagegames.com/wiki/Torque/Script/Tutorials/Using_Basic_AI_Commands
Let the Fun Begin!
Welcome !!!!!!!!!
First, let's actually spawn a bot. Copy the following line of code into the text input field at the bottom of the console window and hit enter:
new AIPlayer(Bob) { datablock = "PlayerBody"; position = LocalClientConnection.camera.getPosition(); };
I guess I didn't read it correctly. I see where it says fly around with the camera and do this.
So how do I raycast and put at item where the raycast hits. I realize I need a start and an end, and to specify what masks. I want to place the item where the cursor or crosshair is, if within say, 5 meters.
How do I do that? How do I tell it when it hits something to place an object. Please someone spare me the agony. This is making me nuts. It has to be doable, you can do it in the World Creator. There should be some line of script somewhere that tells you how to place an item at the exact place you are looking.
***EDIT***
I tried this, as you can see I am a total moron. I get an "unable to find object, attempting to call function" in the console for the .getworldbox, and .getfowardvector.
I really hope someone takes pity on me. I've been at this the entire day.
function Test::onUse(%this,%user,%client)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
%player = %client.player;
%startPosition = %player.getWorldBoxCenter();
%forwardVector = %player.getForwardVector();
%endPosition = VectorScale( %forwardVector , 10 );
%endPosition = VectorAdd( %startPosition, %endPosition );
%hitObject = containerRayCast( %startPosition ,
%endPosition, -1 , %player );
if (%hitObject = 1)
new Staticshape(Test) {
datablock = "Test2";
//position = LocalClientConnection.camera.getTransform();
//position = LocalClientConnection.camera.getPosition();
//position = LocalClientConnection.getEyeTransform();
};
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Test Used');
}
06/29/2008 (6:03 pm)
I can't make sense of how to use that properly. A raycast maybe? I don't know how to set one up that would place the object where it casts to. I read the "position = LocalClientConnection.camera.getPosition();" line from
http://tdn.garagegames.com/wiki/Torque/Script/Tutorials/Using_Basic_AI_Commands
Let the Fun Begin!
Welcome !!!!!!!!!
First, let's actually spawn a bot. Copy the following line of code into the text input field at the bottom of the console window and hit enter:
new AIPlayer(Bob) { datablock = "PlayerBody"; position = LocalClientConnection.camera.getPosition(); };
I guess I didn't read it correctly. I see where it says fly around with the camera and do this.
So how do I raycast and put at item where the raycast hits. I realize I need a start and an end, and to specify what masks. I want to place the item where the cursor or crosshair is, if within say, 5 meters.
How do I do that? How do I tell it when it hits something to place an object. Please someone spare me the agony. This is making me nuts. It has to be doable, you can do it in the World Creator. There should be some line of script somewhere that tells you how to place an item at the exact place you are looking.
***EDIT***
I tried this, as you can see I am a total moron. I get an "unable to find object, attempting to call function" in the console for the .getworldbox, and .getfowardvector.
I really hope someone takes pity on me. I've been at this the entire day.
function Test::onUse(%this,%user,%client)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
%player = %client.player;
%startPosition = %player.getWorldBoxCenter();
%forwardVector = %player.getForwardVector();
%endPosition = VectorScale( %forwardVector , 10 );
%endPosition = VectorAdd( %startPosition, %endPosition );
%hitObject = containerRayCast( %startPosition ,
%endPosition, -1 , %player );
if (%hitObject = 1)
new Staticshape(Test) {
datablock = "Test2";
//position = LocalClientConnection.camera.getTransform();
//position = LocalClientConnection.camera.getPosition();
//position = LocalClientConnection.getEyeTransform();
};
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Test Used');
}
#9
position=player.getTransform()
because Transform includes position AND rotation
the Y coordinate is in front of the player, so we need to add 1 torque unit to the Y coordinate so that the object is placed in front of the player... or subtract 1 torque unit?
we need something like
function serverCmdPlacementRay(%client)
{
%StartPos=%client.player.gettransform();
%Eye=%client.player.getEyeVector();
%EndPos=vectorScale(%Eye, -1);
%EndPos=vectorsub(%StartPosn %EndPos);
}
That's from the RpgDialog resource.
I also found this
http://tdn.garagegames.com/wiki/TorqueScript_Console_Functions_16
It explains the syntax behind Raycast and Container Searches.
Tony
06/30/2008 (11:41 am)
OK, tryposition=player.getTransform()
because Transform includes position AND rotation
the Y coordinate is in front of the player, so we need to add 1 torque unit to the Y coordinate so that the object is placed in front of the player... or subtract 1 torque unit?
we need something like
function serverCmdPlacementRay(%client)
{
%StartPos=%client.player.gettransform();
%Eye=%client.player.getEyeVector();
%EndPos=vectorScale(%Eye, -1);
%EndPos=vectorsub(%StartPosn %EndPos);
}
That's from the RpgDialog resource.
I also found this
http://tdn.garagegames.com/wiki/TorqueScript_Console_Functions_16
It explains the syntax behind Raycast and Container Searches.
Tony
#10
I feel so frickin stupid.
06/30/2008 (5:53 pm)
I tried both, I guess I'm just to much of a retard for script, and need to stick to modelling objects. I looked over the Console Functions Wiki, i understand bascially how the syntax goes, but I don't understand how to actually put the raycast into a use function that'll take the coordinates it gets and put the item there. I feel so frickin stupid.
#11
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
%player = %this;
%eye = %player.getEyeVector();
%vec = vectorScale(%vec, %distance);
//Get the starting position for the raycast
%startPoint = %player.getEyeTransform();
//This should be the ending position for the raycast
%endPoint = VectorAdd(%startPoint,%vec);
//Echo out the positions
echo("StartPoint = " + %startpoint);
echo("EndPoint = " + %endpoint);
//%startPosition = %player.getWorldBoxCenter();
//%forwardVector = %player.getForwardVector();
//%endPosition = VectorScale( %forwardVector , 10 );
//%endPosition = VectorAdd( %startPosition, %endPosition );
//%info = ContainerRayCast(%startPosition, %endPosition, -1, %player);
new Staticshape(Test) {
datablock = "Test2";
//position = Steve.getTransform();
position = %endPoint;
//position = LocalClientConnection.camera.getTransform();
//position = LocalClientConnection.camera.getPosition();
//position = %endPosition();
};
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Lumber Used');
}
As you can see I have tried lots of things, and commented out lots of things. It sort of works now. I can pick up the item, and use it. It places the TEST item , at what appears to be my avatar's center.
It echoes back the same start and end location.
It does not decrease in inventory. I can run around pressing B, making dozens of copies, even leaving them in the air. Perhaps that is useful for someone as is? I however want it to be placed where my crosshairs are, within say "arm's reach" if the raycast hits anything.
Any suggestions? I am unsure how I got lucky enough to get anything to work.
***EDIT***
Well, this works. Now all I have to do is:
1.Model the actual object I want to use.(np there)
2.Get the object to stick to interior surfaces without sticking INTO the wall, and rotated correctly.
Here is what I came up with. It allows me to place the object the distance within and up to the distance I sat.
function Lumber::onUse(%obj,%this,%user,%player)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
//STILL SORTING OUT THE MASKS, WHAT TO USE AND WHAT NOT TO USE, AND HOW TO SPECIFY.
//ALSO HAVE TO FIGURE OUT HOW TO ROTATE AND PLACE ITEM PROPERLY(I.E., NOT INSIDE OBJECTS)
{
%player = %this;
%eye = %player.getEyeVector();
//Get the starting position for the raycast
%startPoint = %player.getEyeTransform();
//This should be the ending position for the raycast
%endPoint = vectorScale(%eye, 20 );
%endPoint = vectorAdd(%startPoint,%endPoint);
//Echo out the positions
echo("StartPoint = " + %startpoint);
echo("EndPoint = " + %endpoint);
new Staticshape(Test) {
datablock = "Test2";
position = %endPoint;
};
// this needs work, I can't get inventory to decline for this item
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Lumber Used');
}
**I hope this helps someone**
06/30/2008 (9:57 pm)
Function Test::onUse(%obj,%this,%user,%player,%distance)//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
{
%player = %this;
%eye = %player.getEyeVector();
%vec = vectorScale(%vec, %distance);
//Get the starting position for the raycast
%startPoint = %player.getEyeTransform();
//This should be the ending position for the raycast
%endPoint = VectorAdd(%startPoint,%vec);
//Echo out the positions
echo("StartPoint = " + %startpoint);
echo("EndPoint = " + %endpoint);
//%startPosition = %player.getWorldBoxCenter();
//%forwardVector = %player.getForwardVector();
//%endPosition = VectorScale( %forwardVector , 10 );
//%endPosition = VectorAdd( %startPosition, %endPosition );
//%info = ContainerRayCast(%startPosition, %endPosition, -1, %player);
new Staticshape(Test) {
datablock = "Test2";
//position = Steve.getTransform();
position = %endPoint;
//position = LocalClientConnection.camera.getTransform();
//position = LocalClientConnection.camera.getPosition();
//position = %endPosition();
};
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Lumber Used');
}
As you can see I have tried lots of things, and commented out lots of things. It sort of works now. I can pick up the item, and use it. It places the TEST item , at what appears to be my avatar's center.
It echoes back the same start and end location.
It does not decrease in inventory. I can run around pressing B, making dozens of copies, even leaving them in the air. Perhaps that is useful for someone as is? I however want it to be placed where my crosshairs are, within say "arm's reach" if the raycast hits anything.
Any suggestions? I am unsure how I got lucky enough to get anything to work.
***EDIT***
Well, this works. Now all I have to do is:
1.Model the actual object I want to use.(np there)
2.Get the object to stick to interior surfaces without sticking INTO the wall, and rotated correctly.
Here is what I came up with. It allows me to place the object the distance within and up to the distance I sat.
function Lumber::onUse(%obj,%this,%user,%player)
//On use, place this item at the location the player's crosshair is at
//as long as it is in range and not on a vehicle, another player, or water.
//STILL SORTING OUT THE MASKS, WHAT TO USE AND WHAT NOT TO USE, AND HOW TO SPECIFY.
//ALSO HAVE TO FIGURE OUT HOW TO ROTATE AND PLACE ITEM PROPERLY(I.E., NOT INSIDE OBJECTS)
{
%player = %this;
%eye = %player.getEyeVector();
//Get the starting position for the raycast
%startPoint = %player.getEyeTransform();
//This should be the ending position for the raycast
%endPoint = vectorScale(%eye, 20 );
%endPoint = vectorAdd(%startPoint,%endPoint);
//Echo out the positions
echo("StartPoint = " + %startpoint);
echo("EndPoint = " + %endpoint);
new Staticshape(Test) {
datablock = "Test2";
position = %endPoint;
};
// this needs work, I can't get inventory to decline for this item
%user.decInventory(%this,1);
if (%user.client)
messageClient(%user.client, 'Lumber Used');
}
**I hope this helps someone**
#12
You're doing great! I started out as a modeller also, so programming/scripting does not come easily to me, either.
But you've made great progress here. Don't get discouraged. I've owned the engine for two and a half years and you're doing just as well as I am.
One thing I notice, for decreasing inventory, instead of 1, try -- "minus minus" just like you used ++ to increase by one, -- should decrease by 1.
Tony
07/02/2008 (3:55 am)
Charlie, You're doing great! I started out as a modeller also, so programming/scripting does not come easily to me, either.
But you've made great progress here. Don't get discouraged. I've owned the engine for two and a half years and you're doing just as well as I am.
One thing I notice, for decreasing inventory, instead of 1, try -- "minus minus" just like you used ++ to increase by one, -- should decrease by 1.
Tony
Torque Owner Infinitum3D
Are there any console errors?
A few more details will help.
Thanks!
Tony