Author Topic: servercmdSelectObject  (Read 1609 times)

I'm trying to make a function that returns an object which is directly or within a few Torque Units of your camera. I've copied part of the code below from Return to Blockland, and it seems to be a generic Torque function. I edited it slightly as I don't have access to a client's GUI functions and whether a client clicked something or not, so I'm using getEyeVector/Point:
Code: [Select]
function serverCmdSelectObject(%client)
{
   // mouseVec = vector from camera point to 3d mouse coords (normalized)
   %mouseVec = %client.player.getEyeVector();
   // cameraPoint = the world position of the camera
   %cameraPoint = %client.player.getEyePoint();
   messageclient(%client,"","%cameraPoint = " @ %cameraPoint);
   messageclient(%client,"","Transform = " @ %client.player.getTransform());
   //Determine how far should the picking ray extend into the world?
   %selectRange = 2;
   // scale mouseVec to the range the player is able to select with mouse
   %mouseScaled = VectorScale(%mouseVec, %selectRange);
   // cameraPoint = the world position of the camera
   // rangeEnd = camera point + length of selectable range
   %rangeEnd = VectorAdd(%cameraPoint, %mouseScaled);

   // Search for anything that is selectable – below are some examples
   %searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::CorpseObjectType |
      $TypeMasks::ItemObjectType | $TypeMasks::TriggerObjectType;

   // Search for objects within the range that fit the masks above
   // If we are in first person mode, we make sure player is not selectable by setting fourth parameter (exempt
   // from collisions) when calling ContainerRayCast
   %player = %client.player;
   if ($firstPerson)
   {
  %scanTarg = ContainerRayCast (%cameraPoint, %rangeEnd, %searchMasks, %player);
   }
   else //3rd person - player is selectable in this case
   {
  %scanTarg = ContainerRayCast (%cameraPoint, %rangeEnd, %searchMasks);
   }

   // a target in range was found so select it
   messageclient(%client,"","%scanTarg = " @ %scanTarg);
   if (%scanTarg)
   {
      %targetObject = firstWord(%scanTarg);

      messageclient(%client,"",%targetObject);
   }
   messageclient(%client,"","Done");
}

The code seems to return when I am looking at a clone of myself (the only bot availiable right now made with %client.createPlayer();) but not when I look at an interior, brick, item or any vehicle other than a Horse - a player 'Armour' object. How, in particular, would I get it to return on the Item or Brick?

EDIT: Also, does Torque have arrays, and if yes, what syntax do you use to make them work?
« Last Edit: May 06, 2007, 10:35:57 AM by Space Guy »

I think badspot's "editor" for blockland retail does somthing like this.

You need to set searchmasks as this will determine what the raycast can "see" as it were.

Code: [Select]
%searchMasks = $TypeMasks::PlayerObjectType | $TypeMasks::CorpseObjectType | $TypeMasks::ItemObjectType | $TypeMasks::TriggerObjectType | $TypeMasks::InteriorObjectType | $TypeMasks::ShapeBaseObjectType;
Bricks can be found using $TypeMasks::FXBrickObjectType, and should be put into the string above separated by a | thing.

As for arrays, you can do them simply by doing %variable[%number] = "cow"; and supposing %number was 4, then %variable4 = cow. As for multidimensional arrays, I have no idea. I've never used one.

%variable4 or %variable[4]? If it's the first, what if I had defined both %variable and %variable4, then typed %variable[4] = "...";? I think multidimensional arrays can just use [across+down*rowwidth].

Thanks about the FXBrick thing, though. I wasn't sure exactly what name to use.

%variable[%i++] in a loop would set %variable1,%variable2,%variable3 for as many times as the loop or w/e is run.

%variable4 would be used to return the value set.

Thanks. Having 1d- and 2d-arrays will be useful to me, a lot.