Author Topic: Dynamic crosshair - can't use function 'getEyePoint'/'getEyeVector' on object  (Read 1355 times)

I'm making script that fires a looping raycast from the player's eye node, and changes the player's crosshair depending on the object their looking at based on it's typemask

There is no error when executing the script, but i'm not sure what args to use where, what object to play the script on, or whatever, so that the script plays on the player to fire the raycast, and affects the player's client to change their crosshair, so i keep ending up with this in my console
Quote
Add-Ons/Server_DynamicCrosshair/server.cs (41): Unable to find object: '' attempting to call function 'getEyePoint'
BackTrace: ->crosshairTarget
Add-Ons/Server_DynamicCrosshair/server.cs (42): Unable to find object: '' attempting to call function 'getEyeVector'
BackTrace: ->crosshairTarget

My script:
http://pastebin.com/raw/BTampewy

And yes i am aware of the whole situation with crosshairs, but nevermind that, this is just a private thing for now
« Last Edit: June 08, 2016, 05:27:17 AM by Masterlegodude »

The geteyepoint() and geteyevector() functions are on the player object, not the client.

Do a findclientbyname("name").dump(); and you'll find those functions aren't there.
Then do a findclientbyname("name").player.dump(); and you'll see them on the player object.

I changed some things around to be %player instead of %client but i'm still getting that message

Revised script:
http://pastebin.com/raw/4a4j7Hwf

The message specifically refers to these two lines though
Code: [Select]
   %eye = %player.getEyePoint();
   %ev = %player.getEyeVector();

Am i doing something incorrectly or is there a failure in consistency that i'm overlooking?
« Last Edit: June 08, 2016, 05:27:55 AM by Masterlegodude »

You just need to fix your variables I think. In spawnPlayer function, put crosshairTarget(%obj) instead and use %obj instead of %player. I've never seen dpawnPlayer with more than %this so maybe even use %this.player instead.

Onclientleavegame has undefined %player, use %client.player.

%client = %player.client in crosshairTarget function.

That should fix it

You're mixing client and server sided code. This add-on can't work.

Okay, so here it is currently
Code: [Select]
if(isPackage(CrosshairTargeting))
deactivatePackage(CrosshairTargeting);

package CrosshairTargeting
{
   function GameConnection::SpawnPlayer(%this)
   {
      crosshairTarget(%this.player);
      if (isObject(%obj.client))
      {
         crossHair.setBitmap("Base/client/ui/crosshair");
      }
      return parent::SpawnPlayer(%this);
   }
   function Armor::onDisabled(%this, %pl, %enabled)
   {
      if (isObject(%pl.client))
      {
         cancel(%pl.crosshairTargetLoop);
         crossHair.setBitmap("Base/client/ui/crosshair");
      }
      return Parent::onDisabled(%this, %pl, %enabled);
   }
   function GameConnection::onClientLeaveGame(%client)
   {
      cancel(%client.player.crosshairTargetLoop);
      return parent::onClientLeaveGame(%client);
   }
};
activatePackage(CrosshairTargeting);

function crosshairTarget(%obj)
{
   %client = %player.client;
   if (isObject(%obj.crosshairTargetLoop))
      cancel(%obj.crosshairTargetLoop);

   %eye = %obj.getEyePoint();
   %ev = %obj.getEyeVector();
   %length = 64;
   %mask = $Typemasks::All;
   %raycast = containerRaycast(%eye, VectorAdd(%eye,VectorScale(%ev,%length)),%mask,%ignore_this_object);

   %hit = firstWord(%raycast);
   if (%hit)
      %end = getWords(%raycast, 1, 3);

   if (%hit)
      %client.targetPos = %end;
   else
      %client.targetPos = "";

   %client.target = %hit;
   %type = getType(%client.target);

   if (%client.lastTargetPos $= "" || %type $= "PLAYER" || %type $= "BOT" || %type $= "VEHICLE")
   {
      %client.lastTargetPos = %client.targetPos;
      if (%type $= "PLAYER" || %type $= "BOT")
      {
         %client.centerPrint("\c6Player or bot.",3);
         if(isObject(%client))
         {
            crossHair.setBitmap("Add-Ons/Server_DynamicCrosshair/crossHair_targeted");
         }
      }
      else if (%type $= "VEHICLE")
      {
         %client.centerPrint("\c6Vehicle.",3);
         if(isObject(%client))
         {
            crossHair.setBitmap("Add-Ons/Server_DynamicCrosshair/crossHair_ally");
         }
      }
      else
      {
         %client.centerPrint("\c6Etc.",3);
         if(isObject(%client))
         {
            crossHair.setBitmap("base/client/ui/crossHair");
         }
      }
   }
   %obj.crosshairTargetLoop = schedule(30, 0, crosshairTarget, %obj);
}

Now the console says this
Quote
Add-Ons/Server_DynamicCrosshair/server.cs (38): Unable to find object: '' attempting to call function 'getEyePoint'
BackTrace: ->crosshairTarget
Add-Ons/Server_DynamicCrosshair/server.cs (39): Unable to find object: '' attempting to call function 'getEyeVector'
BackTrace: ->crosshairTarget
Add-Ons/Server_DynamicCrosshair/server.cs (54): Unable to find function getType

Lines 38 and 39
Code: [Select]
   %eye = %obj.getEyePoint();
   %ev = %obj.getEyeVector();

Line 54, which probably broke due to using %client = %player.client; instead of %client = %obj.client;
Code: [Select]
   %type = getType(%client.target);


You're mixing client and server sided code. This add-on can't work.
Surely there must be a way, using raycasts to get typemasks is a server-side thing and you can change the player's crosshair in a weapon image's script(s) with this
Code: [Select]
if(isObject(%obj.client))
{
crossHair.setBitmap("[DIRECTORY TO IMAGE]");
}
So there must be a way to do it with raycasts, right?

And while crosshairs are a client thing, i think you might be able to force players to download the images by using the DecalData datablock, i think the old pill item did that for it's item icon

Surely there must be a way, using raycasts to get typemasks is a server-side thing and you can change the player's crosshair in a weapon image's script(s) with this
Code: [Select]
if(isObject(%obj.client))
{
crossHair.setBitmap("[DIRECTORY TO IMAGE]");
}
So there must be a way to do it with raycasts, right?

And while crosshairs are a client thing, i think you might be able to force players to download the images by using the DecalData datablock, i think the old pill item did that for it's item icon

No, you can't, crosshair is a client side object and your code runs on the server. Test the thing on a dedicated server (nothing happens) or with other players (it will change your crosshair instead of theirs) and you will see.

on line 34 %player is undefined

In addition, on line 8 you're calling crosshairTarget(); before the player object is made.
gameconnection::SpawnPlayer actually creates the player object. You can't call your function before the player object exists.

As far as I can tell, right now this add-on could only work for the host.
The only way I can think of to get it to work for anyone else would be to have 2 add-ons.  A client-side and a server-side.
The server-side would do all of the calculations, and then send a message to the client telling it to update.
The client-side would just recieve the message, and do the update.