You can use
function mouseOver()
myX as float
myY as float
my3dX as float
my3dY as float
my3dZ as float
rayStartX as float
rayStartY as float
rayStartZ as float
rayEndX as float
rayEndY as float
rayEndZ as float
myX=getpointerx()
myY=getpointery()
my3dX=Get3DVectorXFromScreen(myX,myY)
my3dY=Get3DVectorYFromScreen(myX,myY)
my3dZ=Get3DVectorZFromScreen(myX,myY)
rayStartX=my3dX+GetCameraX(1)
rayStartY=my3dY+GetCameraY(1)
rayStartZ=my3dZ+GetCameraZ(1)
rayEndX=800*my3dX+GetCameraX(1)
rayEndY=800*my3dY+GetCameraY(1)
rayEndZ=800*my3dZ+GetCameraZ(1)
theObjectHit= ObjectRayCast(0,rayStartX,rayStartY,rayStartZ,rayEndX,rayEndY,rayEndZ)
// Move camera with WASD
// Rotate Camera with Arrow Keys
MoveCameraLocalX(1,GetRawKeyState(68) - GetRawKeyState(65))
MoveCameraLocalZ(1,GetRawKeyState(87) - GetRawKeyState(83))
RotateCameraGlobalY(1,GetRawKeyState(39) - GetRawKeyState(37))
RotateCameraLocalX(1,GetRawKeyState(40) - GetRawKeyState(38))
cx# = GetCameraX(1)
cy# = GetCameraY(1)
cz# = GetCameraZ(1)
pxRaw# = Get3DVectorXFromScreen(myX,myY)
pyRaw# = Get3DVectorYFromScreen(myX,myY)
pzRaw# = Get3DVectorZFromScreen(myX,myY)
// get pointer vector y added to camera's y position
pyRelative# = pyRaw# + cy#
// find distance between camera's y position and pyRelative#
dist# = cy# - pyRelative#
// calculate scaling value by finding how many times dist# goes into the camera's y position
s# = cy# / dist#
// find the intersection point by multiplying pointer vector by s# and adding it to the camera position.
// ignoring Y in this case since it should be 0 anyway.
ix# = cx# + pxRaw# * s#
iz# = cz# + pzRaw# * s#
endfunction theObjectHit
To get 2D coordinates in 3D space
The pzRaw# variable in here is your Z coordinate
But its is more to do with Get3DVectorX,Y,ZFromScreen commands - where MyX and MyY is the current mouse pointer position using GetPOinterX(), GetPOinterY() commands
pxRaw# = Get3DVectorXFromScreen(myX,myY)
pyRaw# = Get3DVectorYFromScreen(myX,myY)
pzRaw# = Get3DVectorZFromScreen(myX,myY)