Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using GTA;
- using GTA.Math;
- using GTA.Native;
- public class SearchCone : Script
- {
- public SearchCone()
- {
- Tick += OnTick;
- }
- private bool active = false;
- bool areTheseClose(float h1, float h2, float separation)
- {
- var diff = Math.Abs(h1 - h2);
- if (diff < separation)
- return true;
- if (Math.Abs(diff - 360) < separation)
- return true;
- return false;
- }
- void OnTick(object sender, EventArgs e)
- {
- Ped player = Game.Player.Character;
- if (!player.IsInVehicle())
- {
- return;
- }
- if (Game.IsControlJustPressed(0, Control.VehicleHandbrake))
- {
- active = !active;
- UI.Notify("Plate viewer " + (active ? "enabled" : "disabled"));
- }
- if (!active)
- {
- return;
- }
- Vehicle vehicle = player.CurrentVehicle;
- Vector3 vehPos = vehicle.Position;
- const float searchDist = 30.0f;
- Vehicle[] vehicles = World.GetAllVehicles();
- float closestDist = searchDist;
- string text = "";
- float screenX = 0.0f;
- float screenY = 0.0f;
- for (int i = 0; i < vehicles.Length; i++)
- {
- if (vehicles[i] != vehicle)
- {
- Vector3 targetPos = vehicles[i].Position;
- Vector3 direction = targetPos - vehPos;
- direction.Normalize();
- float vehDirection = Convert.ToSingle(Math.Atan2(direction.Y, direction.X) * (180.0f / Math.PI));
- float myHeading = (player.Heading + 90.0f) % 360;
- OutputArgument x = new OutputArgument();
- OutputArgument y = new OutputArgument();
- bool success = Function.Call<bool>(Hash._WORLD3D_TO_SCREEN2D, targetPos.X, targetPos.Y, targetPos.Z, x, y);
- bool close = areTheseClose(vehDirection, myHeading, 10.0f);
- if (success && close)// && areTheseClose(vehDirection, myHeading, 45.0f))
- {
- Vector3 plv = player.Position;
- float dist = World.GetDistance(plv, targetPos);
- if (dist < searchDist)
- {
- if (dist < closestDist)
- {
- closestDist = dist;
- string name = vehicles[i].FriendlyName;
- string numplate = vehicles[i].NumberPlate;
- text = "^\n" + name + "\n" + numplate + "\n";
- screenX = x.GetResult<float>();
- screenY = y.GetResult<float>();
- }
- }
- }
- }
- }
- if (text != "")
- {
- ShowVehicleTag(text, screenX, screenY);
- }
- }
- private static void ShowVehicleTag(string text, float x, float y)
- {
- Function.Call(Hash.SET_TEXT_FONT, 0);
- Function.Call(Hash.SET_TEXT_SCALE, 0.4, 0.4);
- Function.Call(Hash.SET_TEXT_COLOUR, 255, 255, 255, 255);
- Function.Call(Hash.SET_TEXT_WRAP, 0.0, 1.0);
- Function.Call(Hash.SET_TEXT_CENTRE, 0);
- Function.Call(Hash.SET_TEXT_DROPSHADOW, 0, 0, 0, 0, 0);
- Function.Call(Hash.SET_TEXT_EDGE, 1, 0, 0, 0, 205);
- Function.Call(Hash._SET_TEXT_ENTRY, "STRING");
- Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
- Function.Call(Hash._DRAW_TEXT, x, y);
- Function.Call(Hash.DRAW_RECT, x + 0.03f, y + 0.057f, 0.07f, 0.06f, 75, 75, 75, 175);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment