Liberty Unleashed

Scripting => Script Help => Topic started by: Theremin on October 07, 2015, 09:46:16 pm

Title: How to use ScreenPosToWorld?
Post by: Theremin on October 07, 2015, 09:46:16 pm
How to use ScreenPosToWorld? It either returns false or crashes my client. I saw a fourth parameter has been added in 0.1.0.15 update:
Quote
Scripting - Added a depth parameter to ScreenPosToWorld (client) - ScreenPosToWorld( float x, float y, float depth ), ScreenPosToWorld( Vector3 pos, float depth )
then Vortrex wrote something about the fact that it wasn't working:
Quote
ScreenPosToWorld is now not working.
It returns an instance in Vector form like it should, but ...
The vector is composed of "1.#R 1.#R 1.R"
Each object in the instance is "1.#QNAN"
It should be noted that typeof returns Vector, but its unusable.
Can somebody provide a working example?
Title: Re: How to use ScreenPosToWorld?
Post by: sasha19323 on October 08, 2015, 11:05:06 am
It works weird, but:
Code: ("Client-side") [Select]
function onScriptLoad()
{
  ShowMouseCursor(true);
  fDepth <- 10.0;
}
function onClientMouseClick(button, down, x, y)
{
  if (down)
  {
   local pos = ScreenPosToWorld(VectorScreen(x, y), fDepth);
   CallServerFunc(YOUR_PATH_HERE, "CreateObject2", 1344, pos.x, pos.y, pos.z);
  }
}
Code: ("Server-side") [Select]
RegisterRemoteFunc("CreateObject2");
function CreateObject2(model, x, y, z) { CreateObject(model, Vector(x,y,z)); } //CallServerFunc doesn't work w/ Vector class, no idea why