Author Topic: Raycast's  (Read 2293 times)

Can someone explain to me the basics of a raycast? Also, a fix would be helpful for the following code, this was my attempt at a raycast.

Code: [Select]
function serverCmdClientInfoDisplay(%client)
{
%eyePoint = %client.player.getEyePoint();
%eyeVector = %client.player.getEyeVector();
%Range = vectorAdd(%eyePoint,vectorScale(%eyeVector,10));
%raycast = containerRayCast(%eyePoint,%Range,$TypeMasks::PlayerObjectType);

if(isObject(%raycast))
{
bottomPrint(%client, "\c1Name: \c6" @ %raycast.name @ "", 1, 1);
}
}

%raycast.client.getplayername() - i think

Ah, thanks for the help. I was unaware you had to place a "Client" in like that.

Also, it was.

Code: [Select]
%raycast.client.name

You searched for players, and the variable 'name' was defined under client. So you would have to get the players client.

You searched for players, and the variable 'name' was defined under client. So you would have to get the players client.
Just say this:
You searched for a Player, but 'name' was defined under client.  You have to use the player's client
%raycast.client.name



Well, I've got it working with one exception. The console is spammed with "Unknown Function: getEyeVector, and getEyePoint".

Code: [Select]
package SetupRoleplayStats
{
function GameConnection::onClientEnterGame(%this)
{
%this.Roleplay["Class"] = "Test";
%this.Roleplay["Level"] = 1;
schedule(1000, 0, ClientInfoDisplay);
parent::onClientEnterGame(%this);
}
};
activatepackage(SetupRoleplayStats);

function ClientInfoDisplay(%client)
{
%EyeVector = %client.player.getEyeVector();
%EyePoint = %client.player.getEyePoint();
%Range = 10;
%RangeScale = VectorScale(%EyeVector, %Range);
%RangeEnd = VectorAdd(%EyePoint, %RangeScale);

%raycast = containerRayCast(%eyePoint,%RangeEnd,$TypeMasks::PlayerObjectType);

if(isObject(%raycast))
{
bottomPrint(%client, "\c7Name: \c1" @ %raycast.client.name @ " \c7- Class: \c6" @ %raycast.client.Roleplay["Class"] @ " \c7- Level: \c6" @ %raycast.client.Roleplay["Level"] @ "", 1, 1);
}
schedule(500, 0, ClientInfoDisplay);
}

schedule(500, 0, ClientInfoDisplay, %client);

You should also try this:
Code: [Select]
function ClientInfoDisplay(%client)
{
    if(!isObject(%client))
        return;

    if(isObject(%client.player))
    {
%EyeVector = %client.player.getEyeVector();
%EyePoint = %client.player.getEyePoint();
%Range = 10;
%RangeScale = VectorScale(%EyeVector, %Range);
%RangeEnd = VectorAdd(%EyePoint, %RangeScale);

%raycast = containerRayCast(%eyePoint,%RangeEnd,$TypeMasks::PlayerObjectType);
    }

    if(isObject(%raycast))
    {
bottomPrint(%client, "\c7Name: \c1" @ %raycast.client.name @ " \c7- Class: \c6" @ %raycast.client.Roleplay["Class"] @ " \c7- Level: \c6" @ %raycast.client.Roleplay["Level"] @ "", 1, 1);
    }
    schedule(500, 0, ClientInfoDisplay, %client);
}
« Last Edit: December 11, 2009, 07:55:49 PM by Kalphiter »

I suggest putting the schedule in a variable so you can stop it
$Loop = schedule(500, 0, ClientInfoDisplay, %client);

Ok, I'm guessing something is wrong with the following code because the BottomPrint is sent to display even if the player isn't looking at a other player, Specifically the TypeMask I believe.

Code: [Select]
%raycast = containerRayCast(%eyePoint,%RangeEnd,$TypeMasks::PlayerObjectType);

Ok, I'm guessing something is wrong with the following code because the BottomPrint is sent to display even if the player isn't looking at a other player, Specifically the TypeMask I believe.

Code: [Select]
%raycast = containerRayCast(%eyePoint,%RangeEnd,$TypeMasks::PlayerObjectType);
Use if(isObject(firstWord(%raycast))) or better yet, if(%raycast.client.name !$= "")

Nope, the BottomPrint still is sent when not looking at a player.

Try this:
%raycast = containerRayCast(%eyePoint,%RangeEnd,$TypeMasks::PlayerObjectType, %client.player);

Odd enough, that did work. Thank you all for the help, raycast's are a tricky subject I guess.