Get player Camera zoom

Started by vitovc, Sep 02, 2024, 10:08 AM

Previous topic - Next topic

vitovc

This script finds camera zoom, helpful to detect camera hacks (fast zoom for sniper, super zoom (bigger zoom than vanilla) for sniper, zoom usage for rpg and so on). Please note this script is using hardcoded magical number (0.0357106) for normal screen (vanila vcmp, default field of view), if you are using widescreen mod (asi, modded .exe, etc) you will get incorrect values (this is also a way to detect widescreen mods).

rel_pos2d <- function(z_angle, pos_x, pos_y, pos_z, rel_x, rel_y, rel_z){
  local rX = pos_x + rel_x * ::cos(z_angle) - rel_y * ::sin(z_angle);
  local rY = pos_y + rel_x * ::sin(z_angle) + rel_y * ::cos(z_angle);
  local rZ = pos_z + rel_z;
  return ::Vector(rX, rY, rZ);
}
get_angle <- function(x, y, x2, y2){
  return ::atan2(y2 - y, x2 - x);
}
check_cam_zoom <- function(){
  local screen_size = ::GUI.GetScreenSize();
  local cam_from = ::GUI.ScreenPosToWorld(::Vector(screen_size.X * 0.5, screen_size.Y * 0.5, -1));
  local cam_to = ::GUI.ScreenPosToWorld(::Vector(screen_size.X * 0.5, screen_size.Y * 0.5, 1));
  local a = ::get_angle(cam_from.X, cam_from.Y, cam_to.X, cam_to.Y);
  local r = ::GUI.WorldPosToScreen(::rel_pos2d(a, cam_to.X, cam_to.Y, cam_to.Z, 0, -50, 0));
  local l = ::GUI.WorldPosToScreen(::rel_pos2d(a, cam_to.X, cam_to.Y, cam_to.Z, 0, 50, 0));
  local zoom = (((r.X - l.X) / screen_size.X) / 0.0357106);
  ::Console.Print("camera zoom: "+ zoom);
}
...::: vice city :::...
Useful things for vcmp: Relative position and finding an angle (in 3d), 3d line (like laser)

PSL

This feature is great, can work with habi remote call plug-in, directly on the server to operate, very good, thank you very much for sharing this code.