Guest User

RaycastPlate.cs

a guest
May 21st, 2017
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using GTA;
  3. using GTA.Math;
  4. using GTA.Native;
  5.  
  6. public class Raycast : Script
  7. {
  8.     public Raycast()
  9.     {
  10.         Tick += OnTick;
  11.     }
  12.  
  13.     void OnTick(object sender, EventArgs e)
  14.     {
  15.         Ped player = Game.Player.Character;
  16.         if (!player.IsInVehicle())
  17.         {
  18.             return;
  19.         }
  20.         Vehicle vehicle = player.CurrentVehicle;
  21.         float searchdist = 30.0f;
  22.         Vector3 vehPos = vehicle.Position;
  23.         Vector3 vehDir = vehicle.ForwardVector;
  24.         Vector3 vehFor = vehPos + (vehDir * searchdist);
  25.         int ray = Function.Call<int>(Hash._CAST_RAY_POINT_TO_POINT, vehPos.X, vehPos.Y, vehPos.Z, vehFor.X, vehFor.Y, vehFor.Z, 10, vehicle, 7);
  26.  
  27.         OutputArgument hit = new OutputArgument();
  28.         OutputArgument endcoords = new OutputArgument();
  29.         OutputArgument surfacenormal = new OutputArgument();
  30.         OutputArgument entityHit = new OutputArgument();
  31.         Function.Call(Hash._GET_RAYCAST_RESULT, ray, hit, endcoords, surfacenormal, entityHit);
  32.         Vehicle hitVehicle = entityHit.GetResult<Vehicle>();
  33.         Vector3 hitVehPos = hitVehicle.Position;
  34.  
  35.         OutputArgument x = new OutputArgument();
  36.         OutputArgument y = new OutputArgument();
  37.         bool success = Function.Call<bool>(Hash._WORLD3D_TO_SCREEN2D, hitVehPos.X, hitVehPos.Y, hitVehPos.Z, x, y);
  38.         if (success && hitVehicle.Exists())
  39.         {
  40.             string name = hitVehicle.FriendlyName;
  41.             string numplate = hitVehicle.NumberPlate;
  42.             string text = "^\n" + name + "\n" + numplate + "\n";
  43.  
  44.             Function.Call(Hash.SET_TEXT_FONT, 0);
  45.             Function.Call(Hash.SET_TEXT_SCALE, 0.2, 0.2);
  46.             Function.Call(Hash.SET_TEXT_COLOUR, 255, 255, 255, 255);
  47.             Function.Call(Hash.SET_TEXT_WRAP, 0.0, 1.0);
  48.             Function.Call(Hash.SET_TEXT_CENTRE, 0);
  49.             Function.Call(Hash.SET_TEXT_DROPSHADOW, 0, 0, 0, 0, 0);
  50.             Function.Call(Hash.SET_TEXT_EDGE, 1, 0, 0, 0, 205);
  51.             Function.Call(Hash._SET_TEXT_ENTRY, "STRING");
  52.             Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
  53.             Function.Call(Hash._DRAW_TEXT, x.GetResult<float>(), y.GetResult<float>());
  54.             Function.Call(Hash.DRAW_RECT, x.GetResult<float>() + 0.027f, y.GetResult<float>() + 0.043f, 0.058f, 0.056f,
  55.                 75, 75, 75, 175);
  56.         }
  57.     }
  58. }
RAW Paste Data