Author Topic: Control what the client is looking at  (Read 1578 times)

I want to make a command where you can look at a vehicle or player and say /takeControl.
I know you could do something like
Code: [Select]
%client.setControlObject(theObjectID);
but how would you make it so that it automatically finds the object ID when just looking at the player/vehicle?
That would also be nice if someone gave me a topic about getting the player's position and how it could be
useful to use.

Thanks

This should help out a bit, try to understand what's going on.

//%this should be a player object

function getObjectInView(%this)
{
      //shoot a raycast
      %o = false;
      %client = %this.client;
      %eyeVector = %this.getEyeVector();
      %eyePoint = %this.getEyePoint();
      //range the raycast will go until it stops
      %range = 100;
      %rangeScale = VectorScale(%eyeVector, %range);
      %rangeEnd = VectorAdd(%eyePoint, %rangeScale);
      %raycast = containerRayCast(%eyePoint,%rangeEnd,$TypeMasks::FxBrickObjectType | $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::ItemObjectType , %this);
      %o = getWord(%raycast,0);
      
      
      return %o;
}

What is getEyeVector and getEyePoint? I think I have an idea of what they are but someone explain just in case.

What is getEyeVector and getEyePoint? I think I have an idea of what they are but someone explain just in case.
They do exactly what the function name says they do

What is getEyeVector and getEyePoint? I think I have an idea of what they are but someone explain just in case.
Geteyevector returns a vector, with length of 1, in the direction the player is looking
Geteyepoint returns a position where the players eye is located

This should help out a bit, try to understand what's going on.

//%this should be a player object

function getObjectInView(%this)
{
      //shoot a raycast
      %o = false;
      %client = %this.client;
      %eyeVector = %this.getEyeVector();
      %eyePoint = %this.getEyePoint();
      //range the raycast will go until it stops
      %range = 100;
      %rangeScale = VectorScale(%eyeVector, %range);
      %rangeEnd = VectorAdd(%eyePoint, %rangeScale);
      %raycast = containerRayCast(%eyePoint,%rangeEnd,$TypeMasks::FxBrickObjectType | $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::PlayerObjectType | $TypeMasks::ItemObjectType , %this);
      %o = getWord(%raycast,0);
      
      
      return %o;
}


Isn't that just a bit overcomplicated, though?

function ShapeBase::getEyeObject(%this, %range, %masks) {
   %point = %this.getEyePoint();
   return getWord(containerRayCast(%point, vectorAdd(%point, vectorScale(%this.getEyeVector(), %range)), %masks, %this), 0);
}


Or, for improving readability:

function ShapeBase::getEyeObject(%this, %range, %masks) {
   %point = %this.getEyePoint();
   %vector = %this.getEyeVector();

   %path = vectorScale(%vector, %range);
   %stop = vectorAdd(%point, %path);

   %ray = containerRayCast(%point, %stop, %masks, %this);
   return getWord(%ray, 0);
}
« Last Edit: September 26, 2013, 01:13:29 PM by Port »

Isn't that just a bit overcomplicated, though?

function ShapeBase::getEyeObject(%this, %range, %masks) {
   %point = %this.getEyePoint();
   return getWord(containerRayCast(%point, vectorAdd(%point, vectorScale(%this.getEyeVector(), %range)), %masks, %this), 0);
}


Or, for improving readability:

function ShapeBase::getEyeObject(%this, %range, %masks) {
   %point = %this.getEyePoint();
   %vector = %this.getEyePoint();

   %path = vectorScale(%vector, %range);
   %stop = vectorAdd(%point, %path);

   %ray = containerRayCast(%point, %stop, %masks, %this);
   return getWord(%ray, 0);
}

Is it that when you do the function, does it already know what %this, %range, %masks is?
And why do %point and %vector need to be the same thing?

Is it that when you do the function, does it already know what %this, %range, %masks is?
And why do %point and %vector need to be the same thing?

Oops, %vector should be %this.getEyeVector().

So now, to make it so that I can control, would I do something like:

%target = getWord(%ray);
%this.setControlObject(%target);

So now, to make it so that I can control, would I do something like:

%target = getWord(%ray);
%this.setControlObject(%target);


Yep. You can only control certain objects though - like players and vehicles.