manusoftar

getPed method GTA IV

Aug 21st, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. public Ped getPed(Vector3 position, float range, bool includePedInVehicle, Gender gen) {
  2.                 Vector3 camRot = Game.CurrentCamera.Rotation;
  3.                 double toRadian = Math.PI / 180.0;
  4.                 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));
  5.                 Vector3 camPos = Game.CurrentCamera.Position;
  6.                 double difference = double.MaxValue;
  7.                 double distance;
  8.  
  9.                 Vector3 directionPed;
  10.                 int lookingPedIndex = -1;
  11.  
  12.                 Ped[] pedArray = World.GetPeds(camPos, range);
  13.                 for (int i = 0; i < pedArray.Length; i++) {
  14.                     if (Exists(pedArray[i]) && pedArray[i] != Player.Character && pedArray[i].isAlive == true && pedArray[i].Gender==gen) {
  15.                         if (includePedInVehicle == true || pedArray[i].isInVehicle() == false) {
  16.                             directionPed = pedArray[i].Position - camPos;
  17.                             directionPed.Normalize();
  18.                             distance = camRot.DistanceTo(directionPed);
  19.  
  20.                             if (difference > distance) {
  21.                                 difference = distance;
  22.                                 lookingPedIndex = i;
  23.                             }
  24.                         }
  25.                     }
  26.                 }
  27.  
  28.                 if (lookingPedIndex == -1) {
  29.                     return null;
  30.                 } else {
  31.                     return pedArray[lookingPedIndex];
  32.                 }
  33.             }
Advertisement
Add Comment
Please, Sign In to add comment