Advertisement
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 Raycast : Script
- {
- public Raycast()
- {
- Tick += OnTick;
- }
- void OnTick(object sender, EventArgs e)
- {
- Ped player = Game.Player.Character;
- if (!player.IsInVehicle())
- {
- return;
- }
- Vehicle vehicle = player.CurrentVehicle;
- float searchdist = 30.0f;
- Vector3 vehPos = vehicle.Position;
- Vector3 vehDir = vehicle.ForwardVector;
- Vector3 vehFor = vehPos + (vehDir * searchdist);
- 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);
- OutputArgument hit = new OutputArgument();
- OutputArgument endcoords = new OutputArgument();
- OutputArgument surfacenormal = new OutputArgument();
- OutputArgument entityHit = new OutputArgument();
- Function.Call(Hash._GET_RAYCAST_RESULT, ray, hit, endcoords, surfacenormal, entityHit);
- Vehicle hitVehicle = entityHit.GetResult<Vehicle>();
- Vector3 hitVehPos = hitVehicle.Position;
- OutputArgument x = new OutputArgument();
- OutputArgument y = new OutputArgument();
- bool success = Function.Call<bool>(Hash._WORLD3D_TO_SCREEN2D, hitVehPos.X, hitVehPos.Y, hitVehPos.Z, x, y);
- if (success && hitVehicle.Exists())
- {
- string name = hitVehicle.FriendlyName;
- string numplate = hitVehicle.NumberPlate;
- string text = "^\n" + name + "\n" + numplate + "\n";
- Function.Call(Hash.SET_TEXT_FONT, 0);
- Function.Call(Hash.SET_TEXT_SCALE, 0.2, 0.2);
- 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.GetResult<float>(), y.GetResult<float>());
- Function.Call(Hash.DRAW_RECT, x.GetResult<float>() + 0.027f, y.GetResult<float>() + 0.043f, 0.058f, 0.056f,
- 75, 75, 75, 175);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement