Author Topic: /getid that returns the ID, but doesn't message the client?  (Read 846 times)

I want to make a fun script that returns the ID of an object a player is looking at, but I don't want it to message that player.
How can this be done?

The default /getid command looks like this:

Code: serverCmdGetID (26 lines)
function serverCmdGetID(%client)
{
    if(!%client.isAdmin)
        return;

    %player = %client.getControlObject();

    %start = %player.getEyePoint();
    %eyeVec = %player.getEyeVector();
    %vector = VectorScale(%eyeVec, 100);
    %end = VectorAdd(%start, %vector);

    %mask = $TypeMasks::PlayerObjectType | $TypeMasks::StaticShapeObjectType | $TypeMasks::StaticObjectType | $TypeMasks::FxBrickAlwaysObjectType | $TypeMasks::VehicleObjectType;
    %scanTarg = containerRayCast(%start, %end, %mask, %player);

    if(%scanTarg)
    {
        %pos = posFromRaycast(%scanTarg);
        %vec = VectorSub(%pos, %start);
        %dist = VectorLen(%vec);

        %scanObj = getWord(%scanTarg, 0);

        messageClient(%client, '', "objectid = " @ %scanObj @ "  classname = " @ %scanObj.getClassName(); @ " distance = " @ %dist);
    }
}


some more elaboration on the above

all /getid does is shoot off a container raycast in front of the player

to do this, it requires some simple vector math

it basically comes down to two elements: the player's eye point (.getEyePoint(), the position at which the player's 'eyes' are located) and the player's eye vector (.getEyeVector(), a vector3f representing the direction in which the player is looking)

if you've never used containerRayCast before, here's a thread where it's well-explained
(in addition, here's a reference for typemasks and a list of v21 typemasks)

the poopy looks somethin like this:
%eye = %obj.getEyePoint();
%dir = %obj.getEyeVector() //i believe getEyeVector already returns a normalised vector (normalised vector means its length is one w/e)
%add = VectorScale(%dir, %range); //%range will determine how far the raycast goes obv

%ray = containerRayCast(%eye, VectorAdd(%eye, %add), $TypeMasks::sometypehere);

%obj = firstWord(%ray);