Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Ped getPed(Vector3 position, float range, bool includePedInVehicle, Gender gen) {
- Vector3 camRot = Game.CurrentCamera.Rotation;
- double toRadian = Math.PI / 180.0;
- camRot = new Vector3((float)Math.Cos((camRot.Z + 90.0f) * toRadian), (float)Math.Sin((camRot.Z + 90.0f) * toRadian), (float)Math.Sin((Game.CurrentCamera.Rotation.X) * toRadian));
- Vector3 camPos = Game.CurrentCamera.Position;
- double difference = double.MaxValue;
- double distance;
- Vector3 directionPed;
- int lookingPedIndex = -1;
- Ped[] pedArray = World.GetPeds(camPos, range);
- for (int i = 0; i < pedArray.Length; i++) {
- if (Exists(pedArray[i]) && pedArray[i] != Player.Character && pedArray[i].isAlive == true && pedArray[i].Gender==gen) {
- if (includePedInVehicle == true || pedArray[i].isInVehicle() == false) {
- directionPed = pedArray[i].Position - camPos;
- directionPed.Normalize();
- distance = camRot.DistanceTo(directionPed);
- if (difference > distance) {
- difference = distance;
- lookingPedIndex = i;
- }
- }
- }
- }
- if (lookingPedIndex == -1) {
- return null;
- } else {
- return pedArray[lookingPedIndex];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment